GPU Programming Made Simple with Chapel

GPUs are the powerhouse of modern computing systems. Chapel’s general-purpose capabilities for parallelism and locality control makes GPU programming as easy as programming a multi-core CPU. These capabilities makes GPU programming intuitive on a laptop with a GPU, on a leadership-class supercomputer, or anything in between. Chapel supports programming NVIDIA and AMD GPUs in a vendor-neutral way; the same code can be used on GPUs from both vendors without any change.

Example: Matrix Multiplication

config const N = 2000, M = 3000, P = 4000;

var A: [1..N,1..M] real = 1.0;
var B: [1..M,1..P] real = 1.0;
var C: [1..N,1..P] real = 1.0;

forall (i,k) in C.domain {
  for j in 1..M {
    C[i,k] += A[i,j] * B[j,k];
  }
}







config const N = 2000, M = 3000, P = 4000;

var hostA: [1..N,1..M] real = 1.0;
var hostB: [1..M,1..P] real = 1.0;
var hostC: [1..N,1..P] real = 1.0;

on here.gpus[0] {
  var devA = hostA; // allocate on GPU
  var devB = hostB; // and copy from host to device
  var devC: hostC.type;

  forall (i,k) in devC.domain {
    for j in 1..M {
      devC[i,k] += devA[i,j] * devB[j,k];
    }
  }
  hostC = devC; // copy from device to host
}

Key Features of Chapel for GPU Execution