2929#include < algorithm>
3030
3131namespace OCLRT {
32- MemoryManager::MemoryManager (bool enable64kbpages, bool enableLocalMemory,
33- ExecutionEnvironment &executionEnvironment) : allocator32Bit(nullptr ), enable64kbpages(enable64kbpages),
34- localMemorySupported (enableLocalMemory),
35- executionEnvironment(executionEnvironment),
36- hostPtrManager(std::make_unique<HostPtrManager>()),
37- multiContextResourceDestructor(std::make_unique<DeferredDeleter>()) {
38- registeredOsContexts.resize (1 );
39- };
32+ MemoryManager::MemoryManager (bool enable64kbpages, bool enableLocalMemory, ExecutionEnvironment &executionEnvironment)
33+ : allocator32Bit(nullptr ), enable64kbpages(enable64kbpages), localMemorySupported(enableLocalMemory),
34+ executionEnvironment (executionEnvironment), hostPtrManager(std::make_unique<HostPtrManager>()),
35+ multiContextResourceDestructor(std::make_unique<DeferredDeleter>()){};
4036
4137MemoryManager::~MemoryManager () {
42- for (auto osContext : registeredOsContexts) {
43- if (osContext) {
44- osContext->decRefInternal ();
45- }
38+ for (auto &engine : registeredEngines) {
39+ engine.osContext ->decRefInternal ();
4640 }
4741}
4842
@@ -151,15 +145,14 @@ void MemoryManager::checkGpuUsageAndDestroyGraphicsAllocations(GraphicsAllocatio
151145 multiContextResourceDestructor->drain (false );
152146 return ;
153147 }
154- for (auto &deviceCsrs : getCommandStreamReceivers ()) {
155- for (auto &csr : deviceCsrs) {
156- auto osContextId = csr->getOsContext ().getContextId ();
157- auto allocationTaskCount = gfxAllocation->getTaskCount (osContextId);
158- if (gfxAllocation->isUsedByOsContext (osContextId) &&
159- allocationTaskCount > *csr->getTagAddress ()) {
160- csr->getInternalAllocationStorage ()->storeAllocation (std::unique_ptr<GraphicsAllocation>(gfxAllocation), TEMPORARY_ALLOCATION);
161- return ;
162- }
148+ for (auto &engine : getRegisteredEngines ()) {
149+ auto osContextId = engine.osContext ->getContextId ();
150+ auto allocationTaskCount = gfxAllocation->getTaskCount (osContextId);
151+ if (gfxAllocation->isUsedByOsContext (osContextId) &&
152+ allocationTaskCount > *engine.commandStreamReceiver ->getTagAddress ()) {
153+ engine.commandStreamReceiver ->getInternalAllocationStorage ()->storeAllocation (std::unique_ptr<GraphicsAllocation>(gfxAllocation),
154+ TEMPORARY_ALLOCATION);
155+ return ;
163156 }
164157 }
165158 }
@@ -184,14 +177,13 @@ bool MemoryManager::isMemoryBudgetExhausted() const {
184177 return false ;
185178}
186179
187- OsContext *MemoryManager::createAndRegisterOsContext (EngineInstanceT engineType, uint32_t numSupportedDevices, PreemptionMode preemptionMode) {
180+ OsContext *MemoryManager::createAndRegisterOsContext (CommandStreamReceiver *commandStreamReceiver, EngineInstanceT engineType,
181+ uint32_t numSupportedDevices, PreemptionMode preemptionMode) {
188182 auto contextId = ++latestContextId;
189- if (contextId + 1 > registeredOsContexts.size ()) {
190- registeredOsContexts.resize (contextId + 1 );
191- }
192183 auto osContext = new OsContext (executionEnvironment.osInterface .get (), contextId, numSupportedDevices, engineType, preemptionMode);
193184 osContext->incRefInternal ();
194- registeredOsContexts[contextId] = osContext;
185+
186+ registeredEngines.emplace_back (commandStreamReceiver, osContext);
195187
196188 return osContext;
197189}
@@ -354,8 +346,8 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryForImage(const Allocati
354346 return allocateGraphicsMemoryForImageImpl (allocationDataWithSize, std::move (gmm));
355347}
356348
357- const CsrContainer &MemoryManager::getCommandStreamReceivers () const {
358- return executionEnvironment. commandStreamReceivers ;
349+ EngineControlContainer &MemoryManager::getRegisteredEngines () {
350+ return registeredEngines ;
359351}
360352
361353CommandStreamReceiver *MemoryManager::getDefaultCommandStreamReceiver (uint32_t deviceId) const {
0 commit comments