My GPU loses memory ?

I have a little problem I don’t understand…

In the exemple below, I have a struct where I set the grid size (10).

When I want to launch my kernel with that value, I have an error “invalid configuration argument” (asif it was equal to 0). But if I launch it with a hardcoded grid size, it works fine.

What am I doing wrong ???


typedef struct


	int bar;


extern "C" void test( foo* foovar );

my .cpp:

#include "test_kernel.h"

// includes, project

#include <cutil.h>

#include <cuda.h>

#include <cuda_runtime.h>

void runTest()



	foo* foohost = (foo*)malloc(sizeof(foo));

	foohost->bar = 10;


	foo* foodevice;

	CUDA_SAFE_CALL( cudaMalloc( (void**)&foodevice, sizeof(foo) ) );

	CUDA_SAFE_CALL( cudaMemcpy( foodevice, foohost, sizeof(foo), cudaMemcpyHostToDevice ) );

	// RUN

	test( foodevice );


int main(int argc, char** argv) 


	CUT_DEVICE_INIT( argc, argv );


	CUT_EXIT(argc, argv);


my .cu:


__global__ void globaltest()




extern "C" void test( foo* foovar )


	//globaltest<<< 10, 16 >>>(); // OK

	globaltest<<< foovar->bar, 16 >>>(); // FAIL

	cudaError err = cudaGetLastError();

	if( err != cudaSuccess )


		printf( "duh! %s\n", cudaGetErrorString( err ) );



I forgot to mention that the code works fine in Emulation mode, but fails in “real” mode.

Your extern “C” void test( foo* foovar ) is a host function. Therefore, it cannot dereference the device pointer you are passing to it.

Oh I see, thanks a lot !!!