Replace MemObj::flags with MemoryProperties

Change-Id: I886cd775d1eca55964b7c4b05f6c977558a73922
Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
This commit is contained in:
Filip Hazubski
2019-02-06 13:51:16 +01:00
committed by sys_ocldev
parent 2cb3181359
commit a8d4733802
10 changed files with 43 additions and 50 deletions

View File

@@ -5,7 +5,6 @@
*
*/
#include "common/helpers/bit_helpers.h"
#include "runtime/mem_obj/buffer.h"
#include "runtime/mem_obj/mem_obj_helper.h"
#include "runtime/command_queue/command_queue.h"
@@ -29,7 +28,7 @@ namespace OCLRT {
BufferFuncs bufferFactory[IGFX_MAX_CORE] = {};
Buffer::Buffer(Context *context,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -39,7 +38,7 @@ Buffer::Buffer(Context *context,
bool isObjectRedescribed)
: MemObj(context,
CL_MEM_OBJECT_BUFFER,
flags,
properties,
size,
memoryStorage,
hostPtr,
@@ -239,7 +238,7 @@ Buffer *Buffer::create(Context *context,
DBG_LOG(LogMemoryObject, __FUNCTION__, "hostPtr:", hostPtr, "size:", size, "memoryStorage:", memory->getUnderlyingBuffer(), "GPU address:", std::hex, memory->getGpuAddress());
pBuffer = createBufferHw(context,
properties.flags,
properties,
size,
memory->getUnderlyingBuffer(),
hostPtr,
@@ -255,7 +254,6 @@ Buffer *Buffer::create(Context *context,
}
pBuffer->setHostPtrMinSize(size);
pBuffer->isUncacheable = isValueSet(properties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE);
if (copyMemoryFromHostPtr) {
if ((memory->gmm && memory->gmm->isRenderCompressed) || !MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) {
@@ -459,7 +457,7 @@ bool Buffer::isReadWriteOnCpuAllowed(cl_bool blocking, cl_uint numEventsInWaitLi
}
Buffer *Buffer::createBufferHw(Context *context,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -472,7 +470,7 @@ Buffer *Buffer::createBufferHw(Context *context,
auto funcCreate = bufferFactory[hwInfo.pPlatform->eRenderCoreFamily].createBufferFunction;
DEBUG_BREAK_IF(nullptr == funcCreate);
auto pBuffer = funcCreate(context, flags, size, memoryStorage, hostPtr, gfxAllocation,
auto pBuffer = funcCreate(context, properties, size, memoryStorage, hostPtr, gfxAllocation,
zeroCopy, isHostPtrSVM, isImageRedescribed);
DEBUG_BREAK_IF(nullptr == pBuffer);
if (pBuffer) {

View File

@@ -20,7 +20,7 @@ class MemoryManager;
struct MemoryProperties;
typedef Buffer *(*BufferCreatFunc)(Context *context,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -69,7 +69,7 @@ class Buffer : public MemObj {
GraphicsAllocation *graphicsAllocation);
static Buffer *createBufferHw(Context *context,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -121,7 +121,7 @@ class Buffer : public MemObj {
protected:
Buffer(Context *context,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -151,7 +151,7 @@ template <typename GfxFamily>
class BufferHw : public Buffer {
public:
BufferHw(Context *context,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -159,13 +159,13 @@ class BufferHw : public Buffer {
bool zeroCopy,
bool isHostPtrSVM,
bool isObjectRedescribed)
: Buffer(context, flags, size, memoryStorage, hostPtr, gfxAllocation,
: Buffer(context, properties, size, memoryStorage, hostPtr, gfxAllocation,
zeroCopy, isHostPtrSVM, isObjectRedescribed) {}
void setArgStateful(void *memory, bool forceNonAuxMode, bool disableL3Cache) override;
static Buffer *create(Context *context,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -174,7 +174,7 @@ class BufferHw : public Buffer {
bool isHostPtrSVM,
bool isObjectRedescribed) {
auto buffer = new BufferHw<GfxFamily>(context,
flags,
properties,
size,
memoryStorage,
hostPtr,

View File

@@ -65,7 +65,10 @@ void BufferHw<GfxFamily>::setArgStateful(void *memory, bool forceNonAuxMode, boo
surfaceState->setTileMode(RENDER_SURFACE_STATE::TILE_MODE_LINEAR);
surfaceState->setVerticalLineStride(0);
surfaceState->setVerticalLineStrideOffset(0);
if (!disableL3Cache && ((isAligned<MemoryConstants::cacheLineSize>(bufferAddress) && isAligned<MemoryConstants::cacheLineSize>(bufferSize)) || isValueSet(getFlags(), CL_MEM_READ_ONLY) || !this->isMemObjZeroCopy()) && !this->isUncacheable) {
if (!disableL3Cache &&
((isAligned<MemoryConstants::cacheLineSize>(bufferAddress) && isAligned<MemoryConstants::cacheLineSize>(bufferSize)) ||
isValueSet(getFlags(), CL_MEM_READ_ONLY) || !this->isMemObjZeroCopy()) &&
!this->isMemObjUncacheable()) {
surfaceState->setMemoryObjectControlState(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER));
} else {
surfaceState->setMemoryObjectControlState(gmmHelper->getMOCS(GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED));

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Intel Corporation
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -11,6 +11,8 @@
namespace OCLRT {
struct MemoryProperties : MemoryPropertiesBase {
MemoryProperties() : MemoryPropertiesBase(0) {}
MemoryProperties(cl_mem_flags flags) : MemoryPropertiesBase(flags) {}
};
} // namespace OCLRT

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Intel Corporation
* Copyright (C) 2018-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -10,6 +10,7 @@
namespace OCLRT {
struct MemoryPropertiesBase {
MemoryPropertiesBase(cl_mem_flags flags) : flags(flags) {}
cl_mem_flags flags = 0;
cl_mem_flags_intel flags_intel = 0;
};

View File

@@ -827,7 +827,7 @@ Image *Image::redescribeFillImage() {
DEBUG_BREAK_IF(nullptr == createFunction);
auto image = createFunction(context,
flags | CL_MEM_USE_HOST_PTR,
properties.flags | CL_MEM_USE_HOST_PTR,
this->getSize(),
this->getCpuAddress(),
imageFormatNew,
@@ -875,7 +875,7 @@ Image *Image::redescribe() {
DEBUG_BREAK_IF(nullptr == createFunction);
auto image = createFunction(context,
flags | CL_MEM_USE_HOST_PTR,
properties.flags | CL_MEM_USE_HOST_PTR,
this->getSize(),
this->getCpuAddress(),
imageFormatNew,

View File

@@ -5,6 +5,7 @@
*
*/
#include "common/helpers/bit_helpers.h"
#include "runtime/context/context.h"
#include "runtime/command_queue/command_queue.h"
#include "runtime/command_stream/command_stream_receiver.h"
@@ -23,7 +24,7 @@ namespace OCLRT {
MemObj::MemObj(Context *context,
cl_mem_object_type memObjectType,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -31,7 +32,7 @@ MemObj::MemObj(Context *context,
bool zeroCopy,
bool isHostPtrSVM,
bool isObjectRedescribed)
: context(context), memObjectType(memObjectType), flags(flags), size(size),
: context(context), memObjectType(memObjectType), properties(properties), size(size),
memoryStorage(memoryStorage), hostPtr(hostPtr),
isZeroCopy(zeroCopy), isHostPtrSVM(isHostPtrSVM), isObjectRedescribed(isObjectRedescribed),
graphicsAllocation(gfxAllocation) {
@@ -120,8 +121,8 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName,
break;
case CL_MEM_FLAGS:
srcParamSize = sizeof(flags);
srcParam = &flags;
srcParamSize = sizeof(properties.flags);
srcParam = &properties.flags;
break;
case CL_MEM_SIZE:
@@ -141,7 +142,7 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName,
break;
case CL_MEM_USES_SVM_POINTER:
usesSVMPointer = isHostPtrSVM && !!(flags & CL_MEM_USE_HOST_PTR);
usesSVMPointer = isHostPtrSVM && isValueSet(properties.flags, CL_MEM_USE_HOST_PTR);
srcParamSize = sizeof(cl_bool);
srcParam = &usesSVMPointer;
break;
@@ -208,7 +209,7 @@ void MemObj::setAllocatedMapPtr(void *allocatedMapPtr) {
}
cl_mem_flags MemObj::getFlags() const {
return flags;
return properties.flags;
}
bool MemObj::isMemObjZeroCopy() const {
@@ -220,7 +221,7 @@ bool MemObj::isMemObjWithHostPtrSVM() const {
}
bool MemObj::isMemObjUncacheable() const {
return isUncacheable;
return isValueSet(properties.flags_intel, CL_MEM_LOCALLY_UNCACHED_RESOURCE);
}
GraphicsAllocation *MemObj::getGraphicsAllocation() {
@@ -238,28 +239,16 @@ void MemObj::resetGraphicsAllocation(GraphicsAllocation *newGraphicsAllocation)
}
bool MemObj::readMemObjFlagsInvalid() {
if (this->getFlags() & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS)) {
return true;
}
return false;
return isValueSet(properties.flags, CL_MEM_HOST_WRITE_ONLY) || isValueSet(properties.flags, CL_MEM_HOST_NO_ACCESS);
}
bool MemObj::writeMemObjFlagsInvalid() {
if (this->getFlags() & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS)) {
return true;
}
return false;
return isValueSet(properties.flags, CL_MEM_HOST_READ_ONLY) || isValueSet(properties.flags, CL_MEM_HOST_NO_ACCESS);
}
bool MemObj::mapMemObjFlagsInvalid(cl_map_flags mapFlags) {
if ((this->getFlags() & (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS) && (mapFlags & CL_MAP_WRITE)) ||
(this->getFlags() & (CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_NO_ACCESS) && (mapFlags & CL_MAP_READ))) {
return true;
}
return false;
return (writeMemObjFlagsInvalid() && (mapFlags & CL_MAP_WRITE)) ||
(readMemObjFlagsInvalid() && (mapFlags & CL_MAP_READ));
}
void MemObj::setHostPtrMinSize(size_t size) {
@@ -268,7 +257,7 @@ void MemObj::setHostPtrMinSize(size_t size) {
void *MemObj::getCpuAddressForMapping() {
void *ptrToReturn = nullptr;
if ((this->flags & CL_MEM_USE_HOST_PTR)) {
if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR)) {
ptrToReturn = this->hostPtr;
} else {
ptrToReturn = this->memoryStorage;
@@ -277,7 +266,7 @@ void *MemObj::getCpuAddressForMapping() {
}
void *MemObj::getCpuAddressForMemoryTransfer() {
void *ptrToReturn = nullptr;
if ((this->flags & CL_MEM_USE_HOST_PTR) && this->isMemObjZeroCopy()) {
if (isValueSet(properties.flags, CL_MEM_USE_HOST_PTR) && this->isMemObjZeroCopy()) {
ptrToReturn = this->hostPtr;
} else {
ptrToReturn = this->memoryStorage;
@@ -286,7 +275,7 @@ void *MemObj::getCpuAddressForMemoryTransfer() {
}
void MemObj::releaseAllocatedMapPtr() {
if (allocatedMapPtr) {
DEBUG_BREAK_IF((flags & CL_MEM_USE_HOST_PTR));
DEBUG_BREAK_IF(isValueSet(properties.flags, CL_MEM_USE_HOST_PTR));
memoryManager->freeSystemMemory(allocatedMapPtr);
}
allocatedMapPtr = nullptr;

View File

@@ -6,6 +6,7 @@
*/
#pragma once
#include "mem_obj_types.h"
#include "runtime/api/cl_types.h"
#include "runtime/helpers/base_object.h"
#include "runtime/helpers/mipmap.h"
@@ -35,7 +36,7 @@ class MemObj : public BaseObject<_cl_mem> {
MemObj(Context *context,
cl_mem_object_type memObjectType,
cl_mem_flags flags,
MemoryProperties properties,
size_t size,
void *memoryStorage,
void *hostPtr,
@@ -113,7 +114,7 @@ class MemObj : public BaseObject<_cl_mem> {
Context *context;
cl_mem_object_type memObjectType;
cl_mem_flags flags;
MemoryProperties properties;
size_t size;
size_t hostPtrMinSize = 0;
void *memoryStorage;
@@ -127,7 +128,6 @@ class MemObj : public BaseObject<_cl_mem> {
bool isZeroCopy;
bool isHostPtrSVM;
bool isObjectRedescribed;
bool isUncacheable = false;
MemoryManager *memoryManager = nullptr;
GraphicsAllocation *graphicsAllocation;
GraphicsAllocation *mcsAllocation = nullptr;