- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我开发了一种使用推力
的算法。我的办公室计算机有一张支持 CUDA 的卡,其架构为:
--- General information about Device 0 Name: Quadro 2000 Compute Capability: 2.1 Clock Rate: 1251000 kHz Device Overlap: Enabled Kernel Execution Timeout: Disabled
在这台机器上,我的算法运行没有错误。但是,当尝试生成 device_vector
时,实验室机器上的干净构建会抛出讨厌的 thrust::system::system_error
。两台机器都运行 RedHat 6 并且配置相同,除了多个图形卡。该实验室机器包含三个支持 CUDA 的卡,具有以下架构:
--- General information about Device 0 Name: Tesla C2050 Compute Capability: 2.0 Clock Rate: 1147000 kHz Device Overlap: Enabled Kernel Execution Timeout: Disabled
--- General information about Device 1 Name: Quadro 2000 Compute Capability: 2.1 Clock Rate: 1251000 kHz Device Overlap: Enabled Kernel Execution Timeout: Disabled
--- General information about Device 2 Name: Quadro 2000 Compute Capability: 2.1 Clock Rate: 1251000 kHz Device Overlap: Enabled Kernel Execution Timeout: Enabled`
我知道 thrust
需要针对目标架构进行编译才能工作。因此,我将 CUDA 设备设置为 1
。但是,错误仍然存在。
作为调试措施,我在 device_vector
分配之前放置了一个 cudaGetDevice()
调用。设备被正确地声明为 1
。
int device;
CUDA_CHECK_RETURN(cudaGetDevice(&device), __FILE__, __LINE__);
std::cout << "Operating on device " << device << std::endl; // <-- device 1
// copy the turns to the runtime
thrust::device_vector<MalfunctionTurn> d_turns = turns; // <-- error here
我已无计可施,无法调试它。有没有人见过这样的错误?更值得注意的是,cudaSetDevice()
是否存在我不知道的限制?我很担心,因为不同机器上的两张相同的卡不能运行相同的代码。
提前致谢。
编辑
编译命令行:nvcc -rdc=true -arch=sm_21 -O3 file
这是一个重现错误的最小示例:
#define DEVICE __device__
#define HOST __host__
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
template <typename T, std::size_t N>
class Container {
public:
DEVICE HOST
Container() {
}
private:
T data[N];
};
typedef Container<double, 7> double7;
template <std::size_t N = 10 >
class History {
public:
DEVICE HOST
History() {
}
DEVICE HOST
virtual ~History() {
}
private:
double7 history[N];
};
int main() {
try {
thrust::host_vector<History<> > histories(1);
thrust::device_vector<History<> > d_histories = histories;
} catch (const thrust::system_error &) {
std::cerr << "boo boo" << std::endl;
}
return 0;
}
最佳答案
据我所知,您的代码(在幕后)违反了 usage of classes with virtual functions 上的 CUDA 限制。 :
It is not allowed to pass as an argument to a
__global__
function an object of a class with virtual functions.
如果我拿走你的代码并删除:
#include <JARSS.h>
并将其替换为:
#define HOST __host__
#define DEVICE __device__
我可以编译它。然而,在引擎盖下,推力执行这条线:
thrust::device_vector<History<> > d_histories = histories;
通过启动一个内核,该内核将主机上的对象作为参数复制到设备。 (例如,您可以使用 nvprof
验证内核启动。)这是 thrust 的常见行为。问题在于那些具有虚拟析构函数的对象不能以这种方式复制。
与您的问题所述相反,此代码不应在任何 CUDA 机器上正确运行。
您可以通过注释掉虚拟析构函数来“修复”您的代码。如果您需要多态行为,对实际代码的修复可能比这更复杂。应该仍然可以使用带有推力的多态对象行为,请参阅 this answer一个有效的例子。
关于linux - CUDA 多设备问题,thrust::system_error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26025281/
以下 CUDA Thrust 程序崩溃: #include #include int main(void) { thrust::device_vector vec; for (int i(
我使用 cuda 内核对推力 vector 执行 S 形激活: thrust::device_vector output = input; float * output_ptr = thrust::r
我一直在尝试实现一些需要在 thrust::complexes 上调用 reduce 的代码,编译器向我发出错误消息: cannot pass an argument with a user-prov
我是 CUDA 的新手,而且很吃力。当提供 counting_iterator 时,我似乎无法让 thrust::for_each 算法工作。这是我的简单仿函数: struct print_Funct
我实际上正在学习CUDA和thrust,我正在尝试用.cpp做一个项目,。 hpp 文件和 .cu, .cuh 文件。因此,我做了第一个小实现(见下面的代码),但是我有一个编译错误。这是 output
我想覆盖低级 CUDA 设备内存分配器(实现为 thrust::system::cuda::detail::malloc()),以便它使用自定义分配器而不是直接调用 cudaMalloc()在主机 (
当我在main函数中使用thrust::device_vector时,可以正确的传递给内核函数,代码如下: thrust::device_vector device_a(2); thrust::h
我在 CUDA 中使用这种 vector 方法的 vector 方法,因为我仍然习惯于 Matlab 和 Python 风格的编程环境。我能够从设备 vector 中的主机端提取数据,但现在我不确定如
我正在尝试使用 thrust::raw_pointer_cast 转换原始指针以捕获仿函数中的输出。我尝试了多种方法来将指针传递给 float ,但不断出现内存冲突和两个智能感知错误 thrust::
gather与scatter正好相反: scatter是顺序输入根据map确定撒点输出位置。 #include #include #include ... // mark even indice
我是 Thrust 的新手,有件事我不明白。 Thrust 是异步还是同步? 如果我编写以下代码,所花费的时间不是0。但在其他标签中,其他用户报告的结果为0。真相是什么? clock_t start,
我的编译器 (PGI) 不支持 #pragma once 但是我想包含的库(推力)使用它们。 这个问题有解决办法吗? 最佳答案 您可以使用guardonce将 #pragma Once 语句转换为标准
我的设备上有两个整数数组 dmap 和 dflag相同的长度我用推力设备指针 dmapt 和dflagt dmap 数组中有一些值为 -1 的元素。我想要删除这些 -1 和相应的值dflag 数组。
Thrust 能够对编码器隐藏各种细节,并且声称 Thrust 会根据系统规范在一定程度上设置参数。 Thrust 如何选择最佳参数化,以及如何处理不同机器上的各种代码? Thrust 实现这种通用库
我在当前项目中使用了 Thrust,所以我不必写 device_vector自己抽象或(分段)扫描内核。 到目前为止,我已经使用推力抽象完成了我的所有工作,但是对于简单的内核或不容易转换为 for_e
我想做这样的事情: BaseFunctor* f = new MyFunctor(); thrust::transform(it1,it2,MyFunctor); 目标是让用户能够传递不同的仿函数(具
当我尝试实现任何仿函数时,我得到了不好的结果。例如,我尝试了一个类似于 thrust::negate 的否定仿函数下面是一个示例代码,它使用内置的否定仿函数产生了良好的结果: int data[10]
我正在使用 OpenCV 加载一个 .png 文件,我想使用 thrust 库提取它的蓝色强度值。 我的代码是这样的: 使用 OpenCV IplImage 指针加载图像 将图像数据复制到thrust
我有一个奇怪的问题,我无法解决。它与 boost +推力代码相关联。 代码: #include #include #include #include #include #include #
是否可以使用 Thrust 创建一个 device_vectors 数组?我知道我不能创建一个 device_vector 的 device_vector,但是我将如何创建一个 device_vect
我是一名优秀的程序员,十分优秀!