floating point exception while running mexcuda file / then Segmentation Vioaltion

Hi,
I have a question regarding running a matlab file that calls mexcuda function.
I have a c code that I compiled as a mexfile in matlab and called in matlab and it ran well. When I tried to convert this file to cuda ,initially by adding the gpuInit() and including the required libraries, it's compiled well with mexcuda code.cu, but when calling it as a function within the matlab code, it causes a run-time error (floating point exception). What could be the problem?
Please note that my cuda compiler is 7.5, and I made sure that some cuda examples ,like mexGPUExample provided in mathworks, works well.
Thank you in advance.

2 Comments

I'm afraid you'll have to show us the code.
Thank you for ur reply! please read my update down as an answer, I hope you can help.

Sign in to comment.

Answers (1)

I sent the input image to the cuda mex function as a gpuArray and I received it by mxGPUCreateFromMxArray(prhs[0]);and then read it by mxGPUGetDataReadOnly. This helped getting red of floating point error. But now a segmentation violation run-time error occurs , and after tracking its source, it becomes clear that the variable I received from mxGPUCreateFromMxArray(prhs[0]) and read by mxGPUGetDataReadOnly causes it but I don't know why. It is of type (unsigned char *)that reads the mxGPUArray that should be already received from mxGPUCreateFromMxArray(prhs[0]).
>>Inside mexFunction:
mxGPUArray const * imgbytesgpup;
unsigned char* d_imgbytes;
imgbytesgpup=mxGPUCreateFromMxArray(prhs[0]);
d_imgbytes=(unsigned char*)(mxGPUGetDataReadOnly(imgbytesgpup)); :
:
>>Then the segmentation violation happens when trying to read d_imgbytes (to print it or to assign it to another variable).
Is it a memory issue that happens while transfering the input image to the cuda mex file? Checking the GPU memory in matlab shows me that my GPU available memory becomes NaN after each single run, so each time I free it before running it. Another question, is it mandatory to send my image from matlab to the cuda mex function as gpuArray? as when I were using : imgbytes = (unsigned char*)mxGetData(prhs[0]) ; A floating point error occurs
I'd be grateful if anyone has an idea of the potential reasons.
Thank you in advance.

Asked:

on 11 Jun 2017

Commented:

on 15 Jun 2017

Community Treasure Hunt

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

Start Hunting!