TensorFlow to Fortran
TF2 enables the integration of TensorFlow models into C++/Fortran projects seamlessly, without the need for TensorFlow installation or compilation. Explore the examples to understand how to incorporate a TensorFlow tf.Model
into your C++/Fortran project.
TF2 utilizes CppFlow and the TensorFlow C API to execute models. This project simplifies the management and execution of models in C++/Fortran, handling concerns about void, malloc, or free operations. With TF2, you can effortlessly:
- Open saved models created with TensorFlow
- Execute TensorFlow neural networks in C++/Fortran
- Perform tensor manipulation directly from C++
Before installing the required dependencies, check the official TensorFlow compatibility matrix to ensure version compatibility with your system and build environment.
- TensorFlow C API = 2.10.0
The code has been tested with the following configuration:
- GNU Compiler = 9.3.0
- CUDA = 11.2
- cuDNN = 8.1
To install TF2, follow these steps after downloading the dependencies:
- Define installation directories
export SRC_DIR=<path-to-TF2-source-dir>
export BUILD_DIR=<path-to-build-dir>
export INSTALL_DIR=<path-to-install-dir>
- Define dependencies directories
export TensorFlow_DIR=<path-to-tensorflow-dir>
- Prepare installation directories
rm -rf $BUILD_DIR $INSTALL_DIR
mkdir $BUILD_DIR
cd $BUILD_DIR
- Configure CMake
cmake $SRC_DIR \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-DBUILD_EXAMPLES=OFF \
-Dtensorflow_INCLUDE_DIR=$TensorFlow_DIR/include \
-Dtensorflow_LIBRARY=$TensorFlow_DIR/lib/libtensorflow.so
- Install
make -j 4
make install
If you use this code or find this work useful in your research, please cite us:
@software{ivan_zanardi_2025_15571515,
author = {Ivan Zanardi},
title = {TF2: TensorFlow to Fortran},
month = {06},
year = {2025},
publisher = {Zenodo},
version = {v0.1.0},
doi = {10.5281/zenodo.15571515},
url = {https://doi.org/10.5281/zenodo.15571515}
}
TF2 is distributed under the MIT License. You are welcome to utilize, modify, and contribute to this project in accordance with the terms outlined in the license