简体   繁体   English

矩阵最大在Matlab上的Matlab

[英]matrix max a la matlab on gpu

I'm porting some code from Matlab to run on an Nvidia GPU. 我正在从Matlab移植一些代码以在Nvidia GPU上运行。 I can't figure out a way to do the following: 我想不通以下方法:

B = max(A, 0)

where A and B are matrices. 其中A和B是矩阵。 In words, I need to replace negative values in a matrix with zeros. 换句话说,我需要将矩阵中的负值替换为零。 I know how to write a kernel function to do with, but I'd like to stick with cuBLAS or magma calls if possible (to avoid adding nvcc to my build process). 我知道如何编写与之相关的内核函数,但如果可能的话,我想坚持使用cuBLAS或岩浆调用(以避免在构建过程中添加nvcc)。

I've come up with something using thrust: 我想出了一些推力的方法:

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

If this is incorrect, or if there is a better solution I'm open for other suggestions. 如果这不正确,或者有更好的解决方案,我欢迎您提出其他建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM