| 1 |
/* |
| 2 |
* Copyright (C) 2019-2024 Intel Corporation |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "opencl/source/sharings/unified/unified_sharing.h" |
| 9 |
|
| 10 |
#include "shared/source/helpers/string.h" |
| 11 |
#include "shared/source/helpers/surface_format_info.h" |
| 12 |
#include "shared/source/helpers/timestamp_packet.h" |
| 13 |
#include "shared/source/memory_manager/allocation_properties.h" |
| 14 |
|
| 15 |
#include "opencl/source/cl_device/cl_device.h" |
| 16 |
#include "opencl/source/context/context.h" |
| 17 |
#include "opencl/source/sharings/sharing_factory.h" |
| 18 |
|
| 19 |
#include <unordered_map> |
| 20 |
|
| 21 |
namespace NEO { |
| 22 |
|
| 23 |
const uint32_t UnifiedSharingFunctions::sharingId = SharingType::UNIFIED_SHARING; |
| 24 |
|
| 25 |
UnifiedSharing::UnifiedSharing(UnifiedSharingFunctions *sharingFunctions, UnifiedSharingHandleType memoryType) |
| 26 |
: sharingFunctions(sharingFunctions), |
| 27 |
memoryType(memoryType) { |
| 28 |
} |
| 29 |
|
| 30 |
void UnifiedSharing::synchronizeObject(UpdateData &updateData) { |
| 31 |
updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL; |
| 32 |
} |
| 33 |
|
| 34 |
void UnifiedSharing::releaseResource(MemObj *memObject, uint32_t rootDeviceIndex) { |
| 35 |
} |
| 36 |
|
| 37 |
GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, AllocationType allocationType) { |
| 38 |
return createGraphicsAllocation(context, description, nullptr, allocationType); |
| 39 |
} |
| 40 |
|
| 41 |
GraphicsAllocation *UnifiedSharing::createGraphicsAllocation(Context *context, UnifiedSharingMemoryDescription description, ImageInfo *imgInfo, AllocationType allocationType) { |
| 42 |
auto memoryManager = context->getMemoryManager(); |
| 43 |
|
| 44 |
if (description.type != UnifiedSharingHandleType::win32Nt && description.type != UnifiedSharingHandleType::linuxFd && description.type != UnifiedSharingHandleType::win32Shared) |
| 45 |
return nullptr; |
| 46 |
|
| 47 |
const AllocationProperties properties{context->getDevice(0)->getRootDeviceIndex(), |
| 48 |
false, // allocateMemory |
| 49 |
imgInfo, |
| 50 |
allocationType, |
| 51 |
context->getDeviceBitfieldForAllocation(context->getDevice(0)->getRootDeviceIndex())}; |
| 52 |
MemoryManager::OsHandleData osHandleData{description.handle}; |
| 53 |
return memoryManager->createGraphicsAllocationFromSharedHandle(osHandleData, properties, false, false, true, nullptr); |
| 54 |
} |
| 55 |
|
| 56 |
template <> |
| 57 |
UnifiedSharingFunctions *Context::getSharing() { |
| 58 |
UNRECOVERABLE_IF(UnifiedSharingFunctions::sharingId >= sharingFunctions.size()) |
| 59 |
return reinterpret_cast<UnifiedSharingFunctions *>(sharingFunctions[UnifiedSharingFunctions::sharingId].get()); |
| 60 |
} |
| 61 |
|
| 62 |
} // namespace NEO |