Skip to content

Commit 5ac1d12

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
Connect UnifiedMemoryProperties with MemoryPropertiesFlags
-Add support to SvmAllocationData -Refactor parseMemoryProperties -Add allocation flags Related-To: NEO-4011 Change-Id: I3728d2319aeef983dbcc3f8702da9a303a4e2b9c Signed-off-by: Gibala <krzysztof.gibala@intel.com>
1 parent ac0471a commit 5ac1d12

File tree

59 files changed

+318
-267
lines changed

Some content is hidden

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

59 files changed

+318
-267
lines changed

core/memory_manager/unified_memory_manager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "core/unified_memory/unified_memory.h"
1010
#include "core/utilities/spinlock.h"
1111

12+
#include "memory_properties_flags.h"
13+
1214
#include <cstdint>
1315
#include <map>
1416
#include <mutex>
@@ -23,7 +25,7 @@ struct SvmAllocationData {
2325
GraphicsAllocation *gpuAllocation = nullptr;
2426
size_t size = 0;
2527
InternalMemoryType memoryType = InternalMemoryType::SVM;
26-
uint64_t allocationFlagsProperty;
28+
MemoryPropertiesFlags allocationFlagsProperty;
2729
void *device = nullptr;
2830
};
2931

@@ -72,7 +74,7 @@ class SVMAllocsManager {
7274
UnifiedMemoryProperties() = default;
7375
UnifiedMemoryProperties(InternalMemoryType memoryType) : memoryType(memoryType){};
7476
InternalMemoryType memoryType = InternalMemoryType::NOT_SPECIFIED;
75-
uint64_t allocationFlags = 0;
77+
MemoryPropertiesFlags allocationFlags;
7678
void *device = nullptr;
7779
};
7880

core/memory_properties/memory_properties_flags.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ struct MemoryPropertiesFlags {
1515
MemoryFlags flags;
1616
uint32_t allFlags = 0;
1717
};
18-
static_assert(sizeof(MemoryPropertiesFlags::flags) == sizeof(MemoryPropertiesFlags::allFlags), "");
18+
union {
19+
MemoryAllocFlags allocFlags;
20+
uint32_t allAllocFlags = 0;
21+
};
22+
static_assert(sizeof(MemoryPropertiesFlags::flags) == sizeof(MemoryPropertiesFlags::allFlags) && sizeof(MemoryPropertiesFlags::allocFlags) == sizeof(MemoryPropertiesFlags::allAllocFlags), "");
1923
};
2024
} // namespace NEO

core/memory_properties/memory_properties_flags_common.inl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ struct MemoryFlags {
2525
uint32_t allowUnrestrictedSize : 1;
2626
uint32_t forceSharedPhysicalMemory : 1;
2727
};
28+
29+
struct MemoryAllocFlags {
30+
uint32_t allocWriteCombined : 1;
31+
uint32_t allocDefault : 1;
32+
};
33+
2834
} // namespace NEO

public/cl_ext_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* Internal only cl types *
4242
**************************/
4343

44+
using cl_mem_alloc_flags_intel = cl_bitfield;
4445
using cl_mem_properties_intel = cl_bitfield;
4546
using cl_mem_flags_intel = cl_mem_flags;
4647
using cl_mem_info_intel = cl_uint;

runtime/api/api.cpp

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ cl_mem CL_API_CALL clCreateBuffer(cl_context context,
611611
cl_mem buffer = nullptr;
612612
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
613613

614-
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0);
614+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0, 0);
615615
if (isFieldValid(flags, MemObjHelper::validFlagsForBuffer)) {
616616
Buffer::validateInputAndCreateBuffer(context, memoryProperties, flags, 0, size, hostPtr, retVal, buffer);
617617
} else {
@@ -643,7 +643,8 @@ cl_mem CL_API_CALL clCreateBufferWithPropertiesINTEL(cl_context context,
643643
MemoryPropertiesFlags memoryProperties;
644644
cl_mem_flags flags = 0;
645645
cl_mem_flags_intel flagsIntel = 0;
646-
if (MemoryPropertiesParser::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::BUFFER)) {
646+
cl_mem_alloc_flags_intel allocflags = 0;
647+
if (MemoryPropertiesParser::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::BUFFER)) {
647648
Buffer::validateInputAndCreateBuffer(context, memoryProperties, flags, flagsIntel, size, hostPtr, retVal, buffer);
648649
} else {
649650
retVal = CL_INVALID_VALUE;
@@ -786,7 +787,7 @@ cl_mem CL_API_CALL clCreateImage(cl_context context,
786787
retVal = validateObjects(WithCastToInternal(context, &pContext));
787788

788789
if (retVal == CL_SUCCESS) {
789-
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0);
790+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0, 0);
790791
if (isFieldValid(flags, MemObjHelper::validFlagsForImage)) {
791792
image = Image::validateAndCreateImage(pContext, memoryProperties, flags, 0, imageFormat, imageDesc, hostPtr, retVal);
792793
} else {
@@ -825,10 +826,11 @@ cl_mem CL_API_CALL clCreateImageWithPropertiesINTEL(cl_context context,
825826
MemoryPropertiesFlags memoryProperties;
826827
cl_mem_flags flags = 0;
827828
cl_mem_flags_intel flagsIntel = 0;
829+
cl_mem_alloc_flags_intel allocflags = 0;
828830
retVal = validateObjects(WithCastToInternal(context, &pContext));
829831

830832
if (retVal == CL_SUCCESS) {
831-
if (MemoryPropertiesParser::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::IMAGE)) {
833+
if (MemoryPropertiesParser::parseMemoryProperties(properties, memoryProperties, flags, flagsIntel, allocflags, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::IMAGE)) {
832834
image = Image::validateAndCreateImage(pContext, memoryProperties, flags, flagsIntel, imageFormat, imageDesc, hostPtr, retVal);
833835
} else {
834836
retVal = CL_INVALID_VALUE;
@@ -875,7 +877,7 @@ cl_mem CL_API_CALL clCreateImage2D(cl_context context,
875877
retVal = validateObjects(WithCastToInternal(context, &pContext));
876878

877879
if (retVal == CL_SUCCESS) {
878-
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0);
880+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0, 0);
879881
image2D = Image::validateAndCreateImage(pContext, memoryProperties, flags, 0, imageFormat, &imageDesc, hostPtr, retVal);
880882
}
881883

@@ -926,7 +928,7 @@ cl_mem CL_API_CALL clCreateImage3D(cl_context context,
926928
retVal = validateObjects(WithCastToInternal(context, &pContext));
927929

928930
if (retVal == CL_SUCCESS) {
929-
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0);
931+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0, 0);
930932
image3D = Image::validateAndCreateImage(pContext, memoryProperties, flags, 0, imageFormat, &imageDesc, hostPtr, retVal);
931933
}
932934

@@ -1088,7 +1090,7 @@ cl_int CL_API_CALL clGetImageParamsINTEL(cl_context context,
10881090
}
10891091
if (CL_SUCCESS == retVal) {
10901092
surfaceFormat = (SurfaceFormatInfo *)Image::getSurfaceFormatFromTable(memFlags, imageFormat);
1091-
retVal = Image::validate(pContext, MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memFlags, 0), surfaceFormat, imageDesc, nullptr);
1093+
retVal = Image::validate(pContext, MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memFlags, 0, 0), surfaceFormat, imageDesc, nullptr);
10921094
}
10931095
if (CL_SUCCESS == retVal) {
10941096
retVal = Image::getImageParams(pContext, memFlags, surfaceFormat, imageDesc, imageRowPitch, imageSlicePitch);
@@ -3445,7 +3447,10 @@ void *clHostMemAllocINTEL(
34453447
}
34463448

34473449
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY);
3448-
if (!MemObjHelper::parseUnifiedMemoryProperties(properties, unifiedMemoryProperties)) {
3450+
cl_mem_flags flags = 0;
3451+
cl_mem_flags_intel flagsIntel = 0;
3452+
cl_mem_alloc_flags_intel allocflags = 0;
3453+
if (!MemoryPropertiesParser::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel, allocflags, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::UNKNOWN)) {
34493454
err.set(CL_INVALID_VALUE);
34503455
return nullptr;
34513456
}
@@ -3478,7 +3483,10 @@ void *clDeviceMemAllocINTEL(
34783483
}
34793484

34803485
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::DEVICE_UNIFIED_MEMORY);
3481-
if (!MemObjHelper::parseUnifiedMemoryProperties(properties, unifiedMemoryProperties)) {
3486+
cl_mem_flags flags = 0;
3487+
cl_mem_flags_intel flagsIntel = 0;
3488+
cl_mem_alloc_flags_intel allocflags = 0;
3489+
if (!MemoryPropertiesParser::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel, allocflags, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::UNKNOWN)) {
34823490
err.set(CL_INVALID_VALUE);
34833491
return nullptr;
34843492
}
@@ -3512,7 +3520,10 @@ void *clSharedMemAllocINTEL(
35123520
}
35133521

35143522
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::SHARED_UNIFIED_MEMORY);
3515-
if (!MemObjHelper::parseUnifiedMemoryProperties(properties, unifiedMemoryProperties)) {
3523+
cl_mem_flags flags = 0;
3524+
cl_mem_flags_intel flagsIntel = 0;
3525+
cl_mem_alloc_flags_intel allocflags = 0;
3526+
if (!MemoryPropertiesParser::parseMemoryProperties(properties, unifiedMemoryProperties.allocationFlags, flags, flagsIntel, allocflags, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::UNKNOWN)) {
35163527
err.set(CL_INVALID_VALUE);
35173528
return nullptr;
35183529
}
@@ -3595,7 +3606,7 @@ cl_int clGetMemAllocInfoINTEL(
35953606
return retVal;
35963607
}
35973608
case CL_MEM_ALLOC_FLAGS_INTEL: {
3598-
retVal = info.set<uint64_t>(unifiedMemoryAllocation->allocationFlagsProperty);
3609+
retVal = info.set<uint32_t>(unifiedMemoryAllocation->allocationFlagsProperty.allAllocFlags);
35993610
return retVal;
36003611
}
36013612
case CL_MEM_ALLOC_DEVICE_INTEL: {

runtime/helpers/mem_properties_parser_helper.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
namespace NEO {
1414

15-
bool NEO::MemoryPropertiesParser::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryPropertiesFlags &memoryProperties, cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel, ObjType objectType) {
15+
bool NEO::MemoryPropertiesParser::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryPropertiesFlags &memoryProperties,
16+
cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel, cl_mem_alloc_flags_intel &allocflags, ObjType objectType) {
1617
if (properties == nullptr) {
1718
return true;
1819
}
@@ -25,12 +26,15 @@ bool NEO::MemoryPropertiesParser::parseMemoryProperties(const cl_mem_properties_
2526
case CL_MEM_FLAGS_INTEL:
2627
flagsIntel |= static_cast<cl_mem_flags_intel>(properties[i + 1]);
2728
break;
29+
case CL_MEM_ALLOC_FLAGS_INTEL:
30+
allocflags |= static_cast<cl_mem_alloc_flags_intel>(properties[i + 1]);
31+
break;
2832
default:
2933
return false;
3034
}
3135
}
3236

33-
memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, flagsIntel);
37+
memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, flagsIntel, allocflags);
3438

3539
switch (objectType) {
3640
case MemoryPropertiesParser::ObjType::BUFFER:

runtime/helpers/mem_properties_parser_helper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class MemoryPropertiesParser {
2222
IMAGE,
2323
};
2424

25-
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryPropertiesFlags &memoryProperties, cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel, ObjType objectType);
25+
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryPropertiesFlags &memoryProperties,
26+
cl_mem_flags &flags, cl_mem_flags_intel &flagsIntel, cl_mem_alloc_flags_intel &allocflags, ObjType objectType);
2627

2728
static AllocationProperties getAllocationProperties(uint32_t rootDeviceIndex, MemoryPropertiesFlags memoryProperties, bool allocateMemory,
2829
size_t size, GraphicsAllocation::AllocationType type, bool multiStorageResource) {

runtime/helpers/memory_properties_flags_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class MemoryPropertiesFlagsParser {
1616
public:
1717
static void addExtraMemoryPropertiesFlags(MemoryPropertiesFlags &propertiesFlags, cl_mem_flags flags, cl_mem_flags_intel flagsIntel);
1818

19-
static MemoryPropertiesFlags createMemoryPropertiesFlags(cl_mem_flags flags, cl_mem_flags_intel flagsIntel);
19+
static MemoryPropertiesFlags createMemoryPropertiesFlags(cl_mem_flags flags, cl_mem_flags_intel flagsIntel, cl_mem_alloc_flags_intel allocflags);
2020
};
2121
} // namespace NEO

runtime/helpers/memory_properties_flags_helpers_base.inl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace NEO {
1515

16-
MemoryPropertiesFlags MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(cl_mem_flags flags, cl_mem_flags_intel flagsIntel) {
16+
MemoryPropertiesFlags MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(cl_mem_flags flags, cl_mem_flags_intel flagsIntel, cl_mem_alloc_flags_intel allocflags) {
1717
MemoryPropertiesFlags memoryPropertiesFlags;
1818

1919
if (isValueSet(flags, CL_MEM_READ_WRITE)) {
@@ -72,6 +72,14 @@ MemoryPropertiesFlags MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(c
7272
memoryPropertiesFlags.flags.forceSharedPhysicalMemory = true;
7373
}
7474

75+
if (isValueSet(allocflags, CL_MEM_ALLOC_WRITE_COMBINED_INTEL)) {
76+
memoryPropertiesFlags.allocFlags.allocWriteCombined = true;
77+
}
78+
79+
if (allocflags == CL_MEM_ALLOC_DEFAULT_INTEL) {
80+
memoryPropertiesFlags.allocFlags.allocDefault = true;
81+
}
82+
7583
addExtraMemoryPropertiesFlags(memoryPropertiesFlags, flags, flagsIntel);
7684

7785
return memoryPropertiesFlags;

runtime/mem_obj/buffer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ Buffer *Buffer::create(Context *context,
126126
size_t size,
127127
void *hostPtr,
128128
cl_int &errcodeRet) {
129-
return create(context, MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0), flags, 0, size, hostPtr, errcodeRet);
129+
return create(context, MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0, 0), flags, 0, size, hostPtr, errcodeRet);
130130
}
131131

132132
Buffer *Buffer::create(Context *context,
@@ -322,7 +322,7 @@ Buffer *Buffer::create(Context *context,
322322

323323
Buffer *Buffer::createSharedBuffer(Context *context, cl_mem_flags flags, SharingHandler *sharingHandler,
324324
GraphicsAllocation *graphicsAllocation) {
325-
auto sharedBuffer = createBufferHw(context, MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0), flags, 0, graphicsAllocation->getUnderlyingBufferSize(), nullptr, nullptr, graphicsAllocation, false, false, false);
325+
auto sharedBuffer = createBufferHw(context, MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, 0, 0), flags, 0, graphicsAllocation->getUnderlyingBufferSize(), nullptr, nullptr, graphicsAllocation, false, false, false);
326326

327327
sharedBuffer->setSharingHandler(sharingHandler);
328328
return sharedBuffer;
@@ -406,7 +406,7 @@ Buffer *Buffer::createSubBuffer(cl_mem_flags flags,
406406
const cl_buffer_region *region,
407407
cl_int &errcodeRet) {
408408
DEBUG_BREAK_IF(nullptr == createFunction);
409-
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, flagsIntel);
409+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, flagsIntel, 0);
410410
auto buffer = createFunction(this->context, memoryProperties, flags, 0, region->size,
411411
ptrOffset(this->memoryStorage, region->origin),
412412
this->hostPtr ? ptrOffset(this->hostPtr, region->origin) : nullptr,
@@ -538,7 +538,7 @@ Buffer *Buffer::createBufferHwFromDevice(const Device *device,
538538

539539
auto funcCreate = bufferFactory[hwInfo.platform.eRenderCoreFamily].createBufferFunction;
540540
DEBUG_BREAK_IF(nullptr == funcCreate);
541-
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, flagsIntel);
541+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(flags, flagsIntel, 0);
542542
auto pBuffer = funcCreate(nullptr, memoryProperties, flags, flagsIntel, size, memoryStorage, hostPtr, gfxAllocation,
543543
zeroCopy, isHostPtrSVM, isImageRedescribed);
544544
pBuffer->executionEnvironment = device->getExecutionEnvironment();

0 commit comments

Comments
 (0)