I am trying to understand how template is being used here:
template <uint32_t N_ATOMIC=32>
struct ParallelCounter {
public:
uint32_t count[N_ATOMIC];
// spread the counts across the counter
__device__ __host__ void set(uint32_t x) {
for(int i=0; i < N_ATOMIC; i++) count[i]=x/N_ATOMIC;
}
};
#ifndef SPREAD
#define SPREAD 32
#endif
__device__ ParallelCounter<SPREAD> myCounter;
__global__ void initCounter() {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
if(tid == 0)
myCounter.set(0);
}
All the examples on templates that I have seen so far have some variable in < > in first line above. But why we are having a constant uint32_t N_ATOMIC=32 here. if it is a constant, how would the template be useful? It is fixed for a particular type. Am I right? Thanks