Default floating point precision with mexcuda

조회 수: 17 (최근 30일)
Sofie Lovdal
Sofie Lovdal 2018년 7월 3일
댓글: Joss Knight 2018년 7월 22일
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!

채택된 답변

Joss Knight
Joss Knight 2018년 7월 3일
편집: Joss Knight 2018년 7월 3일
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
Sofie Lovdal
Sofie Lovdal 2018년 7월 20일
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 2018년 7월 22일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by