mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Refactor parts of createDeviceImpl.
- Move portions of code to dedicated methods. Change-Id: I9abec23785f3f3201dce42a7a840ca4a450c4cc1
This commit is contained in:

committed by
sys_ocldev

parent
8a69656446
commit
f59c191915
@ -348,4 +348,14 @@ void CommandStreamReceiver::setExperimentalCmdBuffer(std::unique_ptr<Experimenta
|
|||||||
experimentalCmdBuffer = std::move(cmdBuffer);
|
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
|
} // namespace OCLRT
|
||||||
|
@ -21,16 +21,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "runtime/command_stream/csr_definitions.h"
|
||||||
#include "runtime/command_stream/linear_stream.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/command_stream/submissions_aggregator.h"
|
||||||
#include "runtime/helpers/completion_stamp.h"
|
#include "runtime/command_stream/thread_arbitration_policy.h"
|
||||||
#include "runtime/helpers/aligned_memory.h"
|
|
||||||
#include "runtime/helpers/address_patch.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/helpers/options.h"
|
||||||
#include "runtime/indirect_heap/indirect_heap.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 <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
@ -142,6 +142,8 @@ class CommandStreamReceiver {
|
|||||||
virtual enum CommandStreamReceiverType getType() = 0;
|
virtual enum CommandStreamReceiverType getType() = 0;
|
||||||
void setExperimentalCmdBuffer(std::unique_ptr<ExperimentalCommandBuffer> &&cmdBuffer);
|
void setExperimentalCmdBuffer(std::unique_ptr<ExperimentalCommandBuffer> &&cmdBuffer);
|
||||||
|
|
||||||
|
bool initializeTagAllocation();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setDisableL3Cache(bool val) {
|
void setDisableL3Cache(bool val) {
|
||||||
disableL3Cache = val;
|
disableL3Cache = val;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
* OTHER DEALINGS IN THE SOFTWARE.
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "runtime/device/device.h"
|
||||||
#include "hw_cmds.h"
|
#include "hw_cmds.h"
|
||||||
#include "runtime/built_ins/built_ins.h"
|
#include "runtime/built_ins/built_ins.h"
|
||||||
#include "runtime/built_ins/sip.h"
|
#include "runtime/built_ins/sip.h"
|
||||||
@ -28,7 +29,6 @@
|
|||||||
#include "runtime/command_stream/experimental_command_buffer.h"
|
#include "runtime/command_stream/experimental_command_buffer.h"
|
||||||
#include "runtime/command_stream/preemption.h"
|
#include "runtime/command_stream/preemption.h"
|
||||||
#include "runtime/compiler_interface/compiler_interface.h"
|
#include "runtime/compiler_interface/compiler_interface.h"
|
||||||
#include "runtime/device/device.h"
|
|
||||||
#include "runtime/device/device_vector.h"
|
#include "runtime/device/device_vector.h"
|
||||||
#include "runtime/device/driver_info.h"
|
#include "runtime/device/driver_info.h"
|
||||||
#include "runtime/execution_environment/execution_environment.h"
|
#include "runtime/execution_environment/execution_environment.h"
|
||||||
@ -128,41 +128,30 @@ Device::~Device() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
|
bool Device::createDeviceImpl(const HardwareInfo *pHwInfo, Device &outDevice) {
|
||||||
outDevice.executionEnvironment->initGmm(pHwInfo);
|
auto executionEnvironment = outDevice.executionEnvironment;
|
||||||
CommandStreamReceiver *commandStreamReceiver = createCommandStream(pHwInfo);
|
executionEnvironment->initGmm(pHwInfo);
|
||||||
if (!commandStreamReceiver) {
|
if (!executionEnvironment->initializeCommandStreamReceiver(pHwInfo)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
outDevice.executionEnvironment->commandStreamReceiver.reset(commandStreamReceiver);
|
executionEnvironment->initializeMemoryManager(outDevice.executionEnvironment->memoryManager.get(), outDevice.getEnabled64kbPages());
|
||||||
|
|
||||||
if (!outDevice.executionEnvironment->memoryManager) {
|
CommandStreamReceiver *commandStreamReceiver = executionEnvironment->commandStreamReceiver.get();
|
||||||
outDevice.executionEnvironment->memoryManager.reset(commandStreamReceiver->createMemoryManager(outDevice.getEnabled64kbPages()));
|
if (!commandStreamReceiver->initializeTagAllocation()) {
|
||||||
} 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) {
|
|
||||||
return false;
|
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;
|
auto pDevice = &outDevice;
|
||||||
|
|
||||||
if (!pDevice->osTime) {
|
if (!pDevice->osTime) {
|
||||||
pDevice->osTime = OSTime::create(commandStreamReceiver->getOSInterface());
|
pDevice->osTime = OSTime::create(commandStreamReceiver->getOSInterface());
|
||||||
}
|
}
|
||||||
pDevice->driverInfo.reset(DriverInfo::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();
|
pDevice->initializeCaps();
|
||||||
|
|
||||||
|
@ -20,16 +20,36 @@
|
|||||||
* 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/memory_manager/memory_manager.h"
|
#include "runtime/command_stream/command_stream_receiver.h"
|
||||||
#include "runtime/gmm_helper/gmm_helper.h"
|
#include "runtime/gmm_helper/gmm_helper.h"
|
||||||
|
#include "runtime/memory_manager/memory_manager.h"
|
||||||
#include "runtime/os_interface/device_factory.h"
|
#include "runtime/os_interface/device_factory.h"
|
||||||
|
|
||||||
namespace OCLRT {
|
namespace OCLRT {
|
||||||
ExecutionEnvironment::ExecutionEnvironment() = default;
|
ExecutionEnvironment::ExecutionEnvironment() = default;
|
||||||
ExecutionEnvironment::~ExecutionEnvironment() = default;
|
ExecutionEnvironment::~ExecutionEnvironment() = default;
|
||||||
|
extern CommandStreamReceiver *createCommandStream(const HardwareInfo *pHwInfo);
|
||||||
|
|
||||||
void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) {
|
void ExecutionEnvironment::initGmm(const HardwareInfo *hwInfo) {
|
||||||
gmmHelper.reset(new GmmHelper(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
|
} // namespace OCLRT
|
||||||
|
@ -39,6 +39,8 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
|
|||||||
ExecutionEnvironment();
|
ExecutionEnvironment();
|
||||||
~ExecutionEnvironment() override;
|
~ExecutionEnvironment() override;
|
||||||
void initGmm(const HardwareInfo *hwInfo);
|
void initGmm(const HardwareInfo *hwInfo);
|
||||||
|
bool initializeCommandStreamReceiver(const HardwareInfo *pHwInfo);
|
||||||
|
void initializeMemoryManager(MemoryManager *externalMemoryManager, bool enable64KBpages);
|
||||||
std::unique_ptr<MemoryManager> memoryManager;
|
std::unique_ptr<MemoryManager> memoryManager;
|
||||||
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
|
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
|
||||||
};
|
};
|
||||||
|
@ -329,6 +329,17 @@ TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenItIsDestroye
|
|||||||
EXPECT_TRUE(destructorCalled);
|
EXPECT_TRUE(destructorCalled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(CommandStreamReceiverSimpleTest, givenCommandStreamReceiverWhenInitializeTagAllocationIsCalledThenTagAllocationIsBeingAllocated) {
|
||||||
|
std::unique_ptr<OsAgnosticMemoryManager> memoryManager(new OsAgnosticMemoryManager);
|
||||||
|
std::unique_ptr<MockCommandStreamReceiver> csr(new MockCommandStreamReceiver);
|
||||||
|
csr->setMemoryManager(memoryManager.get());
|
||||||
|
EXPECT_EQ(nullptr, csr->getTagAllocation());
|
||||||
|
EXPECT_TRUE(csr->getTagAddress() == nullptr);
|
||||||
|
csr->initializeTagAllocation();
|
||||||
|
EXPECT_NE(nullptr, csr->getTagAllocation());
|
||||||
|
EXPECT_TRUE(csr->getTagAddress() != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhenRequiredIsCalledWithBlockingFlagSetThenItReturnsImmediately) {
|
TEST(CommandStreamReceiverSimpleTest, givenCSRWhenWaitBeforeMakingNonResidentWhenRequiredIsCalledWithBlockingFlagSetThenItReturnsImmediately) {
|
||||||
MockCommandStreamReceiver csr;
|
MockCommandStreamReceiver csr;
|
||||||
uint32_t tag = 0;
|
uint32_t tag = 0;
|
||||||
|
@ -20,13 +20,13 @@
|
|||||||
* OTHER DEALINGS IN THE SOFTWARE.
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "test.h"
|
|
||||||
#include "runtime/device/device.h"
|
#include "runtime/device/device.h"
|
||||||
#include "runtime/gmm_helper/gmm_helper.h"
|
|
||||||
#include "runtime/execution_environment/execution_environment.h"
|
#include "runtime/execution_environment/execution_environment.h"
|
||||||
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
#include "runtime/gmm_helper/gmm_helper.h"
|
||||||
#include "runtime/helpers/options.h"
|
#include "runtime/helpers/options.h"
|
||||||
|
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
|
||||||
#include "runtime/platform/platform.h"
|
#include "runtime/platform/platform.h"
|
||||||
|
#include "test.h"
|
||||||
#include "unit_tests/mocks/mock_csr.h"
|
#include "unit_tests/mocks/mock_csr.h"
|
||||||
|
|
||||||
using namespace OCLRT;
|
using namespace OCLRT;
|
||||||
@ -97,6 +97,27 @@ TEST(ExecutionEnvironment, givenDeviceWhenItIsDestroyedThenMemoryManagerIsStillA
|
|||||||
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
|
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeCommandStreamReceiverIsCalledThenItIsInitalized) {
|
||||||
|
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
|
||||||
|
executionEnvironment->initializeCommandStreamReceiver(platformDevices[0]);
|
||||||
|
EXPECT_NE(nullptr, executionEnvironment->commandStreamReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerIsCalledThenItIsInitalized) {
|
||||||
|
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
|
||||||
|
executionEnvironment->initializeCommandStreamReceiver(platformDevices[0]);
|
||||||
|
executionEnvironment->initializeMemoryManager(nullptr, false);
|
||||||
|
EXPECT_NE(nullptr, executionEnvironment->memoryManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerWithExternalMemoryManagerIsCalledThenItIsSetToExternal) {
|
||||||
|
std::unique_ptr<MemoryManager> memoryManager(new OsAgnosticMemoryManager);
|
||||||
|
std::unique_ptr<ExecutionEnvironment> executionEnvironment(new ExecutionEnvironment);
|
||||||
|
executionEnvironment->initializeCommandStreamReceiver(platformDevices[0]);
|
||||||
|
executionEnvironment->initializeMemoryManager(memoryManager.get(), false);
|
||||||
|
EXPECT_EQ(memoryManager.get(), executionEnvironment->commandStreamReceiver->getMemoryManager());
|
||||||
|
}
|
||||||
|
|
||||||
auto destructorId = 0u;
|
auto destructorId = 0u;
|
||||||
static_assert(sizeof(ExecutionEnvironment) == (is64bit ? 48 : 28), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
|
static_assert(sizeof(ExecutionEnvironment) == (is64bit ? 48 : 28), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user