Skip to content

Pattern Interface programming methodology

Dinei A. Rockenbach edited this page Feb 26, 2024 · 2 revisions

We recommend programmers follow the methodology described here when using GSParLib Pattern Interface.

Map pattern

To use the Map pattern, programmers may follow three simple steps:

  1. identify where are the stateless data-parallel regions of the code to apply the Map pattern;
  2. check whether the operation computed in the data-parallel region is compatible with CUDA C or OpenCL C, which is a requirement for GSParLib's GPU kernel code; and
  3. define the Map pattern object with the GPU kernel core, configure the desired properties such as batch size and device to be used when executing the pattern, and set the pattern's parameters.

In the following image we use the GSPAR_STRINGIZE_SOURCE macro to pass the GPU kernel code to the pattern, which is a code wrapper.

Methodology to use GSParLib's Map pattern

Reduce pattern

The methodology to use the Reduce pattern comprises two steps:

  1. check if there is a data container that is being reduced to a single value by a binary associative and commutative operator; and
  2. define the Reduce pattern object with the output name, input name, and operator, configure the desired properties such as the device to be used when executing the pattern, and set the pattern's parameters.

In the following image we are setting total as the output name, vec as the input name, and + as the operator.

Methodology to use GSParLib's Reduce pattern

Using GSParLib Pattern Interface on sequential code

The following image illustrates applying these steps in a simple sequential vector sum function. We highlighted the GSParLib code in blue. The first step is to identify the stateless data-parallel regions of the code, which is the for loop that performs the vector summation. In the second step, we check if the operation (highlighted by a dashed orange box) is compatible with CUDA or OpenCL GPU kernel code. This operation is compatible with both backends. In the third step, we define the pattern with the operation from the second step. After defining the pattern, we set the parameters and run it using the size variable. This simple example demonstrates the application of GSParLib in sequential source code, which does not involve multi-core parallelism.

Applying the methodology on a sample Vector Sum algorithm

Clone this wiki locally