Based on the code in,SYCL 1.2.1 spec (rev 7) section 4.8.9.3 I wrote the following:
#include <CL/sycl.hpp>
namespace sycl = cl::sycl;
const int Nproc = 8;
int
main(int argc, char *argv[])
{
int x[Nproc];
sycl::device dev = sycl::default_selector().select_device();
class MyKernel;
sycl::queue myQueue(dev);
sycl::program myProgram(myQueue.get_context());
myProgram.build_from_name<MyKernel>();
{
sycl::buffer<unsigned int, 1> xbuffer((unsigned int *)x, sycl::range<1> {Nproc});
myQueue.submit([&](sycl::handler& cgh) {
auto xaccessor = xbuffer.get_access<sycl::access::mode::discard_write, sycl::access::target::global_buffer>(cgh);
cgh.parallel_for<class MyKernel>(
sycl::nd_range<1>(sycl::range<1>(Nproc),sycl::range<1>(Nproc)),
myProgram.get_kernel<MyKernel>(),
[=] (sycl::nd_item<1> item) {
xaccessor[item.get_global_linear_id()]= item.get_global_linear_id();
}
);
}
);
}
for (int i=0; i<Nproc; i++) printf("%2d ", x[i]);
printf("\n");
}
Using OneAPI beta07 this compiles with numerous errors.
%dpcpp -O3 -g -mavx2 -o bug3 bug3.cpp -lOpenCL -lsycl
bug3.cpp:16:13: error: no member named 'build_from_name' in 'cl::sycl::program'
myProgram.build_from_name<MyKernel>();
~~~~~~~~~ ^
bug3.cpp:16:29: error: 'MyKernel' does not refer to a value
myProgram.build_from_name<MyKernel>();
^
bug3.cpp:13:9: note: declared here
class MyKernel;
^
bug3.cpp:16:39: error: expected expression
myProgram.build_from_name<MyKernel>();
^
bug3.cpp:23:13: error: no matching member function for call to 'parallel_for'
cgh.parallel_for<class MyKernel>(
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/local/opt/inteloneapi/compiler/latest/linux/bin/../include/sycl/CL/sycl/handler.hpp:807:8: note: candidate template ignored: could not match 'range' against 'nd_range'
void parallel_for(range<Dims> NumWorkItems, id<Dims> WorkItemOffset,
^
/local/opt/inteloneapi/compiler/latest/linux/bin/../include/sycl/CL/sycl/handler.hpp:856:3: note: candidate template ignored: substitution failure [with KernelName = MyKernel, KernelType = (lambda at bug3.cpp:26:13), Dims = 1, Reduction = cl::sycl::kernel]: no member named 'accessor_mode' in 'cl::sycl::kernel'
parallel_for(nd_range<Dims> Range, Reduction Redu, KernelType KernelFunc) {
^
.
.
.
There seem to be a number of problems with the example in the spec. One, there doesn't seem to be a "build_from_name" method in OneAPI nor in the spec itself. Two, example uses both "MyProgram" and "myProgram" (minor nit but leads me to believe this isn't from verified code). Lastly I don't recognize a parallel_for with a signature that would match that of the example.
Just curious about what's wrong.
Submitted the issue (way back when....)