Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法调用CUDA内存上的推力_Cuda_Thrust - Fatal编程技术网

无法调用CUDA内存上的推力

无法调用CUDA内存上的推力,cuda,thrust,Cuda,Thrust,我正在尝试使用推力库查找数组(已经存在于CUDA内存中)的和。这里很少有人回答说,通过使用推力::设备ptr包装它是可能的,但它为我抛出了一个错误 初始代码 cudaMemcpy((void *)(data + stride), (void *)d_output, sizeof(unsigned int) * rows * cols, cudaMemcpyDeviceToHost); thrust::device_vector<unsigned int> vec((data + st

我正在尝试使用推力库查找数组(已经存在于CUDA内存中)的和。这里很少有人回答说,通过使用推力::设备ptr包装它是可能的,但它为我抛出了一个错误

初始代码

cudaMemcpy((void *)(data + stride), (void *)d_output, sizeof(unsigned int) * rows * cols, cudaMemcpyDeviceToHost);
thrust::device_vector<unsigned int> vec((data + stride), (data + stride + (rows * cols)));
sum = thrust::reduce(vec.begin(), vec.end());
有什么问题吗? 非常感谢您抽出时间

*罗伯特·克罗维拉的编辑输入 错误是使用了步幅。 我有一个问题(与上述声明有关)

根据toggle的值,我需要调用推力

if(toggle) {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_output);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_output + (rows * cols)));
}
else {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_X);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_X + (rows * cols)));
}
if(切换){
推力:装置输出端(d输出端);
推力:设备输出趋势((d_输出+(行*列));
}
否则{
推力:装置输出端(d_X);
推力:设备输出趋势((d_X+(行*列));
}
但是编译说outputPtrBegin和outputPtrEnd没有声明,因为它们在if语句中。如何在使用之前声明这些设备指针?

这是错误的:

thrust::device_ptr<unsigned int> outputPtrEnd((d_output + stride + (rows * cols)));
关于你的第二个问题(请将新问题作为新问题发布),而不是:

if(toggle) {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_output);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_output + (rows * cols)));
}
else {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_X);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_X + (rows * cols)));
}
if(切换){
推力:装置输出端(d输出端);
推力:设备输出趋势((d_输出+(行*列));
}
否则{
推力:装置输出端(d_X);
推力:设备输出趋势((d_X+(行*列));
}
这样做:

thrust::device_ptr<unsigned int> outputPtrBegin;
thrust::device_ptr<unsigned int> outputPtrEnd;
if(toggle) outputPtrBegin=thrust::device_pointer_cast<unsigned int>(d_output);
else outputPtrBegin=thrust::device_pointer_cast<unsigned_int>(d_X);
outputPtrEnd = outputPtrBegin + (rows * cols);
推力::设备输出PTRBEGIN;
推力:设备输出趋势;
if(toggle)outputPtrBegin=推力::设备指针投射(d_输出);
else outputPtrBegin=推力::设备\指针\强制转换(d\u X);
outputPtrEnd=outputPtrBegin+(行*列);
这是错误的:

thrust::device_ptr<unsigned int> outputPtrEnd((d_output + stride + (rows * cols)));
关于你的第二个问题(请将新问题作为新问题发布),而不是:

if(toggle) {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_output);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_output + (rows * cols)));
}
else {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_X);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_X + (rows * cols)));
}
if(切换){
推力:装置输出端(d输出端);
推力:设备输出趋势((d_输出+(行*列));
}
否则{
推力:装置输出端(d_X);
推力:设备输出趋势((d_X+(行*列));
}
这样做:

thrust::device_ptr<unsigned int> outputPtrBegin;
thrust::device_ptr<unsigned int> outputPtrEnd;
if(toggle) outputPtrBegin=thrust::device_pointer_cast<unsigned int>(d_output);
else outputPtrBegin=thrust::device_pointer_cast<unsigned_int>(d_X);
outputPtrEnd = outputPtrBegin + (rows * cols);
推力::设备输出PTRBEGIN;
推力:设备输出趋势;
if(toggle)outputPtrBegin=推力::设备指针投射(d_输出);
else outputPtrBegin=推力::设备\指针\强制转换(d\u X);
outputPtrEnd=outputPtrBegin+(行*列);
这是错误的:

thrust::device_ptr<unsigned int> outputPtrEnd((d_output + stride + (rows * cols)));
关于你的第二个问题(请将新问题作为新问题发布),而不是:

if(toggle) {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_output);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_output + (rows * cols)));
}
else {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_X);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_X + (rows * cols)));
}
if(切换){
推力:装置输出端(d输出端);
推力:设备输出趋势((d_输出+(行*列));
}
否则{
推力:装置输出端(d_X);
推力:设备输出趋势((d_X+(行*列));
}
这样做:

thrust::device_ptr<unsigned int> outputPtrBegin;
thrust::device_ptr<unsigned int> outputPtrEnd;
if(toggle) outputPtrBegin=thrust::device_pointer_cast<unsigned int>(d_output);
else outputPtrBegin=thrust::device_pointer_cast<unsigned_int>(d_X);
outputPtrEnd = outputPtrBegin + (rows * cols);
推力::设备输出PTRBEGIN;
推力:设备输出趋势;
if(toggle)outputPtrBegin=推力::设备指针投射(d_输出);
else outputPtrBegin=推力::设备\指针\强制转换(d\u X);
outputPtrEnd=outputPtrBegin+(行*列);
这是错误的:

thrust::device_ptr<unsigned int> outputPtrEnd((d_output + stride + (rows * cols)));
关于你的第二个问题(请将新问题作为新问题发布),而不是:

if(toggle) {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_output);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_output + (rows * cols)));
}
else {
    thrust::device_ptr<unsigned int> outputPtrBegin(d_X);
    thrust::device_ptr<unsigned int> outputPtrEnd((d_X + (rows * cols)));
}
if(切换){
推力:装置输出端(d输出端);
推力:设备输出趋势((d_输出+(行*列));
}
否则{
推力:装置输出端(d_X);
推力:设备输出趋势((d_X+(行*列));
}
这样做:

thrust::device_ptr<unsigned int> outputPtrBegin;
thrust::device_ptr<unsigned int> outputPtrEnd;
if(toggle) outputPtrBegin=thrust::device_pointer_cast<unsigned int>(d_output);
else outputPtrBegin=thrust::device_pointer_cast<unsigned_int>(d_X);
outputPtrEnd = outputPtrBegin + (rows * cols);
推力::设备输出PTRBEGIN;
推力:设备输出趋势;
if(toggle)outputPtrBegin=推力::设备指针投射(d_输出);
else outputPtrBegin=推力::设备\指针\强制转换(d\u X);
outputPtrEnd=outputPtrBegin+(行*列);

什么是步幅?在初始代码中,它看起来像字节偏移量。是吗?嗨,是的,只是个补偿。即使设置为零,我也会遇到相同的错误。“即使设置为零,我也会遇到相同的错误。”这令人费解。如果是这样的话,我的答案不是解释问题的根本原因(尽管你们的业务规模明显不同)。如果你能提供完整的代码就更好了。对不起,我实际上是在编辑那个评论。这段代码在while循环中(以(rows*cols)的步长递增步长值)。第一次迭代已经成功运行(我在打印值时又遇到了一个错误&当stride=0时,它无法打印第一个printf,尽管代码已经执行了),再次抱歉。什么是stride?在初始代码中,它看起来像字节偏移量。是吗?嗨,是的,只是个补偿。即使设置为零,我也会遇到相同的错误。“即使设置为零,我也会遇到相同的错误。”这令人费解。如果是这样的话,我的答案不是解释问题的根本原因(尽管你们的业务规模明显不同)。如果你能提供完整的代码就更好了。对不起,我实际上是在编辑那个评论。这段代码在while循环中(以(rows*cols)的步长递增步长值)。第一次迭代已经成功运行(我在打印值时又遇到了一个错误&当stride=0时,它无法打印第一个printf,尽管代码已经执行了),再次抱歉。什么是stride?在初始代码中,它看起来像字节偏移量。是吗?嗨,是的,只是个补偿。即使设置为零,我也会遇到相同的错误。“即使设置为零,我也会遇到相同的错误。”这令人费解。如果是这样的话,我的答案不是解释问题的根本原因(尽管你们的业务规模明显不同)。如果你能提供完整的代码就更好了。对不起,我实际上是在编辑那个评论。这段代码在while循环中(以(rows*cols)的步长递增步长值)。第一次迭代已经成功运行(我在打印值时又遇到了一个错误&当stride=0时,它无法打印第一个printf,尽管代码已经执行了),再次抱歉。什么是stride?在初始代码中,它看起来像字节偏移量。是吗?嗨,是的,只是个补偿。即使设置为零,我也会遇到相同的错误。“即使设置为零,我也会遇到相同的错误。”这令人费解。如果是,,