For the final project in this Programing Languages and Translators (PLT) course, my group implemented a MATLAB like mathematical programming language that creates executables with shared CPU and GPU computation.
The Eclipse project and complete source code can be downloaded using SVN here. You will need the ANTLR 2.7.6 plugin for Eclipse (here).
Our compiler consists of a frontend written in JAVA with the help of ANTLR, and a backend C++ library that forwards calls to the GPU via OpenGL. Compilation is a two-step process: first a source file written in Matpix is compiled into a C++ source file. Then the C++ source file is compiled and linked against the Matpix “Standard” library. The resulting executable performs branch operations and forwards all arithmetic operations to the GPU.
Matpix syntax and language features are very similar to MATLAB. Matpix has user-defined functions, matrix slicing, colon notation for ranges, and dynamic matrix resizing. All the standard arithmetic and logical operators, as well as control flow, dot product, and transpose are also included. Please see the final documentation here for a complete list of language features.
Matpix has a single Matrix type, and each matrix is initialized as a 2D texture on the GPU. The GPU computations are implemented as shader programs that perform atomic unary and binary arithmetic (and logical) operations. Dot product operations are also implemented as a separate shader program.
To highlight the ease of use of use for writing efficient programs in Matpix, we implemented a Gauss-Jordan elimination, and used this to perform a linear regression. The following example Matpix program implements a linear regression that, once compiled, will execute on the GPU. Please see the report for more details on this example (as well as implementation for the “inv” function