Working with objects and hls::task

Open
#15 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
18/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp
Domain
compilers

Research direction

Start by reproducing the example in main.cc with hls_task.h using the provided Makefile, then run Vitis HLS csynth_design and the C simulation. Inspect the hls::task interface and the compiler diagnostics to establish whether non-static methods or lambdas are supported. Done means documenting a validated usage pattern or clearly recording the limitation and supported alternative.

Written by the indexing model from the issue text.

Description

Hi everyone,
I have a question regarding the usage of hls::task when using an OOP structure for the design.
Suppose to have the following design in main.cc:

#include <hls_task.h>

class Counter {
  unsigned int _cnt=0; 

  public:
  Counter(void) = default; 

  void stream(
    hls::stream<bool>& inStream, 
    hls::stream<unsigned int>& outStream
    ) {
    if (inStream.read()) {
      outStream.write(_cnt++); 
    }
  }
};

void dut(
  hls::stream<bool>& inStream, 
  hls::stream<unsigned int>& outStream
  ) {
#pragma HLS dataflow
  hls_thread_local Counter cnt; 
  hls_thread_local hls::task t(cnt.stream, inStream, outStream); 
}

Using the following Makefile:

VITIS_ROOT := /eda/xilinx/Vitis_HLS/2022.2/include
CXX := /usr/bin/g++

all:
	$(CXX) main.cc -o main.out -I$(VITIS_ROOT)

When compiling the design:

fab@fedora: $ make
/usr/bin/g++ main.cc -o main.out -I/eda/xilinx/Vitis_HLS/2022.2/include
main.cc: In function ‘void dut(hls::stream<bool>&, hls::stream<unsigned int>&)’:
main.cc:25:36: error: invalid use of non-static member function ‘void Counter::stream(hls::stream<bool>&, hls::stream<unsigned int>&)’
   25 |   hls_thread_local hls::task t(cnt.stream, inStream, outStream);

If we try in Vitis HLS:

vitis_hls> csynth_design 
INFO: [HLS 200-1510] Running: csynth_design 
INFO: [HLS 200-111] Finished File checks and directory preparation: CPU user time: 0.01 seconds. CPU system time: 0.01 seconds. Elapsed time: 0.01 seconds; current allocated memory: 772.094 MB.
INFO: [HLS 200-10] Analyzing design file 'main.cc' ... 
ERROR: [HLS 207-2295] reference to non-static member function must be called (main.cc:25:36)

Since when compiling this design I get the error ERROR: Invalid use of non-static member function from the compiler, what is the best solution to wrap the method of a class so that it can be used in an hls::task? With exposed objects like the one I posted here, I can define some helper functions and use the objects as global variables, but now I am starting to call the tasks inside the class itself and this is not feasible anymore. I tried a lambda but it doesn't work. This is the error I get in execution of the C simulation:

terminate called after throwing an instance of 'std::system_error'
  what(): Resource temporarily unavailable.

Thanks in advance :)

Dominant language
ReScript
Stars
810
Forks
188
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Xilinx/Vitis-HLS-Introductory-Examples

All issues in Xilinx/Vitis-HLS-Introductory-Examples

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.