Skip to content

Commit 48f01f2

Browse files
Move core part of MemoryPropertiesHelpers to shared
Signed-off-by: Mateusz Jablonski <[email protected]>
1 parent afa45bd commit 48f01f2

File tree

69 files changed

+454
-411
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+454
-411
lines changed

opencl/source/api/api.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
#include "opencl/source/event/user_event.h"
3434
#include "opencl/source/execution_environment/cl_execution_environment.h"
3535
#include "opencl/source/gtpin/gtpin_notify.h"
36+
#include "opencl/source/helpers/cl_memory_properties_helpers.h"
3637
#include "opencl/source/helpers/get_info_status_mapper.h"
37-
#include "opencl/source/helpers/memory_properties_helpers.h"
3838
#include "opencl/source/helpers/queue_helpers.h"
3939
#include "opencl/source/helpers/validators.h"
4040
#include "opencl/source/kernel/kernel.h"
@@ -1187,7 +1187,7 @@ cl_int CL_API_CALL clGetImageParamsINTEL(cl_context context,
11871187
auto pClDevice = pContext->getDevice(0);
11881188
surfaceFormat = Image::getSurfaceFormatFromTable(memFlags, imageFormat,
11891189
pClDevice->getHardwareInfo().capabilityTable.supportsOcl21Features);
1190-
retVal = Image::validate(pContext, MemoryPropertiesHelper::createMemoryProperties(memFlags, 0, 0, &pClDevice->getDevice()),
1190+
retVal = Image::validate(pContext, ClMemoryPropertiesHelper::createMemoryProperties(memFlags, 0, 0, &pClDevice->getDevice()),
11911191
surfaceFormat, imageDesc, nullptr);
11921192
}
11931193
if (CL_SUCCESS == retVal) {
@@ -3809,9 +3809,9 @@ void *clHostMemAllocINTEL(
38093809
cl_mem_flags flags = 0;
38103810
cl_mem_flags_intel flagsIntel = 0;
38113811
cl_mem_alloc_flags_intel allocflags = 0;
3812-
if (!MemoryPropertiesHelper::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel,
3813-
allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN,
3814-
*neoContext)) {
3812+
if (!ClMemoryPropertiesHelper::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel,
3813+
allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN,
3814+
*neoContext)) {
38153815
err.set(CL_INVALID_VALUE);
38163816
return nullptr;
38173817
}
@@ -3851,9 +3851,9 @@ void *clDeviceMemAllocINTEL(
38513851
cl_mem_flags flags = 0;
38523852
cl_mem_flags_intel flagsIntel = 0;
38533853
cl_mem_alloc_flags_intel allocflags = 0;
3854-
if (!MemoryPropertiesHelper::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel,
3855-
allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN,
3856-
*neoContext)) {
3854+
if (!ClMemoryPropertiesHelper::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel,
3855+
allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN,
3856+
*neoContext)) {
38573857
err.set(CL_INVALID_VALUE);
38583858
return nullptr;
38593859
}
@@ -3905,9 +3905,9 @@ void *clSharedMemAllocINTEL(
39053905
}
39063906
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY, neoContext->getRootDeviceIndices(), subDeviceBitfields);
39073907
unifiedMemoryProperties.device = unifiedMemoryPropertiesDevice;
3908-
if (!MemoryPropertiesHelper::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel,
3909-
allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN,
3910-
*neoContext)) {
3908+
if (!ClMemoryPropertiesHelper::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel,
3909+
allocflags, MemoryPropertiesHelper::ObjType::UNKNOWN,
3910+
*neoContext)) {
39113911
err.set(CL_INVALID_VALUE);
39123912
return nullptr;
39133913
}

opencl/source/helpers/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ set(RUNTIME_SRCS_HELPERS_BASE
1616
${CMAKE_CURRENT_SOURCE_DIR}/cl_hw_helper.h
1717
${CMAKE_CURRENT_SOURCE_DIR}/cl_hw_helper_base.inl
1818
${CMAKE_CURRENT_SOURCE_DIR}/cl_hw_helper_bdw_and_later.inl
19+
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}cl_memory_properties_helpers.cpp
20+
${CMAKE_CURRENT_SOURCE_DIR}/cl_memory_properties_helpers.h
21+
${CMAKE_CURRENT_SOURCE_DIR}/cl_memory_properties_helpers_base.inl
1922
${CMAKE_CURRENT_SOURCE_DIR}/cl_preemption_helper.cpp
2023
${CMAKE_CURRENT_SOURCE_DIR}/cl_preemption_helper.h
2124
${CMAKE_CURRENT_SOURCE_DIR}/convert_color.h
@@ -34,9 +37,6 @@ set(RUNTIME_SRCS_HELPERS_BASE
3437
${CMAKE_CURRENT_SOURCE_DIR}/hardware_commands_helper_bdw_and_later.inl
3538
${CMAKE_CURRENT_SOURCE_DIR}/helper_options.cpp
3639
${CMAKE_CURRENT_SOURCE_DIR}/implicit_scaling_ocl.cpp
37-
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}memory_properties_helpers.cpp
38-
${CMAKE_CURRENT_SOURCE_DIR}/memory_properties_helpers.h
39-
${CMAKE_CURRENT_SOURCE_DIR}/memory_properties_helpers_base.inl
4040
${CMAKE_CURRENT_SOURCE_DIR}/mipmap.cpp
4141
${CMAKE_CURRENT_SOURCE_DIR}/mipmap.h
4242
${CMAKE_CURRENT_SOURCE_DIR}/properties_helper.h

opencl/source/helpers/memory_properties_helpers.cpp renamed to opencl/source/helpers/cl_memory_properties_helpers.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/*
2-
* Copyright (C) 2020-2021 Intel Corporation
2+
* Copyright (C) 2021 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
66
*/
77

88
#include "opencl/source/cl_device/cl_device.h"
99
#include "opencl/source/context/context.h"
10-
#include "opencl/source/helpers/memory_properties_helpers_base.inl"
10+
#include "opencl/source/helpers/cl_memory_properties_helpers_base.inl"
1111
#include "opencl/source/mem_obj/mem_obj_helper.h"
1212

1313
namespace NEO {
1414

15-
void MemoryPropertiesHelper::addExtraMemoryProperties(MemoryProperties &properties, cl_mem_flags flags, cl_mem_flags_intel flagsIntel) {
15+
void ClMemoryPropertiesHelper::addExtraMemoryProperties(MemoryProperties &properties, cl_mem_flags flags, cl_mem_flags_intel flagsIntel) {
1616
}
1717

18-
bool MemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &memoryProperties,
19-
cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel,
20-
cl_mem_alloc_flags_intel &allocflags, ObjType objectType, Context &context) {
18+
bool ClMemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &memoryProperties,
19+
cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel,
20+
cl_mem_alloc_flags_intel &allocflags, MemoryPropertiesHelper::ObjType objectType, Context &context) {
2121
Device *pDevice = &context.getDevice(0)->getDevice();
2222

2323
if (properties != nullptr) {
@@ -38,7 +38,7 @@ bool MemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_intel
3838
}
3939
}
4040

41-
memoryProperties = MemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, allocflags, pDevice);
41+
memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, allocflags, pDevice);
4242

4343
switch (objectType) {
4444
case MemoryPropertiesHelper::ObjType::BUFFER:
@@ -53,16 +53,4 @@ bool MemoryPropertiesHelper::parseMemoryProperties(const cl_mem_properties_intel
5353
return true;
5454
}
5555

56-
void MemoryPropertiesHelper::fillPoliciesInProperties(AllocationProperties &allocationProperties, const MemoryProperties &memoryProperties, const HardwareInfo &hwInfo, bool deviceOnlyVisibilty) {
57-
fillCachePolicyInProperties(allocationProperties,
58-
memoryProperties.flags.locallyUncachedResource,
59-
memoryProperties.flags.readOnly,
60-
deviceOnlyVisibilty,
61-
0);
62-
}
63-
64-
uint32_t MemoryPropertiesHelper::getCacheRegion(const MemoryProperties &memoryProperties) {
65-
return 0;
66-
}
67-
6856
} // namespace NEO
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#pragma once
9+
#include "shared/source/helpers/memory_properties_helpers.h"
10+
11+
#include "opencl/extensions/public/cl_ext_private.h"
12+
13+
namespace NEO {
14+
15+
class Context;
16+
17+
class ClMemoryPropertiesHelper {
18+
public:
19+
static void addExtraMemoryProperties(MemoryProperties &properties, cl_mem_flags flags, cl_mem_flags_intel flagsIntel);
20+
static MemoryProperties createMemoryProperties(cl_mem_flags flags, cl_mem_flags_intel flagsIntel,
21+
cl_mem_alloc_flags_intel allocflags, const Device *pDevice);
22+
23+
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &memoryProperties,
24+
cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel, cl_mem_alloc_flags_intel &allocflags,
25+
MemoryPropertiesHelper::ObjType objectType, Context &context);
26+
};
27+
} // namespace NEO

opencl/source/helpers/memory_properties_helpers_base.inl renamed to opencl/source/helpers/cl_memory_properties_helpers_base.inl

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
#include "shared/source/helpers/bit_helpers.h"
99

1010
#include "opencl/extensions/public/cl_ext_private.h"
11-
#include "opencl/source/helpers/memory_properties_helpers.h"
11+
#include "opencl/source/helpers/cl_memory_properties_helpers.h"
1212

1313
#include "CL/cl_ext_intel.h"
1414

1515
namespace NEO {
1616

17-
MemoryProperties MemoryPropertiesHelper::createMemoryProperties(cl_mem_flags flags, cl_mem_flags_intel flagsIntel,
18-
cl_mem_alloc_flags_intel allocflags, const Device *pDevice) {
17+
MemoryProperties ClMemoryPropertiesHelper::createMemoryProperties(cl_mem_flags flags, cl_mem_flags_intel flagsIntel,
18+
cl_mem_alloc_flags_intel allocflags, const Device *pDevice) {
1919
MemoryProperties memoryProperties;
2020

2121
if (isValueSet(flags, CL_MEM_READ_WRITE)) {
@@ -91,33 +91,4 @@ MemoryProperties MemoryPropertiesHelper::createMemoryProperties(cl_mem_flags fla
9191

9292
return memoryProperties;
9393
}
94-
95-
AllocationProperties MemoryPropertiesHelper::getAllocationProperties(
96-
uint32_t rootDeviceIndex, MemoryProperties memoryProperties, bool allocateMemory, size_t size,
97-
GraphicsAllocation::AllocationType type, bool multiStorageResource, const HardwareInfo &hwInfo,
98-
DeviceBitfield subDevicesBitfieldParam, bool deviceOnlyVisibilty) {
99-
100-
auto deviceBitfield = adjustDeviceBitfield(rootDeviceIndex, memoryProperties, subDevicesBitfieldParam);
101-
AllocationProperties allocationProperties(rootDeviceIndex, allocateMemory, size, type, multiStorageResource, deviceBitfield);
102-
fillPoliciesInProperties(allocationProperties, memoryProperties, hwInfo, deviceOnlyVisibilty);
103-
return allocationProperties;
104-
}
105-
106-
void MemoryPropertiesHelper::fillCachePolicyInProperties(AllocationProperties &allocationProperties, bool uncached, bool readOnly,
107-
bool deviceOnlyVisibilty, uint32_t cacheRegion) {
108-
allocationProperties.flags.uncacheable = uncached;
109-
auto cacheFlushRequired = !uncached && !readOnly && !deviceOnlyVisibilty;
110-
allocationProperties.flags.flushL3RequiredForRead = cacheFlushRequired;
111-
allocationProperties.flags.flushL3RequiredForWrite = cacheFlushRequired;
112-
allocationProperties.cacheRegion = cacheRegion;
113-
}
114-
115-
DeviceBitfield MemoryPropertiesHelper::adjustDeviceBitfield(uint32_t rootDeviceIndex, const MemoryProperties &memoryProperties,
116-
DeviceBitfield deviceBitfieldIn) {
117-
if (rootDeviceIndex == memoryProperties.pDevice->getRootDeviceIndex()) {
118-
return deviceBitfieldIn & memoryProperties.pDevice->getDeviceBitfield();
119-
}
120-
return deviceBitfieldIn;
121-
}
122-
12394
} // namespace NEO

opencl/source/mem_obj/buffer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "opencl/source/cl_device/cl_device.h"
2929
#include "opencl/source/command_queue/command_queue.h"
3030
#include "opencl/source/context/context.h"
31-
#include "opencl/source/helpers/memory_properties_helpers.h"
31+
#include "opencl/source/helpers/cl_memory_properties_helpers.h"
3232
#include "opencl/source/helpers/validators.h"
3333
#include "opencl/source/mem_obj/mem_obj_helper.h"
3434
#include "opencl/source/os_interface/ocl_reg_path.h"
@@ -108,15 +108,15 @@ cl_mem Buffer::validateInputAndCreateBuffer(cl_context context,
108108
MemoryProperties memoryProperties{};
109109
cl_mem_alloc_flags_intel allocflags = 0;
110110
cl_mem_flags_intel emptyFlagsIntel = 0;
111-
if ((false == MemoryPropertiesHelper::parseMemoryProperties(nullptr, memoryProperties, flags, emptyFlagsIntel, allocflags,
112-
MemoryPropertiesHelper::ObjType::BUFFER, *pContext)) ||
111+
if ((false == ClMemoryPropertiesHelper::parseMemoryProperties(nullptr, memoryProperties, flags, emptyFlagsIntel, allocflags,
112+
MemoryPropertiesHelper::ObjType::BUFFER, *pContext)) ||
113113
(false == MemObjHelper::validateMemoryPropertiesForBuffer(memoryProperties, flags, emptyFlagsIntel, *pContext))) {
114114
retVal = CL_INVALID_VALUE;
115115
return nullptr;
116116
}
117117

118-
if ((false == MemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
119-
MemoryPropertiesHelper::ObjType::BUFFER, *pContext)) ||
118+
if ((false == ClMemoryPropertiesHelper::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags,
119+
MemoryPropertiesHelper::ObjType::BUFFER, *pContext)) ||
120120
(false == MemObjHelper::validateMemoryPropertiesForBuffer(memoryProperties, flags, flagsIntel, *pContext))) {
121121
retVal = CL_INVALID_PROPERTY;
122122
return nullptr;
@@ -154,7 +154,7 @@ Buffer *Buffer::create(Context *context,
154154
size_t size,
155155
void *hostPtr,
156156
cl_int &errcodeRet) {
157-
return create(context, MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),
157+
return create(context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),
158158
flags, 0, size, hostPtr, errcodeRet);
159159
}
160160

@@ -424,7 +424,7 @@ Buffer *Buffer::createSharedBuffer(Context *context, cl_mem_flags flags, Sharing
424424
auto rootDeviceIndex = context->getDevice(0)->getRootDeviceIndex();
425425
auto size = multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex)->getUnderlyingBufferSize();
426426
auto sharedBuffer = createBufferHw(
427-
context, MemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),
427+
context, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()),
428428
flags, 0, size, nullptr, nullptr, std::move(multiGraphicsAllocation),
429429
false, false, false);
430430

@@ -514,7 +514,7 @@ Buffer *Buffer::createSubBuffer(cl_mem_flags flags,
514514
cl_int &errcodeRet) {
515515
DEBUG_BREAK_IF(nullptr == createFunction);
516516
MemoryProperties memoryProperties =
517-
MemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, 0, &this->context->getDevice(0)->getDevice());
517+
ClMemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, 0, &this->context->getDevice(0)->getDevice());
518518
auto buffer = createFunction(this->context, memoryProperties, flags, 0, region->size,
519519
ptrOffset(this->memoryStorage, region->origin),
520520
this->hostPtr ? ptrOffset(this->hostPtr, region->origin) : nullptr,
@@ -688,7 +688,7 @@ Buffer *Buffer::createBufferHwFromDevice(const Device *device,
688688
auto funcCreate = bufferFactory[hwInfo.platform.eRenderCoreFamily].createBufferFunction;
689689
DEBUG_BREAK_IF(nullptr == funcCreate);
690690

691-
MemoryProperties memoryProperties = MemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, 0, device);
691+
MemoryProperties memoryProperties = ClMemoryPropertiesHelper::createMemoryProperties(flags, flagsIntel, 0, device);
692692
auto pBuffer = funcCreate(nullptr, memoryProperties, flags, flagsIntel, size, memoryStorage, hostPtr, std::move(multiGraphicsAllocation),
693693
zeroCopy, isHostPtrSVM, isImageRedescribed);
694694

0 commit comments

Comments
 (0)