I'm working on vectorAdd sample application which was provided along with oneAPI basekit. When I tried printing the sum inside kernel, I get the following error.
Please find attached source code and error when compiled.
//Source code
cgh.parallel_for<class VectorAdd>(num_items, [=](id<1> wiID) {
sum_accessor[wiID] = addend_1_accessor[wiID] + addend_2_accessor[wiID];
std::cout<<"Sum : "<<sum_accessor[wiID]<<std::endl; // I want to print this sum
});
During compilation I get the following error.
//Error generated while compiling
usr/lib/gcc/x86_64-linux-gnu/7.4.0/../../../../include/c++/7.4.0/bits/ostream.tcc:359:25: error: SYCL kernel cannot have a class with a virtual function table
extern template class basic_ostream<char>;
^
vector-add.cpp:159:6: note: used here
std::cout<<"Sum : "<<sum_accessor[wiID]<<std::endl;
^
vector-add.cpp:159:11: error: SYCL kernel cannot use a global variable
std::cout<<"Sum : "<<sum_accessor[wiID]<<std::endl;