struct elements only on host howto to define a struct that has elements not used on device


I would like to define a struct which does not only have functions which are only host but also member variables. It is because I don’t need these on the device and would like to save that space on the device.

something like this

struct myStruct {

	 uint var1;

	 __host__ uint varOnlyOnHost;

	__host__ hostFunction() {

		//use varOnlyOnHost here



is there a way to get this kind of behaviour?



I don’t believe it is legal to specify memory types like that inside structures. What follows is completely idle speculation. I have absolutely no idea whether it could work or not:

nvcc speaks a little C++, so it might be possible to do something close to what you want via class inheritance, ie. define a base class which holds just the data you want to use on the device, then define derived classes from the base class which decorates it with whatever host functionality you need to add. Some casting magic and polymorphism on the part of the host can probably give you back the base class when you need to move it to GPU memory.

Just out of curiosity, how do you envision the memory transfer in such a scenario working from host to device or vice versa?