2020-01-11 18:25:26 +01:00
|
|
|
/*
|
2023-01-26 16:21:09 +00:00
|
|
|
* Copyright (C) 2020-2023 Intel Corporation
|
2020-01-11 18:25:26 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "program_initialization.h"
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/compiler_interface/linker.h"
|
|
|
|
|
#include "shared/source/device/device.h"
|
2020-07-10 17:04:42 +02:00
|
|
|
#include "shared/source/helpers/blit_commands_helper.h"
|
2023-02-01 16:23:01 +00:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/string.h"
|
2022-12-07 11:51:44 +00:00
|
|
|
#include "shared/source/memory_manager/allocation_properties.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
|
|
|
|
#include "shared/source/memory_manager/unified_memory_manager.h"
|
|
|
|
|
#include "shared/source/program/program_info.h"
|
2020-01-11 18:25:26 +01:00
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
|
2023-02-08 17:05:30 +00:00
|
|
|
GraphicsAllocation *allocateGlobalsSurface(NEO::SVMAllocsManager *const svmAllocManager, NEO::Device &device, size_t totalSize, size_t zeroInitSize, bool constant,
|
2022-12-21 04:39:44 +01:00
|
|
|
LinkerInput *const linkerInput, const void *initData) {
|
2020-01-11 18:25:26 +01:00
|
|
|
bool globalsAreExported = false;
|
2020-10-07 12:37:13 +02:00
|
|
|
GraphicsAllocation *gpuAllocation = nullptr;
|
2020-12-23 13:47:18 +00:00
|
|
|
auto rootDeviceIndex = device.getRootDeviceIndex();
|
|
|
|
|
auto deviceBitfield = device.getDeviceBitfield();
|
2020-10-07 12:37:13 +02:00
|
|
|
|
2020-01-11 18:25:26 +01:00
|
|
|
if (linkerInput != nullptr) {
|
|
|
|
|
globalsAreExported = constant ? linkerInput->getTraits().exportsGlobalConstants : linkerInput->getTraits().exportsGlobalVariables;
|
|
|
|
|
}
|
2023-03-28 10:58:35 +00:00
|
|
|
bool lockingSucceeded = false;
|
2020-01-11 18:25:26 +01:00
|
|
|
if (globalsAreExported && (svmAllocManager != nullptr)) {
|
2022-04-07 13:09:40 +00:00
|
|
|
RootDeviceIndicesContainer rootDeviceIndices;
|
|
|
|
|
rootDeviceIndices.push_back(rootDeviceIndex);
|
2020-12-23 13:47:18 +00:00
|
|
|
std::map<uint32_t, DeviceBitfield> subDeviceBitfields;
|
|
|
|
|
subDeviceBitfields.insert({rootDeviceIndex, deviceBitfield});
|
2023-03-22 03:30:27 +00:00
|
|
|
NEO::SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY, 1, rootDeviceIndices, subDeviceBitfields);
|
2022-09-23 13:05:43 +00:00
|
|
|
unifiedMemoryProperties.device = &device;
|
2023-02-08 17:05:30 +00:00
|
|
|
auto ptr = svmAllocManager->createUnifiedMemoryAllocation(totalSize, unifiedMemoryProperties);
|
2020-01-11 18:25:26 +01:00
|
|
|
DEBUG_BREAK_IF(ptr == nullptr);
|
|
|
|
|
if (ptr == nullptr) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2022-09-23 13:05:43 +00:00
|
|
|
auto usmAlloc = svmAllocManager->getSVMAlloc(ptr);
|
|
|
|
|
UNRECOVERABLE_IF(usmAlloc == nullptr);
|
|
|
|
|
gpuAllocation = usmAlloc->gpuAllocations.getGraphicsAllocation(rootDeviceIndex);
|
2023-03-28 10:58:35 +00:00
|
|
|
lockingSucceeded = device.getMemoryManager()->lockResource(gpuAllocation) != nullptr;
|
2020-01-11 18:25:26 +01:00
|
|
|
} else {
|
2022-02-04 13:59:01 +00:00
|
|
|
auto allocationType = constant ? AllocationType::CONSTANT_SURFACE : AllocationType::GLOBAL_SURFACE;
|
2020-12-23 13:47:18 +00:00
|
|
|
gpuAllocation = device.getMemoryManager()->allocateGraphicsMemoryWithProperties({rootDeviceIndex,
|
2020-04-16 17:24:38 +02:00
|
|
|
true, // allocateMemory
|
2023-02-08 17:05:30 +00:00
|
|
|
totalSize, allocationType,
|
2020-04-16 17:24:38 +02:00
|
|
|
false, // isMultiStorageAllocation
|
2020-12-23 13:47:18 +00:00
|
|
|
deviceBitfield});
|
2020-01-11 18:25:26 +01:00
|
|
|
}
|
2020-10-07 12:37:13 +02:00
|
|
|
|
|
|
|
|
if (!gpuAllocation) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-26 16:21:09 +00:00
|
|
|
auto &rootDeviceEnvironment = device.getRootDeviceEnvironment();
|
2022-12-15 13:33:28 +00:00
|
|
|
auto &productHelper = device.getProductHelper();
|
2020-10-07 12:37:13 +02:00
|
|
|
|
2023-02-08 17:05:30 +00:00
|
|
|
bool isOnlyBssData = (totalSize == zeroInitSize);
|
|
|
|
|
if (false == isOnlyBssData) {
|
|
|
|
|
auto initSize = totalSize - zeroInitSize;
|
2023-03-28 10:58:35 +00:00
|
|
|
auto success = MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *gpuAllocation, lockingSucceeded),
|
2023-02-08 17:05:30 +00:00
|
|
|
device, gpuAllocation, 0, initData, initSize);
|
|
|
|
|
UNRECOVERABLE_IF(!success);
|
|
|
|
|
}
|
2020-10-07 12:37:13 +02:00
|
|
|
return gpuAllocation;
|
2020-01-11 18:25:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace NEO
|