Skip to content

Commit 7f3c4d3

Browse files
committed
[22/n] Internal 4GB allocator.
- Finalize Instruction Heap removal. Change-Id: Idd7df94a228238a5157c3251180fc3c8d3a189df
1 parent 2be5934 commit 7f3c4d3

File tree

12 files changed

+2
-170
lines changed

12 files changed

+2
-170
lines changed

runtime/command_queue/command_queue.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,6 @@ uint32_t CommandQueue::getTaskLevelFromWaitList(uint32_t taskLevel,
217217
return taskLevel;
218218
}
219219

220-
size_t CommandQueue::getInstructionHeapReservedBlockSize() const {
221-
return alignUp(device->getCommandStreamReceiver().getInstructionHeapCmdStreamReceiverReservedSize(),
222-
MemoryConstants::cacheLineSize);
223-
}
224-
225220
IndirectHeap &CommandQueue::getIndirectHeap(IndirectHeap::Type heapType,
226221
size_t minRequiredSize) {
227222
DEBUG_BREAK_IF(static_cast<uint32_t>(heapType) >= ARRAY_COUNT(indirectHeap));
@@ -243,10 +238,6 @@ IndirectHeap &CommandQueue::getIndirectHeap(IndirectHeap::Type heapType,
243238
if (!heapMemory) {
244239
size_t reservedSize = 0;
245240
auto finalHeapSize = defaultHeapSize;
246-
if (heapType == IndirectHeap::INSTRUCTION) {
247-
finalHeapSize = optimalInstructionHeapSize;
248-
reservedSize = getInstructionHeapReservedBlockSize();
249-
}
250241

251242
minRequiredSize += reservedSize;
252243

@@ -274,11 +265,6 @@ IndirectHeap &CommandQueue::getIndirectHeap(IndirectHeap::Type heapType,
274265
heap = new IndirectHeap(heapMemory);
275266
heap->overrideMaxSize(finalHeapSize);
276267
}
277-
278-
if (heapType == IndirectHeap::INSTRUCTION) {
279-
device->getCommandStreamReceiver().initializeInstructionHeapCmdStreamReceiverReservedBlock(*heap);
280-
heap->align(MemoryConstants::cacheLineSize);
281-
}
282268
}
283269

284270
return *heap;

runtime/command_queue/command_queue.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ class CommandQueue : public BaseObject<_cl_command_queue> {
333333
Context *getContextPtr() { return context; }
334334

335335
LinearStream &getCS(size_t minRequiredSize = 1024u);
336-
size_t getInstructionHeapReservedBlockSize() const;
337336
IndirectHeap &getIndirectHeap(IndirectHeap::Type heapType,
338337
size_t minRequiredSize = 0u);
339338

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,6 @@ void CommandStreamReceiver::setRequiredScratchSize(uint32_t newRequiredScratchSi
219219
}
220220
}
221221

222-
size_t CommandStreamReceiver::getInstructionHeapCmdStreamReceiverReservedSize() const {
223-
return PreemptionHelper::getInstructionHeapSipKernelReservedSize(*memoryManager->device);
224-
}
225-
226-
void CommandStreamReceiver::initializeInstructionHeapCmdStreamReceiverReservedBlock(LinearStream &ih) const {
227-
return PreemptionHelper::initializeInstructionHeapSipKernelReservedBlock(ih, *memoryManager->device);
228-
}
229-
230222
GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) {
231223
UNRECOVERABLE_IF(debugSurface != nullptr);
232224
debugSurface = memoryManager->allocateGraphicsMemory(size);

runtime/command_stream/command_stream_receiver.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@ class CommandStreamReceiver {
116116
virtual void waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep) = 0;
117117
MOCKABLE_VIRTUAL bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMicroseconds, uint32_t taskCountToWait);
118118

119-
// returns size of block that needs to be reserved at the beginning of each instruction heap for CommandStreamReceiver
120-
MOCKABLE_VIRTUAL size_t getInstructionHeapCmdStreamReceiverReservedSize() const;
121-
122-
// allows CommandStreamReceiver to prepopulate reserved block in instruction heap
123-
MOCKABLE_VIRTUAL void initializeInstructionHeapCmdStreamReceiverReservedBlock(LinearStream &ih) const;
124-
125119
void setSamplerCacheFlushRequired(SamplerCacheFlushState value) { this->samplerCacheFlushRequired = value; }
126120

127121
// Collect patch info data

runtime/command_stream/preemption.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -104,29 +104,6 @@ void PreemptionHelper::adjustDefaultPreemptionMode(RuntimeCapabilityTable &devic
104104
}
105105
}
106106

107-
size_t PreemptionHelper::getInstructionHeapSipKernelReservedSize(Device &device) {
108-
if (device.getPreemptionMode() != PreemptionMode::MidThread) {
109-
return 0;
110-
}
111-
112-
return BuiltIns::getInstance().getSipKernel(SipKernelType::Csr, device).getBinarySize();
113-
}
114-
115-
void PreemptionHelper::initializeInstructionHeapSipKernelReservedBlock(LinearStream &ih, Device &device) {
116-
if (device.getPreemptionMode() != PreemptionMode::MidThread) {
117-
return;
118-
}
119-
120-
const SipKernel &sip = BuiltIns::getInstance().getSipKernel(SipKernelType::Csr, device);
121-
size_t sipSize = sip.getBinarySize();
122-
UNRECOVERABLE_IF(sipSize > ih.getAvailableSpace());
123-
UNRECOVERABLE_IF(0 != ih.getUsed());
124-
void *blockForSip = ih.getSpace(sipSize);
125-
UNRECOVERABLE_IF(nullptr == blockForSip);
126-
auto err = memcpy_s(blockForSip, sipSize, sip.getBinary(), sipSize);
127-
UNRECOVERABLE_IF(err != 0);
128-
}
129-
130107
PreemptionMode PreemptionHelper::getDefaultPreemptionMode(const HardwareInfo &hwInfo) {
131108
return DebugManager.flags.ForcePreemptionMode.get() == -1
132109
? hwInfo.capabilityTable.defaultPreemptionMode

runtime/command_stream/preemption.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ class PreemptionHelper {
4141
static bool allowMidThreadPreemption(Kernel *kernel, Device &device);
4242
static void adjustDefaultPreemptionMode(RuntimeCapabilityTable &deviceCapabilities, bool allowMidThread, bool allowThreadGroup, bool allowMidBatch);
4343

44-
static size_t getInstructionHeapSipKernelReservedSize(Device &device);
45-
static void initializeInstructionHeapSipKernelReservedBlock(LinearStream &ih, Device &device);
46-
4744
template <typename GfxFamily>
4845
static size_t getRequiredPreambleSize(const Device &device);
4946

runtime/indirect_heap/indirect_heap.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ namespace OCLRT {
3030
class GraphicsAllocation;
3131

3232
constexpr size_t defaultHeapSize = 64 * KB;
33-
constexpr size_t optimalInstructionHeapSize = 512 * KB;
3433
constexpr size_t maxSshSize = defaultHeapSize - MemoryConstants::pageSize;
3534

3635
class IndirectHeap : public LinearStream {
@@ -41,7 +40,6 @@ class IndirectHeap : public LinearStream {
4140
DYNAMIC_STATE = 0,
4241
GENERAL_STATE,
4342
INDIRECT_OBJECT,
44-
INSTRUCTION,
4543
SURFACE_STATE,
4644
NUM_TYPES
4745
};

unit_tests/command_queue/command_queue_tests.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,6 @@ TEST_P(CommandQueueIndirectHeapTest, IndirectHeapContainsAtLeast64KB) {
421421
auto &indirectHeap = cmdQ.getIndirectHeap(this->GetParam(), sizeof(uint32_t));
422422
if (this->GetParam() == IndirectHeap::SURFACE_STATE) {
423423
EXPECT_EQ(64 * KB - MemoryConstants::pageSize, indirectHeap.getAvailableSpace());
424-
} else if (this->GetParam() == IndirectHeap::INSTRUCTION) {
425-
EXPECT_EQ(optimalInstructionHeapSize, indirectHeap.getAvailableSpace());
426424
} else {
427425
EXPECT_EQ(64 * KB, indirectHeap.getAvailableSpace());
428426
}
@@ -478,9 +476,6 @@ TEST_P(CommandQueueIndirectHeapTest, MemoryManagerWithReusableAllocationsWhenAsk
478476

479477
auto memoryManager = pDevice->getMemoryManager();
480478
auto allocationSize = defaultHeapSize * 2;
481-
if (this->GetParam() == IndirectHeap::INSTRUCTION) {
482-
allocationSize = optimalInstructionHeapSize * 2;
483-
}
484479

485480
auto allocation = memoryManager->allocateGraphicsMemory(allocationSize);
486481
memoryManager->storeAllocation(std::unique_ptr<GraphicsAllocation>(allocation), REUSABLE_ALLOCATION);
@@ -627,7 +622,6 @@ INSTANTIATE_TEST_CASE_P(
627622
IndirectHeap::DYNAMIC_STATE,
628623
IndirectHeap::GENERAL_STATE,
629624
IndirectHeap::INDIRECT_OBJECT,
630-
IndirectHeap::INSTRUCTION,
631625
IndirectHeap::SURFACE_STATE));
632626

633627
typedef Test<DeviceFixture> CommandQueueCSTest;
@@ -733,40 +727,6 @@ HWTEST_F(WaitForQueueCompletionTests, whenFinishIsCalledThenCallWaitWithoutQuick
733727
EXPECT_FALSE(cmdQ->requestedUseQuickKmdSleep);
734728
}
735729

736-
constexpr char sipPattern[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 39, 41};
737-
static_assert(false == isAligned<MemoryConstants::cacheLineSize>(sizeof(sipPattern)),
738-
"Will be checking for automatic cacheline alignment, so pattern length must not be a multiple of cacheline");
739-
constexpr size_t alignedPatternSize = alignUp(sizeof(sipPattern), MemoryConstants::cacheLineSize);
740-
741-
TEST(CommandQueueGetIndirectHeap, whenNewInstructionHeapIsBeingCreatedThenCommandStreamReceiverCanReserveAMemoryBlockAtItsBegining) {
742-
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::create<MockDevice>(nullptr));
743-
MockCommandStreamReceiver *csr = new MockCommandStreamReceiver;
744-
mockDevice->resetCommandStreamReceiver(csr);
745-
746-
csr->instructionHeapReserveredData.assign(sipPattern, sipPattern + sizeof(sipPattern));
747-
MockCommandQueue cmdQ{nullptr, mockDevice.get(), nullptr};
748-
IndirectHeap &heap = cmdQ.getIndirectHeap(OCLRT::IndirectHeap::INSTRUCTION, 8192);
749-
EXPECT_LE(8192U, heap.getAvailableSpace());
750-
EXPECT_EQ(alignedPatternSize, heap.getUsed());
751-
752-
ASSERT_LE(sizeof(sipPattern), heap.getMaxAvailableSpace());
753-
char *reservedBlock = reinterpret_cast<char *>(heap.getCpuBase());
754-
auto dataFoundInReservedBlock = ArrayRef<char>(reservedBlock, sizeof(sipPattern));
755-
auto expectedData = ArrayRef<char>(csr->instructionHeapReserveredData);
756-
EXPECT_THAT(dataFoundInReservedBlock, testing::ContainerEq(expectedData));
757-
}
758-
759-
TEST(CommandQueueGetIndirectHeap, whenCheckingForCsrInstructionHeapReservedBlockSizeThenCachelineAlignmentIsExpected) {
760-
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::create<MockDevice>(nullptr));
761-
MockCommandStreamReceiver *csr = new MockCommandStreamReceiver;
762-
mockDevice->resetCommandStreamReceiver(csr);
763-
csr->instructionHeapReserveredData.assign(sipPattern, sipPattern + sizeof(sipPattern));
764-
MockCommandQueue cmdQ{nullptr, mockDevice.get(), nullptr};
765-
766-
EXPECT_GE(alignedPatternSize, csr->getInstructionHeapCmdStreamReceiverReservedSize());
767-
EXPECT_EQ(alignedPatternSize, cmdQ.getInstructionHeapReservedBlockSize());
768-
}
769-
770730
TEST(CommandQueue, givenEnqueueAcquireSharedObjectsWhenNoObjectsThenReturnSuccess) {
771731
MockContext context;
772732
CommandQueue cmdQ(&context, nullptr, 0);

unit_tests/command_stream/command_stream_receiver_hw_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,7 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, givenCsrInBatchingModeWhenSusbsequ
27632763
dispatchFlags);
27642764

27652765
EXPECT_EQ(expectedUsed + additionalSize, mockCsr->peekTotalMemoryUsed());
2766+
mockCsr->flushBatchedSubmissions();
27662767
}
27672768

27682769
struct MockedMemoryManager : public OsAgnosticMemoryManager {

unit_tests/command_stream/command_stream_receiver_tests.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -260,36 +260,4 @@ TEST_F(CommandStreamReceiverTest, givenForced32BitAddressingWhenDebugSurfaceIsAl
260260
HWTEST_F(CommandStreamReceiverTest, givenDefaultCommandStreamReceiverThenDefaultDispatchingPolicyIsImmediateSubmission) {
261261
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
262262
EXPECT_EQ(CommandStreamReceiver::DispatchMode::ImmediateDispatch, csr.dispatchMode);
263-
}
264-
265-
TEST(CommandStreamReceiver, cmdStreamReceiverReservedBlockInInstructionHeapIsBasedOnPreemptionHelper) {
266-
auto mockDevice = std::unique_ptr<MockDevice>(MockDevice::create<MockDevice>(nullptr));
267-
mockDevice->setPreemptionMode(PreemptionMode::MidThread);
268-
{
269-
MockBuiltins mockBuiltins;
270-
mockBuiltins.overrideGlobalBuiltins();
271-
{
272-
auto sipOverride = std::unique_ptr<OCLRT::SipKernel>(new OCLRT::SipKernel(OCLRT::SipKernelType::Csr, getSipProgramWithCustomBinary()));
273-
mockBuiltins.overrideSipKernel(std::move(sipOverride));
274-
}
275-
276-
size_t reservedSize = mockDevice->getCommandStreamReceiver().getInstructionHeapCmdStreamReceiverReservedSize();
277-
size_t expectedSize = OCLRT::PreemptionHelper::getInstructionHeapSipKernelReservedSize(*mockDevice);
278-
EXPECT_NE(0U, expectedSize);
279-
EXPECT_EQ(expectedSize, reservedSize);
280-
ASSERT_LE(expectedSize, reservedSize);
281-
282-
StackVec<char, 4096> cmdStreamIhBuffer;
283-
cmdStreamIhBuffer.resize(reservedSize);
284-
LinearStream cmdStreamReceiverInstrucionHeap{cmdStreamIhBuffer.begin(), cmdStreamIhBuffer.size()};
285-
mockDevice->getCommandStreamReceiver().initializeInstructionHeapCmdStreamReceiverReservedBlock(cmdStreamReceiverInstrucionHeap);
286-
287-
StackVec<char, 4096> preemptionHelperIhBuffer;
288-
preemptionHelperIhBuffer.resize(expectedSize);
289-
LinearStream preemptionHelperInstrucionHeap{preemptionHelperIhBuffer.begin(), preemptionHelperIhBuffer.size()};
290-
PreemptionHelper::initializeInstructionHeapSipKernelReservedBlock(preemptionHelperInstrucionHeap, *mockDevice);
291-
292-
cmdStreamIhBuffer.resize(expectedSize);
293-
EXPECT_THAT(preemptionHelperIhBuffer, testing::ContainerEq(cmdStreamIhBuffer));
294-
}
295-
}
263+
}

0 commit comments

Comments
 (0)