2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2023-01-05 11:41:06 +00:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
2022-07-24 04:21:16 +00:00
|
|
|
|
2020-05-28 11:38:43 +02:00
|
|
|
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-02-26 14:21:01 +01:00
|
|
|
#include "opencl/extensions/public/cl_ext_private.h"
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/api/cl_types.h"
|
|
|
|
|
#include "opencl/source/helpers/base_object.h"
|
2020-11-10 16:48:18 +01:00
|
|
|
#include "opencl/source/helpers/destructor_callbacks.h"
|
2023-01-05 11:41:06 +00:00
|
|
|
#include "opencl/source/helpers/properties_helper.h"
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/sharings/sharing.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2019-09-24 16:05:17 +02:00
|
|
|
#include "memory_properties_flags.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2023-01-05 11:41:06 +00:00
|
|
|
struct MapInfo;
|
|
|
|
|
class MapOperationsHandler;
|
2018-07-31 09:52:48 +02:00
|
|
|
class ExecutionEnvironment;
|
2017-12-21 00:45:38 +01:00
|
|
|
class GraphicsAllocation;
|
|
|
|
|
struct KernelInfo;
|
|
|
|
|
class MemoryManager;
|
|
|
|
|
class Context;
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
|
struct OpenCLObjectMapper<_cl_mem> {
|
|
|
|
|
typedef class MemObj DerivedType;
|
|
|
|
|
};
|
|
|
|
|
|
2020-12-04 09:54:30 +00:00
|
|
|
namespace CreateMemObj {
|
|
|
|
|
struct AllocationInfo {
|
|
|
|
|
GraphicsAllocation *mapAllocation = nullptr;
|
|
|
|
|
GraphicsAllocation *memory = nullptr;
|
2022-02-04 13:59:01 +00:00
|
|
|
AllocationType allocationType = AllocationType::UNKNOWN;
|
2020-12-04 09:54:30 +00:00
|
|
|
|
|
|
|
|
bool zeroCopyAllowed = true;
|
|
|
|
|
bool isHostPtrSVM = false;
|
|
|
|
|
|
|
|
|
|
bool alignementSatisfied = true;
|
|
|
|
|
bool allocateMemory = true;
|
|
|
|
|
bool copyMemoryFromHostPtr = false;
|
|
|
|
|
|
|
|
|
|
bool transferNeeded = false;
|
|
|
|
|
};
|
|
|
|
|
} // namespace CreateMemObj
|
|
|
|
|
|
|
|
|
|
using AllocationInfoType = StackVec<CreateMemObj::AllocationInfo, 1>;
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
class MemObj : public BaseObject<_cl_mem> {
|
|
|
|
|
public:
|
2019-03-14 11:18:57 +01:00
|
|
|
constexpr static cl_ulong maskMagic = 0xFFFFFFFFFFFFFF00LL;
|
|
|
|
|
constexpr static cl_ulong objectMagic = 0xAB2212340CACDD00LL;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
MemObj(Context *context,
|
|
|
|
|
cl_mem_object_type memObjectType,
|
2020-04-22 14:37:30 +02:00
|
|
|
const MemoryProperties &memoryProperties,
|
2019-09-24 16:05:17 +02:00
|
|
|
cl_mem_flags flags,
|
|
|
|
|
cl_mem_flags_intel flagsIntel,
|
2017-12-21 00:45:38 +01:00
|
|
|
size_t size,
|
|
|
|
|
void *memoryStorage,
|
|
|
|
|
void *hostPtr,
|
2022-06-24 18:38:34 +00:00
|
|
|
MultiGraphicsAllocation &&multiGraphicsAllocation,
|
2017-12-21 00:45:38 +01:00
|
|
|
bool zeroCopy,
|
|
|
|
|
bool isHostPtrSVM,
|
|
|
|
|
bool isObjectRedescrbied);
|
|
|
|
|
~MemObj() override;
|
|
|
|
|
|
|
|
|
|
cl_int getMemObjectInfo(cl_mem_info paramName,
|
|
|
|
|
size_t paramValueSize,
|
|
|
|
|
void *paramValue,
|
|
|
|
|
size_t *paramValueSizeRet);
|
|
|
|
|
cl_int setDestructorCallback(void(CL_CALLBACK *funcNotify)(cl_mem, void *),
|
|
|
|
|
void *userData);
|
|
|
|
|
|
|
|
|
|
void *getCpuAddress() const;
|
|
|
|
|
void *getHostPtr() const;
|
|
|
|
|
bool getIsObjectRedescribed() const { return isObjectRedescribed; };
|
|
|
|
|
size_t getSize() const;
|
2018-02-13 13:20:34 +01:00
|
|
|
|
2021-10-15 11:03:30 +00:00
|
|
|
MapOperationsHandler &getMapOperationsHandler();
|
|
|
|
|
MapOperationsHandler *getMapOperationsHandlerIfExists();
|
2021-10-18 15:07:01 +00:00
|
|
|
bool addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, MemObjSizeArray &size, MemObjOffsetArray &offset, uint32_t mipLevel, GraphicsAllocation *graphicsAllocation);
|
2021-10-15 11:03:30 +00:00
|
|
|
bool findMappedPtr(void *mappedPtr, MapInfo &outMapInfo);
|
|
|
|
|
void removeMappedPtr(void *mappedPtr);
|
2019-11-07 14:15:04 +01:00
|
|
|
void *getBasePtrForMap(uint32_t rootDeviceIndex);
|
2018-02-13 13:20:34 +01:00
|
|
|
|
|
|
|
|
MOCKABLE_VIRTUAL void setAllocatedMapPtr(void *allocatedMapPtr);
|
|
|
|
|
void *getAllocatedMapPtr() const { return allocatedMapPtr; }
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
void setHostPtrMinSize(size_t size);
|
2018-02-13 13:20:34 +01:00
|
|
|
void releaseAllocatedMapPtr();
|
2020-09-17 22:27:22 +02:00
|
|
|
void releaseMapAllocation(uint32_t rootDeviceIndex, bool asyncDestroy);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
bool isMemObjZeroCopy() const;
|
|
|
|
|
bool isMemObjWithHostPtrSVM() const;
|
2019-01-30 10:57:42 +01:00
|
|
|
bool isMemObjUncacheable() const;
|
2019-08-30 08:18:34 +02:00
|
|
|
bool isMemObjUncacheableForSurfaceState() const;
|
2018-02-17 22:26:28 +01:00
|
|
|
virtual void transferDataToHostPtr(MemObjSizeArray ©Size, MemObjOffsetArray ©Offset) { UNRECOVERABLE_IF(true); };
|
|
|
|
|
virtual void transferDataFromHostPtr(MemObjSizeArray ©Size, MemObjOffsetArray ©Offset) { UNRECOVERABLE_IF(true); };
|
2018-02-08 20:55:31 +01:00
|
|
|
|
2020-06-02 13:38:13 +02:00
|
|
|
GraphicsAllocation *getGraphicsAllocation(uint32_t rootDeviceIndex) const;
|
2018-07-04 10:41:58 +02:00
|
|
|
void resetGraphicsAllocation(GraphicsAllocation *newGraphicsAllocation);
|
2020-06-02 13:38:13 +02:00
|
|
|
void removeGraphicsAllocation(uint32_t rootDeviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
GraphicsAllocation *getMcsAllocation() { return mcsAllocation; }
|
|
|
|
|
void setMcsAllocation(GraphicsAllocation *alloc) { mcsAllocation = alloc; }
|
|
|
|
|
|
|
|
|
|
bool readMemObjFlagsInvalid();
|
|
|
|
|
bool writeMemObjFlagsInvalid();
|
|
|
|
|
bool mapMemObjFlagsInvalid(cl_map_flags mapFlags);
|
|
|
|
|
|
2019-08-26 09:27:30 +02:00
|
|
|
MOCKABLE_VIRTUAL bool isTiledAllocation() const;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
void *getCpuAddressForMapping();
|
|
|
|
|
void *getCpuAddressForMemoryTransfer();
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<SharingHandler> &getSharingHandler() { return sharingHandler; }
|
2018-02-08 22:59:03 +01:00
|
|
|
SharingHandler *peekSharingHandler() const { return sharingHandler.get(); }
|
2017-12-21 00:45:38 +01:00
|
|
|
void setSharingHandler(SharingHandler *sharingHandler) { this->sharingHandler.reset(sharingHandler); }
|
|
|
|
|
void setParentSharingHandler(std::shared_ptr<SharingHandler> &handler) { sharingHandler = handler; }
|
|
|
|
|
unsigned int acquireCount = 0;
|
2018-07-04 10:41:58 +02:00
|
|
|
Context *getContext() const { return context; }
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
void destroyGraphicsAllocation(GraphicsAllocation *allocation, bool asyncDestroy);
|
2019-09-10 08:35:57 +02:00
|
|
|
bool checkIfMemoryTransferIsRequired(size_t offsetInMemObject, size_t offsetInHostPtr, const void *ptr, cl_command_type cmdType);
|
2018-07-09 15:03:42 +02:00
|
|
|
bool mappingOnCpuAllowed() const;
|
2018-02-17 22:26:28 +01:00
|
|
|
virtual size_t calculateOffsetForMapping(const MemObjOffsetArray &offset) const { return offset[0]; }
|
|
|
|
|
size_t calculateMappedPtrLength(const MemObjSizeArray &size) const { return calculateOffsetForMapping(size); }
|
2018-02-21 15:25:46 +01:00
|
|
|
cl_mem_object_type peekClMemObjType() const { return memObjectType; }
|
2018-03-14 11:07:51 +01:00
|
|
|
size_t getOffset() const { return offset; }
|
2018-12-12 14:36:45 +01:00
|
|
|
MemoryManager *getMemoryManager() const {
|
|
|
|
|
return memoryManager;
|
|
|
|
|
}
|
2019-04-08 14:49:35 +02:00
|
|
|
void setMapAllocation(GraphicsAllocation *allocation) {
|
2020-07-23 14:52:32 +02:00
|
|
|
mapAllocations.addAllocation(allocation);
|
2019-04-08 14:49:35 +02:00
|
|
|
}
|
2020-07-23 14:52:32 +02:00
|
|
|
GraphicsAllocation *getMapAllocation(uint32_t rootDeviceIndex) const {
|
2019-04-08 14:49:35 +02:00
|
|
|
if (associatedMemObject) {
|
2020-07-23 14:52:32 +02:00
|
|
|
return associatedMemObject->getMapAllocation(rootDeviceIndex);
|
2019-04-08 14:49:35 +02:00
|
|
|
}
|
2020-07-23 14:52:32 +02:00
|
|
|
return mapAllocations.getGraphicsAllocation(rootDeviceIndex);
|
2019-04-08 14:49:35 +02:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-04-22 14:37:30 +02:00
|
|
|
const cl_mem_flags &getFlags() const { return flags; }
|
|
|
|
|
const cl_mem_flags &getFlagsIntel() const { return flagsIntel; }
|
2020-05-28 11:38:43 +02:00
|
|
|
const MultiGraphicsAllocation &getMultiGraphicsAllocation() const { return multiGraphicsAllocation; }
|
2020-12-04 09:54:30 +00:00
|
|
|
static void cleanAllGraphicsAllocations(Context &context, MemoryManager &memoryManager, AllocationInfoType &allocationInfo, bool isParentObject);
|
2021-07-01 16:00:22 +00:00
|
|
|
MemObj *getHighestRootMemObj() {
|
|
|
|
|
if (!associatedMemObject) {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
return associatedMemObject->getHighestRootMemObj();
|
|
|
|
|
}
|
2022-10-18 08:39:46 +00:00
|
|
|
MemObj *getAssociatedMemObject() {
|
|
|
|
|
return associatedMemObject;
|
|
|
|
|
}
|
2023-01-04 11:47:05 +00:00
|
|
|
void setSizeInPoolAllocator(size_t size) {
|
|
|
|
|
this->sizeInPoolAllocator = size;
|
|
|
|
|
}
|
2019-04-16 15:42:23 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
protected:
|
|
|
|
|
void getOsSpecificMemObjectInfo(const cl_mem_info ¶mName, size_t *srcParamSize, void **srcParam);
|
2020-05-27 17:12:32 +02:00
|
|
|
void storeProperties(const cl_mem_properties *properties);
|
2020-06-02 13:38:13 +02:00
|
|
|
void checkUsageAndReleaseOldAllocation(uint32_t rootDeviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
Context *context;
|
|
|
|
|
cl_mem_object_type memObjectType;
|
2020-04-22 14:37:30 +02:00
|
|
|
MemoryProperties memoryProperties;
|
2019-09-24 16:05:17 +02:00
|
|
|
cl_mem_flags flags = 0;
|
2019-10-15 10:35:14 +02:00
|
|
|
cl_mem_flags_intel flagsIntel = 0;
|
2017-12-21 00:45:38 +01:00
|
|
|
size_t size;
|
2023-01-04 11:47:05 +00:00
|
|
|
size_t sizeInPoolAllocator = 0;
|
2017-12-21 00:45:38 +01:00
|
|
|
size_t hostPtrMinSize = 0;
|
|
|
|
|
void *memoryStorage;
|
|
|
|
|
void *hostPtr;
|
2018-02-13 13:20:34 +01:00
|
|
|
void *allocatedMapPtr = nullptr;
|
2017-12-21 00:45:38 +01:00
|
|
|
size_t offset = 0;
|
|
|
|
|
MemObj *associatedMemObject = nullptr;
|
|
|
|
|
cl_uint refCount = 0;
|
2018-07-31 09:52:48 +02:00
|
|
|
ExecutionEnvironment *executionEnvironment = nullptr;
|
2017-12-21 00:45:38 +01:00
|
|
|
bool isZeroCopy;
|
|
|
|
|
bool isHostPtrSVM;
|
|
|
|
|
bool isObjectRedescribed;
|
|
|
|
|
MemoryManager *memoryManager = nullptr;
|
2020-05-28 11:38:43 +02:00
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation;
|
2017-12-21 00:45:38 +01:00
|
|
|
GraphicsAllocation *mcsAllocation = nullptr;
|
2020-07-23 14:52:32 +02:00
|
|
|
MultiGraphicsAllocation mapAllocations;
|
2017-12-21 00:45:38 +01:00
|
|
|
std::shared_ptr<SharingHandler> sharingHandler;
|
2020-05-27 17:12:32 +02:00
|
|
|
std::vector<uint64_t> propertiesVector;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-11-10 16:48:18 +01:00
|
|
|
MemObjDestructorCallbacks destructorCallbacks;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|