I have these template functions for use inline on device with cuda
template <class T> __device__ inline T& cmin(T&a,T&b){return (a<b)?(a):(b);};
template <class T> __device__ inline T& cmax(T&a,T&b){return (a>b)?(a):(b);};
In the code I have
cmin(z[i],y[j])-cmax(x[i],z[j])
for int arrays x,y,and z. I get the error:
error: no instance of function template "cmax" matches the argument list
argument types are: (int, int)
I get the error for cmax but not cmin. If I replace the cmax line with
#define cmax(a,b) ((a)>(b))?(a):(b)
that works just fine, but I don't want #defines, they are problematic. What the heck is going on here?
EDIT: here is the full calling function. times is typedef int.
__global__ void compute_integral_y_isums(times * admit, times * discharge, times * Mx, times * isums, ar_size N){
// computes the sums for each j
// blocks on j,
// threads on i since we will be summing over i.
// sumation over J should be handled by either a different kernel or on the cpu.
ar_index tid = threadIdx.x;
ar_index i = blockIdx.x; // summing for patient i
ar_index j = threadIdx.x; // across other patients j
__shared__ times cache[threadsPerBlock];
times Iy = 0;
while(j<N){
// R code: max(0,min(Mx[i],d3[j,'Discharge.time'])-max(d3[i,'Admission.time'],Mx[j]))
times imin = cmin(Mx[i],discharge[j]);
times imax = cmax(admit[i],Mx[j]);
Iy += cmax(0,imin-imax);
j += blockDim.x;
}
cache[tid] = Iy;
__syncthreads();
// reduce
/***REMOVED***/
}