Skip to content

Commit

Permalink
[SYCL] Rewrite some E2E tests into unit-tests (intel#15877)
Browse files Browse the repository at this point in the history
The main idea behind this (and other PRs I will eventually submit) is
that we shouldn't use `SYCL_UR_TRACE` in our unit-tests unless
absolutely necessary (like testing shutdown sequence).

The reason behind this is the fact that we have unit-tests
infrastructure which is more than capable of ensuring that we called the
right UR APIs with the right arguments. There is no need to waste our CI
time on compiling and running the same test on different devices if we
can easily test the same via our UR mock infrastructure.
  • Loading branch information
AlexeySachkov authored Oct 30, 2024
1 parent 4add105 commit dd7446c
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 160 deletions.
62 changes: 0 additions & 62 deletions sycl/test-e2e/Basic/enqueue_barrier.cpp

This file was deleted.

97 changes: 0 additions & 97 deletions sycl/test-e2e/ESIMD/esimd_check_vc_codegen.cpp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// REQUIRES: gpu && linux && (opencl || level_zero)

// RUN: %{build} -o %t.out
// RUN: env NEOReadDebugKeys=1 CreateMultipleRootDevices=3 SYCL_UR_TRACE=2 %{run} %t.out
// RUN: env NEOReadDebugKeys=1 CreateMultipleRootDevices=3 %{run} %t.out

// Test to check that we can compile and link a kernel bundle for multiple
// devices and run the kernel on each device.
Expand Down
17 changes: 17 additions & 0 deletions sycl/unittests/kernel-and-program/KernelBuildOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,20 @@ TEST(KernelBuildOptions, KernelBundleBasic) {
auto LinkBundle = sycl::link(ObjBundle, ObjBundle.get_devices());
EXPECT_EQ(BuildOpts, "-link-img");
}

TEST(KernelBuildOptions, ESIMDParallelForBasic) {
sycl::unittest::UrMock<> Mock;
sycl::platform Plt = sycl::platform();
setupCommonMockAPIs(Mock);

const sycl::device Dev = Plt.get_devices()[0];
sycl::queue Queue{Dev};

Queue.submit([&](sycl::handler &cgh) {
cgh.parallel_for<BuildOptsTestKernel>(
sycl::range{1024}, [=](sycl::id<1>) /* SYCL_ESIMD_KERNEL */ {});
});

EXPECT_EQ(BuildOpts,
"-compile-img -vc-codegen -disable-finalizer-msg -link-img");
}
100 changes: 100 additions & 0 deletions sycl/unittests/queue/Barrier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//==------------------- Barrier.cpp --- queue unit tests -------------------==//
//
// 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
//
//===----------------------------------------------------------------------===//

#include <helpers/TestKernel.hpp>
#include <helpers/UrMock.hpp>

#include <gtest/gtest.h>

static unsigned NumOfEventsWaitWithBarrierCalls = 0;

static ur_result_t redefined_urEnqueueEventsWaitWithBarrier(void *) {
NumOfEventsWaitWithBarrierCalls++;

return UR_RESULT_SUCCESS;
}

TEST(Queue, HandlerBarrier) {
sycl::unittest::UrMock<> Mock;
mock::getCallbacks().set_before_callback(
"urEnqueueEventsWaitWithBarrier",
&redefined_urEnqueueEventsWaitWithBarrier);
NumOfEventsWaitWithBarrierCalls = 0;

sycl::queue Q;

Q.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
Q.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });

Q.submit([&](sycl::handler &cgh) { cgh.ext_oneapi_barrier(); });

ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u);
}

TEST(Queue, ExtOneAPISubmitBarrier) {
sycl::unittest::UrMock<> Mock;
mock::getCallbacks().set_before_callback(
"urEnqueueEventsWaitWithBarrier",
&redefined_urEnqueueEventsWaitWithBarrier);
NumOfEventsWaitWithBarrierCalls = 0;

sycl::queue Q;

Q.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
Q.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });

Q.ext_oneapi_submit_barrier();

ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u);
}

TEST(Queue, HandlerBarrierWithWaitList) {
sycl::unittest::UrMock<> Mock;
mock::getCallbacks().set_before_callback(
"urEnqueueEventsWaitWithBarrier",
&redefined_urEnqueueEventsWaitWithBarrier);
NumOfEventsWaitWithBarrierCalls = 0;

sycl::queue Q1;
sycl::queue Q2;
sycl::queue Q3;

auto E1 = Q1.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
auto E2 = Q2.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });

Q3.submit([&](sycl::handler &cgh) { cgh.ext_oneapi_barrier({E1, E2}); });

ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u);
}

TEST(Queue, ExtOneAPISubmitBarrierWithWaitList) {
sycl::unittest::UrMock<> Mock;
mock::getCallbacks().set_before_callback(
"urEnqueueEventsWaitWithBarrier",
&redefined_urEnqueueEventsWaitWithBarrier);
NumOfEventsWaitWithBarrierCalls = 0;

sycl::queue Q1;
sycl::queue Q2;
sycl::queue Q3;

auto E1 = Q1.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });
auto E2 = Q2.submit(
[&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); });

Q3.ext_oneapi_submit_barrier({E1, E2});

ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u);
}
1 change: 1 addition & 0 deletions sycl/unittests/queue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ add_sycl_unittest(QueueTests OBJECT
InOrderQueue.cpp
InteropRetain.cpp
Properties.cpp
Barrier.cpp
)

0 comments on commit dd7446c

Please sign in to comment.