-
Notifications
You must be signed in to change notification settings - Fork 822
Expand file tree
/
Copy pathmemory_manager.hpp
More file actions
279 lines (238 loc) · 13.4 KB
/
memory_manager.hpp
File metadata and controls
279 lines (238 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//==-------------- memory_manager.hpp - SYCL standard header file ----------==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#pragma once
#include <detail/sycl_mem_obj_i.hpp>
#include <sycl/access/access.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/ext/oneapi/experimental/enqueue_types.hpp> // for prefetch_type
#include <sycl/id.hpp>
#include <sycl/property_list.hpp>
#include <sycl/range.hpp>
#include <unified-runtime/ur_api.h>
#include <memory>
#include <vector>
namespace sycl {
inline namespace _V1 {
namespace detail {
class queue_impl;
class event_impl;
class events_range;
class context_impl;
using EventImplPtr = std::shared_ptr<detail::event_impl>;
// The class contains methods that work with memory. All operations with
// device memory should go through MemoryManager.
class MemoryManager {
public:
// The following method releases memory allocation of memory object.
// Depending on the context it releases memory on host or on device.
static void release(context_impl *TargetContext, SYCLMemObjI *MemObj,
void *MemAllocation, events_range DepEvents,
ur_event_handle_t &OutEvent);
// The following method allocates memory allocation of memory object.
// Depending on the context it allocates memory on host or on device.
static void *allocate(context_impl *TargetContext, SYCLMemObjI *MemObj,
bool InitFromUserData, void *HostPtr,
events_range DepEvents, ur_event_handle_t &OutEvent);
// The following method creates OpenCL sub buffer for specified
// offset, range, and memory object.
static void *allocateMemSubBuffer(context_impl *TargetContext,
void *ParentMemObj, size_t ElemSize,
size_t Offset, range<3> Range,
events_range DepEvents,
ur_event_handle_t &OutEvent);
// Allocates buffer in specified context taking into account situations such
// as host ptr or cl_mem provided by user. TargetContext should be device
// one(not host).
static void *allocateMemBuffer(context_impl *TargetContext,
SYCLMemObjI *MemObj, void *UserPtr,
bool HostPtrReadOnly,
bool BackendOwnedWriteBack, size_t Size,
const EventImplPtr &InteropEvent,
context_impl *InteropContext,
const sycl::property_list &PropsList,
ur_event_handle_t &OutEventToWait);
// Allocates images in specified context taking into account situations such
// as host ptr or cl_mem provided by user. TargetContext should be device
// one(not host).
static void *allocateMemImage(
context_impl *TargetContext, SYCLMemObjI *MemObj, void *UserPtr,
bool HostPtrReadOnly, size_t Size, const ur_image_desc_t &Desc,
const ur_image_format_t &Format, const EventImplPtr &InteropEvent,
context_impl *InteropContext, const sycl::property_list &PropsList,
ur_event_handle_t &OutEventToWait);
// Releases memory object(buffer or image). TargetContext should be device
// one(not host).
static void releaseMemObj(context_impl *TargetContext, SYCLMemObjI *MemObj,
void *MemAllocation, void *UserPtr);
static void *allocateHostMemory(SYCLMemObjI *MemObj, void *UserPtr,
bool HostPtrReadOnly, size_t Size,
const sycl::property_list &PropsList);
static void *allocateInteropMemObject(context_impl *TargetContext,
void *UserPtr,
const EventImplPtr &InteropEvent,
context_impl *InteropContext,
const sycl::property_list &PropsList,
ur_event_handle_t &OutEventToWait);
static void *allocateImageObject(context_impl *TargetContext, void *UserPtr,
bool HostPtrReadOnly,
const ur_image_desc_t &Desc,
const ur_image_format_t &Format,
const sycl::property_list &PropsList);
static void *allocateBufferObject(context_impl *TargetContext, void *UserPtr,
bool HostPtrReadOnly,
bool BackendOwnedWriteBack,
const size_t Size,
const sycl::property_list &PropsList);
// Copies memory between: host and device, host and host,
// device and device if memory objects bound to the one context.
static void copy(SYCLMemObjI *SYCLMemObj, void *SrcMem, queue_impl *SrcQueue,
unsigned int DimSrc, sycl::range<3> SrcSize,
sycl::range<3> SrcAccessRange, sycl::id<3> SrcOffset,
unsigned int SrcElemSize, void *DstMem, queue_impl *TgtQueue,
unsigned int DimDst, sycl::range<3> DstSize,
sycl::range<3> DstAccessRange, sycl::id<3> DstOffset,
unsigned int DstElemSize,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t &OutEvent);
static void fill(SYCLMemObjI *SYCLMemObj, void *Mem, queue_impl &Queue,
size_t PatternSize, const unsigned char *Pattern,
unsigned int Dim, sycl::range<3> Size,
sycl::range<3> AccessRange, sycl::id<3> AccessOffset,
unsigned int ElementSize,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t &OutEvent);
static void *map(SYCLMemObjI *SYCLMemObj, void *Mem, queue_impl &Queue,
access::mode AccessMode, unsigned int Dim,
sycl::range<3> Size, sycl::range<3> AccessRange,
sycl::id<3> AccessOffset, unsigned int ElementSize,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t &OutEvent);
static void unmap(SYCLMemObjI *SYCLMemObj, void *Mem, queue_impl &Queue,
void *MappedPtr, std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t &OutEvent);
static void copy_usm(const void *SrcMem, queue_impl &Queue, size_t Len,
void *DstMem, std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t *OutEvent);
static void context_copy_usm(const void *SrcMem, context_impl *Context,
size_t Len, void *DstMem);
static void fill_usm(void *DstMem, queue_impl &Queue, size_t Len,
const std::vector<unsigned char> &Pattern,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t *OutEvent);
static void
prefetch_usm(void *Ptr, queue_impl &Queue, size_t Len,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t *OutEvent,
sycl::ext::oneapi::experimental::prefetch_type Dest =
sycl::ext::oneapi::experimental::prefetch_type::device);
static void advise_usm(const void *Ptr, queue_impl &Queue, size_t Len,
ur_usm_advice_flags_t Advice,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t *OutEvent);
static void copy_2d_usm(const void *SrcMem, size_t SrcPitch,
queue_impl &Queue, void *DstMem, size_t DstPitch,
size_t Width, size_t Height,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t *OutEvent);
static void fill_2d_usm(void *DstMem, queue_impl &Queue, size_t Pitch,
size_t Width, size_t Height,
const std::vector<unsigned char> &Pattern,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t *OutEvent);
static void memset_2d_usm(void *DstMem, queue_impl &Queue, size_t Pitch,
size_t Width, size_t Height, char Value,
std::vector<ur_event_handle_t> DepEvents,
ur_event_handle_t *OutEvent);
static void
copy_to_device_global(const void *DeviceGlobalPtr, bool IsDeviceImageScoped,
queue_impl &Queue, size_t NumBytes, size_t Offset,
const void *SrcMem,
const std::vector<ur_event_handle_t> &DepEvents,
ur_event_handle_t *OutEvent);
static void
copy_from_device_global(const void *DeviceGlobalPtr, bool IsDeviceImageScoped,
queue_impl &Queue, size_t NumBytes, size_t Offset,
void *DstMem,
const std::vector<ur_event_handle_t> &DepEvents,
ur_event_handle_t *OutEvent);
// Command buffer extension methods
static void ext_oneapi_copyD2D_cmd_buffer(
sycl::detail::context_impl *Context,
ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj,
void *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize,
sycl::range<3> SrcAccessRange, sycl::id<3> SrcOffset,
unsigned int SrcElemSize, void *DstMem, unsigned int DimDst,
sycl::range<3> DstSize, sycl::range<3> DstAccessRange,
sycl::id<3> DstOffset, unsigned int DstElemSize,
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
ur_exp_command_buffer_sync_point_t *OutSyncPoint);
static void ext_oneapi_copyD2H_cmd_buffer(
sycl::detail::context_impl *Context,
ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj,
void *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize,
sycl::range<3> SrcAccessRange, sycl::id<3> SrcOffset,
unsigned int SrcElemSize, char *DstMem, unsigned int DimDst,
sycl::range<3> DstSize, sycl::id<3> DstOffset, unsigned int DstElemSize,
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
ur_exp_command_buffer_sync_point_t *OutSyncPoint);
static void ext_oneapi_copyH2D_cmd_buffer(
sycl::detail::context_impl *Context,
ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj,
char *SrcMem, unsigned int DimSrc, sycl::range<3> SrcSize,
sycl::id<3> SrcOffset, unsigned int SrcElemSize, void *DstMem,
unsigned int DimDst, sycl::range<3> DstSize,
sycl::range<3> DstAccessRange, sycl::id<3> DstOffset,
unsigned int DstElemSize,
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
ur_exp_command_buffer_sync_point_t *OutSyncPoint);
static void ext_oneapi_copy_usm_cmd_buffer(
context_impl *Context, const void *SrcMem,
ur_exp_command_buffer_handle_t CommandBuffer, size_t Len, void *DstMem,
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
ur_exp_command_buffer_sync_point_t *OutSyncPoint);
static void ext_oneapi_fill_usm_cmd_buffer(
sycl::detail::context_impl *Context,
ur_exp_command_buffer_handle_t CommandBuffer, void *DstMem, size_t Len,
const std::vector<unsigned char> &Pattern,
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
ur_exp_command_buffer_sync_point_t *OutSyncPoint);
static void ext_oneapi_fill_cmd_buffer(
sycl::detail::context_impl *Context,
ur_exp_command_buffer_handle_t CommandBuffer, SYCLMemObjI *SYCLMemObj,
void *Mem, size_t PatternSize, const unsigned char *Pattern,
unsigned int Dim, sycl::range<3> Size, sycl::range<3> AccessRange,
sycl::id<3> AccessOffset, unsigned int ElementSize,
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
ur_exp_command_buffer_sync_point_t *OutSyncPoint);
static void ext_oneapi_prefetch_usm_cmd_buffer(
sycl::detail::context_impl *Context,
ur_exp_command_buffer_handle_t CommandBuffer, void *Mem, size_t Length,
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
ur_exp_command_buffer_sync_point_t *OutSyncPoint,
sycl::ext::oneapi::experimental::prefetch_type Dest =
sycl::ext::oneapi::experimental::prefetch_type::device);
static void ext_oneapi_advise_usm_cmd_buffer(
sycl::detail::context_impl *Context,
ur_exp_command_buffer_handle_t CommandBuffer, const void *Mem,
size_t Length, ur_usm_advice_flags_t Advice,
std::vector<ur_exp_command_buffer_sync_point_t> Deps,
ur_exp_command_buffer_sync_point_t *OutSyncPoint);
static void copy_image_bindless(
queue_impl &Queue, const void *Src, void *Dst,
const ur_image_desc_t &SrcDesc, const ur_image_desc_t &DstDesc,
const ur_image_format_t &SrcFormat, const ur_image_format_t &DstFormat,
const ur_exp_image_copy_flags_t Flags,
const ur_exp_image_copy_input_types_t InputTypes,
ur_rect_offset_t SrcOffset, ur_rect_offset_t DstOffset,
ur_rect_region_t CopyExtent,
const std::vector<ur_event_handle_t> &DepEvents,
ur_event_handle_t *OutEvent);
};
} // namespace detail
} // namespace _V1
} // namespace sycl