Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/enzyme_ad/jax/Passes/ConvertParallelToGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1886,13 +1886,12 @@ struct InnerParallelSerialization : public OpRewritePattern<scf::ParallelOp> {
if (!parallelOp->getParentOfType<enzymexla::GPUWrapperOp>()) {
return failure();
}
size_t parallelCount = 0;

size_t enclosingGpuDims = 0;
auto par = parallelOp;
while ((par = par->getParentOfType<scf::ParallelOp>())) {
parallelCount++;
}
// is presently one of the three outer parallel loops;
if (parallelCount < 2)
while ((par = par->getParentOfType<scf::ParallelOp>()))
enclosingGpuDims += par.getNumLoops();
if (enclosingGpuDims < 6)
return failure();
Comment thread
vimarsh6739 marked this conversation as resolved.
Outdated

// For a parallel loop, we essentially need to create an n-dimensional loop
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// RUN: enzymexlamlir-opt %s --pass-pipeline="builtin.module(convert-parallel-to-gpu1)" | FileCheck %s

module {
func.func @fused_siblings(%g0: index, %g1: index, %g2: index,
%b0: index, %b1: index, %b2: index,
%arg: memref<8xf64>) {
%r = "enzymexla.gpu_wrapper"(%g0, %g1, %g2, %b0, %b1, %b2) ({
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%c8 = arith.constant 8 : index
%cst = arith.constant 1.0 : f64
scf.parallel (%i0, %i1, %i2, %i3, %i4, %i5) =
(%c0, %c0, %c0, %c0, %c0, %c0) to (%g0, %g1, %g2, %b0, %b1, %b2)
step (%c1, %c1, %c1, %c1, %c1, %c1) {
scf.parallel (%j) = (%c0) to (%c8) step (%c1) {
memref.store %cst, %arg[%j] : memref<8xf64>
scf.reduce
}
scf.parallel (%k) = (%c0) to (%c8) step (%c1) {
memref.store %cst, %arg[%k] : memref<8xf64>
scf.reduce
}
scf.parallel (%l) = (%c0) to (%c8) step (%c1) {
memref.store %cst, %arg[%l] : memref<8xf64>
scf.reduce
}
scf.reduce
}
"enzymexla.polygeist_yield"() : () -> ()
}) : (index, index, index, index, index, index) -> index
return
}
}

// CHECK-LABEL: func.func @fused_siblings(
// CHECK: "enzymexla.alternatives"() ({
// CHECK: "enzymexla.gpu_error"() ({
// CHECK: scf.if %{{.*}} {
// CHECK: gpu.launch blocks(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}) threads(%{{.*}}, %{{.*}}, %{{.*}}) in (%{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}, %{{.*}} = %{{.*}}) {
// CHECK: scf.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} {
// CHECK: memref.store %{{.*}}, %{{.*}}[%{{.*}}] : memref<8xf64>
// CHECK: }
// CHECK: scf.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} {
// CHECK: memref.store %{{.*}}, %{{.*}}[%{{.*}}] : memref<8xf64>
// CHECK: }
// CHECK: scf.for %{{.*}} = %{{.*}} to %{{.*}} step %{{.*}} {
// CHECK: memref.store %{{.*}}, %{{.*}}[%{{.*}}] : memref<8xf64>
// CHECK: }
// CHECK: gpu.terminator
// CHECK: "enzymexla.polygeist_yield"() : () -> ()
// CHECK: "enzymexla.polygeist_yield"() : () -> ()