This wrapper provides an interface between MATLAB and OpenCL in a fashion similar to that of Mathematica's OpenCLLink. Control everything in the environment, copy data back and forth, launch threads in an intuitive fashion, all organized in a class and done by simple function interface. It takes only 2 calls to compile a kernel, copy buffers, launch threads and read the data back. The class includes:
obj = OpenCLInterface - Constructor which queries all available devices.
obj.PrintDevices - Print all available devices.
obj.GetGPUDevices - Get ids of all GPU devices.
obj.GetCPUDevices - Get ids of all CPU devices.
obj.CreateFunction - Read kernel code from file or string, compile it and cache it.
obj.Run - Launch the kernel with the specified local and global workloads, scalars and buffers with their memory flags. Buffers specified as Outputs will contain the result data after execution.
Sample Program layout:
obj = OpenCLInterface;
obj.CreateFunction(deviceId,code,'KernelName');
obj.Run(globalWorkload,LocalWorkload,scalar,buffer1,MemoryFlagsOfBuffer1,buffer2,MemoryFlagsOfBuffer2);
MESC Labs (2021). OpenCL Matlab Wrapper (https://www.mathworks.com/matlabcentral/fileexchange/46826-opencl-matlab-wrapper), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
We currently assess the functionality of this wrapper against the older (unmaintained) opencl toolbox. It seems that we identified a major limitation. It seems to be required to allocate for every device buffer a host buffer. Is there a way to avoid that?