Refactor parts of createDeviceImpl.

- Move portions of code to dedicated methods.

Change-Id: I9abec23785f3f3201dce42a7a840ca4a450c4cc1
This commit is contained in:
Mrozek, Michal
2018-07-16 17:11:43 +02:00
committed by sys_ocldev
parent 8a69656446
commit f59c191915
7 changed files with 88 additions and 33 deletions

View File

@ -348,4 +348,14 @@ void CommandStreamReceiver::setExperimentalCmdBuffer(std::unique_ptr<Experimenta
experimentalCmdBuffer = std::move(cmdBuffer);
}
bool CommandStreamReceiver::initializeTagAllocation() {
auto tagAllocation = memoryManager->allocateGraphicsMemory(sizeof(uint32_t));
if (!tagAllocation) {
return false;
}
this->setTagAllocation(tagAllocation);
return true;
}
} // namespace OCLRT

View File

@ -21,16 +21,16 @@
*/
#pragma once
#include "runtime/command_stream/csr_definitions.h"
#include "runtime/command_stream/linear_stream.h"
#include "runtime/command_stream/thread_arbitration_policy.h"
#include "runtime/command_stream/submissions_aggregator.h"
#include "runtime/helpers/completion_stamp.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/command_stream/thread_arbitration_policy.h"
#include "runtime/helpers/address_patch.h"
#include "runtime/helpers/aligned_memory.h"
#include "runtime/helpers/completion_stamp.h"
#include "runtime/helpers/flat_batch_buffer_helper.h"
#include "runtime/helpers/options.h"
#include "runtime/indirect_heap/indirect_heap.h"
#include "runtime/helpers/flat_batch_buffer_helper.h"
#include "runtime/command_stream/csr_definitions.h"
#include <cstddef>
#include <cstdint>
@ -142,6 +142,8 @@ class CommandStreamReceiver {
virtual enum CommandStreamReceiverType getType() = 0;
void setExperimentalCmdBuffer(std::unique_ptr<ExperimentalCommandBuffer> &&cmdBuffer);
bool initializeTagAllocation();
protected:
void setDisableL3Cache(bool val) {
disableL3Cache = val;

View File

@ -20,6 +20,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/device/device.h"
#include "hw_cmds.h"
#include "runtime/built_ins/built_ins.h"
#include "runtime/built_ins/sip.h"
@ -28,7 +29,6 @@
#include "runtime/command_stream/experimental_command_buffer.h"
#include "runtime/command_stream/preemption.h"
#include "runtime/compiler_interface/compiler_interface.h"
#include "runtime/device/device.h"
#include "runtime/device/device_vector.h"
#include "runtime/device/driver_info.h"
#include "runtime/execution_environment/execution_environment.h"
@ -128,41 +128,30 @@ Device::~Device() {
}
bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
outDevice.executionEnvironment->initGmm(pHwInfo);
CommandStreamReceiver *commandStreamReceiver = createCommandStream(pHwInfo);
if (!commandStreamReceiver) {
auto executionEnvironment = outDevice.executionEnvironment;
executionEnvironment->initGmm(pHwInfo);
if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo)) {
return false;
}
outDevice.executionEnvironment->commandStreamReceiver.reset(commandStreamReceiver);
executionEnvironment->initializeMemoryManager(outDevice.executionEnvironment->memoryManager.get(), outDevice.getEnabled64kbPages());
if (!outDevice.executionEnvironment->memoryManager) {
outDevice.executionEnvironment->memoryManager.reset(commandStreamReceiver->createMemoryManager(outDevice.getEnabled64kbPages()));
} else {
commandStreamReceiver->setMemoryManager(outDevice.executionEnvironment->memoryManager.get());
}
DEBUG_BREAK_IF(nullptr == outDevice.executionEnvironment->memoryManager);
outDevice.executionEnvironment->memoryManager->csr = commandStreamReceiver;
auto pTagAllocation = outDevice.executionEnvironment->memoryManager->allocateGraphicsMemory(sizeof(uint32_t));
if (!pTagAllocation) {
CommandStreamReceiver *commandStreamReceiver = executionEnvironment->commandStreamReceiver.get();
if (!commandStreamReceiver->initializeTagAllocation()) {
return false;
}
auto pTagMemory = reinterpret_cast<uint32_t *>(pTagAllocation->getUnderlyingBuffer());
// Initialize HW tag to a known value
*pTagMemory = DebugManager.flags.EnableNullHardware.get() ? -1 : initialHardwareTag;
commandStreamReceiver->setTagAllocation(pTagAllocation);
executionEnvironment->memoryManager->csr = commandStreamReceiver;
auto pDevice = &outDevice;
if (!pDevice->osTime) {
pDevice->osTime = OSTime::create(commandStreamReceiver->getOSInterface());
}
pDevice->driverInfo.reset(DriverInfo::create(commandStreamReceiver->getOSInterface()));
pDevice->tagAddress = pTagMemory;
pDevice->tagAddress = reinterpret_cast<uint32_t *>(commandStreamReceiver->getTagAllocation()->getUnderlyingBuffer());
// Initialize HW tag to a known value
*pDevice->tagAddress = DebugManager.flags.EnableNullHardware.get() ? -1 : initialHardwareTag;
pDevice->initializeCaps();

View File

@ -20,16 +20,36 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/execution_environment/execution_environment.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/command_stream/command_stream_receiver.h"
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/os_interface/device_factory.h"
namespace OCLRT {
ExecutionEnvironment::ExecutionEnvironment() = default;
ExecutionEnvironment::~ExecutionEnvironment() = default;
extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo);
void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) {
gmmHelper.reset(new GmmHelper(hwInfo));
}
bool ExecutionEnvironment::initializeCommandStreamReceiver(const HardwareInfo *pHwInfo) {
CommandStreamReceiver *commandStreamReceiver = createCommandStream(pHwInfo);
if (!commandStreamReceiver) {
return false;
}
this->commandStreamReceiver.reset(commandStreamReceiver);
return true;
}
void ExecutionEnvironment::initializeMemoryManager(MemoryManager *externalMemoryManager, bool enable64KBpages) {
if (!externalMemoryManager) {
memoryManager.reset(commandStreamReceiver->createMemoryManager(enable64KBpages));
commandStreamReceiver->setMemoryManager(memoryManager.get());
} else {
commandStreamReceiver->setMemoryManager(externalMemoryManager);
}
DEBUG_BREAK_IF(!this->memoryManager);
}
} // namespace OCLRT

View File

@ -39,6 +39,8 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
ExecutionEnvironment();
~ExecutionEnvironment() override;
void initGmm(const HardwareInfo *hwInfo);
bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo);
void initializeMemoryManager(MemoryManager *externalMemoryManager, bool enable64KBpages);
std::unique_ptr<MemoryManager> memoryManager;
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
};