Default floating point precision with mexcuda

3 views (last 30 days)
Dear experts,
What is the default floating point precision when using mexcuda to compile a cuda project that enters from a mex file?
I am doing some image processing operations on the GPU, and the collected result differs in the order of 10^-5 per pixel when the pixel values are scaled between [0, 1]. I am trying to figure out if this could be due to (accumulating) floating point precision inaccuracy or if I need to try to spot some small bugs.
I do use doubles and not floats in my cuda kernels, but I have read that for some nvcc compiler settings the doubles might be silently cast to floats instead. What is the case with the default mexcuda settings?
I am using Matlab 2018a, Cuda Toolkit 9.0, Cuda driver 9.2 and compile with the command mexcuda -dynamic mexWrapper.cu.
Thankful for any input!

Accepted Answer

Joss Knight
Joss Knight on 3 Jul 2018
Edited: Joss Knight on 3 Jul 2018
No, the compiler never casts anything to float. There are options to use some fast math operations that are slightly less conformant to the IEEE standard (such as fast multiply add or FMAD), but this only applies to single precision maths.
Many of the image processing functions in MATLAB do however cast to single, because they assume the source image is uint8 and thus you gain only artificial accuracy from doubles; so perhaps the issue is that you're comparing your kernels to MATLAB's single precision versions.
If you want to see exactly what options are passed to nvcc by mexcuda then just use the -v verbose option. You can modify those options by editing one of the variables used, such as NVCC_FLAGS, for instance:
mexcuda mexWrapper.cu NVCC_FLAGS=--use_fast_math
  2 Comments
Sofie Lovdal
Sofie Lovdal on 20 Jul 2018
Dear Joss,
A belated thanks for your reply. It was definitely helpful to be able to rule out floating point precision issues when pinpointing the problems. Resolving a small bug made the differences between my CUDA program and the reference program smaller, but a difference still exists. I have not been able to pinpoint this, but it is within an acceptable error range. Cheers!
Joss Knight
Joss Knight on 22 Jul 2018
Most likely the answers are just equally incorrect. All floating point operations have rounding error, and when you compute on the GPU you are using a different algorithm, so you get a different, equally valid, answer.

Sign in to comment.

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!