Skip to content

Commit 817ba40

Browse files
Stop accessing task count from out-of-bound in opencl and shared ult
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
1 parent 7c068cb commit 817ba40

File tree

4 files changed

+35
-11
lines changed

4 files changed

+35
-11
lines changed

opencl/test/unit_test/command_stream/command_stream_receiver_flush_task_4_tests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,9 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenStaticPartitioningEnabledWhen
647647
mockCsr.storeMakeResidentAllocations = true;
648648

649649
DispatchFlags dispatchFlags = DispatchFlagsHelper::createDefaultDispatchFlags();
650+
651+
cleanupHeaps();
652+
initHeaps();
650653
mockCsr.flushTask(commandStream,
651654
0,
652655
&dsh,
@@ -759,4 +762,4 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenTagValueNotMeetingTaskCountTo
759762

760763
const auto ret = mockCsr->waitForCompletionWithTimeout(WaitParams{true, true, 10}, taskCountToWait);
761764
EXPECT_EQ(NEO::WaitStatus::NotReady, ret);
762-
}
765+
}

opencl/test/unit_test/fixtures/ult_command_stream_receiver_fixture.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ struct UltCommandStreamReceiverTest
3030
ClDeviceFixture::SetUp();
3131
ClHardwareParse::SetUp();
3232

33-
size_t sizeStream = 512;
34-
size_t alignmentStream = 0x1000;
3533
cmdBuffer = alignedMalloc(sizeStream, alignmentStream);
3634
dshBuffer = alignedMalloc(sizeStream, alignmentStream);
3735
iohBuffer = alignedMalloc(sizeStream, alignmentStream);
@@ -42,6 +40,14 @@ struct UltCommandStreamReceiverTest
4240
ASSERT_NE(nullptr, iohBuffer);
4341
ASSERT_NE(nullptr, sshBuffer);
4442

43+
initHeaps();
44+
45+
flushTaskFlags.threadArbitrationPolicy = NEO::HwHelper::get(hardwareInfo.platform.eRenderCoreFamily).getDefaultThreadArbitrationPolicy();
46+
47+
pDevice->getGpgpuCommandStreamReceiver().setupContext(*pDevice->getDefaultEngine().osContext);
48+
}
49+
50+
void initHeaps() {
4551
commandStream.replaceBuffer(cmdBuffer, sizeStream);
4652
auto graphicsAllocation = new MockGraphicsAllocation(cmdBuffer, sizeStream);
4753
commandStream.replaceGraphicsAllocation(graphicsAllocation);
@@ -58,18 +64,18 @@ struct UltCommandStreamReceiverTest
5864
ssh.replaceBuffer(sshBuffer, sizeStream);
5965
graphicsAllocation = new MockGraphicsAllocation(sshBuffer, sizeStream);
6066
ssh.replaceGraphicsAllocation(graphicsAllocation);
61-
62-
flushTaskFlags.threadArbitrationPolicy = NEO::HwHelper::get(hardwareInfo.platform.eRenderCoreFamily).getDefaultThreadArbitrationPolicy();
63-
64-
pDevice->getGpgpuCommandStreamReceiver().setupContext(*pDevice->getDefaultEngine().osContext);
6567
}
6668

67-
void TearDown() override {
68-
pDevice->getGpgpuCommandStreamReceiver().flushBatchedSubmissions();
69+
void cleanupHeaps() {
6970
delete dsh.getGraphicsAllocation();
7071
delete ioh.getGraphicsAllocation();
7172
delete ssh.getGraphicsAllocation();
7273
delete commandStream.getGraphicsAllocation();
74+
}
75+
76+
void TearDown() override {
77+
pDevice->getGpgpuCommandStreamReceiver().flushBatchedSubmissions();
78+
cleanupHeaps();
7379

7480
alignedFree(sshBuffer);
7581
alignedFree(iohBuffer);
@@ -167,5 +173,8 @@ struct UltCommandStreamReceiverTest
167173
uint32_t latestSentDcFlushTaskCount;
168174
uint32_t latestSentNonDcFlushTaskCount;
169175
uint32_t dcFlushRequiredTaskCount;
176+
177+
const size_t sizeStream = 512;
178+
const size_t alignmentStream = 0x1000;
170179
};
171180
} // namespace NEO

opencl/test/unit_test/mocks/mock_buffer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ class MockBufferStorage {
2020
public:
2121
MockBufferStorage() : mockGfxAllocation(data, sizeof(data) / 2),
2222
multiGfxAllocation(GraphicsAllocationHelper::toMultiGraphicsAllocation(&mockGfxAllocation)) {
23+
initDevice();
2324
}
25+
2426
MockBufferStorage(bool unaligned) : mockGfxAllocation(unaligned ? alignUp(&data, 4) : alignUp(&data, 64), sizeof(data) / 2),
2527
multiGfxAllocation(GraphicsAllocationHelper::toMultiGraphicsAllocation(&mockGfxAllocation)) {
28+
initDevice();
29+
}
30+
void initDevice() {
31+
VariableBackup<uint32_t> maxOsContextCountBackup(&MemoryManager::maxOsContextCount);
32+
device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
2633
}
2734
~MockBufferStorage() {
2835
if (mockGfxAllocation.getDefaultGmm()) {
@@ -31,7 +38,7 @@ class MockBufferStorage {
3138
}
3239
char data[128];
3340
MockGraphicsAllocation mockGfxAllocation;
34-
std::unique_ptr<MockDevice> device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
41+
std::unique_ptr<MockDevice> device;
3542
MultiGraphicsAllocation multiGfxAllocation;
3643
};
3744

shared/test/unit_test/command_container/command_container_tests.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,12 @@ TEST_P(CommandContainerHeaps, givenCommandContainerForDifferentRootDevicesThenHe
616616

617617
auto executionEnvironment = new NEO::ExecutionEnvironment();
618618
const size_t numDevices = 2;
619+
619620
executionEnvironment->prepareRootDeviceEnvironments(numDevices);
620621
for (auto i = 0u; i < numDevices; i++) {
621622
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
622623
}
624+
executionEnvironment->calculateMaxOsContextCount();
623625
auto device0 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 0u));
624626
auto device1 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 1u));
625627

@@ -643,10 +645,12 @@ TEST_P(CommandContainerHeaps, givenCommandContainerForDifferentRootDevicesThenHe
643645
TEST_F(CommandContainerHeaps, givenCommandContainerForDifferentRootDevicesThenCmdBufferAllocationIsCreatedWithCorrectRootDeviceIndex) {
644646
auto executionEnvironment = new NEO::ExecutionEnvironment();
645647
const size_t numDevices = 2;
648+
646649
executionEnvironment->prepareRootDeviceEnvironments(numDevices);
647650
for (auto i = 0u; i < numDevices; i++) {
648651
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
649652
}
653+
executionEnvironment->calculateMaxOsContextCount();
650654
auto device0 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 0u));
651655
auto device1 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 1u));
652656

@@ -670,6 +674,7 @@ TEST_F(CommandContainerHeaps, givenCommandContainerForDifferentRootDevicesThenIn
670674
for (auto i = 0u; i < numDevices; i++) {
671675
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
672676
}
677+
executionEnvironment->calculateMaxOsContextCount();
673678
auto device0 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 0u));
674679
auto device1 = std::unique_ptr<MockDevice>(Device::create<MockDevice>(executionEnvironment, 1u));
675680

@@ -783,4 +788,4 @@ TEST_F(CommandContainerTest, givenCmdContainerWhenCloseAndAllocateNextCommandBuf
783788
EXPECT_EQ(cmdContainer.getCmdBufferAllocations().size(), 1u);
784789
cmdContainer.closeAndAllocateNextCommandBuffer();
785790
EXPECT_EQ(cmdContainer.getCmdBufferAllocations().size(), 2u);
786-
}
791+
}

0 commit comments

Comments
 (0)