Cuda总是出错
我已经在LINUX下安装了CUDA,大多数情况下,下面这个简单的代码会抛出错误Cuda总是出错,cuda,Cuda,我已经在LINUX下安装了CUDA,大多数情况下,下面这个简单的代码会抛出错误 // Kernel that executes on the CUDA device __global__ void square_array(float *a, int N) { int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx<N) a[idx] = a[idx] * a[idx]; } // main routine that ex
// Kernel that executes on the CUDA device
__global__ void square_array(float *a, int N)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx<N) a[idx] = a[idx] * a[idx];
}
// main routine that executes on the host
int main(void)
{
cudaSetDevice(0);
cudaDeviceSynchronize();
cudaThreadSynchronize();
cudaError_t cudaError;
float *a_h, *a_d; // Pointer to host & device arrays
const int N = 10; // Number of elements in arrays
size_t size = N * sizeof(float);
a_h = (float *)malloc(size); // Allocate array on host
cudaError=cudaMalloc((void **) &a_d, size); // Allocate array on device
if(cudaError!=cudaSuccess)
{
printf("asdasd1");
}
//// Initialize host array and copy it to CUDA device
for (int i=0; i<N; i++) a_h[i] = (float)i;
cudaError=cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);
if(cudaError!=cudaSuccess)
{
printf("asdasd2");
}
//// Do calculation on device:
int block_size = 4;
int n_blocks = N/block_size + (N%block_size == 0 ? 0:1);
square_array <<< n_blocks, block_size >>> (a_d, N);
//// Retrieve result from device and store it in host array
cudaMemcpy(a_h, a_d, sizeof(float)*N, cudaMemcpyDeviceToHost);
//// Print results
for (int i=0; i<N; i++) printf("%d %f\n", i, a_h[i]);
//// Cleanup
free(a_h); cudaFree(a_d);
我用:nvcc pi.cu-arch=sm_11-o asd.out编译它
我在Windows上也有同样的问题,那会是什么问题呢?在你们的提示下,我重新安装了NVIDIA驱动程序和CUDA;我认为这是可行的
Mon Dec 15 23:43:23 2014
+------------------------------------------------------+
| NVIDIA-SMI 340.29 Driver Version: 340.29 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce 8500 GT Off | 0000:01:00.0 N/A | N/A |
| N/A 66C P0 N/A / N/A | 53MiB / 511MiB | N/A Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Compute processes: GPU Memory |
| GPU PID Process name Usage |
|=============================================================================|
| 0 Not Supported |
+-----------------------------------------------------------------------------+
代码不会抛出任何错误;
THX ALL:有什么错误?请缩进代码以提高可读性。错误位于:cudaMemcpy和cudaMalloc。请使用printf%s\n、cudaGetErrorStringcudaError获取一些描述性错误消息。运行nvidia smi。如果出现错误,请以root用户身份重新运行nvidia smi。如果有效,那么返回并运行测试。如果它们开始工作,请注意linux入门指南。在上一篇文章中,您展示了一个指示CUDA 6.5的deviceQuery列表。作为答案发布的nvidia smi输出显示驱动程序版本331.113。CUDA 6.5与驱动程序版本331.113不兼容。如果正确安装CUDA 6.5,则不会出现此问题。我建议您使用重新安装CUDA 6.5,并确保与CUDA 6.5安装程序关联的驱动程序也已安装340.29或更新版本。