|
| 1 | +//==--------------------- Wait.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 <CL/opencl.h> |
| 10 | +#include <CL/sycl.hpp> |
| 11 | +#include <CL/sycl/backend/opencl.hpp> |
| 12 | + |
| 13 | +#include <gtest/gtest.h> |
| 14 | +#include <helpers/PiMock.hpp> |
| 15 | +#include <detail/queue_impl.hpp> |
| 16 | + |
| 17 | +namespace { |
| 18 | +using namespace cl::sycl; |
| 19 | + |
| 20 | +static bool QueueRetainCalled; |
| 21 | +pi_result unexpectedQueueRetain(pi_queue Queue) { return PI_INVALID_QUEUE; } |
| 22 | +pi_result expectedQueueRetain(pi_queue Queue) { QueueRetainCalled = true; return PI_SUCCESS; } |
| 23 | + |
| 24 | +bool preparePiMock(platform &Plt) { |
| 25 | + if (Plt.is_host()) { |
| 26 | + std::cout << "Not run on host - no PI events created in that case" |
| 27 | + << std::endl; |
| 28 | + return false; |
| 29 | + } |
| 30 | + if (detail::getSyclObjImpl(Plt)->getPlugin().getBackend() != |
| 31 | + backend::opencl) { |
| 32 | + std::cout << "Not run on non-OpenCL backend" |
| 33 | + << std::endl; |
| 34 | + return false; |
| 35 | + } |
| 36 | + return true; |
| 37 | +} |
| 38 | + |
| 39 | +TEST(PiInteropTest, CheckRetain) { |
| 40 | + platform Plt{default_selector()}; |
| 41 | + if (!preparePiMock(Plt)) |
| 42 | + return; |
| 43 | + context Ctx{Plt.get_devices()[0]}; |
| 44 | + |
| 45 | + unittest::PiMock Mock{Plt}; |
| 46 | + |
| 47 | + // The queue construction should not call to piQueueRetain. Instead piQueueCreate should return the "retained" queue. |
| 48 | + QueueRetainCalled = false; |
| 49 | + Mock.redefine<detail::PiApiKind::piQueueRetain>(unexpectedQueueRetain); |
| 50 | + queue Q{Ctx, default_selector()}; |
| 51 | + EXPECT_FALSE(QueueRetainCalled); |
| 52 | + |
| 53 | + QueueRetainCalled = false; |
| 54 | + Mock.redefine<detail::PiApiKind::piQueueRetain>(expectedQueueRetain); |
| 55 | + cl_command_queue OCLQ = get_native<backend::opencl>(Q); |
| 56 | + EXPECT_TRUE(QueueRetainCalled); |
| 57 | + |
| 58 | + // The make_queue should not call to piQueueRetain. The piextCreateQueueWithNative handle should do the "retain" if needed. |
| 59 | + QueueRetainCalled = false; |
| 60 | + Mock.redefine<detail::PiApiKind::piQueueRetain>(unexpectedQueueRetain); |
| 61 | + queue Q1 = make_queue<backend::opencl>(OCLQ, Ctx); |
| 62 | + EXPECT_FALSE(QueueRetainCalled); |
| 63 | +} |
| 64 | + |
| 65 | +} // namespace |
0 commit comments