基于SYCL 1.2.1规范(rev 7) 4.8.9.3节中的代码,我编写了以下代码:
#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");
}使用OneAPI beta07进行编译时会出现许多错误。
%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) {
^
.
.
.该规范中的示例似乎存在一些问题。首先,在OneAPI中似乎没有“OneAPI”方法,也没有规范本身。第二,示例同时使用"MyProgram“和"myProgram”(较小的nit,但使我相信这不是来自验证的代码)。最后,我不认识一个具有与示例签名相匹配的签名的parallel_for。
只是好奇到底出了什么问题。
发布于 2022-06-12 16:19:08
提交问题(早在.时)
https://stackoverflow.com/questions/62645410
复制相似问题