|
| 1 | +//==------------ Regression.cpp --- Scheduler 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 "SchedulerTest.hpp" |
| 10 | +#include "SchedulerTestUtils.hpp" |
| 11 | + |
| 12 | +#include <helpers/CommonRedefinitions.hpp> |
| 13 | +#include <helpers/PiMock.hpp> |
| 14 | + |
| 15 | +using namespace sycl; |
| 16 | + |
| 17 | +static std::tuple<detail::NDRDescT, detail::Requirement> initializeRefValues() { |
| 18 | + detail::NDRDescT NDRDesc; |
| 19 | + NDRDesc.GlobalSize = range<3>(1, 2, 3); |
| 20 | + NDRDesc.LocalSize = range<3>(1, 1, 1); |
| 21 | + |
| 22 | + int val; |
| 23 | + buffer<int, 1> Buf(&val, range<1>(1)); |
| 24 | + detail::Requirement MockReq = getMockRequirement(Buf); |
| 25 | + return {NDRDesc, MockReq}; |
| 26 | +} |
| 27 | + |
| 28 | +static pi_result redefinedEnqueueNativeKernel( |
| 29 | + pi_queue queue, void (*user_func)(void *), void *args, size_t cb_args, |
| 30 | + pi_uint32 num_mem_objects, const pi_mem *mem_list, |
| 31 | + const void **args_mem_loc, pi_uint32 num_events_in_wait_list, |
| 32 | + const pi_event *event_wait_list, pi_event *event) { |
| 33 | + void **CastedBlob = (void **)args; |
| 34 | + auto [NDRDesc, MockReq] = initializeRefValues(); |
| 35 | + |
| 36 | + std::vector<detail::Requirement *> Reqs = |
| 37 | + *(static_cast<std::vector<detail::Requirement *> *>(CastedBlob[0])); |
| 38 | + EXPECT_EQ(Reqs[0]->MAccessRange[0], MockReq.MAccessRange[0]); |
| 39 | + EXPECT_EQ(Reqs[0]->MAccessRange[1], MockReq.MAccessRange[1]); |
| 40 | + EXPECT_EQ(Reqs[0]->MAccessRange[2], MockReq.MAccessRange[2]); |
| 41 | + |
| 42 | + std::unique_ptr<detail::HostKernelBase> *HostKernel = |
| 43 | + static_cast<std::unique_ptr<detail::HostKernelBase> *>(CastedBlob[1]); |
| 44 | + testing::internal::CaptureStdout(); |
| 45 | + (*HostKernel)->call(NDRDesc, nullptr); |
| 46 | + std::string Output = testing::internal::GetCapturedStdout(); |
| 47 | + EXPECT_EQ(Output, "Blablabla"); |
| 48 | + |
| 49 | + detail::NDRDescT *NDRDescActual = |
| 50 | + static_cast<detail::NDRDescT *>(CastedBlob[2]); |
| 51 | + EXPECT_EQ(NDRDescActual->GlobalSize[0], NDRDesc.GlobalSize[0]); |
| 52 | + EXPECT_EQ(NDRDescActual->GlobalSize[1], NDRDesc.GlobalSize[1]); |
| 53 | + EXPECT_EQ(NDRDescActual->GlobalSize[2], NDRDesc.GlobalSize[2]); |
| 54 | + |
| 55 | + return PI_SUCCESS; |
| 56 | +} |
| 57 | + |
| 58 | +TEST_F(SchedulerTest, CheckArgsBlobInPiEnqueueNativeKernelIsValid) { |
| 59 | + default_selector Selector; |
| 60 | + platform Plt{default_selector()}; |
| 61 | + |
| 62 | + unittest::PiMock Mock{Plt}; |
| 63 | + setupDefaultMockAPIs(Mock); |
| 64 | + Mock.redefine<detail::PiApiKind::piEnqueueNativeKernel>( |
| 65 | + redefinedEnqueueNativeKernel); |
| 66 | + |
| 67 | + auto Kernel = []() { std::cout << "Blablabla"; }; |
| 68 | + detail::HostKernel<decltype(Kernel), void, 1> HKernel(Kernel); |
| 69 | + auto [NDRDesc, MockReq] = initializeRefValues(); |
| 70 | + |
| 71 | + std::unique_ptr<detail::CG> CG{new detail::CGExecKernel( |
| 72 | + /*NDRDesc*/ NDRDesc, |
| 73 | + /*HKernel*/ |
| 74 | + std::make_unique<detail::HostKernel<decltype(Kernel), void, 1>>(HKernel), |
| 75 | + /*SyclKernel*/ nullptr, |
| 76 | + /*ArgsStorage*/ {}, |
| 77 | + /*AccStorage*/ {}, |
| 78 | + /*SharedPtrStorage*/ {}, |
| 79 | + /*Requirements*/ {&MockReq}, |
| 80 | + /*Events*/ {}, |
| 81 | + /*Args*/ {}, |
| 82 | + /*KernelName*/ "", |
| 83 | + /*OSModuleHandle*/ detail::OSUtil::ExeModuleHandle, |
| 84 | + /*Streams*/ {}, |
| 85 | + /*Type*/ detail::CG::RunOnHostIntel)}; |
| 86 | + |
| 87 | + context Ctx{Plt}; |
| 88 | + queue Queue{Ctx, Selector}; |
| 89 | + detail::QueueImplPtr QueueImpl = detail::getSyclObjImpl(Queue); |
| 90 | + |
| 91 | + detail::ExecCGCommand ExecCGCmd{std::move(CG), QueueImpl}; |
| 92 | + detail::EnqueueResultT EnqueueResult = detail::EnqueueResultT( |
| 93 | + detail::EnqueueResultT::SyclEnqueueReady, &ExecCGCmd); |
| 94 | + std::vector<cl::sycl::detail::Command *> ToCleanUp; |
| 95 | + ExecCGCmd.enqueue(EnqueueResult, detail::BlockingT::NON_BLOCKING, ToCleanUp); |
| 96 | +} |
0 commit comments