2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include "unit_tests/command_queue/enqueue_fixture.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "unit_tests/fixtures/hello_world_fixture.h"
|
|
|
|
#include "unit_tests/mocks/mock_csr.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "unit_tests/mocks/mock_submissions_aggregator.h"
|
|
|
|
|
|
|
|
typedef HelloWorldFixture<HelloWorldFixtureFactory> EnqueueKernelFixture;
|
|
|
|
typedef Test<EnqueueKernelFixture> EnqueueKernelTest;
|
|
|
|
|
|
|
|
HWTEST_F(EnqueueKernelTest, givenCsrInBatchingModeWhenFinishIsCalledThenBatchesSubmissionsAreFlushed) {
|
2019-10-29 15:01:53 +08:00
|
|
|
auto mockCsr = new MockCsrHw2<FamilyType>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-04-04 17:34:46 +08:00
|
|
|
mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
|
2017-12-21 07:45:38 +08:00
|
|
|
pDevice->resetCommandStreamReceiver(mockCsr);
|
|
|
|
|
|
|
|
auto mockedSubmissionsAggregator = new mockSubmissionsAggregator();
|
|
|
|
mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator);
|
|
|
|
|
|
|
|
std::atomic<bool> startEnqueueProcess(false);
|
|
|
|
|
|
|
|
MockKernelWithInternals mockKernel(*pDevice);
|
|
|
|
size_t gws[3] = {1, 0, 0};
|
|
|
|
|
|
|
|
auto enqueueCount = 10;
|
|
|
|
auto threadCount = 4;
|
|
|
|
|
|
|
|
auto function = [&]() {
|
|
|
|
//wait until we are signalled
|
|
|
|
while (!startEnqueueProcess)
|
|
|
|
;
|
|
|
|
for (int enqueue = 0; enqueue < enqueueCount; enqueue++) {
|
|
|
|
pCmdQ->enqueueKernel(mockKernel.mockKernel, 1, nullptr, gws, nullptr, 0, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<std::thread> threads;
|
|
|
|
for (auto thread = 0; thread < threadCount; thread++) {
|
|
|
|
threads.push_back(std::thread(function));
|
|
|
|
}
|
|
|
|
|
|
|
|
auto currentTaskCount = 0;
|
|
|
|
|
|
|
|
startEnqueueProcess = true;
|
|
|
|
|
|
|
|
//call a flush while other threads enqueue, we can't drop anything
|
|
|
|
while (currentTaskCount < enqueueCount * threadCount) {
|
|
|
|
clFlush(pCmdQ);
|
2018-08-06 20:55:04 +08:00
|
|
|
auto locker = mockCsr->obtainUniqueOwnership();
|
2017-12-21 07:45:38 +08:00
|
|
|
currentTaskCount = mockCsr->peekTaskCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &thread : threads) {
|
|
|
|
thread.join();
|
|
|
|
}
|
|
|
|
|
2019-09-13 16:11:17 +08:00
|
|
|
pCmdQ->finish();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
EXPECT_GE(mockCsr->flushCalledCount, 1);
|
|
|
|
|
|
|
|
EXPECT_LE(mockCsr->flushCalledCount, enqueueCount * threadCount);
|
|
|
|
|
|
|
|
EXPECT_EQ(mockedSubmissionsAggregator->peekInspectionId() - 1, (uint32_t)mockCsr->flushCalledCount);
|
|
|
|
}
|