我有这些模板函数可以在带有 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);};
在我的代码中
cmin(z[i],y[j])-cmax(x[i],z[j])
对于 int 数组 x、y 和 z。我收到错误:
error: no instance of function template "cmax" matches the argument list
argument types are: (int, int)
我收到 cmax 错误,但没有收到 cmin 错误。如果我用
替换 cmax 行#define cmax(a,b) ((a)>(b))?(a):(b)
工作得很好,但我不想要#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***/
}
最佳答案
Iy += cmax(0,imin-imax);
不合法。您不能将文字 0
绑定(bind)到 int&
引用(但可以绑定(bind)到 const int&
引用)。
关于c++ - 两个几乎相同的调用,一个有效,一个失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4054458/