Templated kernel with class as argument fails

I use a templated kernel that use a classe like this as parameter

#ifndef __test__
#define __test__

typedef struct
	specific data...
} test_t;

Class test
		test_t data;
		    cudaMallocManaged((void**)&data, sizeof(test_t));
		    //filling data

		__device__ double3 compute(......)
			//compute something using data
			return result; 

Each acces to data leads to crash. Why?

The problem you have is not because you are using templates - that is fine. The problem you have is not because you are using a class as a template argument - that is certainly workable in CUDA. Problems accessing data in CUDA are common, but understanding them depends on specifics that you haven’t shown. You can find numerous questions that discuss various data access problems using classes in CUDA, as well as examples of using a class as a templated kernel template argument - its all possible.

I have a weak solution : if i pass my class to a kernel and its data struct as parameter.

The only thing that’s a bit special is that I store my classes in a void* vector and do a static cast before calling them.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.