网上搜了半天,都没有找到一篇详细总结可用于CUDA device上直接使用的数学函数的文章,于是直接去NVIDIA官方的Document中,终于搜索到了CUDA函数手册,在此整理总结,供自己和大家参考使用,先把链接整上:
- CUDA Math手册 (CUDA Math API)
- 整型数学函数 (Integer Mathematical Functions)
- 单精度数学函数(Single Precision Mathematical Functions)
还有好多类型,例如半浮点类型、双精度浮点类型等等,其他自行参考手册,很全面。
为了方便对比,这里顺便提供了C++ Math的参考手册:
- C++ Math中文简略参考手册
C++ Math官方参考手册
#include
#include "cuda_runtime.h"
math.h
库的用法相同,举几个例子:函数功能 | CPU Math | CUDA Math |
---|---|---|
单精度求平方 | float powf(float x, float y) | float powf(float x, float y) |
单精度求根号 | float sqrtf(float x) | float sqrtf(float x) |
可以看出基本都是一一对应的。
其他主要用法还是参考手册~
上一篇:Celix是什么?能做什么?