4

我正在尝试在 __global__ 函数中使用数学函数(pow),但出现此错误:

 calling a __host__ function("std::pow<float, double> ") from a __global__ function is not allowed

我试图检查项目属性->构建->设置->工具设置->优化下的“使用快速数学库”复选框,但没有运气。

我检查了 pow 函数中的类型,它们都是浮点数,我还包含了这些头文件:

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <math.h>
#include <sys/times.h>
#include <sys/resource.h>
#include <limits.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include "utils.h"

也没有 using namespace std

有想法该怎么解决这个吗?

4

1 回答 1

7

您需要更仔细地阅读错误消息。关键信息是

std::pow<float, double>

注意:<float,double>。你有pow一个双精度和单精度参数的调用。CUDA 数学库是通过选定标准库函数的模板重载实现的,但您拥有的参数没有匹配的重载。修复您的代码以具有所有双精度或所有单精度参数,并且错误将消失。

于 2013-02-07T21:07:34.867 回答