diff --git a/opencl/source/memory_manager/os_agnostic_memory_manager.cpp b/opencl/source/memory_manager/os_agnostic_memory_manager.cpp index 08dc1adab5..17f0453ca7 100644 --- a/opencl/source/memory_manager/os_agnostic_memory_manager.cpp +++ b/opencl/source/memory_manager/os_agnostic_memory_manager.cpp @@ -30,14 +30,22 @@ namespace NEO { OsAgnosticMemoryManager::OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment) { + initialize(aubUsage); +} +void OsAgnosticMemoryManager::initialize(bool aubUsage) { // 4 x sizeof(Heap32) + 2 x sizeof(Standard/Standard64k) - size_t reservedCpuAddressRangeSize = is64bit ? (4 * 4 + 2 * (aubUsage ? 32 : 4)) * GB : 0; + size_t reservedCpuAddressRangeSize = (4 * 4 + 2 * (aubUsage ? 32 : 4)) * GB; for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) { auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace; - getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh); + if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh)) { + initialized = false; + return; + } } + + initialized = true; } OsAgnosticMemoryManager::~OsAgnosticMemoryManager() = default; diff --git a/opencl/source/memory_manager/os_agnostic_memory_manager.h b/opencl/source/memory_manager/os_agnostic_memory_manager.h index 6b7b85387e..93103d1206 100644 --- a/opencl/source/memory_manager/os_agnostic_memory_manager.h +++ b/opencl/source/memory_manager/os_agnostic_memory_manager.h @@ -61,6 +61,7 @@ class OsAgnosticMemoryManager : public MemoryManager { OsAgnosticMemoryManager(ExecutionEnvironment &executionEnvironment) : OsAgnosticMemoryManager(false, executionEnvironment) {} OsAgnosticMemoryManager(bool aubUsage, ExecutionEnvironment &executionEnvironment); + void initialize(bool aubUsage); ~OsAgnosticMemoryManager() override; GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness) override; GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex) override { return nullptr; } diff --git a/opencl/test/unit_test/api/cl_get_platform_ids_tests.inl b/opencl/test/unit_test/api/cl_get_platform_ids_tests.inl index b7d7c58369..d329473099 100644 --- a/opencl/test/unit_test/api/cl_get_platform_ids_tests.inl +++ b/opencl/test/unit_test/api/cl_get_platform_ids_tests.inl @@ -65,6 +65,7 @@ TEST(clGetPlatformIDsNegativeTests, GivenFailedInitializationWhenGettingPlatform platformsImpl->clear(); } + TEST(clGetPlatformIDsNegativeTests, whenFailToCreateDeviceThenClGetPlatfomsIdsReturnsOutOfHostMemoryError) { VariableBackup createFuncBackup{&DeviceFactory::createRootDeviceFunc}; DeviceFactory::createRootDeviceFunc = [](ExecutionEnvironment &executionEnvironment, uint32_t rootDeviceIndex) -> std::unique_ptr { diff --git a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp index 9664a03653..ea91829267 100644 --- a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -92,6 +92,17 @@ TEST(ExecutionEnvironment, givenPlatformWhenItIsCreatedThenItCreatesMemoryManage EXPECT_NE(nullptr, executionEnvironment->memoryManager); } +TEST(ExecutionEnvironment, givenMemoryManagerIsNotInitializedInExecutionEnvironmentThanCreateDevicesReturnsEmptyDeviceVector) { + class FailedInitializeMemoryManagerExecutionEnvironment : public MockExecutionEnvironment { + bool initializeMemoryManager() override { return false; } + }; + + auto executionEnvironment = std::make_unique(); + prepareDeviceEnvironments(*executionEnvironment); + auto devices = DeviceFactory::createDevices(*executionEnvironment); + EXPECT_TRUE(devices.empty()); +} + TEST(ExecutionEnvironment, givenDeviceWhenItIsDestroyedThenMemoryManagerIsStillAvailable) { ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); executionEnvironment->initializeMemoryManager(); diff --git a/opencl/test/unit_test/memory_manager/gfx_partition_tests.inl b/opencl/test/unit_test/memory_manager/gfx_partition_tests.inl index efbf3f7ba6..53211c326f 100644 --- a/opencl/test/unit_test/memory_manager/gfx_partition_tests.inl +++ b/opencl/test/unit_test/memory_manager/gfx_partition_tests.inl @@ -123,7 +123,7 @@ TEST(GfxPartitionTest, testGfxPartitionUnsupportedRange) { } MockGfxPartition gfxPartition; - EXPECT_THROW(gfxPartition.init(maxNBitValue(48 + 1), reservedCpuAddressRangeSize, 0, 1), std::exception); + EXPECT_FALSE(gfxPartition.init(maxNBitValue(48 + 1), reservedCpuAddressRangeSize, 0, 1)); } TEST(GfxPartitionTest, testGfxPartitionFullRange48BitSVMHeap64KBSplit) { @@ -178,7 +178,7 @@ class MockOsMemory : public OSMemory { OSMemory::ReservedCpuAddressRange reserveCpuAddressRange(void *baseAddress, size_t sizeToReserve, size_t alignment) override { reserveCount++; - return MockOSMemoryReservedCpuAddressRange(reinterpret_cast(0x10000), sizeToReserve, alignment); + return MockOSMemoryReservedCpuAddressRange(returnAddress, sizeToReserve, alignment); }; void getMemoryMaps(MemoryMaps &outMemoryMaps) override {} @@ -188,6 +188,7 @@ class MockOsMemory : public OSMemory { void *osReserveCpuAddressRange(void *baseAddress, size_t sizeToReserve) override { return nullptr; } void osReleaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize) override {} + void *returnAddress = reinterpret_cast(0x10000); static uint32_t reserveCount; }; @@ -208,3 +209,36 @@ TEST(GfxPartitionTest, given47bitGpuAddressSpaceWhenInitializingMultipleGfxParti EXPECT_EQ(1u, static_cast(gfxPartitions[0]->osMemory.get())->getReserveCount()); } + +TEST(GfxPartitionTest, testGfxPartitionFullRange47BitSVMFailedIfReservedCpuRangeSizeIsZero) { + if (is32bit) { + GTEST_SKIP(); + } + + MockGfxPartition gfxPartition; + EXPECT_FALSE(gfxPartition.init(maxNBitValue(47), 0, 0, 1)); +} + +TEST(GfxPartitionTest, testGfxPartitionFullRange47BitSVMFailedIfReturnedReservedCpuRangeIsNull) { + if (is32bit) { + GTEST_SKIP(); + } + + auto mockOsMemory = new MockOsMemory; + mockOsMemory->returnAddress = nullptr; + MockGfxPartition gfxPartition; + gfxPartition.osMemory.reset(mockOsMemory); + EXPECT_FALSE(gfxPartition.init(maxNBitValue(47), reservedCpuAddressRangeSize, 0, 1)); +} + +TEST(GfxPartitionTest, testGfxPartitionFullRange47BitSVMFailedIfReturnedReservedCpuRangeIsNotAligned) { + if (is32bit) { + GTEST_SKIP(); + } + + auto mockOsMemory = new MockOsMemory; + mockOsMemory->returnAddress = reinterpret_cast(0x10001); + MockGfxPartition gfxPartition; + gfxPartition.osMemory.reset(mockOsMemory); + EXPECT_FALSE(gfxPartition.init(maxNBitValue(47), reservedCpuAddressRangeSize, 0, 1)); +} diff --git a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp index 86659f8263..5cf8c71933 100644 --- a/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp +++ b/opencl/test/unit_test/memory_manager/memory_manager_tests.cpp @@ -39,6 +39,7 @@ #include "opencl/test/unit_test/mocks/mock_deferrable_deletion.h" #include "opencl/test/unit_test/mocks/mock_deferred_deleter.h" #include "opencl/test/unit_test/mocks/mock_execution_environment.h" +#include "opencl/test/unit_test/mocks/mock_gfx_partition.h" #include "opencl/test/unit_test/mocks/mock_gmm.h" #include "opencl/test/unit_test/mocks/mock_graphics_allocation.h" #include "opencl/test/unit_test/mocks/mock_kernel.h" @@ -629,6 +630,35 @@ TEST_F(MemoryAllocatorTest, given32BitDeviceWhenPrintfSurfaceIsCreatedThen32BitA } } +TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenItIsInitialized) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + OsAgnosticMemoryManager memoryManager(executionEnvironment); + EXPECT_TRUE(memoryManager.isInitialized()); +} + +TEST(OsAgnosticMemoryManager, givenDefaultAubUsageMemoryManagerWhenItIsCreatedThenItIsInitialized) { + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + OsAgnosticMemoryManager memoryManager(true, executionEnvironment); + EXPECT_TRUE(memoryManager.isInitialized()); +} + +TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedAndGfxPartitionInitIsFailedThenItIsNotInitialized) { + class TestedOsAgnosticMemoryManager : public OsAgnosticMemoryManager { + public: + using OsAgnosticMemoryManager::gfxPartitions; + using OsAgnosticMemoryManager::OsAgnosticMemoryManager; + }; + + MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); + TestedOsAgnosticMemoryManager memoryManager(executionEnvironment); + EXPECT_TRUE(memoryManager.isInitialized()); + + auto failedInitGfxPartition = std::make_unique(); + memoryManager.gfxPartitions[0].reset(failedInitGfxPartition.release()); + memoryManager.initialize(false /*aubUsage*/); + EXPECT_FALSE(memoryManager.isInitialized()); +} + TEST(OsAgnosticMemoryManager, givenDefaultMemoryManagerWhenItIsCreatedThenForce32BitAllocationsIsFalse) { MockExecutionEnvironment executionEnvironment(defaultHwInfo.get()); OsAgnosticMemoryManager memoryManager(executionEnvironment); diff --git a/opencl/test/unit_test/mocks/mock_gfx_partition.h b/opencl/test/unit_test/mocks/mock_gfx_partition.h index 35c0130710..dda844988d 100644 --- a/opencl/test/unit_test/mocks/mock_gfx_partition.h +++ b/opencl/test/unit_test/mocks/mock_gfx_partition.h @@ -40,3 +40,10 @@ class MockGfxPartition : public GfxPartition { OSMemory::ReservedCpuAddressRange reservedCpuAddressRange; }; + +class FailedInitGfxPartition : public MockGfxPartition { + public: + virtual bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool) override { + return false; + } +}; diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index bb9430a3dd..f7d6e8a008 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -236,6 +236,23 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenforcePinAllowedWhenMem EXPECT_NE(nullptr, memoryManager->pinBBs[device->getRootDeviceIndex()]); } +TEST_F(DrmMemoryManagerTest, givenDefaultDrmMemoryManagerWhenItIsCreatedThanItIsInitialized) { + EXPECT_TRUE(memoryManager->isInitialized()); +} + +TEST_F(DrmMemoryManagerTest, givenDefaultDrmMemoryManagerWhenItIsCreatedAndGfxPartitionInitIsFailedThenItIsNotInitialized) { + EXPECT_TRUE(memoryManager->isInitialized()); + + auto failedInitGfxPartition = std::make_unique(); + memoryManager->gfxPartitions[0].reset(failedInitGfxPartition.release()); + memoryManager->initialize(gemCloseWorkerMode::gemCloseWorkerInactive); + EXPECT_FALSE(memoryManager->isInitialized()); +} + +TEST_F(DrmMemoryManagerTest, defaultDrmMemoryManagerIsInitialized) { + EXPECT_TRUE(memoryManager->isInitialized()); +} + TEST_F(DrmMemoryManagerTest, pinBBisCreated) { mock->ioctl_expected.gemUserptr = 1; mock->ioctl_expected.gemClose = 1; diff --git a/shared/source/execution_environment/execution_environment.cpp b/shared/source/execution_environment/execution_environment.cpp index d1455da1e6..3acbe1278e 100644 --- a/shared/source/execution_environment/execution_environment.cpp +++ b/shared/source/execution_environment/execution_environment.cpp @@ -24,9 +24,9 @@ ExecutionEnvironment::~ExecutionEnvironment() { rootDeviceEnvironments.clear(); } -void ExecutionEnvironment::initializeMemoryManager() { +bool ExecutionEnvironment::initializeMemoryManager() { if (this->memoryManager) { - return; + return memoryManager->isInitialized(); } int32_t setCommandStreamReceiverType = CommandStreamReceiverType::CSR_HW; @@ -46,7 +46,8 @@ void ExecutionEnvironment::initializeMemoryManager() { memoryManager = MemoryManager::createMemoryManager(*this); break; } - DEBUG_BREAK_IF(!this->memoryManager); + + return memoryManager->isInitialized(); } void ExecutionEnvironment::calculateMaxOsContextCount() { diff --git a/shared/source/execution_environment/execution_environment.h b/shared/source/execution_environment/execution_environment.h index 7d9b42d502..057dffbd5f 100644 --- a/shared/source/execution_environment/execution_environment.h +++ b/shared/source/execution_environment/execution_environment.h @@ -21,7 +21,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject ExecutionEnvironment(); ~ExecutionEnvironment() override; - void initializeMemoryManager(); + MOCKABLE_VIRTUAL bool initializeMemoryManager(); void calculateMaxOsContextCount(); void prepareRootDeviceEnvironments(uint32_t numRootDevices); void setPerContextMemorySpace() { diff --git a/shared/source/memory_manager/gfx_partition.cpp b/shared/source/memory_manager/gfx_partition.cpp index 04c4bd2472..5dc440c1b1 100644 --- a/shared/source/memory_manager/gfx_partition.cpp +++ b/shared/source/memory_manager/gfx_partition.cpp @@ -64,7 +64,7 @@ void GfxPartition::freeGpuAddressRange(uint64_t ptr, size_t size) { } } -void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool) { +bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool) { /* * I. 64-bit builds: @@ -125,10 +125,16 @@ void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe heapInit(HeapIndex::HEAP_SVM, 0ull, gfxBase); } else if (gpuAddressSpace == maxNBitValue(47)) { if (reservedCpuAddressRange.alignedPtr == nullptr) { - UNRECOVERABLE_IF(cpuAddressRangeSizeToReserve == 0); + if (cpuAddressRangeSizeToReserve == 0) { + return false; + } reservedCpuAddressRange = osMemory->reserveCpuAddressRange(cpuAddressRangeSizeToReserve, GfxPartition::heapGranularity); - UNRECOVERABLE_IF(reservedCpuAddressRange.originalPtr == nullptr); - UNRECOVERABLE_IF(!isAligned(reservedCpuAddressRange.alignedPtr)); + if (reservedCpuAddressRange.originalPtr == nullptr) { + return false; + } + if (!isAligned(reservedCpuAddressRange.alignedPtr)) { + return false; + } } gfxBase = reinterpret_cast(reservedCpuAddressRange.alignedPtr); gfxTop = gfxBase + cpuAddressRangeSizeToReserve; @@ -137,7 +143,9 @@ void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe gfxBase = 0ull; heapInit(HeapIndex::HEAP_SVM, 0ull, 0ull); } else { - initAdditionalRange(gpuAddressSpace, gfxBase, gfxTop, rootDeviceIndex, numRootDevices); + if (!initAdditionalRange(gpuAddressSpace, gfxBase, gfxTop, rootDeviceIndex, numRootDevices)) { + return false; + } } } @@ -161,6 +169,8 @@ void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe // Split HEAP_STANDARD64K among root devices auto gfxStandard64KBSize = alignDown(gfxStandardSize / numRootDevices, GfxPartition::heapGranularity); heapInit(HeapIndex::HEAP_STANDARD64KB, gfxBase + rootDeviceIndex * gfxStandard64KBSize, gfxStandard64KBSize); + + return true; } } // namespace NEO diff --git a/shared/source/memory_manager/gfx_partition.h b/shared/source/memory_manager/gfx_partition.h index 39172f8f73..574b5d2533 100644 --- a/shared/source/memory_manager/gfx_partition.h +++ b/shared/source/memory_manager/gfx_partition.h @@ -37,10 +37,10 @@ class GfxPartition { GfxPartition(OSMemory::ReservedCpuAddressRange &sharedReservedCpuAddressRange); MOCKABLE_VIRTUAL ~GfxPartition(); - void init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices) { - init(gpuAddressSpace, cpuAddressRangeSizeToReserve, rootDeviceIndex, numRootDevices, false); + bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices) { + return init(gpuAddressSpace, cpuAddressRangeSizeToReserve, rootDeviceIndex, numRootDevices, false); } - void init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool); + MOCKABLE_VIRTUAL bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool); void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) { getHeap(heapIndex).init(base, size); @@ -91,7 +91,7 @@ class GfxPartition { static const std::array heapNonSvmNames; protected: - void initAdditionalRange(uint64_t gpuAddressSpace, uint64_t &gfxBase, uint64_t &gfxTop, uint32_t rootDeviceIndex, size_t numRootDevices); + bool initAdditionalRange(uint64_t gpuAddressSpace, uint64_t &gfxBase, uint64_t &gfxTop, uint32_t rootDeviceIndex, size_t numRootDevices); class Heap { public: diff --git a/shared/source/memory_manager/gfx_partition_init_additional_range.cpp b/shared/source/memory_manager/gfx_partition_init_additional_range.cpp index bdacd10fe3..cfef320773 100644 --- a/shared/source/memory_manager/gfx_partition_init_additional_range.cpp +++ b/shared/source/memory_manager/gfx_partition_init_additional_range.cpp @@ -9,8 +9,8 @@ namespace NEO { -void GfxPartition::initAdditionalRange(uint64_t gpuAddressSpace, uint64_t &gfxBase, uint64_t &gfxTop, uint32_t rootDeviceIndex, size_t numRootDevices) { - UNRECOVERABLE_IF("Invalid GPU Address Range!"); +bool GfxPartition::initAdditionalRange(uint64_t gpuAddressSpace, uint64_t &gfxBase, uint64_t &gfxTop, uint32_t rootDeviceIndex, size_t numRootDevices) { + return false; } } // namespace NEO diff --git a/shared/source/memory_manager/memory_manager.h b/shared/source/memory_manager/memory_manager.h index 08d57f794b..c07d0a224b 100644 --- a/shared/source/memory_manager/memory_manager.h +++ b/shared/source/memory_manager/memory_manager.h @@ -61,6 +61,7 @@ class MemoryManager { }; MemoryManager(ExecutionEnvironment &executionEnvironment); + bool isInitialized() const { return initialized; } virtual ~MemoryManager(); MOCKABLE_VIRTUAL void *allocateSystemMemory(size_t size, size_t alignment); @@ -216,6 +217,7 @@ class MemoryManager { virtual void freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) { return unlockResourceImpl(graphicsAllocation); }; virtual void registerAllocation(GraphicsAllocation *allocation) {} + bool initialized = false; bool forceNonSvmForExternalHostPtr = false; bool force32bitAllocations = false; bool virtualPaddingAvailable = false; diff --git a/shared/source/os_interface/device_factory.cpp b/shared/source/os_interface/device_factory.cpp index 5e4d5bbdcd..69379d3831 100644 --- a/shared/source/os_interface/device_factory.cpp +++ b/shared/source/os_interface/device_factory.cpp @@ -124,11 +124,15 @@ bool DeviceFactory::prepareDeviceEnvironments(ExecutionEnvironment &executionEnv std::vector> DeviceFactory::createDevices(ExecutionEnvironment &executionEnvironment) { std::vector> devices; - auto status = NEO::prepareDeviceEnvironments(executionEnvironment); - if (!status) { + + if (!NEO::prepareDeviceEnvironments(executionEnvironment)) { return devices; } - executionEnvironment.initializeMemoryManager(); + + if (!executionEnvironment.initializeMemoryManager()) { + return devices; + } + for (uint32_t rootDeviceIndex = 0u; rootDeviceIndex < executionEnvironment.rootDeviceEnvironments.size(); rootDeviceIndex++) { auto device = createRootDeviceFunc(executionEnvironment, rootDeviceIndex); if (device) { diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index e0297852c2..f1aab1ab7f 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -38,9 +38,16 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode, ExecutionEnvironment &executionEnvironment) : MemoryManager(executionEnvironment), forcePinEnabled(forcePinAllowed), validateHostPtrMemory(validateHostPtrMemory) { + initialize(mode); +} + +void DrmMemoryManager::initialize(gemCloseWorkerMode mode) { for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) { auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace; - getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh); + if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh)) { + initialized = false; + return; + } localMemAllocs.emplace_back(); } MemoryManager::virtualPaddingAvailable = true; @@ -78,6 +85,8 @@ DrmMemoryManager::DrmMemoryManager(gemCloseWorkerMode mode, pinBBs.push_back(bo); } + + initialized = true; } DrmMemoryManager::~DrmMemoryManager() { diff --git a/shared/source/os_interface/linux/drm_memory_manager.h b/shared/source/os_interface/linux/drm_memory_manager.h index c5fca36e89..8c706663f3 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.h +++ b/shared/source/os_interface/linux/drm_memory_manager.h @@ -29,6 +29,7 @@ class DrmMemoryManager : public MemoryManager { ExecutionEnvironment &executionEnvironment); ~DrmMemoryManager() override; + void initialize(gemCloseWorkerMode mode); void addAllocationToHostPtrManager(GraphicsAllocation *gfxAllocation) override; void removeAllocationFromHostPtrManager(GraphicsAllocation *gfxAllocation) override; void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override; diff --git a/shared/source/os_interface/windows/wddm_memory_manager.cpp b/shared/source/os_interface/windows/wddm_memory_manager.cpp index 9fc547f5b3..d5b1d449dc 100644 --- a/shared/source/os_interface/windows/wddm_memory_manager.cpp +++ b/shared/source/os_interface/windows/wddm_memory_manager.cpp @@ -48,6 +48,8 @@ WddmMemoryManager::WddmMemoryManager(ExecutionEnvironment &executionEnvironment) getWddm(rootDeviceIndex).initGfxPartition(*getGfxPartition(rootDeviceIndex), rootDeviceIndex, gfxPartitions.size(), heapAssigner.apiAllowExternalHeapForSshAndDsh); mallocRestrictions.minAddress = std::max(mallocRestrictions.minAddress, getWddm(rootDeviceIndex).getWddmMinAddress()); } + + initialized = true; } GraphicsAllocation *WddmMemoryManager::allocateShareableMemory(const AllocationData &allocationData) {