两个几乎相同的呼叫,一个工作一个失败

And*_*edd 2 c++ templates cuda

我有这些模板功能,可以在设备上使用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);};
Run Code Online (Sandbox Code Playgroud)

在我的代码中

cmin(z[i],y[j])-cmax(x[i],z[j])
Run Code Online (Sandbox Code Playgroud)

对于int数组x,y和z.我收到错误:

错误:没有函数模板"cmax"的实例与参数列表匹配

      argument types are: (int, int)
Run Code Online (Sandbox Code Playgroud)

我得到cmax但不是cmin的错误.如果我更换cmax线

#define cmax(a,b) ((a)>(b))?(a):(b)
Run Code Online (Sandbox Code Playgroud)

工作正常,但我不想#defines,他们是有问题的.到底发生了什么事?

编辑:这是完整的调用功能.times是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***/
}
Run Code Online (Sandbox Code Playgroud)

asc*_*ler 7

Iy += cmax(0,imin-imax);
Run Code Online (Sandbox Code Playgroud)

不合法.您不能将文字绑定0int&引用(但您const int&可以引用).