cudaMalloc 在 CUDA 中导致 "unknown errors"

标签 cuda

我正在尝试遵循《CUDA By Examples》一书,并且刚刚开始尝试其中的一些示例。

“hello world”程序运行没有问题。对于以下程序,它编译得很好,但是当我执行时,我收到了消息:

simple_kernel_params.cu 第 26 行出现未知错误

第 26 行是第一个 cudaMalloc 命令。

有经验的人可以提供一些提示我应该如何解决这个问题吗?非常感谢!

/*
 * Copyright 1993-2010 NVIDIA Corporation.  All rights reserved.
 *
 * NVIDIA Corporation and its licensors retain all intellectual property and 
 * proprietary rights in and to this software and related documentation. 
 * Any use, reproduction, disclosure, or distribution of this software 
 * and related documentation without an express license agreement from
 * NVIDIA Corporation is strictly prohibited.
 *
 * Please refer to the applicable NVIDIA end user license agreement (EULA) 
 * associated with this source code for terms and conditions that govern 
 * your use of this NVIDIA software.
 * 
 */


#include "../common/book.h"

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

int main( void ) {
    int c;
    int *dev_c;
    HANDLE_ERROR( cudaMalloc( (void**)&dev_c, sizeof(int) ) );

    add<<<1,1>>>( 2, 7, dev_c );

    HANDLE_ERROR( cudaMemcpy( &c, dev_c, sizeof(int),
                          cudaMemcpyDeviceToHost ) );
    printf( "2 + 7 = %d\n", c );
    HANDLE_ERROR( cudaFree( dev_c ) );

    return 0;
}

最佳答案

一些可能是问题根源的想法:

关于cudaMalloc 在 CUDA 中导致 "unknown errors",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29761036/

相关文章:

compiler-construction - 尝试让 CUDA 工作,示例找不到 helper_cuda.h

cuda - 当 block 的数量少于可用的 SM 时,如何将它们调度到 CUDA 中的 SM 中?

visual-studio-2010 - 如何让 VS 2010 识别某些 CUDA 函数

nvidia - cuda内核调用是同步的还是异步的

Cuda 多个 GPU : All GPUs the same model?

c - 我们是否需要考虑 CUDA 的缓存抖动?

matrix - 使用 CUDA 进行动态矩阵乘法

windows - 为什么 CUDA 内核无法在带有 CUDA 9.0 的 VS 2013 中启动

c++ - CUDA:为什么特定的备忘录复制操作总是比其他类似操作花费 10 倍以上

visual-studio-2010 - 如何在 Windows 上为 CUDA 链接库(例如 CUBLAS、CUSPARSE)