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:
parent
7e14b981e1
commit
6a221bc7fc
|
@ -591,7 +591,12 @@ cl_mem CL_API_CALL clCreateBuffer(cl_context context,
|
|||
|
||||
MemoryProperties propertiesStruct;
|
||||
propertiesStruct.flags = flags;
|
||||
|
||||
if (isFieldValid(propertiesStruct.flags, MemObjHelper::validFlagsForBuffer)) {
|
||||
Buffer::validateInputAndCreateBuffer(context, propertiesStruct, size, hostPtr, retVal, buffer);
|
||||
} else {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
err.set(retVal);
|
||||
DBG_LOG_INPUTS("buffer", buffer);
|
||||
|
@ -616,10 +621,10 @@ cl_mem CL_API_CALL clCreateBufferWithPropertiesINTEL(cl_context context,
|
|||
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
|
||||
|
||||
MemoryProperties propertiesStruct;
|
||||
if (!MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct)) {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
} else {
|
||||
if (MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::BUFFER)) {
|
||||
Buffer::validateInputAndCreateBuffer(context, propertiesStruct, size, hostPtr, retVal, buffer);
|
||||
} else {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
err.set(retVal);
|
||||
|
@ -759,7 +764,11 @@ cl_mem CL_API_CALL clCreateImage(cl_context context,
|
|||
|
||||
if (retVal == CL_SUCCESS) {
|
||||
MemoryProperties propertiesStruct(flags);
|
||||
if (isFieldValid(propertiesStruct.flags, MemObjHelper::validFlagsForImage)) {
|
||||
image = Image::validateAndCreateImage(pContext, propertiesStruct, imageFormat, imageDesc, hostPtr, retVal);
|
||||
} else {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCodeHelper err(errcodeRet, retVal);
|
||||
|
@ -794,7 +803,7 @@ cl_mem CL_API_CALL clCreateImageWithPropertiesINTEL(cl_context context,
|
|||
retVal = validateObjects(WithCastToInternal(context, &pContext));
|
||||
|
||||
if (retVal == CL_SUCCESS) {
|
||||
if (MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct)) {
|
||||
if (MemoryPropertiesParser::parseMemoryProperties(properties, propertiesStruct, MemoryPropertiesParser::MemoryPropertiesParser::ObjType::IMAGE)) {
|
||||
image = Image::validateAndCreateImage(pContext, propertiesStruct, imageFormat, imageDesc, hostPtr, retVal);
|
||||
} else {
|
||||
retVal = CL_INVALID_VALUE;
|
||||
|
|
|
@ -7,9 +7,11 @@
|
|||
|
||||
#include "runtime/helpers/mem_properties_parser_helper.h"
|
||||
|
||||
#include "runtime/mem_obj/mem_obj_helper.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
bool NEO::MemoryPropertiesParser::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct) {
|
||||
bool NEO::MemoryPropertiesParser::parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct, ObjType objectType) {
|
||||
if (properties == nullptr) {
|
||||
return true;
|
||||
}
|
||||
|
@ -26,6 +28,17 @@ bool NEO::MemoryPropertiesParser::parseMemoryProperties(const cl_mem_properties_
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
switch (objectType) {
|
||||
case MemoryPropertiesParser::ObjType::BUFFER:
|
||||
return isFieldValid(propertiesStruct.flags, MemObjHelper::validFlagsForBuffer) &&
|
||||
isFieldValid(propertiesStruct.flags_intel, MemObjHelper::validFlagsForBufferIntel);
|
||||
case MemoryPropertiesParser::ObjType::IMAGE:
|
||||
return isFieldValid(propertiesStruct.flags, MemObjHelper::validFlagsForImage) &&
|
||||
isFieldValid(propertiesStruct.flags_intel, MemObjHelper::validFlagsForImageIntel);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,13 @@ namespace NEO {
|
|||
|
||||
class MemoryPropertiesParser {
|
||||
public:
|
||||
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct);
|
||||
enum class ObjType {
|
||||
UNKNOWN,
|
||||
BUFFER,
|
||||
IMAGE,
|
||||
};
|
||||
|
||||
static bool parseMemoryProperties(const cl_mem_properties_intel *properties, MemoryProperties &propertiesStruct, ObjType objectType);
|
||||
|
||||
static AllocationProperties getAllocationProperties(MemoryPropertiesFlags memoryProperties, bool allocateMemory,
|
||||
size_t size, GraphicsAllocation::AllocationType type, bool multiStorageResource) {
|
||||
|
|
|
@ -23,6 +23,7 @@ set(RUNTIME_SRCS_MEM_OBJ
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/definitions/mem_obj_types_common.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/mem_obj_helper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mem_obj_helper.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mem_obj_helper_common.inl
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pipe.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pipe.h
|
||||
)
|
||||
|
|
|
@ -5,9 +5,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "runtime/mem_obj/mem_obj_helper.h"
|
||||
|
||||
#include "common/helpers/bit_helpers.h"
|
||||
#include "runtime/mem_obj/mem_obj_helper_common.inl"
|
||||
|
||||
#include "memory_properties_flags.h"
|
||||
|
||||
|
@ -21,7 +19,8 @@ bool MemObjHelper::validateExtraMemoryProperties(const MemoryProperties &propert
|
|||
return true;
|
||||
}
|
||||
|
||||
void MemObjHelper::addExtraMemoryProperties(MemoryProperties &properties) {
|
||||
}
|
||||
const uint64_t MemObjHelper::extraFlags = 0;
|
||||
|
||||
const uint64_t MemObjHelper::extraFlagsIntel = 0;
|
||||
|
||||
} // namespace NEO
|
||||
|
|
|
@ -22,135 +22,23 @@ namespace NEO {
|
|||
|
||||
class MemObjHelper {
|
||||
public:
|
||||
static bool validateMemoryPropertiesForBuffer(const MemoryProperties &properties) {
|
||||
if (!MemObjHelper::checkUsedFlagsForBuffer(properties)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* 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))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return validateExtraMemoryProperties(properties);
|
||||
}
|
||||
|
||||
static bool validateMemoryPropertiesForImage(const MemoryProperties &properties, cl_mem parent) {
|
||||
if (!MemObjHelper::checkUsedFlagsForImage(properties)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check all the invalid flags combination. */
|
||||
if ((!isValueSet(properties.flags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) &&
|
||||
(isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY) ||
|
||||
isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_READ_ONLY) ||
|
||||
isValueSet(properties.flags, CL_MEM_WRITE_ONLY | CL_MEM_READ_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_WRITE_ONLY | CL_MEM_HOST_READ_ONLY) ||
|
||||
isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS) ||
|
||||
isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS) ||
|
||||
isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_READ_WRITE) ||
|
||||
isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_WRITE_ONLY) ||
|
||||
isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_READ_ONLY))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto parentMemObj = castToObject<MemObj>(parent);
|
||||
if (parentMemObj != nullptr && properties.flags) {
|
||||
auto parentFlags = parentMemObj->getFlags();
|
||||
/* Check whether flags are compatible with parent. */
|
||||
if (isValueSet(properties.flags, CL_MEM_ALLOC_HOST_PTR) ||
|
||||
isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR) ||
|
||||
isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) ||
|
||||
((!isValueSet(parentFlags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) &&
|
||||
(!isValueSet(properties.flags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) &&
|
||||
((isValueSet(parentFlags, CL_MEM_WRITE_ONLY) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_WRITE_ONLY) && isValueSet(properties.flags, CL_MEM_READ_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_READ_ONLY) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_READ_ONLY) && isValueSet(properties.flags, CL_MEM_WRITE_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_WRITE_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_READ_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_HOST_NO_ACCESS) && isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_HOST_NO_ACCESS) && isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY))))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return validateExtraMemoryProperties(properties);
|
||||
}
|
||||
|
||||
static AllocationProperties getAllocationPropertiesWithImageInfo(ImageInfo &imgInfo, bool allocateMemory, const MemoryPropertiesFlags &memoryProperties) {
|
||||
AllocationProperties allocationProperties{allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE};
|
||||
MemoryPropertiesParser::fillPoliciesInProperties(allocationProperties, memoryProperties);
|
||||
return allocationProperties;
|
||||
}
|
||||
|
||||
static bool checkMemFlagsForSubBuffer(cl_mem_flags flags) {
|
||||
const cl_mem_flags allValidFlags =
|
||||
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
||||
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
|
||||
|
||||
return isFieldValid(flags, allValidFlags);
|
||||
}
|
||||
|
||||
static SVMAllocsManager::SvmAllocationProperties getSvmAllocationProperties(cl_mem_flags flags) {
|
||||
SVMAllocsManager::SvmAllocationProperties svmProperties;
|
||||
svmProperties.coherent = isValueSet(flags, CL_MEM_SVM_FINE_GRAIN_BUFFER);
|
||||
svmProperties.hostPtrReadOnly = isValueSet(flags, CL_MEM_HOST_READ_ONLY) || isValueSet(flags, CL_MEM_HOST_NO_ACCESS);
|
||||
svmProperties.readOnly = isValueSet(flags, CL_MEM_READ_ONLY);
|
||||
return svmProperties;
|
||||
}
|
||||
static const uint64_t extraFlags;
|
||||
static const uint64_t extraFlagsIntel;
|
||||
static const uint64_t commonFlags;
|
||||
static const uint64_t commonFlagsIntel;
|
||||
static const uint64_t validFlagsForBuffer;
|
||||
static const uint64_t validFlagsForBufferIntel;
|
||||
static const uint64_t validFlagsForImage;
|
||||
static const uint64_t validFlagsForImageIntel;
|
||||
|
||||
static bool validateMemoryPropertiesForBuffer(const MemoryProperties &properties);
|
||||
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);
|
||||
static SVMAllocsManager::SvmAllocationProperties getSvmAllocationProperties(cl_mem_flags flags);
|
||||
static bool isSuitableForRenderCompression(bool renderCompressed, const MemoryPropertiesFlags &properties, ContextType contextType, bool preferCompression);
|
||||
|
||||
protected:
|
||||
static bool checkUsedFlagsForBuffer(const MemoryProperties &properties) {
|
||||
MemoryProperties acceptedProperties;
|
||||
addCommonMemoryProperties(acceptedProperties);
|
||||
addBufferMemoryProperties(acceptedProperties);
|
||||
addExtraMemoryProperties(acceptedProperties);
|
||||
|
||||
return (isFieldValid(properties.flags, acceptedProperties.flags) &&
|
||||
isFieldValid(properties.flags_intel, acceptedProperties.flags_intel));
|
||||
}
|
||||
|
||||
static bool checkUsedFlagsForImage(const MemoryProperties &properties) {
|
||||
MemoryProperties acceptedProperties;
|
||||
addCommonMemoryProperties(acceptedProperties);
|
||||
addImageMemoryProperties(acceptedProperties);
|
||||
addExtraMemoryProperties(acceptedProperties);
|
||||
|
||||
return (isFieldValid(properties.flags, acceptedProperties.flags) &&
|
||||
isFieldValid(properties.flags_intel, acceptedProperties.flags_intel));
|
||||
}
|
||||
|
||||
static inline void addCommonMemoryProperties(MemoryProperties &properties) {
|
||||
properties.flags |=
|
||||
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
||||
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR |
|
||||
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
|
||||
properties.flags_intel |= CL_MEM_LOCALLY_UNCACHED_RESOURCE | CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE;
|
||||
}
|
||||
|
||||
static inline void addImageMemoryProperties(MemoryProperties &properties) {
|
||||
properties.flags |= CL_MEM_NO_ACCESS_INTEL | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL;
|
||||
}
|
||||
|
||||
static inline void addBufferMemoryProperties(MemoryProperties &properties) {
|
||||
properties.flags |= CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL;
|
||||
properties.flags_intel |= CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL;
|
||||
}
|
||||
|
||||
static void addExtraMemoryProperties(MemoryProperties &properties);
|
||||
static bool validateExtraMemoryProperties(const MemoryProperties &properties);
|
||||
};
|
||||
} // namespace NEO
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/mem_obj/mem_obj_helper.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
bool MemObjHelper::validateMemoryPropertiesForBuffer(const MemoryProperties &properties) {
|
||||
/* 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))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return validateExtraMemoryProperties(properties);
|
||||
}
|
||||
|
||||
bool MemObjHelper::validateMemoryPropertiesForImage(const MemoryProperties &properties, cl_mem parent) {
|
||||
/* Check all the invalid flags combination. */
|
||||
if ((!isValueSet(properties.flags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) &&
|
||||
(isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY) ||
|
||||
isValueSet(properties.flags, CL_MEM_READ_WRITE | CL_MEM_READ_ONLY) ||
|
||||
isValueSet(properties.flags, CL_MEM_WRITE_ONLY | CL_MEM_READ_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_WRITE_ONLY | CL_MEM_HOST_READ_ONLY) ||
|
||||
isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS) ||
|
||||
isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS) ||
|
||||
isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_READ_WRITE) ||
|
||||
isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_WRITE_ONLY) ||
|
||||
isValueSet(properties.flags, CL_MEM_NO_ACCESS_INTEL | CL_MEM_READ_ONLY))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto parentMemObj = castToObject<MemObj>(parent);
|
||||
if (parentMemObj != nullptr && properties.flags) {
|
||||
auto parentFlags = parentMemObj->getFlags();
|
||||
/* Check whether flags are compatible with parent. */
|
||||
if (isValueSet(properties.flags, CL_MEM_ALLOC_HOST_PTR) ||
|
||||
isValueSet(properties.flags, CL_MEM_COPY_HOST_PTR) ||
|
||||
isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) ||
|
||||
((!isValueSet(parentFlags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) &&
|
||||
(!isValueSet(properties.flags, CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL)) &&
|
||||
((isValueSet(parentFlags, CL_MEM_WRITE_ONLY) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_WRITE_ONLY) && isValueSet(properties.flags, CL_MEM_READ_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_READ_ONLY) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_READ_ONLY) && isValueSet(properties.flags, CL_MEM_WRITE_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_READ_WRITE)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_WRITE_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_NO_ACCESS_INTEL) && isValueSet(properties.flags, CL_MEM_READ_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_HOST_NO_ACCESS) && isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY)) ||
|
||||
(isValueSet(parentFlags, CL_MEM_HOST_NO_ACCESS) && isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY))))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return validateExtraMemoryProperties(properties);
|
||||
}
|
||||
|
||||
AllocationProperties MemObjHelper::getAllocationPropertiesWithImageInfo(ImageInfo &imgInfo, bool allocateMemory, const MemoryPropertiesFlags &memoryProperties) {
|
||||
AllocationProperties allocationProperties{allocateMemory, imgInfo, GraphicsAllocation::AllocationType::IMAGE};
|
||||
MemoryPropertiesParser::fillPoliciesInProperties(allocationProperties, memoryProperties);
|
||||
return allocationProperties;
|
||||
}
|
||||
|
||||
bool MemObjHelper::checkMemFlagsForSubBuffer(cl_mem_flags flags) {
|
||||
const cl_mem_flags allValidFlags =
|
||||
CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
||||
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
|
||||
|
||||
return isFieldValid(flags, allValidFlags);
|
||||
}
|
||||
|
||||
SVMAllocsManager::SvmAllocationProperties MemObjHelper::getSvmAllocationProperties(cl_mem_flags flags) {
|
||||
SVMAllocsManager::SvmAllocationProperties svmProperties;
|
||||
svmProperties.coherent = isValueSet(flags, CL_MEM_SVM_FINE_GRAIN_BUFFER);
|
||||
svmProperties.hostPtrReadOnly = isValueSet(flags, CL_MEM_HOST_READ_ONLY) || isValueSet(flags, CL_MEM_HOST_NO_ACCESS);
|
||||
svmProperties.readOnly = isValueSet(flags, CL_MEM_READ_ONLY);
|
||||
return svmProperties;
|
||||
}
|
||||
|
||||
const uint64_t MemObjHelper::commonFlags = extraFlags | CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
|
||||
CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR | CL_MEM_USE_HOST_PTR |
|
||||
CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
|
||||
|
||||
const uint64_t MemObjHelper::commonFlagsIntel = extraFlagsIntel | CL_MEM_LOCALLY_UNCACHED_RESOURCE | CL_MEM_LOCALLY_UNCACHED_SURFACE_STATE_RESOURCE;
|
||||
|
||||
const uint64_t MemObjHelper::validFlagsForBuffer = commonFlags | CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL;
|
||||
|
||||
const uint64_t MemObjHelper::validFlagsForBufferIntel = commonFlagsIntel | CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL;
|
||||
|
||||
const uint64_t MemObjHelper::validFlagsForImage = commonFlags | CL_MEM_NO_ACCESS_INTEL | CL_MEM_ACCESS_FLAGS_UNRESTRICTED_INTEL;
|
||||
|
||||
const uint64_t MemObjHelper::validFlagsForImageIntel = commonFlagsIntel;
|
||||
|
||||
} // namespace NEO
|
|
@ -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 };
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue