Tensor Tiling Library
 
Loading...
Searching...
No Matches
opencl/TTL_import_export.h
Go to the documentation of this file.
1/*
2 * TTL_import_export.h
3 *
4 * Copyright (c) 2023 Mobileye
5 *
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/*
20 * async_work_group_copy_3D3D is not supported by all OpenCL drivers
21 * including some V3.0 drivers. To resolve this define TTL_COPY_3D
22 */
23
24/**
25 * @brief Return an empty event of type TTL_event_t
26 *
27 * @see TTL_event_t for information about how event_t and TTL_event_t relate
28 *
29 * @return The return value allows an empty event to be passed to APIs that
30 * require an event and return/update the value with a new event value.
31 */
32static inline TTL_event_t TTL_get_event() {
33 return (event_t)0;
34}
35
36/**
37 * @def TTL_wait
38 *
39 * Wait for the array of events passed to enter the complete state.
40 */
41static inline void TTL_wait(const int num_events, TTL_event_t *const events) {
42 wait_group_events(num_events, events);
43}
44
45/**
46 * @brief TTL_import
47 *
48 * Begin the asynchronous import of the external tensor to the internal tensor
49 *
50 * @param internal_tensor internal_tensor A TTL_int_tensor_t describing the internal tensor.
51 * @param external_tensor external_tensor A TTL_int_tensor_t describing the external tensor.
52 * @param event event_ptr A pointer to the event which describe the transfer.
53 */
54static inline void __attribute__((overloadable)) TTL_import_base(const TTL_int_tensor_t internal_tensor,
55 const TTL_const_ext_tensor_t external_tensor,
56 TTL_event_t *event) {
57 *event = async_work_group_copy_3D3D((__local void *)internal_tensor.base,
58 0,
59 (__global void *)external_tensor.base,
60 0,
61 internal_tensor.elem_size,
62 internal_tensor.shape.width,
63 internal_tensor.shape.height,
64 internal_tensor.shape.depth,
65 external_tensor.layout.row_spacing,
66 external_tensor.layout.plane_spacing,
67 internal_tensor.layout.row_spacing,
68 internal_tensor.layout.plane_spacing,
69 *event);
70}
71
72/**
73 * @brief Export the external tensor to the internal tensor returning when complete
74 *
75 * @param internal_tensor A TTL_int_tensor_t describing the internal tensor.
76 * @param external_tensor A TTL_int_tensor_t describing the external tensor.
77 * Complete description of what not how here.
78 */
79static inline void TTL_blocking_import_base(const TTL_int_tensor_t internal_tensor,
80 const TTL_const_ext_tensor_t external_tensor) {
81 TTL_event_t event = TTL_get_event();
82 TTL_import_base(internal_tensor, external_tensor, &event);
83 TTL_wait(1, &event);
84}
85
86/**
87 * @brief Begin the asynchronous export of the external tensor to the internal tensor
88 *
89 * @param internal_tensor internal_tensor A TTL_int_tensor_t describing the internal tile.
90 * @param external_tensor external_tensor A TTL_int_sub_tensor_t describing the external tile.
91 * @param event event_ptr A pointer to the event which describe the transfer.
92 *
93 * @note async_work_group_copy_3D3D is not supported by all OpenCL drivers
94 * including some V3.0 drivers. To resolve this define TTL_COPY_3D
95 */
96static inline void TTL_export_base(const TTL_const_int_tensor_t internal_tensor, const TTL_ext_tensor_t external_tensor,
97 TTL_event_t *const event) {
98 *event = async_work_group_copy_3D3D((__global void *)external_tensor.base,
99 0,
100 (__local void *)internal_tensor.base,
101 0,
102 internal_tensor.elem_size,
103 internal_tensor.shape.width,
104 internal_tensor.shape.height,
105 internal_tensor.shape.depth,
106 internal_tensor.layout.row_spacing,
107 internal_tensor.layout.plane_spacing,
108 external_tensor.layout.row_spacing,
109 external_tensor.layout.plane_spacing,
110 *event);
111}
112
113/**
114 * @brief Export the external tensor to the internal tensor returning when complete
115 *
116 * @param internal_tensor A TTL_int_tensor_t describing the internal tile.
117 * @param external_tensor A TTL_int_sub_tensor_t describing the external tile.
118 *
119 * Complete description of what not how here.
120 */
121static inline void TTL_blocking_export_base(const TTL_const_int_tensor_t internal_tensor,
122 const TTL_ext_tensor_t external_tensor) {
123 TTL_event_t event = TTL_get_event();
124 TTL_export_base(internal_tensor, external_tensor, &event);
125 TTL_wait(1, &event);
126}
TTL_const_ext_void_tensor_t TTL_const_ext_tensor_t
TTL_ext_void_tensor_t TTL_ext_tensor_t
TTL_const_int_void_tensor_t TTL_const_int_tensor_t
TTL_int_void_tensor_t TTL_int_tensor_t
static void wait_group_events(int num_events, event_t *event_list)
Wait for events that identify the async_work_group_copy operations to complete.
event_t TTL_event_t
TTL_event_t is a pseudonym for OpenCL event_t.
static event_t async_work_group_copy_3D3D(void *const dst, size_t dst_offset, const void *const src, size_t src_offset, size_t num_bytes_per_element, size_t num_elements_per_line, size_t num_lines, size_t num_planes, size_t src_total_line_length, size_t src_total_plane_spacing, size_t dst_total_line_length, size_t dst_total_plane_spacing, event_t event)
#define __global
The opencl __global namespace is not supported in C.
Definition c/TTL_types.h:26
#define __local
The opencl __local namespace is not supported in C.
Definition c/TTL_types.h:27
unsigned char event_t
event_t is not supported, so provide a harmless placeholder
Definition c/TTL_types.h:28
static void TTL_import_base(const TTL_int_tensor_t internal_tensor, const TTL_const_ext_tensor_t external_tensor, TTL_event_t *event)
TTL_import.
static void TTL_export_base(const TTL_const_int_tensor_t internal_tensor, const TTL_ext_tensor_t external_tensor, TTL_event_t *const event)
Begin the asynchronous export of the external tensor to the internal tensor.
static void TTL_blocking_export_base(const TTL_const_int_tensor_t internal_tensor, const TTL_ext_tensor_t external_tensor)
Export the external tensor to the internal tensor returning when complete.
static void TTL_blocking_import_base(const TTL_int_tensor_t internal_tensor, const TTL_const_ext_tensor_t external_tensor)
Export the external tensor to the internal tensor returning when complete.
static void TTL_wait(const int num_events, TTL_event_t *const events)
static TTL_event_t TTL_get_event()
Return an empty event of type TTL_event_t.
TTL_dim_t row_spacing
The distance between the start of consequtive rows in units of elements.
TTL_dim_t plane_spacing
The distance between the start of consequtive planes in units of elements.
TTL_dim_t depth
Number of planes along dimension z.
TTL_dim_t width
Number of elements along dimension x.
TTL_dim_t height
Number of rows along dimension y.