Debian Codegraph @

opencl/source/sharings/unified/unified_buffer.cpp

raw
1 /*
2 * Copyright (C) 2019-2023 Intel Corporation
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 */
7
8 #include "unified_buffer.h"
9
10 #include "shared/source/helpers/get_info.h"
11
12 #include "opencl/source/context/context.h"
13 #include "opencl/source/mem_obj/buffer.h"
14
15 using namespace NEO;
16
17 Buffer *UnifiedBuffer::createSharedUnifiedBuffer(Context *context, cl_mem_flags flags, UnifiedSharingMemoryDescription extMem, cl_int *errcodeRet) {
18 ErrorCodeHelper errorCode(errcodeRet, CL_SUCCESS);
19
20 auto graphicsAllocation = UnifiedBuffer::createGraphicsAllocation(context, extMem, AllocationType::sharedBuffer);
21 if (!graphicsAllocation) {
22 errorCode.set(CL_INVALID_MEM_OBJECT);
23 return nullptr;
24 }
25
26 UnifiedSharingFunctions *sharingFunctions = context->getSharing<UnifiedSharingFunctions>();
27 auto sharingHandler = new UnifiedBuffer(sharingFunctions, extMem.type);
28 auto rootDeviceIndex = graphicsAllocation->getRootDeviceIndex();
29 auto multiGraphicsAllocation = MultiGraphicsAllocation(rootDeviceIndex);
30 multiGraphicsAllocation.addAllocation(graphicsAllocation);
31
32 return Buffer::createSharedBuffer(context, flags, sharingHandler, std::move(multiGraphicsAllocation));
33 }