matrix max a la matlab on gpu

时间:2017-03-29 12:35:50

标签: blas cublas magma

我从Matlab移植一些代码以在Nvidia GPU上运行。我无法找到一种方法来执行以下操作:

B = max(A, 0)

其中A和B是矩阵。换句话说,我需要用零替换矩阵中的负值。我知道如何编写一个内核函数,但是如果可能的话,我想坚持使用cuBLAS或magma调用(以避免在构建过程中添加nvcc)。

1 个答案:

答案 0 :(得分:1)

我用推力想出了一些东西:

thrust::transform(A, A + m*n, [](double x) { thrust::max(x,0.0); });

如果这不正确,或者有更好的解决方案,我可以提供其他建议。