Firstly: you can call back into MATLAB from your generated C code or generated MEX file, using coder.extrinsic
. If for some reason you have an existing MEX file without source code that you need to call, you can do this in the same way as for any other MATLAB command.
Secondly: if you have some existing C source code that you would like to call from your generated C code or generated MEX file, you can do so with a call to coder.ceval
.
I don't think there's a reason you couldn't do that with OpenCL code, although if you're looking to take advantage of GPU code I would think that the built-in GPU functionality from Parallel Computing Toolbox would be more convenient.