#include <algorithm>
#include <vector>
template <typename Dtype>
__global__ void R_D_CUT(const int n, Dtype* r, Dtype* d
, Dtype cur_r_max, Dtype cur_r_min, Dtype cur_d_max, Dtype cur_d_min) {
CUDA_KERNEL_LOOP(index, n) {
r[index] = __min(cur_r_max, __max(r[index], cur_r_min));
d[index] = __min(cur_d_max, __max(d[index], cur_d_min));
}
}
In above code, it can work well in Window. However, it does not work in Ubuntu due to __min
and __max
function. To fix it by replace __min
to std::min<Dtype>
and max
to std::max<Dtype>
:
template <typename Dtype>
__global__ void R_D_CUT(const int n, Dtype* r, Dtype* d
, Dtype cur_r_max, Dtype cur_r_min, Dtype cur_d_max, Dtype cur_d_min) {
CUDA_KERNEL_LOOP(index, n) {
r[index] = std::min<Dtype>(cur_r_max, std::max<Dtype>(r[index], cur_r_min));
d[index] = std::min<Dtype>(cur_d_max, std::max<Dtype>(d[index], cur_d_min));
}
}
However, when I recompile, I got the error
_layer.cu(7): error: calling a __host__ function("std::min<float> ") from a __global__ function("caffe::R_D_CUT<float> ") is not allowed
_layer.cu(7): error: calling a __host__ function("std::max<float> ") from a __global__ function("caffe::R_D_CUT<float> ") is not allowed
_layer_layer.cu(8): error: calling a __host__ function("std::min<float> ") from a __global__ function("caffe::R_D_CUT<float> ") is not allowed
_layer_layer.cu(8): error: calling a __host__ function("std::max<float> ") from a __global__ function("caffe::R_D_CUT<float> ") is not allowed
_layer_layer.cu(7): error: calling a __host__ function("std::min<double> ") from a __global__ function("caffe::R_D_CUT<double> ") is not allowed
_layer_layer.cu(7): error: calling a __host__ function("std::max<double> ") from a __global__ function("caffe::R_D_CUT<double> ") is not allowed
_layer_layer.cu(8): error: calling a __host__ function("std::min<double> ") from a __global__ function("caffe::R_D_CUT<double> ") is not allowed
_layer_layer.cu(8): error: calling a __host__ function("std::max<double> ") from a __global__ function("caffe::R_D_CUT<double> ") is not allowed
Could you help me to fix it? Thanks