Skip to content

Added launch_config objects to pass kernel properties #2885

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

Open
wants to merge 1 commit into
base: SYCLomatic
Choose a base branch
from
Open
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
49 changes: 40 additions & 9 deletions clang/lib/DPCT/AnalysisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5903,7 +5903,6 @@ void KernelCallExpr::printSubmit(KernelPrinter &Printer) {
Printer << "*" << getEvent() << " = ";
}

printStreamBase(Printer);
if (isDefaultStream()) {
SubmitStmts.DefaultStreamFlag = true;
}
Expand All @@ -5912,8 +5911,12 @@ void KernelCallExpr::printSubmit(KernelPrinter &Printer) {
SubmitStmts.ImplicitSyncFlag = true;
}
if (SubmitStmts.empty()) {
if (ExecutionConfig.Properties.empty()) {
printStreamBase(Printer);
}
printParallelFor(Printer, false);
} else {
printStreamBase(Printer);
(Printer << "submit(").newLine();
printSubmitLambda(Printer);
}
Expand Down Expand Up @@ -5945,12 +5948,20 @@ void KernelCallExpr::printParallelFor(KernelPrinter &Printer, bool IsInSubmit) {
}
}
}
bool UseEnqueueFunctions = !ExecutionConfig.Properties.empty();
if (IsInSubmit) {
Printer.indent() << "cgh.";
Printer.indent();
if (!UseEnqueueFunctions) {
Printer << "cgh.";
}
}
if (!SubmitStmts.NdRangeList.empty() && DpctGlobalInfo::isCommentsEnabled())
Printer.line("// run the kernel within defined ND range");
Printer << "parallel_for";
if (UseEnqueueFunctions) {
Printer << MapNames::getExpNamespace() << "nd_launch";
} else {
Printer << "parallel_for";
}
if (DpctGlobalInfo::isSyclNamedLambda()) {
Printer << "<dpct_kernel_name<class " << getName() << "_"
<< LocInfo.LocHash;
Expand All @@ -5961,16 +5972,26 @@ void KernelCallExpr::printParallelFor(KernelPrinter &Printer, bool IsInSubmit) {
}
(Printer << "(").newLine();
auto B = Printer.block();
std::unique_ptr<KernelPrinter::Block> LaunchConfigBlock;
if (UseEnqueueFunctions) {
(Printer.indent() << (IsInSubmit ? "cgh" : ExecutionConfig.Stream) << ",")
.newLine();
}
static std::string CanIgnoreRangeStr3D =
DpctGlobalInfo::getCtadClass(MapNames::getClNamespace() + "range", 3) +
"(1, 1, 1)";
static std::string CanIgnoreRangeStr1D =
DpctGlobalInfo::getCtadClass(MapNames::getClNamespace() + "range", 1) +
"(1)";
if (ExecutionConfig.NdRange != "") {
if (UseEnqueueFunctions) {
Printer.line(MapNames::getExpNamespace() + "launch_config(");
LaunchConfigBlock = std::move(Printer.block());
}
Printer.line(ExecutionConfig.NdRange + ",");
if (!ExecutionConfig.Properties.empty()) {
Printer << ExecutionConfig.Properties << ", ";
if (UseEnqueueFunctions) {
Printer.line(ExecutionConfig.Properties + "),");
LaunchConfigBlock.reset();
}
Printer.line("[=](", MapNames::getClNamespace(), "nd_item<3> ",
getItemName(), ")", ExecutionConfig.SubGroupSize, " {");
Expand All @@ -5980,6 +6001,10 @@ void KernelCallExpr::printParallelFor(KernelPrinter &Printer, bool IsInSubmit) {
MemVarMap::getHeadWithoutPathCompression(
&(getFuncInfo()->getVarMap()))
->Dim == 1) {
if (UseEnqueueFunctions) {
Printer.line(MapNames::getExpNamespace() + "launch_config(");
LaunchConfigBlock = std::move(Printer.block());
}
DpctGlobalInfo::printCtadClass(Printer.indent(),
MapNames::getClNamespace() + "nd_range", 1)
<< "(";
Expand All @@ -5994,12 +6019,17 @@ void KernelCallExpr::printParallelFor(KernelPrinter &Printer, bool IsInSubmit) {
Printer << ", ";
Printer << ExecutionConfig.LocalSizeFor1D;
(Printer << "), ").newLine();
if (!ExecutionConfig.Properties.empty()) {
Printer << ExecutionConfig.Properties << ", ";
if (UseEnqueueFunctions) {
Printer.line(ExecutionConfig.Properties + "),");
LaunchConfigBlock.reset();
}
Printer.line("[=](" + MapNames::getClNamespace() + "nd_item<1> ",
getItemName(), ")", ExecutionConfig.SubGroupSize, " {");
} else {
if (UseEnqueueFunctions) {
Printer.line(MapNames::getExpNamespace() + "launch_config(");
LaunchConfigBlock = std::move(Printer.block());
}
Printer.indent();
Printer << MapNames::getClNamespace() + "nd_range<3>(";
if (ExecutionConfig.GroupSize == CanIgnoreRangeStr3D) {
Expand All @@ -6013,8 +6043,9 @@ void KernelCallExpr::printParallelFor(KernelPrinter &Printer, bool IsInSubmit) {
Printer << ", ";
Printer << ExecutionConfig.LocalSize;
(Printer << "), ").newLine();
if (!ExecutionConfig.Properties.empty()) {
Printer << ExecutionConfig.Properties << ", ";
if (UseEnqueueFunctions) {
Printer.line(ExecutionConfig.Properties + "),");
LaunchConfigBlock.reset();
}
Printer.line("[=](" + MapNames::getClNamespace() + "nd_item<3> ",
getItemName(), ")", ExecutionConfig.SubGroupSize, " {");
Expand Down
23 changes: 14 additions & 9 deletions clang/test/dpct/sync_api.cu
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ int main() {
// CHECK: {
// CHECK-NEXT: auto exp_props = sycl::ext::oneapi::experimental::properties{sycl::ext::oneapi::experimental::use_root_sync};
// CHECK-EMPTY:
// CHECK-NEXT: dpct::get_in_order_queue().parallel_for(
// CHECK-NEXT: sycl::nd_range<3>(sycl::range<3>(1, 1, 2) * sycl::range<3>(1, 1, 2), sycl::range<3>(1, 1, 2)),
// CHECK-NEXT: exp_props, [=](sycl::nd_item<3> item_ct1) {
// CHECK-NEXT: sycl::ext::oneapi::experimental::nd_launch(
// CHECK-NEXT: dpct::get_in_order_queue(),
// CHECK-NEXT: sycl::ext::oneapi::experimental::launch_config(
// CHECK-NEXT: sycl::nd_range<3>(sycl::range<3>(1, 1, 2) * sycl::range<3>(1, 1, 2), sycl::range<3>(1, 1, 2)),
// CHECK-NEXT: exp_props),
// CHECK-NEXT: [=](sycl::nd_item<3> item_ct1) {
// CHECK-NEXT: kernel();
// CHECK-NEXT: });
// CHECK-NEXT: }
Expand Down Expand Up @@ -193,12 +196,14 @@ int foo3() {
// CHECK-NEXT: auto exp_props = sycl::ext::oneapi::experimental::properties{sycl::ext::oneapi::experimental::use_root_sync};
// CHECK-NEXT: dpct::has_capability_or_fail(dpct::get_in_order_queue().get_device(), {sycl::aspect::fp64});
// CHECK-EMPTY:
// CHECK-NEXT: dpct::get_in_order_queue().parallel_for(
// CHECK-NEXT: sycl::nd_range<3>(sycl::range<3>(1, 1, 1), sycl::range<3>(1, 1, 1)),
// CHECK-NEXT: exp_props, [=](sycl::nd_item<3> item_ct1) {{\[\[}}sycl::reqd_sub_group_size(32){{\]\]}} {
// CHECK-NEXT: foo2();
// CHECK-NEXT: });
// CHECK-NEXT: }
// CHECK-NEXT: sycl::ext::oneapi::experimental::nd_launch(
// CHECK-NEXT: dpct::get_in_order_queue(),
// CHECK-NEXT: sycl::ext::oneapi::experimental::launch_config(
// CHECK-NEXT: sycl::nd_range<3>(sycl::range<3>(1, 1, 1), sycl::range<3>(1, 1, 1)),
// CHECK-NEXT: exp_props),
// CHECK-NEXT: [=](sycl::nd_item<3> item_ct1) {{\[\[}}sycl::reqd_sub_group_size(32){{\]\]}} {
// CHECK-NEXT: foo2();
// CHECK-NEXT: });
foo2<<<1,1>>>();
return 0;
}
Expand Down
9 changes: 6 additions & 3 deletions clang/test/dpct/sync_api_noneusm.cu
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ int main() {
// CHECK: {
// CHECK-NEXT: auto exp_props = sycl::ext::oneapi::experimental::properties{sycl::ext::oneapi::experimental::use_root_sync};
// CHECK-EMPTY:
// CHECK-NEXT: dpct::get_out_of_order_queue().parallel_for(
// CHECK-NEXT: sycl::nd_range<3>(sycl::range<3>(1, 1, 2) * sycl::range<3>(1, 1, 2), sycl::range<3>(1, 1, 2)),
// CHECK-NEXT: exp_props, [=](sycl::nd_item<3> item_ct1) {
// CHECK-NEXT: sycl::ext::oneapi::experimental::nd_launch(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use nd_launch here instead of parallel_for(launch_config...)?
By the way, if we use nd_launch, we should not use KernelPrinter; use CallExprPrinter instead.

Copy link
Contributor Author

@TejaX-Alaghari TejaX-Alaghari Jul 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parallel_for(launch_config...) is used when the work-item range is specified using sycl::range object

When sycl::nd_range object is used nd_range(launch_config...) to be used (ref)

// CHECK-NEXT: dpct::get_out_of_order_queue(),
// CHECK-NEXT: sycl::ext::oneapi::experimental::launch_config(
// CHECK-NEXT: sycl::nd_range<3>(sycl::range<3>(1, 1, 2) * sycl::range<3>(1, 1, 2), sycl::range<3>(1, 1, 2)),
// CHECK-NEXT: exp_props),
// CHECK-NEXT: [=](sycl::nd_item<3> item_ct1) {
// CHECK-NEXT: kernel();
// CHECK-NEXT: });
// CHECK-NEXT: }
Expand Down
Loading