Search code examples
matlabopenclmex

matlab mex with opencl for amd


Is there any way to have a mex routine for matlab with opencl C++ code. I have done earlier C++ CUDA codes and mexed it with MATLAB. I havent been able to do the same with OpenCl. I have an ATI Graphics card which supports OpenCl. Is that the issue that matlab runs only with nvidia graphics card? Can anyone help me with this situation


Solution

  • In short, yes. You should be able to call OpenCL through mex. Mex files are effectively just .dll files, so anything you can do outside of the mex gateway you should be able to do in it. There are a few exceptions in how the mex gateway defines and redefines some things that are not thread safe (printf called from inside a mex file for instance), but you should be able to work around that.

    You should be aware that occasionally there are issues associated with position independent code with OpenCL. Depending on how your OpenCL libraries have been compiled, you may need to recompile them with -fPIC as discussed in this blog post (which describes working with mex and opencl in combination).

    If after working up some equivalent to a "Hello OpenCL World" program you have a snag or error, then repost on that and we should be able to help.

    Happy hacking.