我正在尝试遵循《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;
}
最佳答案
一些可能是问题根源的想法:
- 您需要安装并加载
nvidia_uvm
内核模块(请参阅 Cuda Unknown Error(ErrNo: 30) on cudaMalloc() ) - 根据您的 CUDA 版本(可能不再相关),对 CUDA 子例程的第一次调用可能会失败(请参阅 CUDA cudaMalloc)
关于cudaMalloc 在 CUDA 中导致 "unknown errors",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29761036/