|
| 1 | +//==------------------- Barrier.cpp --- queue unit tests -------------------==// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#include <helpers/TestKernel.hpp> |
| 10 | +#include <helpers/UrMock.hpp> |
| 11 | + |
| 12 | +#include <gtest/gtest.h> |
| 13 | + |
| 14 | +static unsigned NumOfEventsWaitWithBarrierCalls = 0; |
| 15 | + |
| 16 | +static ur_result_t redefined_urEnqueueEventsWaitWithBarrier(void *) { |
| 17 | + NumOfEventsWaitWithBarrierCalls++; |
| 18 | + |
| 19 | + return UR_RESULT_SUCCESS; |
| 20 | +} |
| 21 | + |
| 22 | +TEST(Queue, HandlerBarrier) { |
| 23 | + sycl::unittest::UrMock<> Mock; |
| 24 | + mock::getCallbacks().set_before_callback( |
| 25 | + "urEnqueueEventsWaitWithBarrier", |
| 26 | + &redefined_urEnqueueEventsWaitWithBarrier); |
| 27 | + NumOfEventsWaitWithBarrierCalls = 0; |
| 28 | + |
| 29 | + sycl::queue Q; |
| 30 | + |
| 31 | + Q.submit( |
| 32 | + [&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); }); |
| 33 | + Q.submit( |
| 34 | + [&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); }); |
| 35 | + |
| 36 | + Q.submit([&](sycl::handler &cgh) { cgh.ext_oneapi_barrier(); }); |
| 37 | + |
| 38 | + ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u); |
| 39 | +} |
| 40 | + |
| 41 | +TEST(Queue, ExtOneAPISubmitBarrier) { |
| 42 | + sycl::unittest::UrMock<> Mock; |
| 43 | + mock::getCallbacks().set_before_callback( |
| 44 | + "urEnqueueEventsWaitWithBarrier", |
| 45 | + &redefined_urEnqueueEventsWaitWithBarrier); |
| 46 | + NumOfEventsWaitWithBarrierCalls = 0; |
| 47 | + |
| 48 | + sycl::queue Q; |
| 49 | + |
| 50 | + Q.submit( |
| 51 | + [&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); }); |
| 52 | + Q.submit( |
| 53 | + [&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); }); |
| 54 | + |
| 55 | + Q.ext_oneapi_submit_barrier(); |
| 56 | + |
| 57 | + ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u); |
| 58 | +} |
| 59 | + |
| 60 | +TEST(Queue, HandlerBarrierWithWaitList) { |
| 61 | + sycl::unittest::UrMock<> Mock; |
| 62 | + mock::getCallbacks().set_before_callback( |
| 63 | + "urEnqueueEventsWaitWithBarrier", |
| 64 | + &redefined_urEnqueueEventsWaitWithBarrier); |
| 65 | + NumOfEventsWaitWithBarrierCalls = 0; |
| 66 | + |
| 67 | + sycl::queue Q1; |
| 68 | + sycl::queue Q2; |
| 69 | + sycl::queue Q3; |
| 70 | + |
| 71 | + auto E1 = Q1.submit( |
| 72 | + [&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); }); |
| 73 | + auto E2 = Q2.submit( |
| 74 | + [&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); }); |
| 75 | + |
| 76 | + Q3.submit([&](sycl::handler &cgh) { cgh.ext_oneapi_barrier({E1, E2}); }); |
| 77 | + |
| 78 | + ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u); |
| 79 | +} |
| 80 | + |
| 81 | +TEST(Queue, ExtOneAPISubmitBarrierWithWaitList) { |
| 82 | + sycl::unittest::UrMock<> Mock; |
| 83 | + mock::getCallbacks().set_before_callback( |
| 84 | + "urEnqueueEventsWaitWithBarrier", |
| 85 | + &redefined_urEnqueueEventsWaitWithBarrier); |
| 86 | + NumOfEventsWaitWithBarrierCalls = 0; |
| 87 | + |
| 88 | + sycl::queue Q1; |
| 89 | + sycl::queue Q2; |
| 90 | + sycl::queue Q3; |
| 91 | + |
| 92 | + auto E1 = Q1.submit( |
| 93 | + [&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); }); |
| 94 | + auto E2 = Q2.submit( |
| 95 | + [&](sycl::handler &cgh) { cgh.single_task<TestKernel<1>>([=]() {}); }); |
| 96 | + |
| 97 | + Q3.ext_oneapi_submit_barrier({E1, E2}); |
| 98 | + |
| 99 | + ASSERT_EQ(NumOfEventsWaitWithBarrierCalls, 1u); |
| 100 | +} |
0 commit comments