Default floating point precision with mexcuda
조회 수: 17 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
채택된 답변
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
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 Center 및 File Exchange에서 GPU Computing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!