CUDA内核不执行

时间:2014-11-28 12:55:38

标签: cuda gpu

我试图在我的电脑上开始使用CUDA 6.5。我有WIN 8.1,VS 2013终极版,VGA nvidia NVS 300.一切看起来都不错,构建过程成功完成,但是当我运行程序时,内核不会执行。例如,以下简单代码:

#include "crt/host_runtime.h"
#include <cuda.h>
#include <stdio.h>
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

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

int main() {
    int c;
    int *dev_c;
    cudaMalloc((void**)&dev_c, sizeof(int));
    add << <1, 1 >> >(1, 4, dev_c);
    cudaMemcpy(&c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
    printf("1 + 4 = %d\n", c);
    cudaFree(dev_c);
}

结果是:1 + 4 = 0

但是当我尝试执行默认代码时,会在创建new project -> NVIDIA -> CUDA 6.5时自动生成。它成功构建如下:

1>------ Build started: Project: test13, Configuration: Debug Win32 ------
1>  Compiling CUDA source file kernel.cu...
1>  
1>  c:\Users\malatrab\documents\visual studio 2013\Projects\test13>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2013 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o Debug\kernel.cu.obj "c:\Users\malatrab\documents\visual studio 2013\Projects\test13\kernel.cu" 
1>  kernel.cu
1>  test13.vcxproj -> c:\users\malatrab\documents\visual studio 2013\Projects\test13\Debug\test13.exe
1>  copy "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\cudart*.dll" "c:\users\malatrab\documents\visual studio 2013\Projects\test13\Debug\"
1>  C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\cudart32_65.dll
1>  C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\cudart64_65.dll
1>          2 file(s) copied.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

但是当我执行它时,我得到以下内容:

addKernel launch failed: invalid device function
addWithCuda failed!press any key to continue .....

以及以下内容:

'test13.exe' (Win32): Loaded 'C:\Users\malatrab\Documents\Visual Studio    2013\Projects\test13\Debug\test13.exe'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Users\malatrab\Documents\Visual Studio 2013\Projects\test13\Debug\cudart32_65.dll'. Module was built without symbols.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvcuda.dll'. Cannot find or open the PDB file.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setupapi.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nsi.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Symbols loaded.
'test13.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\dwmapi.dll'
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvapi.dll'. Cannot find or open the PDB file.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wintrust.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\crypt32.dll'. Symbols loaded.
'test13.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msasn1.dll'. Symbols loaded.
The thread 0x1dbc has exited with code 1 (0x1).
The thread 0x1820 has exited with code 1 (0x1).
The program '[1356] test13.exe' has exited with code 1 (0x1).

有没有人知道出了什么问题?

1 个答案:

答案 0 :(得分:1)

无效的设备功能错误意味着您使用错误的设备arch编译选项编译。

因此,内核无法在您的设备上运行。

据我所知,NVS 300的计算能力为1.2,但您需要通过cudaGetDeviceProperties api函数来确定它。

然后,如果它是正确的,你应该将arch编译选项设置为compute_12,sm_12在项目的属性 - > CUDA C / C ++ - &gt;设备 - &gt;代码生成。

希望这有助于解决您的问题。