Skip to content

Commit f8818c5

Browse files
kgibalaCompute-Runtime-Automation
authored andcommitted
Remove OCL object from MemoryProperties 3/n
Wire in MemoryPropertiesFlags support to: -getGraphicsAllocationType -isSuitableForRenderCompression Add variable to MemoryPropertiesFlags: -forceSharedPhysicalMemory Related-To: NEO-3132 Change-Id: I41d91877877437993621577717c274ba3a77336e Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
1 parent f04f1e0 commit f8818c5

File tree

10 files changed

+51
-27
lines changed

10 files changed

+51
-27
lines changed

core/memory_properties/memory_properties_flags_common.inl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ struct MemoryPropertiesFlagsBase {
2727

2828
bool locallyUncachedResource = false;
2929
bool allowUnrestrictedSize = false;
30+
31+
bool forceSharedPhysicalMemory = false;
3032
};
3133

3234
} // namespace NEO

runtime/helpers/memory_properties_flags_helpers_base.inl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ MemoryPropertiesFlags MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(M
6363
if (isValueSet(properties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE)) {
6464
memoryPropertiesFlags.locallyUncachedResource = true;
6565
}
66+
if (isValueSet(properties.flags, CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL)) {
67+
memoryPropertiesFlags.forceSharedPhysicalMemory = true;
68+
}
6669

6770
addExtraMemoryPropertiesFlags(memoryPropertiesFlags, properties);
6871

runtime/mem_obj/buffer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ Buffer *Buffer::create(Context *context,
144144
MemoryManager *memoryManager = context->getMemoryManager();
145145
UNRECOVERABLE_IF(!memoryManager);
146146

147+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
147148
GraphicsAllocation::AllocationType allocationType = getGraphicsAllocationType(
148-
properties,
149+
memoryProperties,
149150
context->isSharedContext,
150151
context->peekContextType(),
151152
HwHelper::renderCompressedBuffersSupported(context->getDevice(0)->getHardwareInfo()),
152153
memoryManager->isLocalMemorySupported(),
153154
HwHelper::get(context->getDevice(0)->getHardwareInfo().platform.eRenderCoreFamily).obtainRenderBufferCompressionPreference(size));
154155

155-
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
156156
checkMemory(memoryProperties, size, hostPtr, errcodeRet, alignementSatisfied, copyMemoryFromHostPtr, memoryManager);
157157

158158
if (errcodeRet != CL_SUCCESS) {
@@ -372,14 +372,14 @@ void Buffer::checkMemory(MemoryPropertiesFlags memoryProperties,
372372
return;
373373
}
374374

375-
GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryProperties &properties, bool sharedContext,
375+
GraphicsAllocation::AllocationType Buffer::getGraphicsAllocationType(const MemoryPropertiesFlags &properties, bool sharedContext,
376376
ContextType contextType, bool renderCompressedBuffers,
377377
bool isLocalMemoryEnabled, bool preferCompression) {
378-
if (is32bit || sharedContext || isValueSet(properties.flags, CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL)) {
378+
if (is32bit || sharedContext || properties.forceSharedPhysicalMemory) {
379379
return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
380380
}
381381

382-
if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) && !isLocalMemoryEnabled) {
382+
if (properties.useHostPtr && !isLocalMemoryEnabled) {
383383
return GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY;
384384
}
385385

runtime/mem_obj/buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class Buffer : public MemObj {
147147
bool &isZeroCopy,
148148
bool &copyMemoryFromHostPtr,
149149
MemoryManager *memMngr);
150-
static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryProperties &properties, bool sharedContext,
150+
static GraphicsAllocation::AllocationType getGraphicsAllocationType(const MemoryPropertiesFlags &properties, bool sharedContext,
151151
ContextType contextType, bool renderCompressedBuffers,
152152
bool localMemoryEnabled, bool preferCompression);
153153
static bool isReadOnlyMemoryPermittedByFlags(cl_mem_flags flags);

runtime/mem_obj/image.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "runtime/helpers/get_info.h"
2222
#include "runtime/helpers/hw_helper.h"
2323
#include "runtime/helpers/hw_info.h"
24+
#include "runtime/helpers/memory_properties_flags_helpers.h"
2425
#include "runtime/helpers/mipmap.h"
2526
#include "runtime/helpers/surface_formats.h"
2627
#include "runtime/mem_obj/buffer.h"
@@ -182,7 +183,8 @@ Image *Image::create(Context *context,
182183
auto hostPtrRowPitch = imageDesc->image_row_pitch ? imageDesc->image_row_pitch : imageWidth * surfaceFormat->ImageElementSizeInBytes;
183184
auto hostPtrSlicePitch = imageDesc->image_slice_pitch ? imageDesc->image_slice_pitch : hostPtrRowPitch * imageHeight;
184185
auto isTilingAllowed = context->isSharedContext ? false : GmmHelper::allowTiling(*imageDesc) && !MemObjHelper::isLinearStorageForced(properties);
185-
imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, properties,
186+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
187+
imgInfo.preferRenderCompression = MemObjHelper::isSuitableForRenderCompression(isTilingAllowed, memoryProperties,
186188
context->peekContextType(), true);
187189

188190
switch (imageDesc->image_type) {

runtime/mem_obj/mem_obj_helper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
#include "common/helpers/bit_helpers.h"
1111

12+
#include "memory_properties_flags.h"
13+
1214
namespace NEO {
1315

14-
bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType, bool preferCompression) {
16+
bool MemObjHelper::isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, ContextType contextType, bool preferCompression) {
1517
return renderCompressed;
1618
}
1719

runtime/mem_obj/mem_obj_helper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "CL/cl.h"
1818
#include "mem_obj_types.h"
19+
#include "memory_properties_flags.h"
1920

2021
namespace NEO {
2122

@@ -114,7 +115,7 @@ class MemObjHelper {
114115
isValueSet(memoryProperties.flags_intel, CL_MEM_FORCE_LINEAR_STORAGE_INTEL);
115116
}
116117

117-
static bool isSuitableForRenderCompression(bool renderCompressed, const MemoryProperties &properties, ContextType contextType, bool preferCompression);
118+
static bool isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, ContextType contextType, bool preferCompression);
118119

119120
protected:
120121
static bool checkUsedFlagsForBuffer(const MemoryProperties &properties) {

unit_tests/context/driver_diagnostics_tests.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "driver_diagnostics_tests.h"
99

1010
#include "core/unit_tests/helpers/debug_manager_state_restore.h"
11+
#include "runtime/helpers/memory_properties_flags_helpers.h"
1112
#include "runtime/mem_obj/mem_obj_helper.h"
1213
#include "unit_tests/mocks/mock_gmm.h"
1314

@@ -487,6 +488,8 @@ TEST_F(PerformanceHintTest, givenUncompressedBufferWhenItsCreatedThenProperPerfo
487488
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(&hwInfo));
488489
cl_device_id deviceId = static_cast<cl_device_id>(device.get());
489490
const MemoryProperties properties(CL_MEM_READ_WRITE);
491+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
492+
490493
size_t size = 0u;
491494

492495
cl_context_properties validProperties[3] = {CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL, CL_CONTEXT_DIAGNOSTICS_LEVEL_ALL_INTEL, 0};
@@ -496,7 +499,7 @@ TEST_F(PerformanceHintTest, givenUncompressedBufferWhenItsCreatedThenProperPerfo
496499
if (context->getMemoryManager()) {
497500
isCompressed = MemObjHelper::isSuitableForRenderCompression(
498501
HwHelper::renderCompressedBuffersSupported(hwInfo),
499-
properties, context->peekContextType(),
502+
memoryProperties, context->peekContextType(),
500503
HwHelper::get(hwInfo.platform.eRenderCoreFamily).obtainRenderBufferCompressionPreference(size)) &&
501504
!is32bit && !context->isSharedContext &&
502505
(!isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) || context->getMemoryManager()->isLocalMemorySupported()) &&

unit_tests/helpers/memory_properties_flags_helpers_tests.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ TEST(MemoryPropertiesFlags, givenValidPropertiesWhenCreateMemoryPropertiesFlagsT
5555
memoryProperties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE;
5656
properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(memoryProperties);
5757
EXPECT_TRUE(properties.locallyUncachedResource);
58+
59+
properties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL);
60+
EXPECT_TRUE(properties.forceSharedPhysicalMemory);
5861
}
5962

6063
TEST(MemoryPropertiesFlags, givenClMemForceLinearStorageFlagWhenCreateMemoryPropertiesFlagsThenReturnProperValue) {

unit_tests/mem_obj/buffer_tests.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "runtime/gmm_helper/resource_info.h"
1515
#include "runtime/helpers/array_count.h"
1616
#include "runtime/helpers/hw_helper.h"
17+
#include "runtime/helpers/memory_properties_flags_helpers.h"
1718
#include "runtime/helpers/options.h"
1819
#include "runtime/mem_obj/buffer.h"
1920
#include "runtime/memory_manager/allocations_list.h"
@@ -321,8 +322,8 @@ TEST(Buffer, givenAllocHostPtrFlagPassedToBufferCreateWhenNoSharedContextOrRende
321322
}
322323

323324
TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferCompressedTypeIsReturnedIn64Bit) {
324-
MemoryProperties properties;
325-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
325+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
326+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
326327
if (is32bit) {
327328
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
328329
} else {
@@ -331,8 +332,8 @@ TEST(Buffer, givenRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenB
331332
}
332333

333334
TEST(Buffer, givenRenderCompressedBuffersDisabledLocalMemoryEnabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturnedIn64Bit) {
334-
MemoryProperties properties;
335-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true);
335+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
336+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true);
336337
if (is32bit) {
337338
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
338339
} else {
@@ -341,28 +342,30 @@ TEST(Buffer, givenRenderCompressedBuffersDisabledLocalMemoryEnabledWhenAllocatio
341342
}
342343

343344
TEST(Buffer, givenSharedContextWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) {
344-
MemoryProperties properties;
345-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
345+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
346+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
346347
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
347348
}
348349

349350
TEST(Buffer, givenSharedContextAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) {
350-
MemoryProperties properties;
351-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
351+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
352+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, true, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
352353
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
353354
}
354355

355356
TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledWhenAllocationTypeIsQueriedThenBufferHostMemoryTypeIsReturned) {
356357
MemoryProperties properties;
357358
properties.flags = CL_MEM_USE_HOST_PTR;
358-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
359+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
360+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
359361
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
360362
}
361363

362364
TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) {
363365
MemoryProperties properties;
364366
properties.flags = CL_MEM_USE_HOST_PTR;
365-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true);
367+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
368+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, true, true);
366369
if (is64bit) {
367370
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type);
368371
} else {
@@ -373,7 +376,8 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledWhenAllocationTypeIsQueried
373376
TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) {
374377
MemoryProperties properties;
375378
properties.flags = CL_MEM_ALLOC_HOST_PTR;
376-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
379+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
380+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
377381
if (is64bit) {
378382
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type);
379383
} else {
@@ -384,14 +388,16 @@ TEST(Buffer, givenAllocHostPtrFlagWhenAllocationTypeIsQueriedThenBufferTypeIsRet
384388
TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryDisabledAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferMemoryTypeIsReturned) {
385389
MemoryProperties properties;
386390
properties.flags = CL_MEM_USE_HOST_PTR;
387-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
391+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
392+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
388393
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
389394
}
390395

391396
TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferMemoryTypeIsReturned) {
392397
MemoryProperties properties;
393398
properties.flags = CL_MEM_USE_HOST_PTR;
394-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true);
399+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
400+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true);
395401
if (is64bit) {
396402
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type);
397403
} else {
@@ -402,14 +408,16 @@ TEST(Buffer, givenUseHostPtrFlagAndLocalMemoryEnabledAndRenderCompressedBuffersE
402408
TEST(Buffer, givenUseHostPointerFlagAndForceSharedPhysicalStorageWhenLocalMemoryIsEnabledThenBufferHostMemoryTypeIsReturned) {
403409
MemoryProperties properties;
404410
properties.flags = CL_MEM_USE_HOST_PTR | CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL;
405-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true);
411+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
412+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, true, true);
406413
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
407414
}
408415

409416
TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocationTypeIsQueriedThenBufferCompressedTypeIsReturned) {
410417
MemoryProperties properties;
411418
properties.flags = CL_MEM_ALLOC_HOST_PTR;
412-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
419+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags(properties);
420+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, true, false, true);
413421
if (is64bit) {
414422
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, type);
415423
} else {
@@ -418,8 +426,8 @@ TEST(Buffer, givenAllocHostPtrFlagAndRenderCompressedBuffersEnabledWhenAllocatio
418426
}
419427

420428
TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhenAllocationTypeIsQueriedThenBufferTypeIsReturned) {
421-
MemoryProperties properties;
422-
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(properties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
429+
MemoryPropertiesFlags memoryProperties = MemoryPropertiesFlagsParser::createMemoryPropertiesFlags({});
430+
auto type = MockPublicAccessBuffer::getGraphicsAllocationType(memoryProperties, false, ContextType::CONTEXT_TYPE_UNRESTRICTIVE, false, false, true);
423431
if (is32bit) {
424432
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY, type);
425433
} else {

0 commit comments

Comments
 (0)