mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Remove OCL object from MemoryProperties 9/n
Refactor: - validateMemoryPropertiesForBuffer Related-To: NEO-3132 Change-Id: Ibdeec8ecdd2025718a3379b333a6c8ef9a8ceabf Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
64e810fb0f
commit
0753dc211d
@ -593,7 +593,7 @@ cl_mem CL_API_CALL clCreateBuffer(cl_context context,
|
||||
propertiesStruct.flags = flags;
|
||||
|
||||
if (isFieldValid(propertiesStruct.flags, MemObjHelper::validFlagsForBuffer)) {
|
||||
Buffer::validateInputAndCreateBuffer(context, propertiesStruct, size, hostPtr, retVal, buffer);
|
||||
Buffer::validateInputAndCreateBuffer(context, propertiesStruct, flags, 0, size, hostPtr, retVal, buffer);
|
||||
} else {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
}
|
||||
@ -622,7 +622,7 @@ cl_mem CL_API_CALL clCreateBufferWithPropertiesINTEL(cl_context context,
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
if (MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::BUFFER)) {
|
||||
Buffer::validateInputAndCreateBuffer(context, propertiesStruct, size, hostPtr, retVal, buffer);
|
||||
Buffer::validateInputAndCreateBuffer(context, propertiesStruct, propertiesStruct.flags, propertiesStruct.flags_intel, size, hostPtr, retVal, buffer);
|
||||
} else {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
}
|
||||
|
@ -80,6 +80,8 @@ bool Buffer::isValidSubBufferOffset(size_t offset) {
|
||||
|
||||
void Buffer::validateInputAndCreateBuffer(cl_context &context,
|
||||
MemoryProperties properties,
|
||||
cl_mem_flags flags,
|
||||
cl_mem_flags_intel flagsIntel,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &retVal,
|
||||
@ -90,7 +92,7 @@ void Buffer::validateInputAndCreateBuffer(cl_context &context,
|
||||
return;
|
||||
}
|
||||
|
||||
if (!MemObjHelper::validateMemoryPropertiesForBuffer(properties)) {
|
||||
if (!MemObjHelper::validateMemoryPropertiesForBuffer(properties, flags, flagsIntel)) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
return;
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ class Buffer : public MemObj {
|
||||
|
||||
static void validateInputAndCreateBuffer(cl_context &context,
|
||||
MemoryProperties properties,
|
||||
cl_mem_flags flags,
|
||||
cl_mem_flags_intel flagsIntel,
|
||||
size_t size,
|
||||
void *hostPtr,
|
||||
cl_int &retVal,
|
||||
|
@ -31,7 +31,7 @@ class MemObjHelper {
|
||||
static const uint64_t validFlagsForImage;
|
||||
static const uint64_t validFlagsForImageIntel;
|
||||
|
||||
static bool validateMemoryPropertiesForBuffer(const MemoryProperties &properties);
|
||||
static bool validateMemoryPropertiesForBuffer(const MemoryProperties &properties, cl_mem_flags flags, cl_mem_flags_intel flagsIntel);
|
||||
static bool validateMemoryPropertiesForImage(const MemoryProperties &properties, cl_mem parent);
|
||||
static AllocationProperties getAllocationPropertiesWithImageInfo(ImageInfo &imgInfo, bool allocateMemory, const MemoryPropertiesFlags &memoryProperties);
|
||||
static bool checkMemFlagsForSubBuffer(cl_mem_flags flags);
|
||||
|
@ -9,16 +9,16 @@
|
||||
|
||||
namespace NEO {
|
||||
|
||||
bool MemObjHelper::validateMemoryPropertiesForBuffer(const MemoryProperties &properties) {
|
||||
bool MemObjHelper::validateMemoryPropertiesForBuffer(const MemoryProperties &properties, cl_mem_flags flags, cl_mem_flags_intel flagsIntel) {
|
||||
/* Check all the invalid flags combination. */
|
||||
if ((isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_READ_ONLY)) ||
|
||||
(isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) ||
|
||||
(isValueSet(properties.flags, CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY)) ||
|
||||
(isValueSet(properties.flags, CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR)) ||
|
||||
(isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) ||
|
||||
(isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) ||
|
||||
(isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY)) ||
|
||||
(isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS))) {
|
||||
if ((isValueSet(flags, CL_MEM_READ_WRITE | CL_MEM_READ_ONLY)) ||
|
||||
(isValueSet(flags, CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY)) ||
|
||||
(isValueSet(flags, CL_MEM_READ_ONLY | CL_MEM_WRITE_ONLY)) ||
|
||||
(isValueSet(flags, CL_MEM_ALLOC_HOST_PTR | CL_MEM_USE_HOST_PTR)) ||
|
||||
(isValueSet(flags, CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR)) ||
|
||||
(isValueSet(flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) ||
|
||||
(isValueSet(flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY)) ||
|
||||
(isValueSet(flags, CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,9 @@ TEST(MemObjHelper, givenClMemForceLinearStorageFlagWhenCheckForLinearStorageForc
|
||||
|
||||
TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsReturned) {
|
||||
MemoryProperties properties;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
cl_mem_flags flags = 0;
|
||||
cl_mem_flags_intel flags_intel = 0;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties, flags, flags_intel));
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags = CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL | CL_MEM_NO_ACCESS_INTEL;
|
||||
@ -64,27 +66,39 @@ TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsR
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags = CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_HOST_NO_ACCESS;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
flags = CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR | CL_MEM_HOST_NO_ACCESS;
|
||||
flags_intel = 0;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties, flags, flags_intel));
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags = CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
flags = CL_MEM_WRITE_ONLY | CL_MEM_COPY_HOST_PTR | CL_MEM_HOST_WRITE_ONLY;
|
||||
flags_intel = 0;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties, flags, flags_intel));
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags = CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_HOST_NO_ACCESS;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
flags = CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR | CL_MEM_HOST_NO_ACCESS;
|
||||
flags_intel = 0;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties, flags, flags_intel));
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
flags = 0;
|
||||
flags_intel = CL_MEM_LOCALLY_UNCACHED_RESOURCE;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties, flags, flags_intel));
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags_intel = CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
flags = 0;
|
||||
flags_intel = CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties, flags, flags_intel));
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags = 0;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
flags = 0;
|
||||
flags_intel = 0;
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForBuffer(properties, flags, flags_intel));
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user