/home/runner/work/HiCR/HiCR/include/hicr/backends/opencl/memoryKernel.hpp Source File

HiCR: /home/runner/work/HiCR/HiCR/include/hicr/backends/opencl/memoryKernel.hpp Source File
HiCR
memoryKernel.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 Huawei Technologies Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
24#pragma once
25
26#include <CL/opencl.hpp>
31
32namespace HiCR::backend::opencl
33{
34
41class MemoryKernel final : public Kernel
42{
43 public:
44
56 std::shared_ptr<HiCR::LocalMemorySlot> destination,
57 const size_t destinationOffset,
58 std::shared_ptr<HiCR::LocalMemorySlot> source,
59 const size_t sourceOffset,
60 size_t size)
61 : opencl::Kernel(),
62 _dst(destination),
63 _src(source),
64 _dstOffset(destinationOffset),
65 _srcOffset(sourceOffset),
66 _size(size),
67 _commManager(commManager){};
68
69 MemoryKernel() = delete;
70
75
81 __INLINE__ void start(const cl::CommandQueue *queue) override { _commManager->memcpyAsync(_dst.lock(), _dstOffset, _src.lock(), _srcOffset, _size, queue); }
82
83 private:
84
88 const std::weak_ptr<HiCR::LocalMemorySlot> _dst;
89
93 const std::weak_ptr<HiCR::LocalMemorySlot> _src;
94
98 const size_t _dstOffset;
99
103 const size_t _srcOffset;
104
108 const size_t _size;
109
113 opencl::CommunicationManager *const _commManager;
114};
115
116} // namespace HiCR::backend::opencl
This file implements the communication manager class for the OpenCL backend.
Definition communicationManager.hpp:41
__INLINE__ void memcpyAsync(const std::shared_ptr< HiCR::LocalMemorySlot > &destination, const size_t dst_offset, const std::shared_ptr< HiCR::LocalMemorySlot > &source, const size_t src_offset, const size_t size, const cl::CommandQueue *queue)
Definition communicationManager.hpp:68
Definition kernel.hpp:37
Definition memoryKernel.hpp:42
__INLINE__ void start(const cl::CommandQueue *queue) override
Definition memoryKernel.hpp:81
~MemoryKernel()
Definition memoryKernel.hpp:74
MemoryKernel(opencl::CommunicationManager *commManager, std::shared_ptr< HiCR::LocalMemorySlot > destination, const size_t destinationOffset, std::shared_ptr< HiCR::LocalMemorySlot > source, const size_t sourceOffset, size_t size)
Definition memoryKernel.hpp:55
Provides a definition for a HiCR Local Memory Slot class.
Provides a failure model and corresponding exception classes.
This file implements the Kernel class for the OpenCL backend.