I have a sizeable function which is used to calculate photon scattering in a liquid. This is about 900 lines of element wise operations, and lookups to arrays stored as uplevel variables, and is called using arrayfun and GPUArrays. Within this function, there are several calls to other smaller matlab functions stored in other m-files. My intention was to experiment with porting these smaller functions to CUDA C and using them as mex files. In creating a small test case for myself to make sure this would work in principle, an error is being thrown when trying to call a mex function in the body of the function that gets invoked using arrayfun. I compiled the mexGPUExample provided in the distcomp toolbox(<MATLAB directory>\toolbox\distcomp\gpu\extern\src\mex), and checked that it worked properly when called directly. When called from within an arrayfun function, i received the error.
"Error using gpuArray/arrayfun
Function passed as first input argument contains unsupported or unknown function mexGPUExample"
In the help for arrayfun (https://www.mathworks.com/help/distcomp/arrayfun.html) it states that "FUN must be a handle to a function that is written in the MATLAB language (i.e., not a MEX-function)." This is, in my case, true, unless I take it to mean that all functions called from within FUN must also be written in the MATLAB language. If this is the intended meaning, would I need to port FUN, as well as all functions called within FUN, to CUDA C in order to make any use of CUDA C?
I've given some sample code below to indicate what I'm trying to do, incase the description was unclear.