0
我很抱歉如果這個問題已經被解決了,但我已經做了一些搜索,到目前爲止我已經空手而歸了。我試圖編譯一個cuda版本的Hello World,從here稍微修改。我的代碼是:CUDA hello_world沒有運行
// This is the REAL "hello world" for CUDA!
// It takes the string "Hello ", prints it, then passes it to CUDA with an array
// of offsets. Then the offsets are added in parallel to produce the string "World!"
// By Ingemar Ragnemalm 2010
#include <stdio.h>
#include <iostream>
const int N = 16;
const int blocksize = 16;
__global__
void hello(char *a, int *b)
{
a[threadIdx.x] += b[threadIdx.x];
}
int main()
{
char a[N] = "Hello \0\0\0\0\0\0";
int b[N] = {15, 10, 6, 0, -11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
char *ad;
int *bd;
const int csize = N*sizeof(char);
const int isize = N*sizeof(int);
printf("%s", a);
cudaMalloc((void**)&ad, csize);
cudaMalloc((void**)&bd, isize);
cudaMemcpy(ad, a, csize, cudaMemcpyHostToDevice);
cudaMemcpy(bd, b, isize, cudaMemcpyHostToDevice);
dim3 dimBlock(blocksize, 1);
dim3 dimGrid(1, 1);
int runtime_version = -1;
auto error_type_runtime = cudaRuntimeGetVersion(&runtime_version);
int driver_version = -1;
auto error_type_driver = cudaDriverGetVersion(&driver_version);
std::cout << "Blocksize: " << blocksize << std::endl;
std::cout << "NumBlocks: " << (N + blocksize - 1)/blocksize << std::endl;
std::cout << "Runtime API: " << runtime_version << std::endl;
std::cout << "cudaRuntimeGetVersion error type: " << error_type_runtime << std::endl;
std::cout << "Driver API: " << driver_version << std::endl;
std::cout << "cudaRuntimeGetVersion error type: " << error_type_driver << std::endl;
hello<<<(N + blocksize - 1)/blocksize, dimBlock>>>(ad, bd);
cudaMemcpy(a, ad, csize, cudaMemcpyDeviceToHost);
cudaFree(ad);
cudaFree(bd);
printf("%s\n", a);
return EXIT_SUCCESS;
}
,但我得到:
$ nvcc cuda_hello_world.cu -arch=sm_20 --std=c++11
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
$ ./a.out
Hello Blocksize: 16
NumBlocks: 1
Runtime API: -1
cudaRuntimeGetVersion error type: 35
Driver API: 0
cudaRuntimeGetVersion error type: 0
Hello
我擡頭CUDA錯誤35,這就是「指示安裝NVIDIA CUDA驅動程序比CUDA運行時庫年紀大了,」但經過運行
$/usr/bin/nvidia-smi
我得到NVIDIA-SMI 375.82驅動程序版本:375.82這是從2017年7月24日,和
$nvcc --version
個
產量:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
所以看起來正確的庫/驅動程序安裝,但NVCC無法找到他們。如果我建立與-v我得到:
$ nvcc cuda_hello_world.cu -arch=sm_20 --std=c++11 -v
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
#$ _SPACE_=
#$ _CUDART_=cudart
#$ _HERE_=/usr/local/cuda-8.0/bin
#$ _THERE_=/usr/local/cuda-8.0/bin
#$ _TARGET_SIZE_=
#$ _TARGET_DIR_=
#$ _TARGET_DIR_=targets/x86_64-linux
#$ TOP=/usr/local/cuda-8.0/bin/..
#$ NVVMIR_LIBRARY_DIR=/usr/local/cuda-8.0/bin/../nvvm/libdevice
#$ LD_LIBRARY_PATH=/usr/local/cuda-8.0/bin/../lib:
#$ PATH=/usr/local/cuda-8.0/bin/../open64/bin:/usr/local/cuda-8.0/bin/../nvvm/bin:/usr/local/cuda-8.0/bin:/home/michael/bin:/home/michael/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games/usr/local/games:/snap/bin:/usr/local/cuda-8.0/bin/:/usr/local/MATLAB/R2016b/bin/
#$ INCLUDES="-I/usr/local/cuda-8.0/bin/../targets/x86_64-linux/include"
#$ LIBRARIES= "-L/usr/local/cuda-8.0/bin/../targets/x86_64-linux/lib/stubs" "-L/usr/local/cuda-8.0/bin/../targets/x86_64-linux/lib"
難道我不納入正確的庫做一個愚蠢的錯誤,或者是完全不同的東西會在這裏?
您的驅動程序安裝已損壞。 「nvidia-smi」運行並顯示典型輸出的事實對於駕駛員來說是一個有用的但不是確定性的診斷。錯誤代碼是確定的,驅動程序安裝已損壞。解決這個問題的一個可能的方法是從乾淨安裝的linux開始,並仔細地遵循CUDA Linux安裝指南。 –
這是有道理的,並解釋了爲什麼更新事件解決了我的問題。謝謝你的幫助 – Putham