Search code examples
xilinxvivadovivado-hlsvitis-ai

question regarding limitations on using c instead of c++ on vitis hls


So I am fairly new to vitis hls but I've read over most of the documentation and I had some concerns on whether there would be limitations with using C instead of C++. I am fairly accustomed with C and have been coding with it for years and never really used C++ but I am aware that it's main purpose is to implement OOP in C. My question on whether C is limited with vitis hls is the use of classes such as hls::task, hls::stream and hls::stream_of_blocks. I figured if I wanted to implement an AXIS interface on my IP block I would have to define the data (input/output) using hls::stream and let's say an input to my function is "int a", I would subsequently use #pragma HLS interface axis depth=50 port=a offset=off to define my interface for the input port a.

My concerns were that since the code is in C, it would fail to recognise the classes in hls i.e., hls::stream.Thus, I would want to know whether this is actually an issue I need to beware of or if it's just an oversight from poor understanding. It would also help so that I know if I should continue working in C or convert my code to C++ (after learning C++ that is).

Thanks for any assistance!


Solution

  • You can write C code and utilize HLS libraries in Vitis or Vivado HLS, as they are designed to be compatible with C/C++ codes. However, there are a few points to consider:

    1. When using HLS libraries, you will need to employ a C++ compiler for your project. This means that your source files should have a ".cpp" extension, even if you are primarily using C code.

    2. To ensure compatibility between your C++ code and C code, you can use the following code block:

       #ifdef __cplusplus   
       extern "C" {
       #endif
                
            // Your C code that uses HLS libraries
                
       #ifdef __cplusplus   
       } 
       #endif
    
    1. Keep in mind that when using HLS libraries, you should treat them as if you were writing C++ code, even if the rest of your code is primarily C-based.

    2. For further information, refer to Chapter 3 of the "Vivado Design Suite User Guide," titled "High-Level Synthesis Coding Styles."

      https://docs.xilinx.com/v/u/en-US/ug902-vivado-high-level-synthesis