2017-10-16 4 views
0

Ich entschuldige mich, wenn dieses Problem schon einmal behoben wurde, aber ich habe ein wenig gesucht und bis jetzt bin ich mit leeren Händen gekommen. Ich versuche eine Cuda-Version von Hello World zu kompilieren, leicht modifiziert von here. Mein Code ist:CUDA hallo_world läuft nicht

// 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; 
} 

Aber ich bekomme:

$ 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 

I 35 cuda Fehler nachgeschlagen, was 'zeigt an, dass die installierte NVIDIA CUDA-Treiber ist älter als die CUDA-Laufzeitbibliothek,' aber nach Lauf

$/usr/bin/nvidia-smi 

bekomme ich NVIDIA-SMI 375,82 Driver Version: 375,82, die vom 24. Juli 2017 ist, und

$nvcc --version 

ergibt:

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 

so sieht es aus wie die richtigen Bibliotheken/Treiber installiert sind, aber nvcc sie nicht finden können. Wenn ich mit -v bauen erhalte ich:

$ 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" 

Bin ich einen dummen Fehler machen, indem nicht die richtigen Bibliotheken einschließlich, oder ist etwas ganz anderes geht hier vor?

+1

Ihre Treiberinstallation ist kaputt. Die Tatsache, dass 'nvidia-smi' läuft und typische Ausgaben anzeigt, ist eine nützliche, aber nicht schlüssige Diagnose für den Fahrer. Der Fehlercode ist schlüssig, dass die Treiberinstallation kaputt ist. Ein möglicher Lösungsansatz besteht darin, mit einer sauberen Installation von Linux zu beginnen und den CUDA linux Installationsleitfaden sorgfältig zu befolgen. –

+0

Das macht Sinn, und erklärt, warum Updates meine Probleme behob. Danke für Ihre Hilfe – Putham

Antwort

-1

Falls jemand anderes dieses Problem hat, konnte ich es lösen. Es stellte sich heraus, dass die einfache Aktualisierung/Aktualisierung von allem (einschließlich der nvidia-Treiber/Bibliotheken) das Problem behob.

Verwandte Themen