Eu já segui algum tutorial sobre como instalar o CUDA no Debian 9.
O melhor até agora, que me permite usar nvcc
, foi o que você pode encontrar em este link .
Agora, o problema é que não consigo encontrar o kit de ferramentas. Eu já tentei usar o comando find
, etc, mas nada. Alguém tem alguma idéia de onde o kit de ferramentas é?
Porque, sempre que eu executo nvcc
para compilar um simples programa "Hello World" usando CUDA, ele dá erros porque ele não consegue encontrar as bibliotecas. E quando tento instalar os exemplos, ele pergunta pelo caminho do kit de ferramentas e não consigo encontrá-lo.
ADICIONADO:
Eu instalei tudo usando:
apt-get install nvidia-cuda-dev nvidia-cuda-toolkit nvidia-driver
Depois disso, eu corri:
nvcc -V
Para verificar se o nvcc foi instalado, a saída foi esta:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Eu faço o download do arquivo .run para o Ubuntu 16.04 e CUDA 8.0:
cuda_8.0.61_375.26_linux-run
Eu ignoro a instalação de drivers e a instalação do kit de ferramentas, e pulo direto para o Samples Installation
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 ]: ??????????
O problema é que ele pede a localização do kit de ferramentas e eu não sei. Eu pressiono enter e, em seguida, tento instalar as amostras, mas este é o erro:
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
Eu já usei o argumento --override, mas ele falha.
Depois disso, tentei pelo menos compilar um dos "primeiros programas" dados por 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);
}
Mas esta é a saída:
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.