Library for Integrating FPGA to TensorFlow
This instruction describes how to build, install and integrate FlexCNN, developed by UCLA VAST LAB, to TensorFlow. This implementation is adapted from the tensorflow custom operation interface.
- Hardware and Operating System
- Requirements and Dependencies
- Build The Library From The Source
- API and Usage
- Project File Tree
- Acknowledgement
For development, the OS should be Ubuntu 18.04 LTS
For testing and depolyment, despite the os requirement above, the server/PC should also equips with Xilinx Virtex UltraScale+ FPGA VCU1525 Development Kit
The Xilinx Runtime v2018.3 should be installed.
If also want to compile the library from source, the Xilinx Deployment Shell v2018.3, Xilinx Development Shell and SDAccel Design Environment v2018.3 should also be installed. You can find them through this link.
This library uses the cmake (version >= 3.0) as the building system and the googletest as the test framework. It also depends on the tensorflow.
- Pull the source code from this repo
git clone [URL of this repo]
- In ./src/libsacc.cpp change the following line (give your project path)
std::string Sacc::lib_base_path = "/path/to/libsacc/";
- Setting environments
cd libsacc source env.sh
- Installing packages
python3.6 -m venv venv source venv/bin/activate sudo apt-get install build-essential libcap-dev sudo apt install opencl-headers pip3 install cython pip3 install numpy pip3 install -r requirements.txt
- Build the library via (execute in the root of the library: "libsacc" directory)
mkdir build cd build cmake .. make all
Now, the FlexCNN library is successfully installed in your system.
-
Make sure you have installed the library successfully (refer to previous section).
-
You first should build the bitstream. To do that, follow the instructions here.
-
Now, that you have the required files, copy the bitstream (.xclbin file), host executable (.exe file) and instructions (.insts file) to
./config
. -
Replace your TensorFlow project with
../tf_DSA
. For that, follow the instructions here
This library follows the tensorflow custom operation interface. You can find details here.
Setting up the environment variable XILINX_XRT
correspondingly (just source the env.sh
in the root of this project) and then you can call this operation in python as below:
import tensorflow as tf
class SaccTest(tf.test.TestCase):
def SaccTest(self):
sacc_module = tf.load_op_library('/path/to/this/lib/libsacc.so')
with tf.Session(''):
result = sacc_module.sacc([[1, 2], [3, 4]])
result.eval()
if __name__ == "__main__":
tf.test.main()
The project file structure is shown below,
.
+-- CMakeList.txt
+-- src
| +-- libsacc.cpp
| +-- xcl2.cpp # xilinx opencl utils
+-- inc
| +-- CMakeLists.txt
| +-- sa_params.h
| +-- sa_types.h
| +-- sacc.hpp
| +-- xcl2.hpp # xilinx runtime support
+-- test
| +-- CMakeLists.txt
| +-- test.cpp
+-- utils
| +-- gen_params.sh
+-- docker
| +-- Dockerfile
| +-- run.sh
+-- data
+-- config
The src
and inc
contain source files and header files.
The data
folder contains bias and weight information used by the accelerator and the config
contains the instructions and the FPGA binary.
The first version of this library was developed by Tong He.