简体   繁体   English

CUDA hello_world未运行

[英]CUDA hello_world not running

I apologize if this problem has been addressed before, but I've done some searching and so far I've come up empty handed. 抱歉,如果您之前已解决此问题,但我已经进行了一些搜索,到目前为止,我还是空手而归。 I'm trying to compile a cuda version of Hello World, slightly modified from here . 我正在尝试编译Hello World的cuda版本, 版本略有改动。 My code is: 我的代码是:

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

But I get: 但是我得到:

$ 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 looked up cuda error 35, which is ' indicates that the installed NVIDIA CUDA driver is older than the CUDA runtime library,' but after running 我查找了cuda错误35,它是“表示已安装的NVIDIA CUDA驱动程序比CUDA运行时库更旧”,但是在运行后

$/usr/bin/nvidia-smi

I get NVIDIA-SMI 375.82 Driver Version: 375.82 which is from Jul 24, 2017, and 我获得了NVIDIA-SMI 375.82驱动程序版本:375.82,该版本从2017年7月24日开始,并且

$nvcc --version

yields: 产量:

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 it looks like the correct libraries/drivers are installed, but nvcc can't find them. 因此看起来好像安装了正确的库/驱动程序,但是nvcc找不到它们。 If I build with -v I get: 如果我使用-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"

Am I making a stupid mistake by not including the correct libraries, or is something totally different going on here? 我是否由于没有包含正确的库而犯了一个愚蠢的错误,还是这里发生的事情完全不同?

In case anyone else has this problem, I was able to solve it. 万一其他人有这个问题,我就能解决。 Turns out that simply updating/upgrading everything (including the nvidia drivers/libraries) fixed the problem. 事实证明,只需更新/升级所有内容(包括nvidia驱动程序/库)即可解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual C ++中使用makefile构建hello_world时遇到问题 - Trouble building hello_world with a makefile in Visual C++ 了解hello_world boost sml state机器库 - Understanding hello_world boost sml state machine library Hello World CUDA编译问题 - Hello World CUDA compilation issues Boost.Python Hello_world 示例中的“分段错误(核心转储)”错误 - “Segmentation fault (core dumped)” Error in Boost.Python Hello_world example 构建 TF micro hello world: make: *** [tensorflow/lite/micro/examples/hello_world/Makefile.inc:34: test_hello_world_test] 错误 1 - Building TF micro hello world: make: *** [tensorflow/lite/micro/examples/hello_world/Makefile.inc:34: test_hello_world_test] Error 1 Hello world,用于使用cuda进行图像处理 - Hello world for using cuda for image processing Visual Studio 2010中的Hello World C ++ CUDA程序(Windows 7) - Hello World C++ CUDA Program in Visual Studio 2010 (Windows 7) Cuda Hello World printf 即使使用 -arch=sm_20 也无法正常工作 - Cuda Hello World printf not working even with -arch=sm_20 在 Windows 中用 C++ 安装/运行“Hello World” - Installing / Running "Hello World" in C++ with Windows 在 CodeBlocks 下运行“hello world”程序 - Running a "hello world" program under CodeBlocks
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM