358 Accelerating MATLAB
®
Performance
These static optimizations are available through two functions, which can be used inter-
changeably: gcompile and arrayfun. gcompile accepts both strings and function handles,
while arrayfun requires function handles. In practice, using gcompile directly can yield
a few percent performance improvement as it avoids some caching checks that arrayfun
incurs. There are two ways for invoking gcompile on MATLAB code. The rst is by using
the M-le convention as follows:
my_fn = gcompile('filename.m'); % compile function to a CUDA kernel
[A, B,...] = my_fn(C,...) % call the compiled function
Alternatively, one can inline function code directly to gcompile statement:
my_fn = gcompile(verbatim);
%{
function