1

根据 SYCL 1.2.1 规范(修订版 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 和规范本身似乎都没有“build_from_name”方法。二,示例同时使用“MyProgram”和“myProgram”(次要但让我相信这不是来自经过验证的代码)。最后,我无法识别具有与示例匹配的签名的 parallel_for。

只是好奇怎么回事。

4

0 回答 0