MATLAB: Default floating point precision with mexcuda

cudafloating point precisionmexcudaParallel Computing Toolbox

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!

Best Answer

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