Skip to content

Commit 7dbd0ea

Browse files
committed
Move Scratch Space functionality to dedicated class
Change-Id: Ic7655c4b971513961aba6823478a139ffc943466
1 parent a9d3575 commit 7dbd0ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+934
-91
lines changed

runtime/command_stream/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ set(RUNTIME_SRCS_COMMAND_STREAM
3232
${CMAKE_CURRENT_SOURCE_DIR}/experimental_command_buffer.inl
3333
${CMAKE_CURRENT_SOURCE_DIR}/linear_stream.cpp
3434
${CMAKE_CURRENT_SOURCE_DIR}/linear_stream.h
35+
${CMAKE_CURRENT_SOURCE_DIR}/scratch_space_controller.cpp
36+
${CMAKE_CURRENT_SOURCE_DIR}/scratch_space_controller.h
37+
${CMAKE_CURRENT_SOURCE_DIR}/scratch_space_controller_base.cpp
38+
${CMAKE_CURRENT_SOURCE_DIR}/scratch_space_controller_base.h
3539
${CMAKE_CURRENT_SOURCE_DIR}/submissions_aggregator.cpp
3640
${CMAKE_CURRENT_SOURCE_DIR}/submissions_aggregator.h
3741
${CMAKE_CURRENT_SOURCE_DIR}/tbx_command_stream_receiver.cpp
@@ -46,3 +50,4 @@ set(RUNTIME_SRCS_COMMAND_STREAM
4650
)
4751
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_COMMAND_STREAM})
4852
set_property(GLOBAL PROPERTY RUNTIME_SRCS_COMMAND_STREAM ${RUNTIME_SRCS_COMMAND_STREAM})
53+
add_subdirectories()

runtime/command_stream/aub_command_stream_receiver.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ CommandStreamReceiver *AUBCommandStreamReceiver::create(const HardwareInfo &hwIn
2424
// Generate the full filename
2525
const auto &gtSystemInfo = *hwInfo.pSysInfo;
2626
std::stringstream strfilename;
27-
strfilename << hwPrefix << "_" << gtSystemInfo.SliceCount << "x" << gtSystemInfo.SubSliceCount << "x" << gtSystemInfo.MaxEuPerSubSlice << "_" << baseName << ".aub";
27+
uint32_t subSlicesPerSlice = gtSystemInfo.SubSliceCount / gtSystemInfo.SliceCount;
28+
strfilename << hwPrefix << "_" << gtSystemInfo.SliceCount << "x" << subSlicesPerSlice << "x" << gtSystemInfo.MaxEuPerSubSlice << "_" << baseName << ".aub";
2829

2930
// clean-up any fileName issues because of the file system incompatibilities
3031
auto fileName = strfilename.str();

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "runtime/command_stream/command_stream_receiver.h"
1010
#include "runtime/command_stream/experimental_command_buffer.h"
1111
#include "runtime/command_stream/preemption.h"
12+
#include "runtime/command_stream/scratch_space_controller.h"
1213
#include "runtime/device/device.h"
1314
#include "runtime/event/event.h"
1415
#include "runtime/gtpin/gtpin_notify.h"
@@ -157,11 +158,6 @@ void CommandStreamReceiver::cleanupResources() {
157158
waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, TEMPORARY_ALLOCATION);
158159
waitForTaskCountAndCleanAllocationList(this->latestFlushedTaskCount, REUSABLE_ALLOCATION);
159160

160-
if (scratchAllocation) {
161-
getMemoryManager()->freeGraphicsMemory(scratchAllocation);
162-
scratchAllocation = nullptr;
163-
}
164-
165161
if (debugSurface) {
166162
getMemoryManager()->freeGraphicsMemory(debugSurface);
167163
debugSurface = nullptr;
@@ -217,6 +213,10 @@ void CommandStreamReceiver::setRequiredScratchSize(uint32_t newRequiredScratchSi
217213
}
218214
}
219215

216+
GraphicsAllocation *CommandStreamReceiver::getScratchAllocation() {
217+
return scratchSpaceController->getScratchSpaceAllocation();
218+
}
219+
220220
void CommandStreamReceiver::initProgrammingFlags() {
221221
isPreambleSent = false;
222222
GSBAFor32BitProgrammed = false;
@@ -310,6 +310,7 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType,
310310
indirectHeap = new IndirectHeap(heapMemory, requireInternalHeap);
311311
indirectHeap->overrideMaxSize(finalHeapSize);
312312
}
313+
scratchSpaceController->reserveHeap(heapType, indirectHeap);
313314
}
314315

315316
void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) {

runtime/command_stream/command_stream_receiver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class LinearStream;
3535
class MemoryManager;
3636
class OsContext;
3737
class OSInterface;
38+
class ScratchSpaceController;
3839
class TimestampPacket;
3940
struct HwPerfCounter;
4041
struct HwTimeStamps;
@@ -116,7 +117,7 @@ class CommandStreamReceiver {
116117
virtual void overrideMediaVFEStateDirty(bool dirty) { mediaVfeStateDirty = dirty; }
117118

118119
void setRequiredScratchSize(uint32_t newRequiredScratchSize);
119-
GraphicsAllocation *getScratchAllocation() const { return scratchAllocation; }
120+
GraphicsAllocation *getScratchAllocation();
120121
GraphicsAllocation *getDebugSurfaceAllocation() const { return debugSurface; }
121122
GraphicsAllocation *allocateDebugSurface(size_t size);
122123

@@ -180,6 +181,7 @@ class CommandStreamReceiver {
180181
std::unique_ptr<ExperimentalCommandBuffer> experimentalCmdBuffer;
181182
std::unique_ptr<InternalAllocationStorage> internalAllocationStorage;
182183
std::unique_ptr<KmdNotifyHelper> kmdNotifyHelper;
184+
std::unique_ptr<ScratchSpaceController> scratchSpaceController;
183185
std::unique_ptr<TagAllocator<HwTimeStamps>> profilingTimeStampAllocator;
184186
std::unique_ptr<TagAllocator<HwPerfCounter>> perfCounterAllocator;
185187
std::unique_ptr<TagAllocator<TimestampPacket>> timestampPacketAllocator;
@@ -194,7 +196,6 @@ class CommandStreamReceiver {
194196
volatile uint32_t *tagAddress = nullptr;
195197

196198
GraphicsAllocation *tagAllocation = nullptr;
197-
GraphicsAllocation *scratchAllocation = nullptr;
198199
GraphicsAllocation *preemptionCsrAllocation = nullptr;
199200
GraphicsAllocation *debugSurface = nullptr;
200201
OSInterface *osInterface = nullptr;

runtime/command_stream/command_stream_receiver_hw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
8181
void handleEventsTimestampPacketTags(LinearStream &csr, DispatchFlags &dispatchFlags, Device &currentDevice);
8282
virtual void programVFEState(LinearStream &csr, DispatchFlags &dispatchFlags);
8383
virtual void initPageTableManagerRegisters(LinearStream &csr){};
84-
void createScratchSpaceAllocation(size_t requiredScratchSizeInBytes);
8584

8685
void addPipeControlWA(LinearStream &commandStream, bool flushDC);
8786
void addDcFlushToPipeControl(typename GfxFamily::PIPE_CONTROL *pCmd, bool flushDC);
@@ -90,6 +89,7 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
9089
size_t getSshHeapSize();
9190

9291
uint64_t getScratchPatchAddress();
92+
void createScratchSpaceController(const HardwareInfo &hwInfoIn);
9393

9494
static void emitNoop(LinearStream &commandStream, size_t bytesToUpdate);
9595

runtime/command_stream/command_stream_receiver_hw.inl

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "runtime/command_stream/command_stream_receiver_hw.h"
99
#include "runtime/command_stream/experimental_command_buffer.h"
1010
#include "runtime/command_stream/linear_stream.h"
11+
#include "runtime/command_stream/scratch_space_controller_base.h"
1112
#include "runtime/device/device.h"
1213
#include "runtime/event/event.h"
1314
#include "runtime/gtpin/gtpin_notify.h"
@@ -51,6 +52,7 @@ CommandStreamReceiverHw<GfxFamily>::CommandStreamReceiverHw(const HardwareInfo &
5152
if (DebugManager.flags.EnableTimestampPacket.get() != -1) {
5253
timestampPacketWriteEnabled = !!DebugManager.flags.EnableTimestampPacket.get();
5354
}
55+
createScratchSpaceController(hwInfoIn);
5456
}
5557

5658
template <typename GfxFamily>
@@ -237,22 +239,21 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
237239
csrSizeRequestFlags.numGrfRequiredChanged = this->lastSentNumGrfRequired != dispatchFlags.numGrfRequired;
238240
csrSizeRequestFlags.specialPipelineSelectModeChanged = this->lastSpecialPipelineSelectMode != dispatchFlags.specialPipelineSelectMode;
239241

240-
size_t requiredScratchSizeInBytes = requiredScratchSize * device.getDeviceInfo().computeUnitsUsedForScratch;
241-
242242
auto force32BitAllocations = getMemoryManager()->peekForce32BitAllocations();
243-
244243
bool stateBaseAddressDirty = false;
245244

246-
if (requiredScratchSize && (!scratchAllocation || scratchAllocation->getUnderlyingBufferSize() < requiredScratchSizeInBytes)) {
247-
if (scratchAllocation) {
248-
scratchAllocation->updateTaskCount(this->taskCount, this->deviceIndex);
249-
internalAllocationStorage->storeAllocation(std::unique_ptr<GraphicsAllocation>(scratchAllocation), TEMPORARY_ALLOCATION);
250-
}
251-
createScratchSpaceAllocation(requiredScratchSizeInBytes);
252-
overrideMediaVFEStateDirty(true);
253-
if (is64bit && !force32BitAllocations) {
254-
stateBaseAddressDirty = true;
245+
bool checkVfeStateDirty = false;
246+
if (requiredScratchSize) {
247+
scratchSpaceController->setRequiredScratchSpace(ssh.getCpuBase(),
248+
requiredScratchSize,
249+
this->taskCount,
250+
this->deviceIndex,
251+
stateBaseAddressDirty,
252+
checkVfeStateDirty);
253+
if (checkVfeStateDirty) {
254+
overrideMediaVFEStateDirty(true);
255255
}
256+
makeResident(*scratchSpaceController->getScratchSpaceAllocation());
256257
}
257258

258259
auto &commandStreamCSR = this->getCS(getRequiredCmdStreamSizeAligned(dispatchFlags, device));
@@ -308,8 +309,8 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
308309

309310
uint64_t newGSHbase = 0;
310311
GSBAFor32BitProgrammed = false;
311-
if (is64bit && scratchAllocation && !force32BitAllocations) {
312-
newGSHbase = (uint64_t)scratchAllocation->getUnderlyingBuffer() - PreambleHelper<GfxFamily>::getScratchSpaceOffsetFor64bit();
312+
if (is64bit && scratchSpaceController->getScratchSpaceAllocation() && !force32BitAllocations) {
313+
newGSHbase = scratchSpaceController->calculateNewGSH();
313314
} else if (is64bit && force32BitAllocations && dispatchFlags.GSBA32BitRequired) {
314315
newGSHbase = getMemoryManager()->allocator32Bit->getBase();
315316
GSBAFor32BitProgrammed = true;
@@ -381,9 +382,6 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
381382

382383
this->makeResident(*tagAllocation);
383384

384-
if (requiredScratchSize)
385-
makeResident(*scratchAllocation);
386-
387385
if (preemptionCsrAllocation)
388386
makeResident(*preemptionCsrAllocation);
389387

@@ -608,22 +606,6 @@ void CommandStreamReceiverHw<GfxFamily>::addPipeControl(LinearStream &commandStr
608606
}
609607
}
610608

611-
template <typename GfxFamily>
612-
uint64_t CommandStreamReceiverHw<GfxFamily>::getScratchPatchAddress() {
613-
//for 32 bit scratch space pointer is being programmed in Media VFE State and is relative to 0 as General State Base Address
614-
//for 64 bit, scratch space pointer is being programmed as "General State Base Address - scratchSpaceOffsetFor64bit"
615-
// and "0 + scratchSpaceOffsetFor64bit" is being programmed in Media VFE state
616-
617-
uint64_t scratchAddress = 0;
618-
if (requiredScratchSize) {
619-
scratchAddress = scratchAllocation->getGpuAddressToPatch();
620-
if (is64bit && !getMemoryManager()->peekForce32BitAllocations()) {
621-
//this is to avoid scractch allocation offset "0"
622-
scratchAddress = PreambleHelper<GfxFamily>::getScratchSpaceOffsetFor64bit();
623-
}
624-
}
625-
return scratchAddress;
626-
}
627609
template <typename GfxFamily>
628610
size_t CommandStreamReceiverHw<GfxFamily>::getRequiredCmdStreamSizeAligned(const DispatchFlags &dispatchFlags, Device &device) {
629611
size_t size = getRequiredCmdStreamSize(dispatchFlags, device);
@@ -821,7 +803,12 @@ void CommandStreamReceiverHw<GfxFamily>::handleEventsTimestampPacketTags(LinearS
821803
}
822804

823805
template <typename GfxFamily>
824-
void CommandStreamReceiverHw<GfxFamily>::createScratchSpaceAllocation(size_t requiredScratchSizeInBytes) {
825-
scratchAllocation = getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, requiredScratchSizeInBytes, GraphicsAllocation::AllocationType::SCRATCH_SURFACE);
806+
void CommandStreamReceiverHw<GfxFamily>::createScratchSpaceController(const HardwareInfo &hwInfoIn) {
807+
scratchSpaceController = std::make_unique<ScratchSpaceControllerBase>(hwInfoIn, executionEnvironment, *internalAllocationStorage.get());
808+
}
809+
810+
template <typename GfxFamily>
811+
uint64_t CommandStreamReceiverHw<GfxFamily>::getScratchPatchAddress() {
812+
return scratchSpaceController->getScratchPatchAddress();
826813
}
827814
} // namespace OCLRT
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "runtime/command_stream/scratch_space_controller.h"
9+
#include "runtime/execution_environment/execution_environment.h"
10+
#include "runtime/helpers/hw_helper.h"
11+
#include "runtime/memory_manager/graphics_allocation.h"
12+
#include "runtime/memory_manager/internal_allocation_storage.h"
13+
#include "runtime/memory_manager/memory_manager.h"
14+
15+
namespace OCLRT {
16+
ScratchSpaceController::ScratchSpaceController(const HardwareInfo &info, ExecutionEnvironment &environment, InternalAllocationStorage &allocationStorage)
17+
: hwInfo(info), executionEnvironment(environment), csrAllocationStorage(allocationStorage) {
18+
auto &hwHelper = HwHelper::get(info.pPlatform->eRenderCoreFamily);
19+
computeUnitsUsedForScratch = hwHelper.getComputeUnitsUsedForScratch(&hwInfo);
20+
}
21+
22+
ScratchSpaceController::~ScratchSpaceController() {
23+
if (scratchAllocation) {
24+
getMemoryManager()->freeGraphicsMemory(scratchAllocation);
25+
}
26+
}
27+
28+
MemoryManager *ScratchSpaceController::getMemoryManager() const {
29+
UNRECOVERABLE_IF(executionEnvironment.memoryManager.get() == nullptr);
30+
return executionEnvironment.memoryManager.get();
31+
}
32+
} // namespace OCLRT
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
#include "runtime/indirect_heap/indirect_heap.h"
10+
#include <cstddef>
11+
#include <cstdint>
12+
13+
namespace OCLRT {
14+
15+
class Device;
16+
class ExecutionEnvironment;
17+
class GraphicsAllocation;
18+
class InternalAllocationStorage;
19+
class MemoryManager;
20+
struct HardwareInfo;
21+
22+
class ScratchSpaceController {
23+
public:
24+
ScratchSpaceController(const HardwareInfo &info, ExecutionEnvironment &environment, InternalAllocationStorage &allocationStorage);
25+
virtual ~ScratchSpaceController();
26+
27+
GraphicsAllocation *getScratchSpaceAllocation() {
28+
return scratchAllocation;
29+
}
30+
virtual void setRequiredScratchSpace(void *sshBaseAddress,
31+
uint32_t requiredPerThreadScratchSize,
32+
uint32_t currentTaskCount,
33+
uint32_t deviceIdx,
34+
bool &stateBaseAddressDirty,
35+
bool &vfeStateDirty) = 0;
36+
virtual uint64_t calculateNewGSH() = 0;
37+
virtual uint64_t getScratchPatchAddress() = 0;
38+
39+
virtual void reserveHeap(IndirectHeap::Type heapType, IndirectHeap *&indirectHeap) = 0;
40+
41+
protected:
42+
MemoryManager *getMemoryManager() const;
43+
44+
const HardwareInfo &hwInfo;
45+
ExecutionEnvironment &executionEnvironment;
46+
GraphicsAllocation *scratchAllocation = nullptr;
47+
InternalAllocationStorage &csrAllocationStorage;
48+
size_t scratchSizeBytes = 0;
49+
bool force32BitAllocation = false;
50+
uint32_t computeUnitsUsedForScratch = 0;
51+
};
52+
} // namespace OCLRT
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "runtime/command_stream/scratch_space_controller_base.h"
9+
#include "runtime/helpers/aligned_memory.h"
10+
#include "runtime/helpers/hw_helper.h"
11+
#include "runtime/helpers/preamble.h"
12+
#include "runtime/memory_manager/memory_constants.h"
13+
#include "runtime/memory_manager/graphics_allocation.h"
14+
#include "runtime/memory_manager/internal_allocation_storage.h"
15+
#include "runtime/memory_manager/memory_manager.h"
16+
17+
namespace OCLRT {
18+
ScratchSpaceControllerBase::ScratchSpaceControllerBase(const HardwareInfo &info, ExecutionEnvironment &environment, InternalAllocationStorage &allocationStorage)
19+
: ScratchSpaceController(info, environment, allocationStorage) {
20+
}
21+
22+
void ScratchSpaceControllerBase::setRequiredScratchSpace(void *sshBaseAddress,
23+
uint32_t requiredPerThreadScratchSize,
24+
uint32_t currentTaskCount,
25+
uint32_t deviceIdx,
26+
bool &stateBaseAddressDirty,
27+
bool &vfeStateDirty) {
28+
size_t requiredScratchSizeInBytes = requiredPerThreadScratchSize * computeUnitsUsedForScratch;
29+
if (requiredScratchSizeInBytes && (!scratchAllocation || scratchSizeBytes < requiredScratchSizeInBytes)) {
30+
if (scratchAllocation) {
31+
scratchAllocation->updateTaskCount(currentTaskCount, deviceIdx);
32+
csrAllocationStorage.storeAllocation(std::unique_ptr<GraphicsAllocation>(scratchAllocation), TEMPORARY_ALLOCATION);
33+
}
34+
scratchSizeBytes = requiredScratchSizeInBytes;
35+
createScratchSpaceAllocation();
36+
vfeStateDirty = true;
37+
force32BitAllocation = getMemoryManager()->peekForce32BitAllocations();
38+
if (is64bit && !force32BitAllocation) {
39+
stateBaseAddressDirty = true;
40+
}
41+
}
42+
}
43+
44+
void ScratchSpaceControllerBase::createScratchSpaceAllocation() {
45+
scratchAllocation = getMemoryManager()->allocateGraphicsMemoryInPreferredPool(AllocationFlags(true), 0, nullptr, scratchSizeBytes, GraphicsAllocation::AllocationType::SCRATCH_SURFACE);
46+
UNRECOVERABLE_IF(scratchAllocation == nullptr);
47+
}
48+
49+
uint64_t ScratchSpaceControllerBase::calculateNewGSH() {
50+
auto &hwHelper = HwHelper::get(hwInfo.pPlatform->eRenderCoreFamily);
51+
auto scratchSpaceOffsetFor64bit = hwHelper.getScratchSpaceOffsetFor64bit();
52+
return reinterpret_cast<uint64_t>(scratchAllocation->getUnderlyingBuffer()) - scratchSpaceOffsetFor64bit;
53+
}
54+
uint64_t ScratchSpaceControllerBase::getScratchPatchAddress() {
55+
//for 32 bit scratch space pointer is being programmed in Media VFE State and is relative to 0 as General State Base Address
56+
//for 64 bit, scratch space pointer is being programmed as "General State Base Address - scratchSpaceOffsetFor64bit"
57+
// and "0 + scratchSpaceOffsetFor64bit" is being programmed in Media VFE state
58+
uint64_t scratchAddress = 0;
59+
if (scratchAllocation) {
60+
scratchAddress = scratchAllocation->getGpuAddressToPatch();
61+
if (is64bit && !getMemoryManager()->peekForce32BitAllocations()) {
62+
auto &hwHelper = HwHelper::get(hwInfo.pPlatform->eRenderCoreFamily);
63+
auto scratchSpaceOffsetFor64bit = hwHelper.getScratchSpaceOffsetFor64bit();
64+
//this is to avoid scractch allocation offset "0"
65+
scratchAddress = scratchSpaceOffsetFor64bit;
66+
}
67+
}
68+
return scratchAddress;
69+
}
70+
71+
void ScratchSpaceControllerBase::reserveHeap(IndirectHeap::Type heapType, IndirectHeap *&indirectHeap) {
72+
}
73+
74+
} // namespace OCLRT

0 commit comments

Comments
 (0)