Skip to content

ivanZanardi/tf2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

TF2

TensorFlow to Fortran


DOI

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++

Dependencies

Before installing the required dependencies, check the official TensorFlow compatibility matrix to ensure version compatibility with your system and build environment.

GPU support

The code has been tested with the following configuration:

Installation

To install TF2, follow these steps after downloading the dependencies:

  1. 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>
  1. Define dependencies directories
export TensorFlow_DIR=<path-to-tensorflow-dir>
  1. Prepare installation directories
rm -rf $BUILD_DIR $INSTALL_DIR
mkdir $BUILD_DIR
cd $BUILD_DIR
  1. 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
  1. Install
make -j 4
make install

Citation

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}
}

License

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