在 __global__ 函数中使用 CUDA 数学函数 - Nsight Eclipse 版 [英] Using CUDA math functions in a __global__ function - Nsight Eclipse Edition

查看:19
本文介绍了在 __global__ 函数中使用 CUDA 数学函数 - Nsight Eclipse 版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use a math function (pow) in a __global__ function but I get this error :

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

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

and I tried to check the "Make use of fast math library" check box under project properties -> build -> settings -> Tool Settings -> optimization and no luck.

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

I checked the types inside the pow function and both are floats, and I've also included these header files:

#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

also no using namespace std

关于如何解决这个问题的任何想法?

any ideas on how to fix this?

推荐答案

你需要仔细阅读错误信息.关键信息是

You need to read the error message more carefully. The key piece of information is

std::pow<float, double>

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

Note: <float,double>. You have a call to pow with a double precision and a single precision argument. The CUDA math library is implemented by template overloading of selected standard library functions, but the arguments you have don't have a matching overload. Fix you code to have either all double precision or all single precision arguments, and the error will disappear.

这篇关于在 __global__ 函数中使用 CUDA 数学函数 - Nsight Eclipse 版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆