Skip to content

[SYCL-MLIR][KernelDisjointSpecialization] Allow functions called indirectly from GPU kernel #9194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,6 @@ void KernelDisjointSpecializationPass::runOnOperation() {
setInnerDisjointAttribute(clonedFunc, isCandidateArg);

for (Operation *op : userMap.getUsers(func)) {
// Due to temporary condition to only allow function called directly by a
// GPU kernel.
assert(op->getParentOfType<gpu::GPUFuncOp>() &&
"Expecting calls only in GPU kernel");

auto call = cast<CallOpInterface>(op);
versionCall(call);

Expand All @@ -221,13 +216,6 @@ bool KernelDisjointSpecializationPass::isCandidateFunction(
return false;
}

// Temporary condition to only allow function called directly by a GPU kernel.
// TODO: allow maximum depth of 2.
Optional<unsigned> maxDepth = polygeist::getMaxDepthFromAnyGPUKernel(func);
assert(maxDepth.has_value() && "Expecting valid maxDepth");
if (maxDepth != 1)
return false;

unsigned numCandidateArgs = count_if(func.getArguments(), isCandidateArg);
if (numCandidateArgs < 2) {
LLVM_DEBUG(llvm::dbgs().indent(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
gpu.module @device_func {
// COM: This function is a candidate, check that it is transformed correctly.
// CHECK-LABEL: func.func private @callee1.specialized(
// CHECK-SAME: %arg0: memref<?x!sycl_accessor_1_f32_r_gb> {sycl.inner.disjoint},
// CHECK-SAME: %arg0: memref<?x!sycl_accessor_1_f32_r_gb> {sycl.inner.disjoint},
// CHECK-SAME: %arg1: memref<?x!sycl_accessor_1_f32_w_gb> {sycl.inner.disjoint})
// CHECK-LABEL: func.func private @callee1(
// CHECK-SAME: %arg0: memref<?x!sycl_accessor_1_f32_r_gb>,
// CHECK-SAME: %arg0: memref<?x!sycl_accessor_1_f32_r_gb>,
// CHECK-SAME: %arg1: memref<?x!sycl_accessor_1_f32_w_gb>)
// CHECK-LABEL: gpu.func @caller1(%arg0: memref<?x!sycl_accessor_1_f32_r_gb>, %arg1: memref<?x!sycl_accessor_1_f32_w_gb>) kernel {

Expand Down Expand Up @@ -150,4 +150,35 @@ gpu.module @device_func {
func.call @callee3(%arg0, %arg1) : (memref<?x!sycl_accessor_2_f32_r_gb>, memref<?x!sycl_accessor_2_f32_w_gb>) -> ()
gpu.return
}

// COM: Check callee (@callee4) called indirectly from GPU kernel (@wrapper4).
// CHECK-LABEL: func.func private @callee4.specialized(
// CHECK-SAME: %arg0: memref<?x!sycl_accessor_1_f32_r_gb> {sycl.inner.disjoint},
// CHECK-SAME: %arg1: memref<?x!sycl_accessor_1_f32_w_gb> {sycl.inner.disjoint})
// CHECK-LABEL: func.func private @callee4(
// CHECK-SAME: %arg0: memref<?x!sycl_accessor_1_f32_r_gb>,
// CHECK-SAME: %arg1: memref<?x!sycl_accessor_1_f32_w_gb>)
// CHECK-LABEL: func.func @caller4(%arg0: memref<?x!llvm.struct<(!sycl_accessor_1_f32_r_gb, !sycl_accessor_1_f32_w_gb)>>) {
// CHECK: scf.if %{{.*}} {
// CHECK-NEXT: func.call @callee4.specialized(%0, %1) : (memref<?x!sycl_accessor_1_f32_r_gb>, memref<?x!sycl_accessor_1_f32_w_gb>) -> ()
// CHECK-NEXT: } else {
// CHECK-NEXT: func.call @callee4(%0, %1) : (memref<?x!sycl_accessor_1_f32_r_gb>, memref<?x!sycl_accessor_1_f32_w_gb>) -> ()
// CHECK-NEXT: }
// CHECK-LABEL: gpu.func @wrapper4(%arg0: memref<?x!llvm.struct<(!sycl_accessor_1_f32_r_gb, !sycl_accessor_1_f32_w_gb)>>) kernel {
// CHECK-NEXT: sycl.call @caller4(%arg0)
func.func private @callee4(%arg0: memref<?x!sycl_accessor_1_f32_r_gb>, %arg1: memref<?x!sycl_accessor_1_f32_w_gb>) {
return
}
func.func @caller4(%arg0: memref<?x!llvm.struct<(!sycl_accessor_1_f32_r_gb, !sycl_accessor_1_f32_w_gb)>>) {
%c0 = arith.constant 0 : index
%c1 = arith.constant 1 : index
%0 = "polygeist.subindex"(%arg0, %c0) : (memref<?x!llvm.struct<(!sycl_accessor_1_f32_r_gb, !sycl_accessor_1_f32_w_gb)>>, index) -> memref<?x!sycl_accessor_1_f32_r_gb>
%1 = "polygeist.subindex"(%arg0, %c1) : (memref<?x!llvm.struct<(!sycl_accessor_1_f32_r_gb, !sycl_accessor_1_f32_w_gb)>>, index) -> memref<?x!sycl_accessor_1_f32_w_gb>
func.call @callee4(%0, %1) : (memref<?x!sycl_accessor_1_f32_r_gb>, memref<?x!sycl_accessor_1_f32_w_gb>) -> ()
return
}
gpu.func @wrapper4(%arg0: memref<?x!llvm.struct<(!sycl_accessor_1_f32_r_gb, !sycl_accessor_1_f32_w_gb)>>) kernel {
sycl.call @caller4(%arg0) {MangledFunctionName = @caller4, TypeName = @RoundedRangeKernel}: (memref<?x!llvm.struct<(!sycl_accessor_1_f32_r_gb, !sycl_accessor_1_f32_w_gb)>>) -> ()
gpu.return
}
}