CNN using HLS

I am pleased to announce the release of the code for the article “How to Implement a Convolutional Neural Network Using High-Level Synthesis”.


The previous article discussed three main aspects:

  1. The used approach to implement a Convolutional Neural Network (CNN)
  2. The elements that I took into account when choosing the neural network architecture
  3. The specific High-Level Synthesis constructs that helped to achieve the targeted performance.


Now you can download the code from GitHub.
The GIT repository contains:

  • The CNN implementation
  • The python codes used for training
  • Modules for each type of layer (convolutional, pooling and fully connected) used for development and testing
  • Short guide on how to set up and run the code

The CNN code is provided as an OpenSource implementation under Apache License 2.0.
I welcome your feedback!


9 Responses

  1. Hello Sergiu Duda,

    Please tell me if you can post the full version of your diploma thesis for review on github, or is it forbidden?

    Thank you in advance.

  2. hello
    ,thanks for usefull information.I want to know whats the input of your code because I cant to simulate it with vivado hls , and how can I simulate it with vivado?can i add synthesis vhdl code to vivado for simulating it?would you mind help me?

    1. Hi Anahita,

      The image is sent as an input to the first CONV layer in nnet.cpp at line 333.

      To simulate it with Vivado, you will first need to export the RTL. For this you have two options:
      * use the button in VIvado HLS which is near the Synthesis button
      * Run a .tcl command: export_design -flow syn -rtl vhdl -format ip_catalog

      Then you need to import the IP in Vivado, through the IP catalog. After this step is done, you can instantiate the IP as any other Xilinx IPs in the Block Design.


  3. Hi!

    Super nice done!

    I have a question about the data width. In the implementation on GitHub, is it using 24 bit floating point data type since its configured with float24_t. How can I change this if i want to implement 16 or int.

    Kind regards,

  4. I’m trying to implement this on Vitis HLS 2020.2 on windows.
    In CSIM I get the following error, I included the C:/Xilinx/Vitis/2020.2/include/multimediaIps/xf_video_mem.hpp to use LineBuffer as well.
    I was not sure if I can post the whole console output hence I only posted the following. I get a few iterances of __GMP_LIBGMP_DLL redifined warnings as well.

    while executing
    “source C:/Users/menuw/Documents/CNN-HLS/new/CNN-using-HLS-master/nnet_stream/neural_net/no_directives/csim.tcl”
    invoked from within
    “hls::main C:/Users/menuw/Documents/CNN-HLS/new/CNN-using-HLS-master/nnet_stream/neural_net/no_directives/csim.tcl”
    (“uplevel” body line 1)
    invoked from within
    “uplevel 1 hls::main {*}$newargs”
    (procedure “hls_proc” line 16)
    invoked from within
    “hls_proc [info nameofexecutable] $argv”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to our newsletter

Do you want to be up to date with our latest articles?