Jacket Basics
From Jacket Wiki
Back to Installation and Activation, Forward to Jacket by Example
Contents |
Introduction
GPU computing with the Jacket starts at the most basic level through the replacement of low-level data structures which normally reside on the CPU with data structures that reside on the GPU. Any functions called on Jacket's GPU matrices result in GPU computation and acceleration. One of Jacket's key values is its transparency for MATLAB users. The only thing you have to know in order to get started with the GPU is the following information on casting CPU data structures to GPU data structures.
Casting to the GPU
Once you have correctly installed Jacket, you will be able to create GPU data structures in the same way that CPU data structures are created. The functions in the following table are used to create GPU data structures:
| Jacket Function | Description | Example |
| GSINGLE | Casts a CPU matrix to a single precision floating point GPU matrix. | A = gsingle(B); |
| GDOUBLE | Casts a CPU matrix to a double precision floating point GPU matrix. | A = gdouble(B); |
| GLOGICAL | Casts a CPU matrix to a binary GPU matrix. All non zero values are set to '1'. The input matrix can be a GPU or CPU datatype. | A = glogical(B); A = glogical(0:4); |
| GINT8, GUINT8, GINT32, GUINT32 | Cast a CPU matrix to a signed and unsigned 8-bit or 32-bit integer GPU matrix respectively. | A = gint8(B); A = guint8(B); A = gint32(B); A = guint32(B); |
| GZEROS, ZEROS | Create a matrix of zeros on the GPU. | A = gzeros(5,'double'); A = zeros(2,6,gdouble); |
| GONES, ONES | Create a matrix of ones on the GPU. | A = gones(5,'double'); A = ones([3 9], gdouble); |
| GEYE | Creates an identity matrix on the GPU. | A = geye(5); |
| GRAND or RAND | Creates a random matrix on the GPU, with uniformly distributed pseudorandom numbers. | A = grand(5,'double'); A = rand(5,gdouble); |
| GRANDN | Creates a random matrix on the GPU, with normally distributed pseudorandom numbers. | A = grandn(5,'double'); A = randn(5,gdouble); |
Once a GPU data structure has been created, any operations on that GPU matrix are performed on the GPU rather than the CPU. To turn off GPU computation, simply cast the data back to the CPU using one of the CPU data types, e.g. DOUBLE. These functions are used as follows:
A = gdouble( B ); % to push B to the GPU from the CPU B = double( A ); % to pull A from the GPU back to the CPU
Additional Jacket Functions
Additional Jacket functions that you will want to be familiar with are:
| Jacket Function | Description | Example |
| GHELP | Retrieve information on the Jacket support for any function. | ghelp sum; |
| GACTIVATE | Used for manual activation of a Jacket license. | gactivate; |
| GVER | Information on the system, the MATLAB version and toolboxes, the Jacket version, and addons present. | gver; |
| GVERSION | Outputs the Jacket version and build revision number. | gversion; |
| GINFO | Information on Jacket run-time and detected graphics cards. | ginfo; |
| GSELECT | Select or query which GPU is in use. | gselect(1); |
| GFOR | Executes FOR loop in parallel on GPU. | gfor n = 1:10; % loop body gend; |
| GCOMPILE | Compile M-code directly into a single CUDA kernel. | my_fn = gcompile('filename.m'); [B C ...] = my_fn(A) |
| GPROFILE | Profile code to compare CPU versus GPU runtimes. | gprofile on; foo; gprofile off; gprofile report; |
| GPROFVIEW | Visual representation of profiling data. | gprofview; |
| GEVAL | Evaluate computation and leave results on GPU. | geval; |
| GSYNC | Block until all queued GPU computation is complete. | gsync(A); |
| GLAUNCH | Prototype, execute, and benchmark CUDA kernels within M-files. | glaunch; |
| GMEX | Compile GPU-enabled MEX files using the Jacket SDK (in Windows). | gmex [options] source.cu; |
| GCACHE | Save GPU compiled code for given script. | gcache; |
| GLOAD | Load from disk directly into the GPU. Requires the Jacket SDK. | gload('filename'); |
| GSAVE | Save data to disk as text file directly from the GPU. Requires the Jacket SDK. | gsave('filename', A); |
| GREAD | Load from disk directly into the GPU, with option to specify the byte range. Requires the Jacket SDK. | gread('filename', OFFSET, BYTES); |
| GWRITE | Save data to disk directly from the GPU, with option to specify the byte range. Requires the Jacket SDK. | gwrite('filename', OFFSET, DATA); |
| Graphics Library | Functions contained in the Graphics Library. | gplot(A); |
Timing Jacket
When timing Jacket code, you need to take care of a variety of factors (such as warming up the GPU, lazy execution etc). To time your code without having to worry about these factors, use TIMEIT.
Jacket Function List
An alphabetical list of functions related to Jacket is provided in the Jacket Function List.
Forward to Jacket by Example