cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jimmystone
Observer
Observer
562 Views
Registered: ‎05-17-2010

Virtual function in C++ Error

Jump to solution

Hi, All

I got an errro when I usd virtual function in HLS

ERROR: [SYNCHK 200-41] test.cpp:18: unsupported pointer reinterpretation from type 'AA' to type '%class.A.4.9.15 = type { i32 (...)**, %struct.ap_uint.3.8.13...' on variable 'aa'.

My code as below

class A {
    public:
        dat_t reg;
        A(dat_t x){
            reg = x;
        }
        virtual dat_t inv(){return 0;};
};

class AA: public A {
    public:
        dat_t reg;

        AA(dat_t x): A(x){
            reg = x;
        }

        dat_t inv(){
            reg = ~reg;
            return reg;
        }
};

void funC(A& a){
    a.inv();
}

void test (
  dat_t *y,
  dat_t x
){

    AA aa = AA(x);
    funC(aa);
    *y = aa.reg;

}

Then I found Vivado HLS supports virtual functions in ug902(2018.2). And It seem my code is OK with it.

Vivado HLS supports virtual functions (including abstract functions) for synthesis, provided that it can statically determine the function during elaboration. Vivado HLS does not support virtual functions for synthesis in the following cases:
• Virtual functions can be defined in a multilayer inheritance class hierarchy but only with a single inheritance.

What do I miss?

Thanks

 

 

0 Kudos
1 Solution

Accepted Solutions
scampbell
Moderator
Moderator
433 Views
Registered: ‎10-04-2011

One thing I will add here is that support for virtual functions has been removed in Vitis HLS. It is recommended then that code be re-written to avoid the use of virtual functions. 

OK, I hope this helps,
Scott

View solution in original post

2 Replies
xilinxacct
Professor
Professor
536 Views
Registered: ‎10-23-2018

@jimmystone 

If you don't need the base class virtual function (i.e. it is only there to define the interface, rather than being 'sometimes' executed... simple define that interface, and only implement in the derived class. another thought... it 'may' want to see the 'override' specifying explicitly. Both of these to help 'provide that it can statically determine the function during elaboration'

Hope that Helps
If so, Please mark as solution accepted. Kudos also welcomed.

 

0 Kudos
scampbell
Moderator
Moderator
434 Views
Registered: ‎10-04-2011

One thing I will add here is that support for virtual functions has been removed in Vitis HLS. It is recommended then that code be re-written to avoid the use of virtual functions. 

OK, I hope this helps,
Scott

View solution in original post