Tutorial: Debugging with Intel® Distribution for GDB*
The Compiler omits the code of the method of a template class if that method is not used in the code. This causes an issue when you want to invoke the omitted function. This is a C++ issue. This issue is seen in DPC++ because the basic classes (range, id, nd_range, accessor, and others) are templates, which have many overloaded operators. Examples:
p index
Output:
$1 = cl::sycl::id<1> = {32}
p index + 5
Output:
Could not find operator+.
As a solution to this, you can explicitly instantiate a template class in your source. Then the methods of the template instance are available in the binary. The instantiations can be surrounded with #ifndef NDEBUG and #endif to avoid code bloat in release builds. Example:
#ifndef NDEBUG template class cl::sycl::id<1>; template class cl::sycl::id<2>; template class cl::sycl::id<3>; template class cl::sycl::range<1>; template class cl::sycl::nd_range<1>; #endif // #ifndef NDEBUG
Elements of an accessor object cannot be accessed using the multi-dimensional access syntax during expression evaluation. See example below:
print anAccessor[5][3][4]
Example output:
Cannot resolve function operator[] to any overloaded instance
Instead, use an id object:
print workItemId
Example output:
$1 = cl::sycl::id<3> = {5, 3, 4}
print anAccessor[workItemId]
Example output:
$2 = 1234