Skip to content
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

[SYCL] moving kernel_compiler sycl cache testing to its own test. #16727

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions sycl/test-e2e/KernelCompiler/kernel_compiler_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

// REQUIRES: ocloc && (opencl || level_zero)
// UNSUPPORTED: accelerator
// UNSUPPORTED-INTENDED: while accelerator is AoT only, this cannot run there.

// -- Test the kernel_compiler with OpenCL source.
// RUN: %{build} -o %t.out
Expand Down
55 changes: 5 additions & 50 deletions sycl/test-e2e/KernelCompiler/kernel_compiler_sycl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

// REQUIRES: (opencl || level_zero)
// UNSUPPORTED: accelerator

// Flaky timeout on CPU. Enable when fixed.
// Depends on SPIR-V Backend & run-time drivers version.
// UNSUPPORTED: spirv-backend && cpu
// UNSUPPORTED-TRACKER: CMPLRLLVM-64705
steffenlarsen marked this conversation as resolved.
Show resolved Hide resolved
// UNSUPPORTED-INTENDED: while accelerator is AoT only, this cannot run there.

// -- Test the kernel_compiler with SYCL source.
// RUN: %{build} -o %t.out
Expand All @@ -23,28 +19,6 @@
// RUN: %{run} %t.out
// RUN: %{l0_leak_check} %{run} %t.out

// -- Test again, with caching.
// 'reading-from-cache' is just a string we pass to differentiate between the
// two runs.

// DEFINE: %{cache_vars} = %{l0_leak_check} env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_TRACE=5 SYCL_CACHE_DIR=%t/cache_dir
// RUN: rm -rf %t/cache_dir
// RUN: %{cache_vars} %t.out 2>&1 | FileCheck %s --check-prefixes=CHECK-WRITTEN-TO-CACHE
// RUN: %{cache_vars} %t.out reading-from-cache 2>&1 | FileCheck %s --check-prefixes=CHECK-READ-FROM-CACHE

// -- Add leak check.
// RUN: rm -rf %t/cache_dir
// RUN: %{l0_leak_check} %{cache_vars} %t.out 2>&1 | FileCheck %s --check-prefixes=CHECK-WRITTEN-TO-CACHE
// RUN: %{l0_leak_check} %{cache_vars} %t.out reading-from-cache 2>&1 | FileCheck %s --check-prefixes=CHECK-READ-FROM-CACHE

// CHECK-WRITTEN-TO-CACHE: [Persistent Cache]: enabled
// CHECK-WRITTEN-TO-CACHE-NOT: [kernel_compiler Persistent Cache]: using cached binary
// CHECK-WRITTEN-TO-CACHE: [kernel_compiler Persistent Cache]: binary has been cached

// CHECK-READ-FROM-CACHE: [Persistent Cache]: enabled
// CHECK-READ-FROM-CACHE-NOT: [kernel_compiler Persistent Cache]: binary has been cached
// CHECK-READ-FROM-CACHE: [kernel_compiler Persistent Cache]: using cached binary

#include <sycl/detail/core.hpp>
#include <sycl/kernel_bundle.hpp>
#include <sycl/usm.hpp>
Expand Down Expand Up @@ -149,7 +123,7 @@ void test_1(sycl::queue &Queue, sycl::kernel &Kernel, int seed) {
sycl::free(usmPtr, Queue);
}

void test_build_and_run(bool readingFromCache) {
void test_build_and_run() {
namespace syclex = sycl::ext::oneapi::experimental;
using source_kb = sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
using exe_kb = sycl::kernel_bundle<sycl::bundle_state::executable>;
Expand Down Expand Up @@ -192,12 +166,8 @@ void test_build_and_run(bool readingFromCache) {
syclex::properties{syclex::build_options{flags}, syclex::save_log{&log},
syclex::registered_kernel_names{"ff_templated<int>"}});

// If the kernel was restored from cache, there will not have been
// any warning issued by the compilation of the kernel.
if (!readingFromCache) {
assert(log.find("warning: 'this_nd_item<1>' is deprecated") !=
std::string::npos);
}
assert(log.find("warning: 'this_nd_item<1>' is deprecated") !=
std::string::npos);

// clang-format off

Expand Down Expand Up @@ -311,23 +281,8 @@ void test_esimd() {
}

int main(int argc, char *argv[]) {
namespace syclex = sycl::ext::oneapi::experimental;
bool readingFromCache = false;

// Check if the argument is present
if (argc > 1) {
std::string argument(argv[1]);
if (argument == "reading-from-cache") {
readingFromCache = true;
} else if (argument == "available") {
sycl::device d;
bool avail = d.ext_oneapi_can_compile(syclex::source_language::sycl);
return avail;
}
}

#ifdef SYCL_EXT_ONEAPI_KERNEL_COMPILER
test_build_and_run(readingFromCache);
test_build_and_run();
test_error();
test_esimd();
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

// REQUIRES: (opencl || level_zero)
// UNSUPPORTED: accelerator
// UNSUPPORTED-INTENDED: while accelerator is AoT only, this cannot run there.

// RUN: %{build} -o %t.out
// RUN: %{run} %t.out 1
Expand Down
1 change: 1 addition & 0 deletions sycl/test-e2e/KernelCompiler/multi_device.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// REQUIRES: (opencl || level_zero) && ocloc
// UNSUPPORTED: accelerator
// UNSUPPORTED-INTENDED: while accelerator is AoT only, this cannot run there.

// RUN: %{build} -o %t.out
// RUN: env NEOReadDebugKeys=1 CreateMultipleRootDevices=3 %{run} %t.out
Expand Down
122 changes: 122 additions & 0 deletions sycl/test-e2e/KernelCompiler/sycl_and_cache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//==- sycl_and_cache.cpp - cache works with kernel_compiler sycl support
//----==//
cperkinsintel marked this conversation as resolved.
Show resolved Hide resolved
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// REQUIRES: (opencl || level_zero)
cperkinsintel marked this conversation as resolved.
Show resolved Hide resolved
// UNSUPPORTED: accelerator
// UNSUPPORTED-INTENDED: while accelerator is AoT only, this cannot run there.

// -- Test the kernel_compiler with SYCL source.
// RUN: %{build} -o %t.out

// -- Run with caching.

// DEFINE: %{cache_vars} = %{l0_leak_check} env SYCL_CACHE_PERSISTENT=1 SYCL_CACHE_TRACE=5 SYCL_CACHE_DIR=%t/cache_dir
// RUN: rm -rf %t/cache_dir
// RUN: %{cache_vars} %t.out 2>&1 | FileCheck %s --check-prefixes=CHECK-WRITTEN-TO-CACHE
// RUN: %{cache_vars} %t.out 2>&1 | FileCheck %s --check-prefixes=CHECK-READ-FROM-CACHE

// CHECK-WRITTEN-TO-CACHE: [Persistent Cache]: enabled
// CHECK-WRITTEN-TO-CACHE-NOT: [kernel_compiler Persistent Cache]: using cached binary
// CHECK-WRITTEN-TO-CACHE: [kernel_compiler Persistent Cache]: binary has been cached

// CHECK-READ-FROM-CACHE: [Persistent Cache]: enabled
// CHECK-READ-FROM-CACHE-NOT: [kernel_compiler Persistent Cache]: binary has been cached
// CHECK-READ-FROM-CACHE: [kernel_compiler Persistent Cache]: using cached binary

#include <sycl/detail/core.hpp>
#include <sycl/kernel_bundle.hpp>
#include <sycl/usm.hpp>

// TODO: remove SYCL_EXTERNAL once it is no longer needed.
auto constexpr SYCLSource = R"===(
#include <sycl/sycl.hpp>

int AddEm(int a, int b){
return a + b + 5;
}

// use extern "C" to avoid name mangling
extern "C" SYCL_EXTERNAL SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((sycl::ext::oneapi::experimental::nd_range_kernel<1>))
void ff_cp(int *ptr) {

// intentionally using deprecated routine, as opposed to this_work_item::get_nd_item<1>()
sycl::nd_item<1> Item = sycl::ext::oneapi::experimental::this_nd_item<1>();

sycl::id<1> GId = Item.get_global_id();
ptr[GId.get(0)] = AddEm(GId.get(0), 37);
}
)===";

void test_1(sycl::queue &Queue, sycl::kernel &Kernel, int seed) {
constexpr int Range = 10;
int *usmPtr = sycl::malloc_shared<int>(Range, Queue);
int start = 3;

sycl::nd_range<1> R1{{Range}, {1}};

bool Passa = true;

memset(usmPtr, 0, Range * sizeof(int));
Queue.submit([&](sycl::handler &Handler) {
Handler.set_arg(0, usmPtr);
Handler.parallel_for(R1, Kernel);
});
Queue.wait();

for (int i = 0; i < Range; i++) {
std::cout << usmPtr[i] << "=" << (i + seed) << " ";
assert(usmPtr[i] == i + seed);
}
std::cout << std::endl;

sycl::free(usmPtr, Queue);
}

void test_build_and_run() {
namespace syclex = sycl::ext::oneapi::experimental;
using source_kb = sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
using exe_kb = sycl::kernel_bundle<sycl::bundle_state::executable>;

sycl::queue q;
sycl::context ctx = q.get_context();

bool ok =
q.get_device().ext_oneapi_can_compile(syclex::source_language::sycl);
if (!ok) {
std::cout << "Apparently this device does not support SYCL source "
"kernel bundle extension: "
<< q.get_device().get_info<sycl::info::device::name>()
<< std::endl;
return;
}

// Create from source.
source_kb kbSrc = syclex::create_kernel_bundle_from_source(
ctx, syclex::source_language::sycl, SYCLSource);

// Compilation of empty prop list, no devices.
exe_kb kbExe = syclex::build(kbSrc);

// extern "C" was used, so the name "ff_cp" is not mangled and can be used
// directly.
sycl::kernel k = kbExe.ext_oneapi_get_kernel("ff_cp");

// Test the kernels.
test_1(q, k, 37 + 5); // ff_cp seeds 37. AddEm will add 5 more.
}

int main(int argc, char *argv[]) {

#ifdef SYCL_EXT_ONEAPI_KERNEL_COMPILER
test_build_and_run();
#else
static_assert(false, "Kernel Compiler feature test macro undefined");
#endif
return 0;
}
3 changes: 1 addition & 2 deletions sycl/test-e2e/KernelCompiler/sycl_device_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

// REQUIRES: level_zero
// UNSUPPORTED: windows

// IGC shader dump not available on Windows.
// UNSUPPORTED-INTENDED: IGC shader dump not available on Windows.

// RUN: %{build} -o %t.out
// RUN: env IGC_DumpToCustomDir=%T.dump IGC_ShaderDumpEnable=1 NEO_CACHE_PERSISTENT=0 %{run} %t.out %T.dump/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
// tests to match the required format and in that case you should just update
// (i.e. reduce) the number and the list below.
//
// NUMBER-OF-UNSUPPORTED-WITHOUT-INFO: 414
// NUMBER-OF-UNSUPPORTED-WITHOUT-INFO: 409
//
// List of improperly UNSUPPORTED tests.
// Remove the CHECK once the test has been properly UNSUPPORTED.
Expand Down Expand Up @@ -283,11 +283,6 @@
// CHECK-NEXT: KernelAndProgram/spec_constants_after_link.cpp
// CHECK-NEXT: KernelAndProgram/spec_constants_after_link.cpp
// CHECK-NEXT: KernelAndProgram/undefined-symbol.cpp
// CHECK-NEXT: KernelCompiler/kernel_compiler_opencl.cpp
// CHECK-NEXT: KernelCompiler/kernel_compiler_sycl.cpp
// CHECK-NEXT: KernelCompiler/kernel_compiler_sycl_jit.cpp
// CHECK-NEXT: KernelCompiler/multi_device.cpp
// CHECK-NEXT: KernelCompiler/sycl_device_flags.cpp
// CHECK-NEXT: LLVMIntrinsicLowering/bitreverse.cpp
// CHECK-NEXT: LLVMIntrinsicLowering/sub_byte_bitreverse.cpp
// CHECK-NEXT: Matrix/SG32/element_wise_abc.cpp
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: 5
// CHECK-NUM-MATCHES: 6
Copy link
Contributor

Choose a reason for hiding this comment

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

Took me a moment to realize why this was increasing. I suppose this is a good reason to let it go up.

//
// This test verifies that `<sycl/sycl.hpp>` isn't used in E2E tests. Instead,
// fine-grained includes should used, see
Expand Down
Loading