Move ownership of command stream receiver to execution environment.

Change-Id: Ibf924347e79f0c6e61141542c7e4c97c7a27e88d
This commit is contained in:
Mrozek, Michal
2018-07-11 14:16:35 +02:00
committed by sys_ocldev
parent 403d5af7f0
commit a126b290b8
7 changed files with 28 additions and 25 deletions

View File

@@ -79,7 +79,7 @@ bool familyEnabled[IGFX_MAX_CORE] = {
}; };
Device::Device(const HardwareInfo &hwInfo, ExecutionEnvironment *executionEnvironment) 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), tagAddress(nullptr), tagAllocation(nullptr), preemptionAllocation(nullptr),
osTime(nullptr), slmWindowStartAddress(nullptr), executionEnvironment(executionEnvironment) { osTime(nullptr), slmWindowStartAddress(nullptr), executionEnvironment(executionEnvironment) {
memset(&deviceInfo, 0, sizeof(deviceInfo)); memset(&deviceInfo, 0, sizeof(deviceInfo));
@@ -106,10 +106,9 @@ Device::~Device() {
if (performanceCounters) { if (performanceCounters) {
performanceCounters->shutdown(); performanceCounters->shutdown();
} }
if (commandStreamReceiver) { if (executionEnvironment->commandStreamReceiver) {
commandStreamReceiver->flushBatchedSubmissions(); executionEnvironment->commandStreamReceiver->flushBatchedSubmissions();
delete commandStreamReceiver; executionEnvironment->commandStreamReceiver.reset(nullptr);
commandStreamReceiver = nullptr;
} }
if (deviceInfo.sourceLevelDebuggerActive && sourceLevelDebugger) { if (deviceInfo.sourceLevelDebuggerActive && sourceLevelDebugger) {
@@ -139,7 +138,7 @@ bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
return false; return false;
} }
outDevice.commandStreamReceiver = commandStreamReceiver; outDevice.executionEnvironment->commandStreamReceiver.reset(commandStreamReceiver);
if (!outDevice.memoryManager) { if (!outDevice.memoryManager) {
outDevice.memoryManager = commandStreamReceiver->createMemoryManager(outDevice.deviceInfo.enabled64kbPages); outDevice.memoryManager = commandStreamReceiver->createMemoryManager(outDevice.deviceInfo.enabled64kbPages);
@@ -265,7 +264,7 @@ unique_ptr_if_unused<Device> Device::release() {
bool Device::isSimulation() { bool Device::isSimulation() {
bool simulation = hwInfo.capabilityTable.isSimulation(hwInfo.pPlatform->usDeviceID); bool simulation = hwInfo.capabilityTable.isSimulation(hwInfo.pPlatform->usDeviceID);
if (commandStreamReceiver->getType() != CommandStreamReceiverType::CSR_HW) { if (executionEnvironment->commandStreamReceiver->getType() != CommandStreamReceiverType::CSR_HW) {
simulation = true; simulation = true;
} }
return simulation; return simulation;

View File

@@ -23,6 +23,7 @@
#pragma once #pragma once
#include "runtime/api/cl_types.h" #include "runtime/api/cl_types.h"
#include "runtime/device/device_info_map.h" #include "runtime/device/device_info_map.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/helpers/base_object.h" #include "runtime/helpers/base_object.h"
#include "runtime/helpers/hw_info.h" #include "runtime/helpers/hw_info.h"
#include "runtime/helpers/engine_node.h" #include "runtime/helpers/engine_node.h"
@@ -38,7 +39,6 @@ class OSTime;
class DriverInfo; class DriverInfo;
struct HardwareInfo; struct HardwareInfo;
class SourceLevelDebugger; class SourceLevelDebugger;
class ExecutionEnvironment;
template <> template <>
struct OpenCLObjectMapper<_cl_device_id> { struct OpenCLObjectMapper<_cl_device_id> {
@@ -153,8 +153,6 @@ class Device : public BaseObject<_cl_device_id> {
const HardwareInfo &hwInfo; const HardwareInfo &hwInfo;
DeviceInfo deviceInfo; DeviceInfo deviceInfo;
CommandStreamReceiver *commandStreamReceiver;
volatile uint32_t *tagAddress; volatile uint32_t *tagAddress;
GraphicsAllocation *tagAllocation; GraphicsAllocation *tagAllocation;
GraphicsAllocation *preemptionAllocation; GraphicsAllocation *preemptionAllocation;
@@ -182,11 +180,11 @@ inline void Device::getCap(const void *&src,
} }
inline CommandStreamReceiver &Device::getCommandStreamReceiver() { inline CommandStreamReceiver &Device::getCommandStreamReceiver() {
return *commandStreamReceiver; return *(executionEnvironment->commandStreamReceiver.get());
} }
inline CommandStreamReceiver *Device::peekCommandStreamReceiver() { inline CommandStreamReceiver *Device::peekCommandStreamReceiver() {
return commandStreamReceiver; return executionEnvironment->commandStreamReceiver.get();
} }
inline volatile uint32_t *Device::getTagAddress() const { inline volatile uint32_t *Device::getTagAddress() const {

View File

@@ -20,6 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/execution_environment/execution_environment.h" #include "runtime/execution_environment/execution_environment.h"
#include "runtime/gmm_helper/gmm_helper.h" #include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/os_interface/device_factory.h" #include "runtime/os_interface/device_factory.h"

View File

@@ -24,12 +24,14 @@
namespace OCLRT { namespace OCLRT {
class GmmHelper; class GmmHelper;
class CommandStreamReceiver;
struct HardwareInfo; struct HardwareInfo;
class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment> { class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment> {
public: public:
ExecutionEnvironment(); ExecutionEnvironment();
~ExecutionEnvironment() override; ~ExecutionEnvironment() override;
void initGmm(const HardwareInfo *hwInfo); void initGmm(const HardwareInfo *hwInfo);
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
protected: protected:
std::unique_ptr<GmmHelper> gmmHelper; std::unique_ptr<GmmHelper> gmmHelper;

View File

@@ -69,4 +69,11 @@ TEST(ExecutionEnvironment, givenDeviceThatHaveRefferencesAfterPlatformIsDestroye
EXPECT_EQ(1, executionEnvironment->getRefInternalCount()); EXPECT_EQ(1, executionEnvironment->getRefInternalCount());
device->decRefInternal(); device->decRefInternal();
}
TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesCommandStreamReceiverInExecutionEnvironment) {
Platform platform;
auto executionEnvironment = platform.peekExecutionEnvironment();
platform.initialize();
EXPECT_NE(nullptr, executionEnvironment->commandStreamReceiver);
} }

View File

@@ -59,21 +59,18 @@ bool MockDevice::hasDriverInfo() {
}; };
void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) { void MockDevice::injectMemoryManager(MockMemoryManager *memoryManager) {
memoryManager->setCommandStreamReceiver(commandStreamReceiver); memoryManager->setCommandStreamReceiver(executionEnvironment->commandStreamReceiver.get());
commandStreamReceiver->setMemoryManager(memoryManager); executionEnvironment->commandStreamReceiver->setMemoryManager(memoryManager);
setMemoryManager(memoryManager); setMemoryManager(memoryManager);
memoryManager->setDevice(this); memoryManager->setDevice(this);
} }
void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) { void MockDevice::resetCommandStreamReceiver(CommandStreamReceiver *newCsr) {
if (commandStreamReceiver) { executionEnvironment->commandStreamReceiver.reset(newCsr);
delete commandStreamReceiver; executionEnvironment->commandStreamReceiver->setMemoryManager(memoryManager);
} executionEnvironment->commandStreamReceiver->setTagAllocation(tagAllocation);
commandStreamReceiver = newCsr; executionEnvironment->commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation);
commandStreamReceiver->setMemoryManager(memoryManager); memoryManager->csr = executionEnvironment->commandStreamReceiver.get();
commandStreamReceiver->setTagAllocation(tagAllocation);
commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation);
memoryManager->csr = commandStreamReceiver;
} }
OCLRT::FailMemoryManager::FailMemoryManager() : MockMemoryManager() { OCLRT::FailMemoryManager::FailMemoryManager() : MockMemoryManager() {

View File

@@ -36,8 +36,8 @@ class MockMemoryManager;
class MockDevice : public Device { class MockDevice : public Device {
public: public:
using Device::commandStreamReceiver;
using Device::createDeviceImpl; using Device::createDeviceImpl;
using Device::executionEnvironment;
using Device::initializeCaps; using Device::initializeCaps;
using Device::sourceLevelDebugger; using Device::sourceLevelDebugger;
@@ -125,8 +125,7 @@ class MockDevice : public Device {
size_t alignment = 256 * MemoryConstants::kiloByte; size_t alignment = 256 * MemoryConstants::kiloByte;
bool uncacheable = getWaTable()->waCSRUncachable; bool uncacheable = getWaTable()->waCSRUncachable;
this->preemptionAllocation = memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable); this->preemptionAllocation = memoryManager->allocateGraphicsMemory(requiredSize, alignment, false, uncacheable);
executionEnvironment->commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation);
commandStreamReceiver->setPreemptionCsrAllocation(preemptionAllocation);
} }
} }
} }