0

I'm porting some code from Matlab to run on an Nvidia GPU. I can't figure out a way to do the following:

B = max(A, 0)

where A and B are matrices. 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).

user2297560
  • 2,953
  • 1
  • 14
  • 11

1 Answers1

1

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.

user2297560
  • 2,953
  • 1
  • 14
  • 11