Confluence will be down for maintenance June 14 2024 at 6AM PT.
Setup for large file systems on GitHub.
git lfs install
Verify that you have git version 2.13.0 (or later) installed.
git version
Verify that you have git-lfs version 2.1.1 (or later) installed.
git-lfs version
Clone the example repository into the "convDemo" directory.
git clone -b Conv_Example --recursive https://github.com/slaclab/snl-Dave.git convDemo
***Note: This repo assumes that you are using the default CNN model. If you are using a different model, make sure you define its structure in all necessary files and follow the instructions in this section.***
In "convDemo/firmware/shared/SnlConvoExample/src/Network.cc," ensure that the model is defined in class Wba. For example, for this model, the class looks like this:
Next, it is time to test the kernels. Modify the following piece of code to reflect the changed layers:
For each layer in your model, change the name of the .txt file you will use to test in the following code:
If you want to add more layers, just copy the example layer code and ensure that you change the variable names accordingly. Pay close attention to the difference between setting weights and setting biases for dense layers. For example:
m_layer3.m_weights[0].set (x, cnt); # weights m_layer3.m_bias[cnt]=x; # biases
In firmware/shared/SnlConvoExample/src/Test.cc, in line 298, feel free to modify the test image. Right now, it is an image of all 1's. You can modify it to be all zeros or some other number. If you do modify the test image, ensure you can recreate it in Keras and pass the image through your trained model to get the raw logits output before the last softmax activation layer. This will be used to compare the results in SNL against your software results.
Now your new model is ready to move on to the next steps.
Set up Xilinx licensing. If you are on the SLAC network:
source convDemo/firmware/setup_env_slac.sh
Otherwise, you will have to install Vivado/Vitis and install the Xilinx licensing.
Go to the HLS target directory and build the HSL.
cd convDemo/firmware/shared/SnlConvoExample make clean
Launch the GUI.
make gui
Close the GUI and run the following commands in the terminal. This will generate an IP zip file.
make clean make
After the process finishes, you will see two lines like this.
INFO: [HLS 200-111] Finished Command export_design CPU user time: 29.47 seconds. CPU system time: 1.24 seconds. Elapsed time: 34.39 seconds; current allocated memory: 16.152 MB. /u1/jaeylee/convDemo/firmware/shared/SnlConvoExample/ip/SnlConvoExample-v1.0-20240213234508-jaeylee-560c31c.zip
Copy the part that begins with "/SnlConvoExample-v1..." to your clipboard. Make sure that the name does not contain "dirty," which means it was made using uncommitted code.
Launch vim to edit the "ruckus.tcl" file under the "SnlConvoExample" directory.
vim ruckus.tcl
Replace the path that begins with "/SnlConvoExample-v1..." with the copied path in your clipboard. Save the modified file.
Now, go to "convDemo/firmware/python/snl_Convo_Example/_Application.py" and create the correct variables that correspond to the weights and biases of your model. To get the correct offset and number fields, go to "convDemo/firmware/shared/SnlConvoExample/ip" and unzip the ip zip file by running
unzip [IP_ZIP_FILE].zip
Then, go to "convDemo/firmware/shared/SnlConvoExample/ip/drivers/processStream_v1_0/src" and run
cat xprocessstream_hw.h
The output will show the offset and number for each variable. Create your variables according to these values. *Note: "number" stands for the "DEPTH" values in the output.
Go to
convDemo/firmware/targets
and run "ls."
This will output a list of available FPGAs. For example,
ConvExampleKcu1500 shared_version.mk SnlConvAlveoU200 SnlLenetKcu105 SnlLenetKcu105HlsBypass
After you select an FPGA (in this case, I selected SnlConvAlveoU200), "cd" into it and run
make clean make
This will take a long time. After it finishes running, run
make gui
This will bring up the Vivado GUI.
Setup the Rogue environment.
cd convDemo/software source setup_env_slac.sh
Run the PCIe firmware update script with the path equal to "convDemo/firmware/targets/<Name of FPGA>/images"
python scripts/updatePcieFpga.py --path .../convDemo/firmware/targets/<Name of FPGA>/images
Reboot the computer.
sudo reboot
Open "software/NoteBook/DataProcessing.ipynb."
After changing the paths to be correct, you will be able to run the cells and get the accuracy of your model compared to the ground truth labels at the end. You will also see a count of all labels your model generated, and you can compare this count to the count you got in "Convo_Example.ipynb" from "convDemo/firmware/python/snl_Convo_example" to see if your FPGA output matches your software output.
Note that the predicted class counter for the FPGA output (left) matches the predicted class counter for the software output (right), meaning that the model was successfully moved to the FPGA.