Nvidia
Debian 9 上的 CUDA - 工具包在哪裡?
我已經遵循了一些關於如何在 Debian 9 中安裝 CUDA 的教程。
到目前為止,讓我使用的最好
nvcc
的一個是您可以在此連結中找到的那個。現在的問題是,我找不到工具包。我已經嘗試使用
find
命令等,但沒有。有人知道工具包在哪裡嗎?因為,每當我執行
nvcc
使用 CUDA 編譯一個簡單的“Hello World”程序時,它都會出錯,因為它找不到庫。當我嘗試安裝範例時,它會詢問工具包路徑,但我找不到它。添加:
我使用以下方法安裝了所有東西:
apt-get install nvidia-cuda-dev nvidia-cuda-toolkit nvidia-driver
在此之後,我跑了:
nvcc -V
要檢查是否安裝了 nvcc,輸出如下:
nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2016 NVIDIA Corporation Built on Sun_Sep__4_22:14:01_CDT_2016
我下載了 ubuntu 16.04 和 CUDA 8.0 的 .run 文件:
cuda_8.0.61_375.26_linux-執行
我跳過了驅動程序的安裝和工具包的安裝,直接跳轉到範例安裝
Do you accept the previously read EULA? accept/decline/quit: accept You are attempting to install on an unsupported configuration. Do you wish to continue? (y)es/(n)o [ default is no ]: y Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26? (y)es/(n)o/(q)uit: n Install the CUDA 8.0 Toolkit? (y)es/(n)o/(q)uit: n Install the CUDA 8.0 Samples? (y)es/(n)o/(q)uit: y Enter CUDA Samples Location [ default is /root ]: /home/sergiobranco/cuda_samples Enter Toolkit Location [ default is /usr/local/cuda-8.0 ]: Error: cannot find Toolkit in /usr/local/cuda-8.0 Enter Toolkit Location [ default is /usr/local/cuda-8.0 ]: ??????????
問題是它要求工具包的位置,而我不知道。我按輸入鍵,然後嘗試安裝範例,但這是錯誤:
Error: unsupported compiler: 6.3.0. Use --override to override this check. Missing recommended library: libXmu.so Error: cannot find Toolkit in /usr/local/cuda-8.0 =========== = Summary = =========== Driver: Not Selected Toolkit: Installation Failed. Using unsupported Compiler. Samples: Cannot find Toolkit in /usr/local/cuda-8.0 Logfile is /tmp/cuda_install_3212.log
我已經使用了 –override 參數,但它失敗了。
在此之後,我嘗試至少編譯 cuda 給出的“第一個程序”之一:
#include <stdio.h> __global__ void saxpy(int n, float a, float *x, float *y) { int i = blockIdx.x*blockDim.x + threadIdx.x; if (i < n) y[i] = a*x[i] + y[i]; } int main(void) { int N = 1<<20; float *x, *y, *d_x, *d_y; x = (float*)malloc(N*sizeof(float)); y = (float*)malloc(N*sizeof(float)); cudaMalloc(&d_x, N*sizeof(float)); cudaMalloc(&d_y, N*sizeof(float)); for (int i = 0; i < N; i++) { x[i] = 1.0f; y[i] = 2.0f; } cudaMemcpy(d_x, x, N*sizeof(float), cudaMemcpyHostToDevice); cudaMemcpy(d_y, y, N*sizeof(float), cudaMemcpyHostToDevice); // Perform SAXPY on 1M elements saxpy<<<(N+255)/256, 256>>>(N, 2.0f, d_x, d_y); cudaMemcpy(y, d_y, N*sizeof(float), cudaMemcpyDeviceToHost); float maxError = 0.0f; for (int i = 0; i < N; i++) maxError = max(maxError, abs(y[i]-4.0f)); printf("Max error: %f\n", maxError); cudaFree(d_x); cudaFree(d_y); free(x); free(y); }
但這是輸出:
nvcc -ccbin clang-3.8 hello.c 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). hello.c:3:1: error: unknown type name '__global__' __global__ ^ hello.c:4:1: error: expected identifier or '(' void saxpy(int n, float a, float *x, float *y) ^ hello.c:14:15: warning: implicitly declaring library function 'malloc' with type 'void *(unsigned long)' [-Wimplicit-function-declaration] x = (float*)malloc(N*sizeof(float)); ^ hello.c:14:15: note: include the header <stdlib.h> or explicitly provide a declaration for 'malloc' hello.c:17:3: warning: implicit declaration of function 'cudaMalloc' is invalid in C99 [-Wimplicit-function-declaration] cudaMalloc(&d_x, N*sizeof(float)); ^ hello.c:25:3: warning: implicit declaration of function 'cudaMemcpy' is invalid in C99 [-Wimplicit-function-declaration] cudaMemcpy(d_x, x, N*sizeof(float), cudaMemcpyHostToDevice); ^ hello.c:25:39: error: use of undeclared identifier 'cudaMemcpyHostToDevice' cudaMemcpy(d_x, x, N*sizeof(float), cudaMemcpyHostToDevice); ^ hello.c:26:39: error: use of undeclared identifier 'cudaMemcpyHostToDevice' cudaMemcpy(d_y, y, N*sizeof(float), cudaMemcpyHostToDevice); ^ hello.c:29:3: error: use of undeclared identifier 'saxpy' saxpy<<<(N+255)/256, 256>>>(N, 2.0f, d_x, d_y); ^ hello.c:29:10: error: expected expression saxpy<<<(N+255)/256, 256>>>(N, 2.0f, d_x, d_y); ^ hello.c:29:29: error: expected expression saxpy<<<(N+255)/256, 256>>>(N, 2.0f, d_x, d_y); ^ hello.c:29:31: warning: expression result unused [-Wunused-value] saxpy<<<(N+255)/256, 256>>>(N, 2.0f, d_x, d_y); ^ hello.c:29:34: warning: expression result unused [-Wunused-value] saxpy<<<(N+255)/256, 256>>>(N, 2.0f, d_x, d_y); ^~~~ hello.c:29:40: warning: expression result unused [-Wunused-value] saxpy<<<(N+255)/256, 256>>>(N, 2.0f, d_x, d_y); ^~~ hello.c:31:39: error: use of undeclared identifier 'cudaMemcpyDeviceToHost' cudaMemcpy(y, d_y, N*sizeof(float), cudaMemcpyDeviceToHost); ^ hello.c:35:16: warning: implicit declaration of function 'max' is invalid in C99 [-Wimplicit-function-declaration] maxError = max(maxError, abs(y[i]-4.0f)); ^ hello.c:35:30: warning: implicitly declaring library function 'abs' with type 'int (int)' [-Wimplicit-function-declaration] maxError = max(maxError, abs(y[i]-4.0f)); ^ hello.c:35:30: note: include the header <stdlib.h> or explicitly provide a declaration for 'abs' hello.c:35:30: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value] maxError = max(maxError, abs(y[i]-4.0f)); ^ hello.c:35:30: note: use function 'fabsf' instead maxError = max(maxError, abs(y[i]-4.0f)); ^~~ fabsf hello.c:35:30: note: include the header <math.h> or explicitly provide a declaration for 'fabsf' hello.c:38:3: warning: implicit declaration of function 'cudaFree' is invalid in C99 [-Wimplicit-function-declaration] cudaFree(d_x); ^ hello.c:40:3: warning: implicit declaration of function 'free' is invalid in C99 [-Wimplicit-function-declaration] free(x); ^ 11 warnings and 8 errors generated.
好吧,最後我能夠安裝所有東西並且工作正常。我將在此處發布有關我如何為 debian 9 執行此操作的完整教程:
第一步:
apt-get install nvidia-cuda-dev nvidia-cuda-toolkit nvidia-driver
要執行上面的命令,您應該檢查此連結,以便更好地了解如何為您的董事會正確執行此操作。
說了這麼多,那我下載下面的執行文件CUDA 8.0
我還必須安裝這些:
apt-get install libglu1-mesa libxi-dev libxmu-dev libglu1-mesa-dev
然後我必須將工具包包含到我的 $PATH 中才能使其工作:
export PATH=$PATH:/usr/lib/nvidia-cuda-toolkit
然後你必須這樣做:
sh /home/username/Downloads/cuda_8.0.61_375.26_linux.run --tar mxvf cp InstallUtils.pm /usr/lib/x86_64-linux-gnu/perl-base/ export $PERL5LIB
現在您可以安裝範例:
sh /home/username/Downloads/cuda_8.0.61_375.26_linux.run
當它詢問工具包路徑時,您應該輸入:
/usr/lib/nvidia-cuda-toolkit
這是我的答案:
Do you accept the previously read EULA? accept/decline/quit: accept You are attempting to install on an unsupported configuration. Do you wish to continue? (y)es/(n)o [ default is no ]: y Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26? (y)es/(n)o/(q)uit: n Install the CUDA 8.0 Toolkit? (y)es/(n)o/(q)uit: n Install the CUDA 8.0 Samples? (y)es/(n)o/(q)uit: y Enter CUDA Samples Location [ default is /root ]: /somewher Enter Toolkit Location [ default is /usr/local/cuda-8.0 ]: /usr/lib/nvidia-cuda-toolkit
它現在應該可以毫無問題地安裝範例。然後您可以轉到安裝它們的文件夾並執行:
nvcc -ccbin clang++-3.8 somefile.cu -o somename
你去吧。. .
如果你想安裝 pycuda,你只需要這樣做:
apt-get install build-essential python-dev python-setuptools libboost-python-dev libboost-thread-dev -y apt-get install python-pycuda