/home/runner/work/HiCR/HiCR/include/hicr/backends/opencl/memoryManager.hpp Source File
HiCR
|
memoryManager.hpp
Go to the documentation of this file.
51 MemoryManager(const std::unordered_map<opencl::Device::deviceIdentifier_t, std::shared_ptr<cl::CommandQueue>> &deviceQueueMap)
63 __INLINE__ std::shared_ptr<HiCR::LocalMemorySlot> allocateLocalMemorySlotImpl(std::shared_ptr<HiCR::MemorySpace> memorySpace, const size_t size) override
79 if (memSpaceType == memSpaceType_t::device) { return allocateLocalDeviceMemorySlot(memorySpace, size); }
80 if (memSpaceType == memSpaceType_t::host) { return allocateLocalHostMemorySlot(memorySpace, size); }
81 HICR_THROW_LOGIC("The passed memory space is not supported by this memory manager. Supported opencl and hwloc\n");
84 __INLINE__ std::shared_ptr<HiCR::LocalMemorySlot> allocateLocalDeviceMemorySlot(const std::shared_ptr<HiCR::MemorySpace> memorySpace, const size_t size)
91 auto deviceBuffer = std::make_shared<cl::Buffer>(context, CL_MEM_READ_WRITE, size, nullptr, &err);
92 if (err != CL_SUCCESS) [[unlikely]] { HICR_THROW_RUNTIME("Can not allocate local memory slot on the device: %d", err); }
94 // Map it to the host in order to get a pointer to the data. Data are mapped in memory for writing
95 auto hostPtr = queue->enqueueMapBuffer(*deviceBuffer, CL_TRUE, CL_MAP_READ | CL_MAP_READ | CL_MAP_WRITE, 0, size, nullptr, nullptr, &err);
96 if (err != CL_SUCCESS || hostPtr == nullptr) [[unlikely]] { HICR_THROW_RUNTIME("Can not retrieve pointer: %d", err); }
98 auto memSlot = std::make_shared<opencl::LocalMemorySlot>(hostPtr, size, deviceBuffer, memorySpace);
104 __INLINE__ std::shared_ptr<HiCR::LocalMemorySlot> allocateLocalHostMemorySlot(const std::shared_ptr<HiCR::MemorySpace> memorySpace, const size_t size)
111 auto hostBuffer = std::make_shared<cl::Buffer>(context, CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, size, nullptr, &err);
112 if (err != CL_SUCCESS) [[unlikely]] { HICR_THROW_RUNTIME("Can not allocate local memory slot on the host: %d", err); }
114 // Map it to the host in order to get a pointer to the data. Data are mapped in memory for writing
115 auto hostPtr = queue->enqueueMapBuffer(*hostBuffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, size, nullptr, nullptr, &err);
116 if (err != CL_SUCCESS || hostPtr == nullptr) [[unlikely]] { HICR_THROW_RUNTIME("Can not retrieve pointer: %d", err); }
118 auto memSlot = std::make_shared<opencl::LocalMemorySlot>(hostPtr, size, hostBuffer, memorySpace);
127 __INLINE__ std::shared_ptr<HiCR::LocalMemorySlot> registerLocalMemorySlotImpl(std::shared_ptr<HiCR::MemorySpace> memorySpace, void *const ptr, const size_t size) override
140 if (openclMemorySpace->getType() == "OpenCL GPU RAM") { memSpaceType = memSpaceType_t::device; }
146 HICR_THROW_RUNTIME("Can not register local memory slot on the provided memory space: %s", memorySpace->getType().c_str());
155 if (err != CL_SUCCESS) [[unlikely]] { HICR_THROW_RUNTIME("Can not register local memory slot on the host: %d", err); }
157 // Map it to the host in order to get a pointer to the data. Data are mapped in memory for writing
158 auto hostPtr = queue->enqueueMapBuffer(*buffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, size, nullptr, nullptr, &err);
159 if (err != CL_SUCCESS || hostPtr == nullptr) [[unlikely]] { HICR_THROW_RUNTIME("Can not retrieve pointer: %d", err); }
165 __INLINE__ void memsetImpl(const std::shared_ptr<HiCR::LocalMemorySlot> memorySlot, int value, size_t size) override
168 if (m == nullptr) [[unlikely]] { HICR_THROW_RUNTIME("Unsupported local memory slot: %s", memorySlot->getMemorySpace()->getType().c_str()); }
174 auto err = queue->enqueueFillBuffer(*(m->getBuffer()), clValue, 0, m->getSize(), nullptr, &completionEvent);
179 __INLINE__ void freeLocalMemorySlotImpl(std::shared_ptr<HiCR::LocalMemorySlot> memorySlot) override
182 if (m == nullptr) [[unlikely]] { HICR_THROW_RUNTIME("Unsupported local memory slot: %s", memorySlot->getMemorySpace()->getType().c_str()); }
188 if (err != CL_SUCCESS) [[unlikely]] { HICR_THROW_RUNTIME("Can not unmap host pointer: %d", err); }
198 __INLINE__ void deregisterLocalMemorySlotImpl(std::shared_ptr<HiCR::LocalMemorySlot> memorySlot) override {}
226 const std::unordered_map<opencl::Device::deviceIdentifier_t, std::shared_ptr<cl::CommandQueue>> _deviceQueueMap;
246 HICR_THROW_LOGIC("The passed memory space is not supported by this memory manager. Supported opencl and hwloc\n");
This file implements the memory space class for the HWLoc-based backend.
This file implements the Device class for the OpenCL backend.
Provides a definition for the local memory slot class for the OpenCL backend.
This file implements the memory space class for the OpenCL backend.
Definition memoryManager.hpp:51
uint64_t deviceIdentifier_t
Definition device.hpp:43
Definition memoryManager.hpp:43
MemoryManager(const std::unordered_map< opencl::Device::deviceIdentifier_t, std::shared_ptr< cl::CommandQueue > > &deviceQueueMap)
Definition memoryManager.hpp:51
~MemoryManager()=default
Provides a definition for the base backend's memory manager class.
Generated by