cuda 9.2 curand_init extremely slow
cuda 9.2 curand_init extremely slow
我有一个程序,我使用 cuda 生成带有随机元素的数组。自从我从 cuda 9.1 升级到 cuda 9.2 以来,所需的时间已经从几分之一秒(约 0.1 秒(增加到近两分钟(不更改任何代码(。问题似乎是 curand_init(( 函数,因为其余部分以大致相同的速度运行。我在库中是否遗漏了更改,这是一个错误还是我的代码有问题? 这是一个例子
#include <iostream>
#include <curand.h>
#include <curand_kernel.h>
#define cudaErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
std::cerr << "cudaAssert: " << cudaGetErrorString(code) << " " << file << ": " << line << std::endl;
if (abort) exit(code);
}
}
__global__
void setup_curand_state (curandState *state, int seed, int dim)
{
int index = threadIdx.x+blockDim.x*blockIdx.x;
if (index < dim)
curand_init(seed, index, 0, &state[index]);
}
__global__
void set_random (float* to, curandState* curand_state, int dim)
{
int index = threadIdx.x+ blockIdx.x* blockDim.x;
if (index < dim)
to [index] = curand_normal (&curand_state[index]);
}
int main () {
int dim = 100000;
float *data;
cudaErrchk (cudaMallocManaged ((void**) &data, dim * sizeof (float)));
curandState* curand_state;
cudaErrchk (cudaMalloc (&curand_state, (dim * sizeof (curandState))));
setup_curand_state <<<(dim + 1023) / 1024, 1024>>> (curand_state, time(NULL), dim);
cudaErrchk (cudaDeviceSynchronize());
set_random <<<(dim + 1023) / 1024, 1024>>> (data, curand_state, dim);
cudaFree (data);
return 0;
}
Mr. Bonobo 在上面的评论中回答:
显然,通过 apt 更新 cuda 默默地破坏了安装。法典 为 9.1 编译仍然可以工作,但速度慢了大约 100/1000 倍。 重新安装 nvidia-cuda-toolkit 解决了错误
相关文章:
- GCC对可能有效的代码抛出init list生存期警告
- GLEW/GLUT:调用init并创建一个窗口后,取消初始化并重新初始化?
- 将 out/in out 参数与 if/switch 的 init 语句一起使用
- 使用 std::ios_base::Init 正确初始化全局变量
- Pybind11: init<> with lambda
- 为什么别名声明不是有效的 init 语句(/simple-declaration)?
- 结构 init:字符**类型的标量初始值设定项两边的大括号
- 为什么基于范围类型的大括号上循环init列表是非法的c++
- 是否可以使用"if constexpr"来声明具有不同类型和init-expr的变量
- Android Studio TextView Init C++
- cuda 9.2 curand_init extremely slow
- Pc Lint,如何使用 init() 抑制类的 err 613(可能使用空 ponter)
- 带有定制 GLFW 二进制 /usr/bin/ld 的 Centos 7: /usr/local/lib/libglfw3.a(init.c.o):".text"部分中无法识别的重定位 (0x2a)
- 如何强制调用类的全局实例的析构函数和构造函数(以便"re-init"类实例)
- 当调用时,为什么ranges ::累积的init as std :: Move(init)
- clang tidy pro type member init resharper
- Android NDK 未定义对 'std::ios_base::Init::Init()' 的引用
- 使用 Git init、fetch 和 checkout 克隆 Git 存储库
- QFILE INIT/分配OP问题当对象是类成员时
- 仅第一个元素init为1