diff --git a/runtime/device/device.cpp b/runtime/device/device.cpp index 368cd1643d..11fc0f4069 100644 --- a/runtime/device/device.cpp +++ b/runtime/device/device.cpp @@ -79,7 +79,7 @@ bool familyEnabled[IGFX_MAX_CORE] = { }; Device::Device(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment) - : memoryManager(nullptr), enabledClVersion(false), hwInfo(hwInfo), commandStreamReceiver(nullptr), + : memoryManager(nullptr), enabledClVersion(false), hwInfo(hwInfo), tagAddress(nullptr), tagAllocation(nullptr), preemptionAllocation(nullptr), osTime(nullptr), slmWindowStartAddress(nullptr), executionEnvironment(executionEnvironment) { memset(&deviceInfo, 0, sizeof(deviceInfo)); @@ -106,10 +106,9 @@ Device::~Device() { if (performanceCounters) { performanceCounters->shutdown(); } - if (commandStreamReceiver) { - commandStreamReceiver->flushBatchedSubmissions(); - delete commandStreamReceiver; - commandStreamReceiver = nullptr; + if (executionEnvironment->commandStreamReceiver) { + executionEnvironment->commandStreamReceiver->flushBatchedSubmissions(); + executionEnvironment->commandStreamReceiver.reset(nullptr); } if (deviceInfo.sourceLevelDebuggerActive && sourceLevelDebugger) { @@ -139,7 +138,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) { return false; } - outDevice.commandStreamReceiver = commandStreamReceiver; + outDevice.executionEnvironment->commandStreamReceiver.reset(commandStreamReceiver); if (!outDevice.memoryManager) { outDevice.memoryManager = commandStreamReceiver->createMemoryManager(outDevice.deviceInfo.enabled64kbPages); @@ -265,7 +264,7 @@ unique_ptr_if_unused Device::release() { bool Device::isSimulation() { bool simulation = hwInfo.capabilityTable.isSimulation(hwInfo.pPlatform->usDeviceID); - if (commandStreamReceiver->getType() != CommandStreamReceiverType::CSR_HW) { + if (executionEnvironment->commandStreamReceiver->getType() != CommandStreamReceiverType::CSR_HW) { simulation = true; } return simulation; diff --git a/runtime/device/device.h b/runtime/device/device.h index 199397e9aa..0f458b8cf6 100644 --- a/runtime/device/device.h +++ b/runtime/device/device.h @@ -23,6 +23,7 @@ #pragma once #include "runtime/api/cl_types.h" #include "runtime/device/device_info_map.h" +#include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/base_object.h" #include "runtime/helpers/hw_info.h" #include "runtime/helpers/engine_node.h" @@ -38,7 +39,6 @@ class OSTime; class DriverInfo; struct HardwareInfo; class SourceLevelDebugger; -class ExecutionEnvironment; template <> struct OpenCLObjectMapper<_cl_device_id> { @@ -153,8 +153,6 @@ class Device : public BaseObject<_cl_device_id> { const HardwareInfo &hwInfo; DeviceInfo deviceInfo; - CommandStreamReceiver *commandStreamReceiver; - volatile uint32_t *tagAddress; GraphicsAllocation *tagAllocation; GraphicsAllocation *preemptionAllocation; @@ -182,11 +180,11 @@ inline void Device::getCap(const void *&src, } inline CommandStreamReceiver &Device::getCommandStreamReceiver() { - return *commandStreamReceiver; + return *(executionEnvironment->commandStreamReceiver.get()); } inline CommandStreamReceiver *Device::peekCommandStreamReceiver() { - return commandStreamReceiver; + return executionEnvironment->commandStreamReceiver.get(); } inline volatile uint32_t *Device::getTagAddress() const { diff --git a/runtime/execution_environment/execution_environment.cpp b/runtime/execution_environment/execution_environment.cpp index 6838a38965..88d6fbe9e1 100644 --- a/runtime/execution_environment/execution_environment.cpp +++ b/runtime/execution_environment/execution_environment.cpp @@ -20,6 +20,7 @@ * OTHER DEALINGS IN THE SOFTWARE. */ +#include "runtime/command_stream/command_stream_receiver.h" #include "runtime/execution_environment/execution_environment.h" #include "runtime/gmm_helper/gmm_helper.h" #include "runtime/os_interface/device_factory.h" diff --git a/runtime/execution_environment/execution_environment.h b/runtime/execution_environment/execution_environment.h index 363bfe4f85..c2a83be749 100644 --- a/runtime/execution_environment/execution_environment.h +++ b/runtime/execution_environment/execution_environment.h @@ -24,12 +24,14 @@ namespace OCLRT { class GmmHelper; +class CommandStreamReceiver; struct HardwareInfo; class ExecutionEnvironment : public ReferenceTrackedObject { public: ExecutionEnvironment(); ~ExecutionEnvironment() override; void initGmm(const HardwareInfo *hwInfo); + std::unique_ptr commandStreamReceiver; protected: std::unique_ptr gmmHelper; diff --git a/unit_tests/execution_environment/execution_environment_tests.cpp b/unit_tests/execution_environment/execution_environment_tests.cpp index 072f4d08a0..6cc92470ec 100644 --- a/unit_tests/execution_environment/execution_environment_tests.cpp +++ b/unit_tests/execution_environment/execution_environment_tests.cpp @@ -69,4 +69,11 @@ TEST(ExecutionEnvironment, givenDeviceThatHaveRefferencesAfterPlatformIsDestroye EXPECT_EQ(1, executionEnvironment->getRefInternalCount()); device->decRefInternal(); +} + +TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesCommandStreamReceiverInExecutionEnvironment) { + Platform platform; + auto executionEnvironment = platform.peekExecutionEnvironment(); + platform.initialize(); + EXPECT_NE(nullptr, executionEnvironment->commandStreamReceiver); } \ No newline at end of file diff --git a/unit_tests/mocks/mock_device.cpp b/unit_tests/mocks/mock_device.cpp index 24cac3a9b4..3373968f70 100644 --- a/unit_tests/mocks/mock_device.cpp +++ b/unit_tests/mocks/mock_device.cpp @@ -59,21 +59,18 @@ bool MockDevice::hasDriverInfo() { }; void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) { - memoryManager->setCommandStreamReceiver(commandStreamReceiver); - commandStreamReceiver->setMemoryManager(memoryManager); + memoryManager->setCommandStreamReceiver(executionEnvironment->commandStreamReceiver.get()); + executionEnvironment->commandStreamReceiver->setMemoryManager(memoryManager); setMemoryManager(memoryManager); memoryManager->setDevice(this); } void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) { - if (commandStreamReceiver) { - delete commandStreamReceiver; - } - commandStreamReceiver = newCsr; - commandStreamReceiver->setMemoryManager(memoryManager); - commandStreamReceiver->setTagAllocation(tagAllocation); - commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation); - memoryManager->csr = commandStreamReceiver; + executionEnvironment->commandStreamReceiver.reset(newCsr); + executionEnvironment->commandStreamReceiver->setMemoryManager(memoryManager); + executionEnvironment->commandStreamReceiver->setTagAllocation(tagAllocation); + executionEnvironment->commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation); + memoryManager->csr = executionEnvironment->commandStreamReceiver.get(); } OCLRT::FailMemoryManager::FailMemoryManager() : MockMemoryManager() { diff --git a/unit_tests/mocks/mock_device.h b/unit_tests/mocks/mock_device.h index 91b1b67be4..2ba27a9166 100644 --- a/unit_tests/mocks/mock_device.h +++ b/unit_tests/mocks/mock_device.h @@ -36,8 +36,8 @@ class MockMemoryManager; class MockDevice : public Device { public: - using Device::commandStreamReceiver; using Device::createDeviceImpl; + using Device::executionEnvironment; using Device::initializeCaps; using Device::sourceLevelDebugger; @@ -125,8 +125,7 @@ class MockDevice : public Device { size_t alignment = 256 * MemoryConstants::kiloByte; bool uncacheable = getWaTable()->waCSRUncachable; this->preemptionAllocation = memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable); - - commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation); + executionEnvironment->commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation); } } }