Skip to content

[SYCL][Tests] Add more syclbin-dump tests #19272

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

Merged
merged 10 commits into from
Jul 9, 2025
Merged
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
2 changes: 2 additions & 0 deletions sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ add_custom_target( sycl-toolchain ALL
DEPENDS sycl-runtime-libraries
sycl-compiler
sycl-ls
syclbin-dump
${XPTIFW_LIBS}
COMMENT "Building SYCL compiler toolchain..."
)
Expand Down Expand Up @@ -472,6 +473,7 @@ set( SYCL_TOOLCHAIN_DEPLOY_COMPONENTS
spirv-to-ir-wrapper
sycl-post-link
sycl-ls
syclbin-dump
clang-resource-headers
OpenCL-Headers
opencl-aot
Expand Down
93 changes: 93 additions & 0 deletions sycl/test-e2e/SYCLBIN/simple_kernel_aot.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// UNSUPPORTED: windows
// UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/19373

// REQUIRES: ocloc

// RUN: %clangxx --offload-new-driver -fsyclbin=input -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device bmg-g21" -o %t.input_bmg_g21_gpu_device_arch.syclbin %s
// RUN: %clangxx --offload-new-driver -fsyclbin=input -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device *" -o %t.input_all_gpu_device_archs.syclbin %s
// RUN: %clangxx --offload-new-driver -fsyclbin=object -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device bmg-g21" -o %t.object_bmg_g21_gpu_device_arch.syclbin %s
// RUN: %clangxx --offload-new-driver -fsyclbin=executable -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device bmg-g21" -o %t.executable_bmg_g21_gpu_device_arch.syclbin %s
// RUN: %clangxx --offload-new-driver -fsyclbin -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device bmg-g21" -o %t.default_bmg_g21_gpu_device_arch.syclbin %s

// RUN: syclbin-dump %t.input_bmg_g21_gpu_device_arch.syclbin | FileCheck %s --check-prefix CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH
// RUN: syclbin-dump %t.input_all_gpu_device_archs.syclbin | FileCheck %s --check-prefix CHECK-INPUT-ALL-GPU-DEVICE-ARCHS
// RUN: syclbin-dump %t.object_bmg_g21_gpu_device_arch.syclbin | FileCheck %s --check-prefix CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH
// RUN: syclbin-dump %t.executable_bmg_g21_gpu_device_arch.syclbin | FileCheck %s --check-prefix CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH
// RUN: syclbin-dump %t.default_bmg_g21_gpu_device_arch.syclbin | FileCheck %s --check-prefix CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH

// Checks the generated SYCLBIN contents of a simple SYCL free function kernel.

#include <sycl/sycl.hpp>

extern "C" {
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY(
(sycl::ext::oneapi::experimental::single_task_kernel))
void TestKernel(int *Ptr, int Size) {
for (size_t I = 0; I < Size; ++I)
Ptr[I] = I;
}
}

// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH: Version: {{[1-9]+}}
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Global metadata:
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: SYCLBIN/global metadata:
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: state: 0
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Number of Abstract Modules: 1
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Abstract Module 0:
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Metadata:
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH: Number of IR Modules: 0
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Number of Native Device Code Images: 1
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Native device code image 0:
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Metadata:
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: SYCLBIN/native device code image metadata:
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: arch:{{.*}}
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: target:{{.*}}spir64_gen-unknown
// CHECK-INPUT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Raw native device code image bytes: <Binary blob of {{.*}} bytes>

// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS: Version: {{[1-9]+}}
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: Global metadata:
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: SYCLBIN/global metadata:
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: state: 0
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: Number of Abstract Modules: 1
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: Abstract Module 0:
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: Metadata:
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS: Number of IR Modules: 0
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: Number of Native Device Code Images: 1
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: Native device code image 0:
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: Metadata:
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: SYCLBIN/native device code image metadata:
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: arch:{{.*}}
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: target:{{.*}}spir64_gen-unknown
// CHECK-INPUT-ALL-GPU-DEVICE-ARCHS-NEXT: Raw native device code image bytes: <Binary blob of {{.*}} bytes>

// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH: Version: {{[1-9]+}}
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Global metadata:
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: SYCLBIN/global metadata:
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: state: 1
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Number of Abstract Modules: 1
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Abstract Module 0:
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Metadata:
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH: Number of IR Modules: 0
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Number of Native Device Code Images: 1
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Native device code image 0:
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Metadata:
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: SYCLBIN/native device code image metadata:
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: arch:{{.*}}
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: target:{{.*}}spir64_gen-unknown
// CHECK-OBJECT-BMG-G21-GPU-DEVICE-ARCH-NEXT: Raw native device code image bytes: <Binary blob of {{.*}} bytes>

// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH: Version: {{[1-9]+}}
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: Global metadata:
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: SYCLBIN/global metadata:
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: state: 2
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: Number of Abstract Modules: 1
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: Abstract Module 0:
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: Metadata:
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH: Number of IR Modules: 0
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: Number of Native Device Code Images: 1
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: Native device code image 0:
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: Metadata:
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: SYCLBIN/native device code image metadata:
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: arch:{{.*}}
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: target:{{.*}}spir64_gen-unknown
// CHECK-EXECUTABLE-BMG-G21-GPU-DEVICE-ARCH-NEXT: Raw native device code image bytes: <Binary blob of {{.*}} bytes>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be fine to have this in sycl/test instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's try, should work. Still investigating though why it doesn't work in CI - as it works locally. The binary now in the install folder, but still it didn't fix the issue, probably need to add to some other place in CMake files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only reason I see not putting it to sycl/test folder is that the test has a dependency on NEO - especially on ocloc binary, and sycl/test tests should be device-agnostic (no backend runtimes should be present in the environment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, good point. Should it have //REQUIRES: ocloc?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's try, should work. Still investigating though why it doesn't work in CI - as it works locally. The binary now in the install folder, but still it didn't fix the issue, probably need to add to some other place in CMake files.

Maybe we need to do something like in https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/lit.cfg.py#L627?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's try, should work. Still investigating though why it doesn't work in CI - as it works locally. The binary now in the install folder, but still it didn't fix the issue, probably need to add to some other place in CMake files.

Maybe we need to do something like in https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/lit.cfg.py#L627?

Thanks! It works now :)

7 changes: 7 additions & 0 deletions sycl/test-e2e/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,12 @@ def open_check_file(file_name):
if not sycl_ls:
lit_config.fatal("can't find `sycl-ls`")

syclbin_dump = FindTool("syclbin-dump").resolve(
llvm_config, os.pathsep.join([config.dpcpp_bin_dir, config.llvm_tools_dir])
)
if not syclbin_dump:
lit_config.fatal("can't find `syclbin-dump`")

if (
len(config.sycl_build_targets) == 1
and next(iter(config.sycl_build_targets)) == "target-all"
Expand Down Expand Up @@ -807,6 +813,7 @@ def remove_level_zero_suffix(devices):
r"\| \bnot\b", command=FindTool("not"), verbatim=True, unresolved="ignore"
),
ToolSubst("sycl-ls", command=sycl_ls, unresolved="ignore"),
ToolSubst("syclbin-dump", command=syclbin_dump, unresolved="ignore"),
] + feature_tools

# Try and find each of these tools in the DPC++ bin directory, in the llvm tools directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// CHECK-DAG: README.md
// CHECK-DAG: lit.cfg.py
//
// CHECK-NUM-MATCHES: 28
// CHECK-NUM-MATCHES: 29
//
// This test verifies that `<sycl/sycl.hpp>` isn't used in E2E tests. Instead,
// fine-grained includes should used, see
Expand Down
Binary file added sycl/test/syclbin/Inputs/malformed.syclbin
Binary file not shown.
5 changes: 5 additions & 0 deletions sycl/test/syclbin/input_files.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not syclbin-dump nonexistent.syclbin 2>&1 | FileCheck %s --check-prefix CHECK-NONEXISTENT-FILE
// RUN: not syclbin-dump %S/Inputs/malformed.syclbin 2>&1 | FileCheck %s --check-prefix CHECK-MALFORMED-FILE

// CHECK-NONEXISTENT-FILE: Failed to open or read file nonexistent.syclbin
// CHECK-MALFORMED-FILE: Invalid data was encountered while parsing the file
13 changes: 0 additions & 13 deletions sycl/tools/syclbin-dump/syclbin-dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ raw_ostream &operator<<(raw_ostream &OS, const ScopedIndent &) {
return OS.indent(CurrentIndentationLevel);
}

std::string_view StateToString(llvm::object::SYCLBIN::BundleState State) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed as it was not used and it was affecting the code coverage

switch (State) {
case llvm::object::SYCLBIN::BundleState::Input:
return "input";
case llvm::object::SYCLBIN::BundleState::Object:
return "object";
case llvm::object::SYCLBIN::BundleState::Executable:
return "executable";
default:
return "UNKNOWN";
}
}

std::string PropertyValueToString(const llvm::util::PropertyValue &PropVal) {
switch (PropVal.getType()) {
case llvm::util::PropertyValue::UINT32:
Expand Down
Loading