Skip to content

Commit 451b21b

Browse files
committed
[SYCL] Fix kernel name mangling for CUDA/HIP offload with shared libraries
SYCL kernel names are generated during template instantiation using MangleContext. When using SYCL offload to CUDA/HIP, kernel names must be consistent across compilation units, including shared libraries compiled separately. Previous approach only handled cross-ABI scenarios (Microsoft host + Itanium device). This left same-ABI scenarios (Itanium host + Itanium device) broken for shared libraries, as each compilation unit would generate different lambda numbering, resulting in runtime errors: No kernel named _ZTSZZ21performIncrementationENK... was found Solution: For SYCL offload compilation, always use createDeviceMangleContext() instead of createMangleContext(). Device mangling context uses DeviceLambdaManglingNumbers which provides globally consistent lambda numbering across compilation units. This ensures identical kernel names for: - Cross-ABI: Microsoft host + Itanium device (Windows + CUDA/HIP) - Same-ABI: Itanium host + Itanium device (Linux + CUDA/HIP) - Shared libraries compiled separately (.so/.dll) Fixes CMPLRLLVM-69642 Fixes CMPLRLLVM-69415
1 parent 307759c commit 451b21b

File tree

4 files changed

+9
-11
lines changed

4 files changed

+9
-11
lines changed

a.out

681 KB
Binary file not shown.

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7734,18 +7734,19 @@ static void processFunctionInstantiation(Sema &S,
77347734
}
77357735

77367736
static std::unique_ptr<MangleContext> createSYCLMangleContext(ASTContext &Ctx) {
7737-
// For SYCL compilation, ensure kernel name mangling is consistent between
7738-
// host and device compilations when targeting CUDA/HIP backends.
7739-
// When the host uses Microsoft ABI and device uses Itanium ABI, we need
7740-
// to use device-aware mangling context on the host side.
7737+
// For SYCL offload compilation (CUDA/HIP), always use device mangling context
7738+
// to ensure consistent kernel name mangling across compilation units.
7739+
// Device lambda numbering is tracked globally via DeviceLambdaManglingNumbers,
7740+
// which provides stable numbering even for shared libraries compiled separately.
7741+
// This solves both cross-ABI scenarios (Microsoft host + Itanium device) and
7742+
// same-ABI scenarios (Itanium host + Itanium device) where separate compilation
7743+
// would otherwise produce different lambda numbers.
77417744
const TargetInfo *AuxTarget = Ctx.getAuxTargetInfo();
7742-
if (AuxTarget && Ctx.getTargetInfo().getCXXABI().isMicrosoft() &&
7743-
AuxTarget->getCXXABI().isItaniumFamily()) {
7744-
// Host compilation with Microsoft ABI targeting Itanium device
7745+
if (AuxTarget) {
77457746
return std::unique_ptr<MangleContext>(
77467747
Ctx.createDeviceMangleContext(*AuxTarget));
77477748
}
7748-
// All other cases: use standard mangling for the primary target
7749+
// No offload target: use standard mangling
77497750
return std::unique_ptr<MangleContext>(Ctx.createMangleContext());
77507751
}
77517752

string_test_executable

682 KB
Binary file not shown.

sycl/test-e2e/IntermediateLib/multi_lib_app.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// UNSUPPORTED: cuda || hip
2-
// UNSUPPORTED-TRACKER: CMPLRLLVM-69415
3-
41
// DEFINE: %{fPIC_flag} = %if windows %{%} %else %{-fPIC%}
52
// DEFINE: %{shared_lib_ext} = %if windows %{dll%} %else %{so%}
63

0 commit comments

Comments
 (0)