Re-defining built-in types (ex threadIdx.x,...) for __host__ compilation [unit testing]

We’re looking to redefine build-in types for compilation on the host, but have been running into some compilation issues.

Basically we want to do something like this:

// Dummy sample
__host__ __device__ float d_some_function(volatile float* smem_ptr)
 float a = smem_ptr[threadIdx.x];
 float b = smem_ptr[threadIdx.x+1];

 return a*b;


By doing this we could run the same code on the host and just update a global variable “threadIdx” with new values in a loop iterator.

An easy way out seems to be to just redefine:

#ifndef __CUDA_ARCH__
extern uint3 thread_idx;
#define threadIdx thread_idx

But honestly, it’s just not as sleek is it? :)