Move storage of mapped operations to OpenCL context

Relate-To: NEO-6352
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban
2021-10-15 11:03:30 +00:00
committed by Compute-Runtime-Automation
parent ca0138da2e
commit 8c9dd3085b
13 changed files with 230 additions and 85 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -72,3 +72,21 @@ void MapOperationsHandler::remove(void *mappedPtr) {
}
}
}
MapOperationsHandler &NEO::MapOperationsStorage::getHandler(cl_mem memObj) {
return handlers[memObj];
}
MapOperationsHandler *NEO::MapOperationsStorage::getHandlerIfExists(cl_mem memObj) {
auto iterator = handlers.find(memObj);
if (iterator == handlers.end()) {
return nullptr;
}
return &iterator->second;
}
void NEO::MapOperationsStorage::removeHandler(cl_mem memObj) {
auto iterator = handlers.find(memObj);
handlers.erase(iterator);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2020 Intel Corporation
* Copyright (C) 2018-2021 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -9,6 +9,7 @@
#include "opencl/source/helpers/properties_helper.h"
#include <mutex>
#include <unordered_map>
#include <vector>
namespace NEO {
@@ -28,4 +29,16 @@ class MapOperationsHandler {
mutable std::mutex mtx;
};
class MapOperationsStorage {
public:
using HandlersMap = std::unordered_map<cl_mem, MapOperationsHandler>;
MapOperationsHandler &getHandler(cl_mem memObj);
MapOperationsHandler *getHandlerIfExists(cl_mem memObj);
void removeHandler(cl_mem memObj);
protected:
HandlersMap handlers{};
};
} // namespace NEO

View File

@@ -62,9 +62,14 @@ MemObj::~MemObj() {
if (allocatedMapPtr != nullptr) {
needWait = true;
}
if (mapOperationsHandler.size() > 0 && !getCpuAddressForMapping()) {
needWait = true;
if (auto mapOperationsHandler = getMapOperationsHandlerIfExists(); mapOperationsHandler != nullptr) {
if (mapOperationsHandler->size() > 0 && !getCpuAddressForMapping()) {
needWait = true;
}
context->getMapOperationsStorage().removeHandler(this);
}
if (!destructorCallbacks.empty()) {
needWait = true;
}
@@ -172,7 +177,7 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName,
case CL_MEM_MAP_COUNT:
srcParamSize = sizeof(mapCount);
mapCount = static_cast<cl_uint>(mapOperationsHandler.size());
mapCount = static_cast<cl_uint>(getMapOperationsHandler().size());
srcParam = &mapCount;
break;
@@ -382,11 +387,26 @@ void *MemObj::getBasePtrForMap(uint32_t rootDeviceIndex) {
}
}
MapOperationsHandler &MemObj::getMapOperationsHandler() {
return context->getMapOperationsStorage().getHandler(this);
}
MapOperationsHandler *MemObj::getMapOperationsHandlerIfExists() {
return context->getMapOperationsStorage().getHandlerIfExists(this);
}
bool MemObj::addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags,
MemObjSizeArray &size, MemObjOffsetArray &offset,
uint32_t mipLevel) {
return mapOperationsHandler.add(ptr, ptrLength, mapFlags, size, offset,
mipLevel);
return getMapOperationsHandler().add(ptr, ptrLength, mapFlags, size, offset, mipLevel);
}
bool MemObj::findMappedPtr(void *mappedPtr, MapInfo &outMapInfo) {
return getMapOperationsHandler().find(mappedPtr, outMapInfo);
}
void MemObj::removeMappedPtr(void *mappedPtr) {
getMapOperationsHandler().remove(mappedPtr);
}
bool MemObj::isTiledAllocation() const {

View File

@@ -86,9 +86,11 @@ class MemObj : public BaseObject<_cl_mem> {
bool getIsObjectRedescribed() const { return isObjectRedescribed; };
size_t getSize() const;
MapOperationsHandler &getMapOperationsHandler();
MapOperationsHandler *getMapOperationsHandlerIfExists();
bool addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset, uint32_t mipLevel);
bool findMappedPtr(void *mappedPtr, MapInfo &outMapInfo) { return mapOperationsHandler.find(mappedPtr, outMapInfo); }
void removeMappedPtr(void *mappedPtr) { mapOperationsHandler.remove(mappedPtr); }
bool findMappedPtr(void *mappedPtr, MapInfo &outMapInfo);
void removeMappedPtr(void *mappedPtr);
void *getBasePtrForMap(uint32_t rootDeviceIndex);
MOCKABLE_VIRTUAL void setAllocatedMapPtr(void *allocatedMapPtr);
@@ -173,7 +175,6 @@ class MemObj : public BaseObject<_cl_mem> {
void *memoryStorage;
void *hostPtr;
void *allocatedMapPtr = nullptr;
MapOperationsHandler mapOperationsHandler;
size_t offset = 0;
MemObj *associatedMemObject = nullptr;
cl_uint refCount = 0;