我使用的是Xilinx的triSYCL github实现https://github.com/triSYCL/triSYCL。
我正在尝试创建一个有100个生产者/消费者的设计,可以从100个管道进行读/写。我不确定的是,如何创建一个cl::sycl::buffer数组并使用std::iota对其进行初始化。
下面是我的代码:
constexpr size_t T=6;
constexpr size_t n_threads=100;
cl::sycl::buffer<float, n_threads> a { T };
for (int i=0; i<n_threads; i++)
{
auto ba = a[i].get_access<cl::sycl::access::mode::write>();
// Initialize buffer a with increasing integer numbers starting at 0
std::iota(ba.begin(), ba.end(), i*T);
}我得到了以下错误:error: no matching function for call to ‘cl::sycl::buffer<float, 2>::buffer(<brace-enclosed initializer list>)’ cl::sycl::buffer<float, n_threads> a { T };
我是C++编程的新手。所以我不能想出确切的方法来做到这一点。
发布于 2018-02-06 03:44:01
我认为有两点会导致你目前的问题:
据我所知,您正在尝试初始化维度为1且维度为{ 100,1,1 }的缓冲区。为此,a的定义应更改为:
cl::sycl::buffer a(n_threads 1>);
此外,由于维度可以从range模板参数中推断出来,因此您可以使用以下命令实现相同的效果:
cl::sycl::buffer< float >a (cl::sycl::range< 1 >(n_threads));
至于使用std::iota初始化buffer,您有3种选择:
访问器不应用作迭代器(使用.begin(),.end())
案例A:
std::vector<float> data(n_threads); // or std::array<float, n_threads> data;
std::iota(data.begin(), data.end(), 0); // this will create the data { 0, 1, 2, 3, ... }
cl::sycl::buffer<float> a(data.data(), cl::sycl::range<1>(n_threads));
// The data in a are already initialized, you can create an accessor to use them directly案例B:
cl::sycl::buffer<float> a(cl::sycl::range<1>(n_threads));
{
auto ba = a.get_access<cl::sycl::access::mode::write>();
for(size_t i=0; i< n_threads; i++) {
ba[i] = i;
}
}案例C:
cl::sycl::buffer<float> a(cl::sycl::range<1>(n_threads));
cl::sycl::queue q{cl::sycl::default_selector()}; // create a command queue for host or device execution
q.Submit([&](cl::sycl::handler& cgh) {
auto ba = a.get_access<cl::sycl::access::mode::write>();
cgh.parallel_for<class kernel_name>([=](cl::sycl::id<1> i){
ba[i] = i.get(0);
});
});
q.wait_and_throw(); // wait until kernel execution completes还要查看SYCL1.2.1规范https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf的第4.8章,因为它有一个iota的示例
发布于 2018-02-09 03:26:31
免责声明: triSYCL目前是一个研究项目。对于任何严重的事情,请使用ComputeCpp。:-)
如果您确实需要buffer数组,我想您可以使用类似于Is there a way I can create an array of cl::sycl::pipe?的方法
作为一种变体,您可以使用std::vector<cl::sycl::buffer<float>>或std::array<cl::sycl::buffer<float>, n_threads>并使用来自cl::sycl::buffer<float> { T }的循环进行初始化。
https://stackoverflow.com/questions/48611089
复制相似问题