ECE 332 / Hiddens / Lab4 Instructions

Lab4 Instructions

Hand-Written Digit Recognition using DE1-SoC

Objectives

  • Train your neural network on your host machine.
  • Use your trained weights to perform inference on DE1-SoC board.

Prerequisites

  • Completion of Lab 3 and familiarity with the DE1-SoC board.
  • Lab 3 OpenCL kernel to program the board.
  • Lab 3 capture_image.c program to capture image.

Part 1: Training NeuralNet on Host Machine (Optional)

Required files are in the path tests/Inference.

  1. Open Jupyter notebook TrainNN and run all the cells.
  2. This will save the weights for each layer in .bin files.

Testing the Captured Image Inference:

Print each layer output to help debug your C++ code.

  1. Capture the image using the Lab 3 code capture_image.cc and follow the steps.
  2. Run TestImage notebook. This will print each layer’s output. This helps in debugging and implementing each layer in the network.

Part 2: Use Your Trained Weights to Perform Inference on DE1-SoC Board

Compiling .aocx File on the Host Machine (Windows Machine)

  1. Extract de1_soc folder from the resources file.
  2. Setup OpenCL environment:
    • Go to the directory C:\intelFPGA\hld\ and type init_opencl.bat in the command prompt.
  3. Copy the hardware folder to a10_ref folder in the path:
    • C:\intelFPGA\hld\board\a10_ref\
    • Replace the hardware folder, as we don’t have permissions to change environment variables on the host machine. If you’re working on your own system, instead of replacing the folder, set the environment variable AOCL_BOARD_PACKAGE_ROOT to your own directory.
  4. Copy the tests folder to a10_ref folder in the path.
  5. In the command prompt, type:
    • aoc -list-boards
    • This should list all the boards. Delete any other directories that are not needed on the host machine.
  6. Launch Quartus Prime, open the project in the hardware directory named top.qpf, and perform “Compile and Synthesis” (only compile and synthesis, not the entire flow).
  7. Now, copy the .cl file you wrote in Lab 3 to the tests folder in de1-soc in the following path:
    • tests/Inference/device/
  8. Close the Quartus project and go to the tests/Inference directory. Then run the following command:
    • aoc device/<your lab 3 .cl file> -o bin/<kernel name>.aocx -board=de1soc_sharedonly
    • This will compile the .aocx file that uses the hardware project and your multiplication kernel.

Programming FPGA Fabric with .aocx File

  1. Connect the SD card that is flashed with the Linux image to the host machine using the card reader.
  2. Copy the .aocx file generated in the previous step to the SD card (Do not modify any files that are already present in the SD card). This copied file will be available in the DE1-SoC Linux path:
    • /media/fat_partition
  3. Boot the DE1-SoC by inserting the SD card and set up the OpenCL environment as described earlier:
    cd OpenCL/
    source init_opencl.sh