简体   繁体   English

CUDA返回值错误35是什么意思?

[英]What is the meaning of CUDA return value error 35?

My source code of simple C++ cuda code我的简单C++ cuda代码的源代码

#include <iostream>
#include <cuda.h>

using namespace std;

__global__ void AddIntsCUDA(int *a, int *b, int *c)
{
    *c = *a + *b;
}

int main()
{
    int a, b, c;
    int *d_a, *d_b, *d_c;
    int size = sizeof(int);

    cudaMalloc((void **)&d_a, size);
    cudaMalloc((void **)&d_b, size);
    cudaMalloc((void **)&d_c, size);


    a = 10;
    b = 35;
    c = 0;

    cudaMemcpy(d_a, &a, size, cudaMemcpyHostToDevice);
    cudaMemcpy(d_b, &b, size, cudaMemcpyHostToDevice);

    AddIntsCUDA<<<1, 1>>>(d_a, d_b, d_c);

    cudaMemcpy(&c, d_c, size, cudaMemcpyDeviceToHost);

    cout << "The Answer is "<< c << endl;

    cudaFree(d_a);
    cudaFree(d_b);
    cudaFree(d_c);

    system("pause");

    return 0;
}

Console Output output shows c = 0 but i expect sum of a and b output (should like this 45 because a = 10, b = 35) explain me what the hell is happening in this code Console Output output shows c = 0 but i expect sum of a and b output (should like this 45 because a = 10, b = 35) explain me what the hell is happening in this code

Try adding a cudaError_t err = cudaDeviceSynchronize();尝试添加cudaError_t err = cudaDeviceSynchronize(); after the kernel launch and before the copy. kernel 发布之后和复制之前。 And print the value of err .并打印err的值。

Use const char* cudaGetErrorString ( cudaError_t error ) to get the error string at runtime, or look here:使用const char* cudaGetErrorString ( cudaError_t error )在运行时获取错误字符串,或者看这里:
https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html#group__CUDART__TYPES_1gf599e5b8b829ce7db0f5216928f6ecb6 https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html#group__CUDART__TYPES_1gf599e5b8b829ce7db0f5216928f6ecb6

Following your comment that it's error number 35, it seems that you need to update your driver.在您评论错误号为 35 之后,您似乎需要更新驱动程序。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM