Skip to content

[SYCL] Added changes to support multiple archs in command line - #22945

Open
bviyer wants to merge 1 commit into
syclfrom
bviyer-support-passing-multiple-args
Open

[SYCL] Added changes to support multiple archs in command line#22945
bviyer wants to merge 1 commit into
syclfrom
bviyer-support-passing-multiple-args

Conversation

@bviyer

@bviyer bviyer commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

The clang-linker-wrapper --device-compiler=/--device-linker= channel did not distinguish between architectures sharing the same triple, so with-fsycl-targets=spir64_gen,intel_gpu_skl plus per-target -Xsycl-target-backend, all options were emitted under a single spir64_gen-unknown-unknown entry and per-arch tokens leaked across ocloc invocations (e.g. skl's options ended up on the pvc call and vice versa). The driver now emits one --device-compiler/--device-linker per (triple, arch) with tokens joined into a single value; gen entries carry a leading "-device " that the wrapper uses to route each value to the matching ocloc call, while values without "-device" (or from non-gen triples) still apply to every arch of the triple. This feature affects the new-offload-model only.

@bviyer
bviyer requested review from a team as code owners August 14, 2026 20:40
@bviyer bviyer changed the title Added changes to support multiple archs in command line [SYCL] Added changes to support multiple archs in command line Aug 14, 2026
Comment on lines +2738 to +2739
// Value is space-joined; a leading "-device <arch>" routes it to
// that arch only. No -device prefix -> apply to every arch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ocloc doesn't work like that.

ocloc -device X -A -device Y -B - you assume ocloc will apply -A option to the compilation for device X and -B to the compilation for device Y. In fact, -A -B is applied to both compilations.

@sarnex sarnex Aug 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is the -device_options option that may do what you want:

  -device_options <device_type> <options>   Optional OpenCL C compilation options
                                            as defined by OpenCL specification - specific to a single target device.
                                            Multiple product acronyms may be provided - separated by commas.
                                            <device_type> can be product acronym or version passed in -device i.e. dg1 or 12.10.0

I didn't review the PR yet so maybe it doesn't, I just saw Alexey's comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the comment might be misworded (I tried a couple things and forgot to change the comment). I also fixed another issue. Now, I think its doing the right thing:

Here is the output from clang-lnker-wrapper to ocloc:

$ ./bin/clang-linker-wrapper   --host-triple=x86_64-unknown-linux-gnu   "--device-compiler=sycl:spir64_gen-unknown-unknown=-device pvc -options -cl-mad-enable"   "--device-compiler=sycl:spir64_gen-unknown-unknown=-device skl -options -cl-unsafe-math-optimizations"  /tmp/tst_pvc.o /tmp/tst_skl.o --dry-run 2>&1 | grep ocloc
 "<snip>/ocloc" -output_no_suffix -spirv_input -device pvc -device_options pvc -ze-intel-enable-auto-large-GRF-mode -options -cl-mad-enable -output /tmp/a.out-106216.out -file /tmp/a.out-823be2.spv
 "<snip>/ocloc" -output_no_suffix -spirv_input -device skl -options -cl-unsafe-math-optimizations -output /tmp/a.out-0fad9e.out -file /tmp/a.out-d9b0a3.spv

Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
Comment on lines +12349 to +12353
for (const char *T : BuildArgs) {
if (!Joined.empty())
Joined += ' ';
Joined += T;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The dd9abc1 change purposefully tokenizes the options to be passed to the clang-linker-wrapper. We seem to have effectively lost this behavior. Is there a reason why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@bader

bader commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

The clang-linker-wrapper --device-compiler=/--device-linker= channel did not distinguish between architectures sharing the same triple, so with-fsycl-targets=spir64_gen,intel_gpu_skl plus per-target -Xsycl-target-backend, all options were emitted under a single spir64_gen-unknown-unknown entry and per-arch tokens leaked across ocloc invocations (e.g. skl's options ended up on the pvc call and vice versa).

I think we need to fix this design issue to enable support for "multiple archs" i.e. we must use a dedicated key for each -fsycl-target= value.

The driver now emits one --device-compiler/--device-linker per (triple, arch) with tokens joined into a single value; gen entries carry a leading "-device " that the wrapper uses to route each value to the matching ocloc call, while values without "-device" (or from non-gen triples) still apply to every arch of the triple. This feature affects the new-offload-model only.

Joining all options into a single value to reparse them again in clang-link-wrapper tool requires implementing non-trivial logic which is a source of bugs. As Mike noted in his comment, dd9abc1 replaces this approach with simplified logic to fix one of such bugs. I suggest we don't bring it back.

@bviyer

bviyer commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

The clang-linker-wrapper --device-compiler=/--device-linker= channel did not distinguish between architectures sharing the same triple, so with-fsycl-targets=spir64_gen,intel_gpu_skl plus per-target -Xsycl-target-backend, all options were emitted under a single spir64_gen-unknown-unknown entry and per-arch tokens leaked across ocloc invocations (e.g. skl's options ended up on the pvc call and vice versa).

I think we need to fix this design issue to enable support for "multiple archs" i.e. we must use a dedicated key for each -fsycl-target= value.

The driver now emits one --device-compiler/--device-linker per (triple, arch) with tokens joined into a single value; gen entries carry a leading "-device " that the wrapper uses to route each value to the matching ocloc call, while values without "-device" (or from non-gen triples) still apply to every arch of the triple. This feature affects the new-offload-model only.

Joining all options into a single value to reparse them again in clang-link-wrapper tool requires implementing non-trivial logic which is a source of bugs. As Mike noted in his comment, dd9abc1 replaces this approach with simplified logic to fix one of such bugs. I suggest we don't bring it back.

I have put it back. I also added a e2e test.

Comment thread clang/test/Driver/sycl-offload-new-driver.cpp
Comment thread clang/lib/Driver/ToolChains/Clang.cpp
@bviyer
bviyer force-pushed the bviyer-support-passing-multiple-args branch from 196d3a8 to d5cc96a Compare August 22, 2026 00:49
@bviyer
bviyer requested a review from mdtoguchi August 22, 2026 00:50

@mdtoguchi mdtoguchi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK by me

Comment on lines +1673 to +1674
// Raw spir64_gen entry: if the value embeds "-device X", route
// only to arch X. Absent -> shared, applies to every arch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@YuriPlyakhin, does new offload model support -fsycl-target=spir64_gen?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bader , so far we were not going to support it. I'm not aware of anything that changed this decision.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are existing uses of -fsycl-targets=spir64_gen that we will have to support from the old model until we can move folks away from using -fsycl-targets completely when using the new model and --offload-arch.

@bader bader Aug 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so far we were not going to support it

These clang/lib/Driver/ToolChains/SYCL.cpp changes are unnecessary then.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are existing uses of -fsycl-targets=spir64_gen that we will have to support from the old model until we can move folks away from using -fsycl-targets completely when using the new model and --offload-arch.

Can we review those use cases and see if we can avoid -fsycl-targets=spir64_gen in those cases?

@sys-ce-bb

Copy link
Copy Markdown
Contributor

@intel/llvm-gatekeepers please consider merging

Comment on lines +12357 to +12359
// One --device-compiler/--device-linker per token; per-arch routing
// rides on the key (<triple>/<arch>). Preserves dd9abc1's per-token
// AOT forwarding invariant. Wrapper filters by key, no reparse.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would trim some comments.

Suggested change
// One --device-compiler/--device-linker per token; per-arch routing
// rides on the key (<triple>/<arch>). Preserves dd9abc1's per-token
// AOT forwarding invariant. Wrapper filters by key, no reparse.
// One --device-compiler/--device-linker per token; per-arch routing
// rides on the key (<triple>/<arch>).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants