CUDA 3.0 和 cmake 以及仿真模式
我正在尝试在我的 Mac (OSX 10.6) 上使用 CUDA 和 cmake (v 2.8)。到目前为止,它运行良好,我创建了一个小样本只是为了尝试一下(见下文)。但是,当我打开仿真模式时,它无法再调用 CUDA 内核,并且收到以下错误消息:
Cuda error: kernel invoking: invalid device function 。
我还尝试通过调用 nvcc 来编译它手并没有收到错误消息,所以我认为这可能是cmake的问题。
我还注意到 CUDA 3.0 中不推荐使用仿真模式。这是为什么呢? Nvidia 在其发行说明中指出,他们在 Linux 上为 VS 和 cuda-gdb 提供了 Nexus。但是 OSX 呢?我在此处安装的 OSX 版本中找不到 cuda-gdb..?!
在文件下面
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project (test)
find_package(CUDA)
add_definitions(-Wall)
# Use CUDA emulator?
set(CUDA_BUILD_EMULATION ON)
set(CUDA_64_BIT_DEVICE_CODE OFF) # Does not work on a Mac currently
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_FLAGS -m32)
set(CUDA_VERBOSE_BUILD ON)
include_directories("${PROJECT_BINARY_DIR}")
cuda_add_executable(test
test.cu
)
test.cu
#include <cuda.h>
#include <stdlib.h>
#include <stdio.h>
#include "test_kernel.cu"
void checkCUDAError(const char *msg);
int main( int argc, const char** argv )
{
int n = 3;
float* a_h;
a_h = (float *)malloc(sizeof(float)*n);
float* a_d;
cudaMalloc((void**) &a_d, sizeof(float)*n);
hello<<<1,128>>>(a_d, n);
checkCUDAError("kernel invocation");
checkCUDAError("memcpy");
free(a_h);
cudaFree(a_d);
return 0;
}
void checkCUDAError(const char *msg)
{
cudaError_t err = cudaGetLastError();
if( cudaSuccess != err)
{
fprintf(stderr, "Cuda error: %s: %s.\n", msg,
cudaGetErrorString( err) );
exit(EXIT_FAILURE);
}
}
test_kernel.cu
#include <stdio.h>
__global__ void hello(float*a, int i)
{
int j = i+1;
#ifdef _DEVICEEMU
printf("Hello.\n");
#endif
}
I'm trying to use CUDA with cmake (v 2.8) on my Mac (OSX 10.6). So far it works fine, I created a small sample just to try it out (see below). However when I switch on emulation mode, it cannot invoke the CUDA kernel anymore and I get the following error message:
Cuda error: kernel invocation: invalid device function .
I also tried to compile it by invoking nvcc by hand and didn't get the error message, so I think it could be a problem with cmake.
I also noticed that emulation mode is deprecated in CUDA 3.0. Why is this? Nvidia points out in their release notes, that they provide Nexus for VS and cuda-gdb on Linux. But what about OSX? I could not find cuda-gdb in the OSX version I installed here..?!
Below the files
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project (test)
find_package(CUDA)
add_definitions(-Wall)
# Use CUDA emulator?
set(CUDA_BUILD_EMULATION ON)
set(CUDA_64_BIT_DEVICE_CODE OFF) # Does not work on a Mac currently
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_FLAGS -m32)
set(CUDA_VERBOSE_BUILD ON)
include_directories("${PROJECT_BINARY_DIR}")
cuda_add_executable(test
test.cu
)
test.cu
#include <cuda.h>
#include <stdlib.h>
#include <stdio.h>
#include "test_kernel.cu"
void checkCUDAError(const char *msg);
int main( int argc, const char** argv )
{
int n = 3;
float* a_h;
a_h = (float *)malloc(sizeof(float)*n);
float* a_d;
cudaMalloc((void**) &a_d, sizeof(float)*n);
hello<<<1,128>>>(a_d, n);
checkCUDAError("kernel invocation");
checkCUDAError("memcpy");
free(a_h);
cudaFree(a_d);
return 0;
}
void checkCUDAError(const char *msg)
{
cudaError_t err = cudaGetLastError();
if( cudaSuccess != err)
{
fprintf(stderr, "Cuda error: %s: %s.\n", msg,
cudaGetErrorString( err) );
exit(EXIT_FAILURE);
}
}
test_kernel.cu
#include <stdio.h>
__global__ void hello(float*a, int i)
{
int j = i+1;
#ifdef _DEVICEEMU
printf("Hello.\n");
#endif
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅
http://forums.nvidia。 com/index.php?showtopic=166570&st=0&p=1043250&#entry1043250
See
http://forums.nvidia.com/index.php?showtopic=166570&st=0&p=1043250&#entry1043250