diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index c93836fcad..97acbd7cc0 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -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; } diff --git a/runtime/mem_obj/buffer.cpp b/runtime/mem_obj/buffer.cpp index 7603c00ad1..1d589f3a8e 100644 --- a/runtime/mem_obj/buffer.cpp +++ b/runtime/mem_obj/buffer.cpp @@ -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; } diff --git a/runtime/mem_obj/buffer.h b/runtime/mem_obj/buffer.h index a0aa2bd4f8..7666697326 100644 --- a/runtime/mem_obj/buffer.h +++ b/runtime/mem_obj/buffer.h @@ -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, diff --git a/runtime/mem_obj/mem_obj_helper.h b/runtime/mem_obj/mem_obj_helper.h index e60ecbaeac..cea134f71d 100644 --- a/runtime/mem_obj/mem_obj_helper.h +++ b/runtime/mem_obj/mem_obj_helper.h @@ -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); diff --git a/runtime/mem_obj/mem_obj_helper_common.inl b/runtime/mem_obj/mem_obj_helper_common.inl index a94377eb71..edc28fd4ff 100644 --- a/runtime/mem_obj/mem_obj_helper_common.inl +++ b/runtime/mem_obj/mem_obj_helper_common.inl @@ -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; } diff --git a/unit_tests/mem_obj/mem_obj_helper_tests.cpp b/unit_tests/mem_obj/mem_obj_helper_tests.cpp index 56af1b6715..0e7df2db9f 100644 --- a/unit_tests/mem_obj/mem_obj_helper_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_helper_tests.cpp @@ -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)); }