GeForce 335M + Visual Studio 2012

Hi!
I’m sorry for my English.

I have problem with CUDA on my computer (OS: Windows 7 64 bits, GPU: NVidia GeForce GT 335M).
I installed CUDA Toolkit 6.5 and used MS Visual Studio 2012. I created CUDA project, and this standart program don’t run correctly:

#include “cuda_runtime.h”
#include “device_launch_parameters.h”
#include <stdio.h>
global void add( int a, int b, int *c ) {
c = a + b;
}
int main(void) {
int c;
int dev_c;
cudaMalloc( (void
)&dev_c, sizeof(int));
add<<<1,1>>>( 2, 7, dev_c );
cudaError_t error = cudaMemcpy( &c, dev_c, sizeof(int), cudaMemcpyDeviceToHost);
printf( “2 + 7 = %d\n”, c );
printf(“error = %c”, error);
cudaFree( dev_c );

getchar();
return 0;

}

When I start the debugger in openning window:
2 + 7 = 0
and no errors. But when I start the debugger step by step, the compiler calls <vector_types.h> and refers to the following code:

struct device_builtin dim3
{
unsigned int x, y, z;
#if defined(__cplusplus)
host device dim3(unsigned int vx = 1, unsigned int vy = 1, unsigned int vz = 1) : x(vx), y(vy), z(vz) {}
host device dim3(uint3 v) : x(v.x), y(v.y), z(v.z) {}
host device operator uint3(void) { uint3 t; t.x = x; t.y = y; t.z = z; return t; }
#endif /* __cplusplus */
};

and then “No Source Availible” and generete following error:

The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: c:\users\анюта\appdata\local\temp\tmpxft_00001ba8_00000000-2_kernel.cudafe1.stub.c.
The debugger could not locate the source file ‘c:\users\анюта\appdata\local\temp\tmpxft_00001ba8_00000000-2_kernel.cudafe1.stub.c’.

I think, my processor does not see Kernel and anything methods. Why?

What am i doing wrong?
Maybe I need some additional environment settings?

Thanks, Anna

Add proper cuda error checking to your code.

Not sure what that is?

Google “proper cuda error checking”

and take the first hit.

my guess would be that you are compiling with incorrect project settings for your GPU architecture.

Thanks for your reply.
To determine the error, I changed the code of the program as follows:

//Add new method
define gpuErrchk(ans) { gpuAssert((ans), FILE, LINE); }
inline void gpuAssert(cudaError_t code, const char file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr,“GPUassert: %s %s %d\n”, cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
// and change code method _main
gpuErrchk(cudaMalloc( (void
*)&dev_c, sizeof(int)));
add<<<1,1>>>( 2, 7, dev_c );
gpuErrchk(cudaMemcpy( &c, dev_c, sizeof(int), cudaMemcpyDeviceToHost));
printf( “2 + 7 = %d\n”, c );
gpuErrchk(cudaFree( dev_c ));

But the compiler finds that there are no errors. Again, I see in the window:
2 + 7 = 0
And when I start the debugger step by step, the compiler returns the same error.

So… How I can to install project settings for my GPU architecture?

You didn’t do the error checking properly:

[url]What is the canonical way to check for errors using the CUDA runtime API? - Stack Overflow

After the kernel call, you should do something like this:

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

If you are compiling for an incorrect architecture, the error output will be something like “invalid device function”

Your GT335M GPU is a compute capability 1.2 GPU:

[url]https://developer.nvidia.com/cuda-legacy-gpus[/url]

This means you should compile with architectural switches like “compute_12,sm_12”

In VS if you create a CUDA project, I think it defaults to compute capability 2.0 (ie. “compute_20,sm_20”) This won’t work for your cc1.2 GPU.

To change these settings, go into Project…Properties…CUDA…Device

[url]How to set CUDA compiler flags in Visual Studio 2010? - Stack Overflow

Thank you. I couldn’t have done it without you.

I’m sorry, but I have a new problem. Can you help me?

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "cuPrintf.cuh"
#include "cuPrintf.cu"
#include <stdio.h>

#define N 10 

#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
{
	if (code != cudaSuccess) 
	{
		fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
		//if (abort) exit(code);
	}
}

__global__ void kernel() { 
	int tid = blockIdx.x;
	cuPrintf("Block number %d\n", tid); 
} 

int main( void ) { 
	int *dev_a; 
	gpuErrchk(cudaMalloc( (void**)&dev_a, sizeof(int) ));
	kernel<<<N,1>>>();
	gpuErrchk(cudaPeekAtLastError());
	cudaFree( dev_a );
	getchar(); 
}

I haven’t any error, but I also haven’t any result (“Block number …”).
What am i doing wrong? Why program don’t run/work?

You’re not using the cuPrintf functionality correctly. Review the cuda simple printf sample code for correct usage.

Oh! Thanks!
Correctly code:

int main( void ) {
	int *dev_a; 
	gpuErrchk(cudaMalloc( (void**)&dev_a, sizeof(int) )); 

	<b>cudaPrintfInit();</b>
	kernel<<<N,1>>>(); //вызов ядра 
	[b]cudaPrintfDisplay(stdout, true);
	cudaPrintfEnd();[/b]

	gpuErrchk(cudaPeekAtLastError());
	cudaFree( dev_a );
}