Skip to content

[SYCL] clang-offload-bundler returns the first architecture's device code for every intel_gpu_* target #23487

Open

Description

@srividya-sundaram

Describe the bug

With several Intel GPU (or NVIDIA) SYCL targets and separate compile and link in the old offloading model, every architecture gets the device code of the first one.

For example:

clang++ -fsycl -fsycl-targets=intel_gpu_tgllp,intel_gpu_pvc -c foo.cpp -o foo.o
clang++ -fsycl foo.o -o foo

foo.o stores the device code of each GPU under its own bundle ID, sycl-spir64_gen-unknown-unknown-tgllp and sycl-spir64_gen-unknown-unknown-pvc. When the link step extracts the PVC entry, clang-offload-bundler returns the TGLLP entry instead:

clang-offload-bundler -type=o -unbundle -targets=sycl-spir64_gen-unknown-unknown-pvc -input=foo.o -output=pvc.o
# pvc.o contains the TGLLP device code

With -fno-sycl-rdc, running on PVC then fails with:

Kernel ... has no image for the selected device. Its available images target: [intel_gpu_tgllp, intel_gpu_tgllp].

Cause

The bundler expects the architecture in the 6th part of the bundle ID (<kind>-<arch>-<vendor>-<os>-<env>-<target id>), but SYCL bundle IDs only have 5 parts, so tgllp/pvc is parsed as the triple environment and the target ID is empty. All the entries then compare as equal, and the first one is returned:

StringRef TargetIdWithFeature =
Components.size() == 6 ? Components.back() : "";
StringRef TargetId = TargetIdWithFeature.split(':').first;
if (!TargetId.empty() && !clang::StringToOffloadArch(TargetId).isUnknown())
this->TargetID = TargetIdWithFeature;
else
this->TargetID = "";
this->OffloadKind = Components.front();
ArrayRef<StringRef> TripleSlice{&Components[1], /*length=*/4};
llvm::Triple T = llvm::Triple(llvm::join(TripleSlice, "-"));
this->Triple = llvm::Triple(T.getArchName(), T.getVendorName(), T.getOSName(),

It didn't show up with -fsycl-targets=spir64_gen -Xs "-device ...", which produces a single entry.

Expected behavior

Each architecture gets its own device code.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions