mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Refactor flags validation
-create masks for buffer and image flags -create common file for mem_obj_helper -refactor parseMemoryProperties -remove: checkUsedFlagsForBuffer, checkUsedFlagsForImage, addCommonMemoryProperties, addBufferMemoryProperties, addExtraMemoryProperties, addImageMemoryProperties Related-To: NEO-3132 Change-Id: I3c147799de7b104d10d25b2f5262aeda58241d84 Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
7e14b981e1
commit
6a221bc7fc
@ -6,21 +6,25 @@
|
||||
*/
|
||||
|
||||
#include "runtime/helpers/mem_properties_parser_helper.h"
|
||||
#include "runtime/mem_obj/mem_obj_helper.h"
|
||||
|
||||
#include "CL/cl_ext_intel.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
TEST(MemoryPropertiesParser, givenNullPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(nullptr, propertiesStruct));
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(nullptr, propertiesStruct, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::UNKNOWN));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenEmptyPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct));
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::UNKNOWN));
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::BUFFER));
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::IMAGE));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenValidPropertiesWhenParsingMemoryPropertiesThenTrueIsReturned) {
|
||||
@ -33,7 +37,31 @@ TEST(MemoryPropertiesParser, givenValidPropertiesWhenParsingMemoryPropertiesThen
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct));
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::UNKNOWN));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenValidPropertiesWhenParsingMemoryPropertiesForBufferThenTrueIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS,
|
||||
MemObjHelper::validFlagsForBuffer,
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
MemObjHelper::validFlagsForBufferIntel,
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::BUFFER));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenValidPropertiesWhenParsingMemoryPropertiesForImageThenTrueIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS,
|
||||
MemObjHelper::validFlagsForImage,
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
MemObjHelper::validFlagsForImageIntel,
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_TRUE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::IMAGE));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenInvalidPropertiesWhenParsingMemoryPropertiesThenFalseIsReturned) {
|
||||
@ -42,7 +70,81 @@ TEST(MemoryPropertiesParser, givenInvalidPropertiesWhenParsingMemoryPropertiesTh
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct));
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::UNKNOWN));
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::BUFFER));
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::IMAGE));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenInvalidPropertiesWhenParsingMemoryPropertiesForImageThenFalseIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS,
|
||||
MemObjHelper::validFlagsForBuffer,
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
MemObjHelper::validFlagsForBufferIntel,
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::IMAGE));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenInvalidFlagsWhenParsingMemoryPropertiesForImageThenFalseIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS,
|
||||
(1 << 30),
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
MemObjHelper::validFlagsForImageIntel,
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::IMAGE));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenInvalidFlagsIntelWhenParsingMemoryPropertiesForImageThenFalseIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS,
|
||||
MemObjHelper::validFlagsForImage,
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
(1 << 30),
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::IMAGE));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenInvalidPropertiesWhenParsingMemoryPropertiesForBufferThenFalseIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS,
|
||||
MemObjHelper::validFlagsForImage,
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
MemObjHelper::validFlagsForImageIntel,
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::BUFFER));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenInvalidFlagsWhenParsingMemoryPropertiesForBufferThenFalseIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS,
|
||||
(1 << 30),
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
MemObjHelper::validFlagsForBufferIntel,
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::BUFFER));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenInvalidFlagsIntelWhenParsingMemoryPropertiesForBufferThenFalseIsReturned) {
|
||||
cl_mem_properties_intel properties[] = {
|
||||
CL_MEM_FLAGS,
|
||||
MemObjHelper::validFlagsForBuffer,
|
||||
CL_MEM_FLAGS_INTEL,
|
||||
(1 << 30),
|
||||
0};
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
EXPECT_FALSE(MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::ObjType::BUFFER));
|
||||
}
|
||||
|
||||
TEST(MemoryPropertiesParser, givenDifferentParametersWhenCallingFillCachePolicyInPropertiesThenFlushL3FlagsAreCorrectlySet) {
|
||||
|
@ -88,27 +88,6 @@ TEST(MemObjHelper, givenValidPropertiesWhenValidatingMemoryPropertiesThenTrueIsR
|
||||
EXPECT_TRUE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
}
|
||||
|
||||
TEST(MemObjHelper, givenInvalidPropertiesWhenValidatingMemoryPropertiesThenFalseIsReturned) {
|
||||
MemoryProperties properties;
|
||||
properties.flags = (1 << 31);
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags = CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL | CL_MEM_NO_ACCESS_INTEL;
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
|
||||
properties.flags = CL_MEM_NO_ACCESS_INTEL;
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
|
||||
properties.flags_intel = (1 << 31);
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
|
||||
properties.flags = 0;
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForBuffer(properties));
|
||||
EXPECT_FALSE(MemObjHelper::validateMemoryPropertiesForImage(properties, nullptr));
|
||||
}
|
||||
|
||||
struct Image1dWithAccessFlagsUnrestricted : public Image1dDefaults {
|
||||
enum { flags = CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL };
|
||||
};
|
||||
|
Reference in New Issue
Block a user