chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.8k stars 422 forks source link

Column-major ordering #6814

Open apanqasem opened 7 years ago

apanqasem commented 7 years ago

Chapel standard release currently does not provide support for Column-major ordering (CMO) of multi-dimensional arrays.

Language-level support for automatic layout conversion is becoming increasingly important in the context of heterogenous computing. For instance, the performance of the forall loop in the code below will be impacted (potentially by integer factors) by (i) whether data and computation is mapped to host (CPU) or device (GPU) and (ii) if dom follows a row-major or column-major ordering.

  var rows = 1..1024;
  var cols = 1..1024;

  var dom : domain(2) = {rows, cols};

  var A : [dom] real;
  var B : [dom] real;

  forall i in rows {
     for j in cols {
       B[i,j] = A[i,j];
     }
  }

One approach to implementing this feature (suggested by @bradcray) is to have the DefaultRectangular layout take a param argument indicating whether to use row- or column-major order. This can then be invoked as follows

param CMO : bool = true;
var dom : domain(2) dmapped DefaultDist(CMO) = {rows, cols};

The parameter value would dictate if the domains (and access functions) should be reversed (CMO). This approach is probably the least invasive.

Calling DefaultDist() to change the layout might be somewhat counter-intuitive. Another approach is to create a new layout module and invoke it as follows

  var dom : domain(2) dmapped ColMajor() = {rows, cols};

The above would entail a lot code duplication, however.

vasslitvinov commented 3 years ago

@bradcray have we implemented this?

bradcray commented 3 years ago

@vasslitvinov : @daviditen added some support for RMO vs. CMO in https://github.com/chapel-lang/chapel/pull/11316 but I don't know how much testing it's received since then, and from a quick read of the PR's OP, it's not clear to me whether or not it was complete at the time it was merged.