Skip to content

[SYCL] add an e2e test that passes for liboffload with L0#21584

Merged
againull merged 1 commit intointel:syclfrom
EuphoricThinking:liboffload_lit_tests_pr
Apr 1, 2026
Merged

[SYCL] add an e2e test that passes for liboffload with L0#21584
againull merged 1 commit intointel:syclfrom
EuphoricThinking:liboffload_lit_tests_pr

Conversation

@EuphoricThinking
Copy link
Copy Markdown
Contributor

@EuphoricThinking EuphoricThinking commented Mar 20, 2026

The liboffload phase 0 program is added as one of SYCL e2e tests. Moreover, lit configuration files are modified so that the liboffload backend is determined according to sycl-ls output, while the backend specified by the user preserves its precedence. When choosing between devices listed by sycl-ls, the Level Zero backend is preferred.

The tests would not work without this change when liboffload is built, even with llvm-lit --param sycl_devices="offload:gpu" <path>. The backend for liboffload would still be undetermined: the tests are not compiled with the OFFLOAD_BUILD_TARGET option, therefore there is only "" left as a value in the dictionary mapping from backends to targets, resulting in a KeyError. Additionally, OFFLOAD_BUILD_TARGET is never mentioned in any CMakeLists.txt, therefore it has been impossible to use liboffload.

@EuphoricThinking EuphoricThinking requested review from a team as code owners March 20, 2026 19:03
@EuphoricThinking EuphoricThinking force-pushed the liboffload_lit_tests_pr branch from 2ac3b22 to 187486d Compare March 20, 2026 19:22
@EuphoricThinking EuphoricThinking marked this pull request as draft March 20, 2026 19:24
@EuphoricThinking EuphoricThinking force-pushed the liboffload_lit_tests_pr branch 9 times, most recently from abfe1b4 to 3c7b065 Compare March 23, 2026 14:43
@EuphoricThinking EuphoricThinking marked this pull request as ready for review March 23, 2026 14:58
Comment thread sycl/test-e2e/lit.cfg.py
Comment on lines +1061 to +1066
if re.match(r"\[offload:.*", line) and not is_offload_preferred_backend_set:
if re.match(".*Level[ _]Zero.*", line, re.IGNORECASE):
offload_assigned_backend = config.backend_to_target["level_zero"]
is_offload_preferred_backend_set = True
elif re.match(".*nvidia.*", line, re.IGNORECASE):
offload_assigned_backend = config.backend_to_target["cuda"]
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 think we can just assign to config.backend_to_target["offload"] directly and get rid of offload_assigned_backend.

Does the logic here depends on the order of devices/backends in sycl-ls output? I.e. if CUDA comes after L0 in the sycl-ls output, then it will be picked as offload backend. Is this the desired behavior?

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've been afraid I might have overcomplicated, so I'm glad that you point this out.

L0 backend is preferred, but the outcome is not dependent on the order of the devices listed by sycl-ls.

config.backend_to_target["offload"] might be set to target-nvidia if NVIDIA's device is the first one encountered, but is_offload_preferred_backend_set is not set, therefore the condition is still entered in the next iterations. However, when L0 is found, is_offload_preferred_backend_set is set to true, which prevents from entering the condition in the following iterations. If we start with L0 instead, is_offload_preferred_backend_set would be set before we could find NVIDIA - we would not reassign the preferred backend.

I wanted to prevent setting config.backend_to_target["offload"] to "", which was the case with using only OFFLOAD_BUILD_TARGET, but I am not sure whether preferring L0 over other devices is a strategy which is aligned with our goals. On the other hand, we focus on supporting L0 devices. One thing that concerns me is missing backends - for example, HIP is not supported by offload at this moment. Can we encounter only AMD device in our tests?

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, thanks for clarification. We don't run tests on AMD in our CI,

I'm trying to understand what we are trying to achieve.
So, before this change, if we wanted to run tests on cuda via offload backend, we would do something like this:
llvm-lit --param offload_build_target="target-nvidia" --param sycl_devices="offload:gpu" <repo_path>/sycl/test-e2e
To run on L0 probably this:
llvm-lit --param offload_build_target="target-spirv" --param sycl_devices="offload:gpu" <repo_path>/sycl/test-e2e
At least, if I am reading https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/README.md right.

With this change we can still do the same as above, but additionally if "--param offload_build_target" is not provided, we will try to automatically set it. And as you clarified, on machine with both L0 and cuda it will be set to target-spirv.
I think this approach is fine, at least for now.

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.

The test would not work without this change when liboffload is built, even with llvm-lit --param offload_build_target="target-nvidia" --param sycl_devices="offload:gpu" <repo_path>/sycl/test-e2e (as I have checked a moment ago). The backend for liboffload would still be undetermined: the tests are not compiled with the OFFLOAD_BUILD_TARGET option, therefore there is only "" left as a value in the dictionary mapping from backends to targets, resulting in a KeyError. Additionally, OFFLOAD_BUILD_TARGET is never mentioned in any CMakeLists.txt, therefore it has been impossible to use liboffload.

I'll add this clarification to the PR description.

Comment on lines +18 to +20
// Allocate shared memory bound to the device and context associated to the
// queue Replacing malloc_shared with malloc_host would yield a correct
// program that allocated device-visible memory on the host.
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.

NIT: Comment about malloc_host seems excessive and can be removed.

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.

Removed c:

@EuphoricThinking EuphoricThinking force-pushed the liboffload_lit_tests_pr branch from 3c7b065 to 0d2d8dc Compare March 25, 2026 10:33
Comment thread sycl/test-e2e/lit.cfg.py
Comment on lines +1061 to +1066
if re.match(r"\[offload:.*", line) and not is_offload_preferred_backend_set:
if re.match(".*Level[ _]Zero.*", line, re.IGNORECASE):
offload_assigned_backend = config.backend_to_target["level_zero"]
is_offload_preferred_backend_set = True
elif re.match(".*nvidia.*", line, re.IGNORECASE):
offload_assigned_backend = config.backend_to_target["cuda"]
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, thanks for clarification. We don't run tests on AMD in our CI,

I'm trying to understand what we are trying to achieve.
So, before this change, if we wanted to run tests on cuda via offload backend, we would do something like this:
llvm-lit --param offload_build_target="target-nvidia" --param sycl_devices="offload:gpu" <repo_path>/sycl/test-e2e
To run on L0 probably this:
llvm-lit --param offload_build_target="target-spirv" --param sycl_devices="offload:gpu" <repo_path>/sycl/test-e2e
At least, if I am reading https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/README.md right.

With this change we can still do the same as above, but additionally if "--param offload_build_target" is not provided, we will try to automatically set it. And as you clarified, on machine with both L0 and cuda it will be set to target-spirv.
I think this approach is fine, at least for now.

// RUN: %{build} -o %t.out
// RUN: %{run} %t.out

#include <iostream>
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.

Suggested change
#include <iostream>

// Explicitly wait for kernel execution since there is no accessor involved
myQueue.wait();

// Print result
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.

Suggested change
// Print result

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

@intel/llvm-gatekeepers please consider merging

@EuphoricThinking EuphoricThinking force-pushed the liboffload_lit_tests_pr branch from 0d2d8dc to ad4cf19 Compare April 1, 2026 14:26
@againull againull merged commit 4cd5ac6 into intel:sycl Apr 1, 2026
32 checks passed
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.

2 participants