cuda - 使用 CUDA Thrust 进行逐元素幂运算

标签 cuda thrust

有没有办法用 pow 来转换推力矢量?功能?换句话说,我想变换每个元素x向量到pow(x,a) ,与 a一个常数。

最佳答案

请引用Section Transformations在 Thrust 快速入门指南中了解如何编写具有初始化参数的仿函数。

struct saxpy_functor
{
    const float a;

    saxpy_functor(float _a) : a(_a) {}

    __host__ __device__
        float operator()(const float& x, const float& y) const { 
            return a * x + y;
        }
};

关于cuda - 使用 CUDA Thrust 进行逐元素幂运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14353459/

相关文章:

cuda - cublasInit() 什么时候返回 NOT_INITIALIZED 状态?

c++ - 如何使用 CUDA Thrust 执行策略覆盖 Thrust 的低级设备内存分配器

foreach - 如何解决 CUDA Thrust 库 - for_each 同步错误?

memory-management - 了解 Thrust (CUDA) 内存使用情况

c - 分段故障 CUDA-C

python - 在 pyCUDA 中使用 CUDA 类型

cuda - 如何使用 Nsight 读取 CUDA 动态并行的分析结果

c++ - Cusparse 非法内存访问,除非我增加稀疏矩阵的稀疏性

c++ - 使用推力(素数)在 GPU 中编译

c++ - 在 Thrust 的仿函数中使用附加数据字段的最佳方式是什么?