1

I'm trying to start using CUDA 6.5 on my pc. I have WIN 8.1, VS 2013 ultimate, VGA nvidia NVS 300. Everything seems good, the building process completes successfully, but when I run the program the kernel does not execute. As example, the following simple code:

#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);
}

The result is: 1+4=0

But when I try to execute the default code which will generate automatically when creating new project -> NVIDIA -> CUDA 6.5. It builds successfully, as follows:

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 ==========

But when I execute it, I get the following:

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

and also the following:

'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).

Does anyone have an idea what is going wrong?

tomix86
  • 1,336
  • 2
  • 18
  • 29
mustafa
  • 11
  • 2
  • 1
    In your build command line, you specify a target compute capability of 2.0 `-gencode=arch=compute_20,code=\"sm_20,compute_20\"`, but the NVS 300 has a compute capability of 1.2. You should modify the command line accordingly. Also, you may want to add [proper error checking](http://stackoverflow.com/questions/14038589/what-is-the-canonical-way-to-check-for-errors-using-the-cuda-runtime-api). – user703016 Nov 28 '14 at 13:15

1 Answers1

1

Invalid device function error means that you compiled with wrong device arch compile option.

So, the kernel couldn't run on your device.

As I know, NVS 300's compute capability is 1.2, but you need to be sure it by cudaGetDeviceProperties api function.

Then, If it's right, you should set the arch compile option as compute_12,sm_12 at project's property->CUDA C/C++->Device->Code Generation.

Hope this helps your problem.

Wang Wang
  • 115
  • 1
  • 9
  • Finally it worked with me. Thank you very much my friends. Steps: Project properties-> Configuration properties-> CUDA C/C++ -> Device ->change the value with "compute_12,sm_12" – mustafa Nov 28 '14 at 17:42