LibJacket + MATLAB/mex

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

LibJacket + MATLAB/mex

Postby malcolm » Thu Nov 03, 2011 3:56 pm

Just got a good email question about LibJacket integration with MATLAB/mex files, and thought I should post it here since it's a question that comes up frequently:
Hello,
The libjacket wiki currently sports the following text:
"Using libjacket from within Jacket/MATLAB Mex-files is currently unsupported."

I am curious to know whether this means that it is unsupported from within MATLAB+Jacket, MATLAB alone (ie executed from mex files), or both...

I expect that most of your customers who are using MATLAB are using Jacket (for MATLAB) directly, however we are in a position where our code is being migrated from MATLAB to C++ and we are using MEX files to invoke our new C++ code as we migrate pieces over. As we are not using Jacket directly within MATLAB, I was hoping that we would have the ability to make libjacket calls within our new code-base (which is invoked from MEX files). I've put together some test cases, and have had some difficulty ("Unexpected unknown exception from MEX file." in most non-trivial cases)...


We don't support LibJacket + Jacket/MATLAB/mex at all yet. The best approach here would be to use the JacketSDK with Jacket/MATLAB/mex.

It is likely that using the standard MATLAB-provided MEX interface, you could get LibJacket + MATLAB/mex to work. You'll probably want to use mexLock() to ensure 'clear all' doesn't disrupt the LibJacket memory manager.

You mention getting an unhandled exception. Be sure to wrap your LibJacket code in a try/catch (see below). Let us know what exceptions are getting thrown, and we'll work on fixing up those loose ends so things runs smoothly.

As always, thanks for being patient and giving it a try!
Jimi

Code: Select all
#include <mex.h>
#include <jacket.h>
using namespace jkt;
void mexFunction(int nlhs, mxArray **plhs, int nrhs, const mxArray **prhs)
{
    try {
        f32 a = f32::rand(4);
        display(a);
    } catch (gexception &e) {
        mexErrMsgIdAndTxt("my:code", "libjacket exception: %s", e.what());
    }
}
James Malcolm (malcolm@accelereyes.com)
User avatar
malcolm
 
Posts: 600
Joined: Sat Jun 14, 2008 11:00 pm

Return to [archive-commercial] Programming & Development with ArrayFire

cron