如何使用数值函数和CUDA

时间:2015-08-04 18:16:40

标签: c++ cuda

以下结构帮助我计算最小值。我打算在主机和GPU上使用这个结构。如果为CUDA编译,则CUDA_FUNC将替换为__device__

struct Min{

    template <class T>
    CUDA_FUNC static T init(){
        return std::numeric_limits<T>::max();
    }

    template <class T>
    CUDA_FUNC static T reduce(T a, T b){
        return std::min(a, b);
    }

};

现在,编译器告诉我它不能在内核中使用std :: min,因为它是一个宿主函数,这并不奇怪。当我删除std::时,当然我不能在不使用CUDA时编译。

那么对于一个应该能够为CUDA编译以及没有CUDA的类来使用这个min函数的正确方法是什么?

0 个答案:

没有答案