-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathasync_kernel.cc
More file actions
161 lines (140 loc) · 6.3 KB
/
async_kernel.cc
File metadata and controls
161 lines (140 loc) · 6.3 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
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tflite/core/async/c/async_kernel.h"
#include <cstddef>
#include "tflite/core/async/async_kernel_internal.h"
#include "tflite/core/async/c/types.h"
TfLiteAsyncKernel* TfLiteAsyncKernelCreate(void* kernel_data) {
TfLiteAsyncKernel* ret = new TfLiteAsyncKernel{};
if (!ret) return nullptr;
ret->kernel_data = kernel_data;
return ret;
}
void* TfLiteAsyncKernelGetKernelData(const TfLiteAsyncKernel* async_kernel) {
if (!async_kernel) return nullptr;
return async_kernel->kernel_data;
}
void TfLiteAsyncKernelSetRegisterBuffer(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*register_buffer)(
TfLiteAsyncKernel* async_kernel, TfLiteOpaqueContext* context,
TfLiteIoType io_type, const TfLiteBackendBuffer* buffer,
const TfLiteAttributeMap* attrs, TfLiteBufferHandle handle)) {
if (!async_kernel) return;
async_kernel->register_buffer = register_buffer;
}
void TfLiteAsyncKernelSetRegisterBufferSlice(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*register_buffer_slice)(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context,
TfLiteBufferHandle buffer_pool,
const TfLiteAttributeMap* attrs,
TfLiteBufferHandle handle)) {
if (!async_kernel) return;
async_kernel->register_buffer_slice = register_buffer_slice;
}
void TfLiteAsyncKernelSetUnregisterBuffer(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*unregister_buffer)(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context,
TfLiteBufferHandle handle)) {
if (!async_kernel) return;
async_kernel->unregister_buffer = unregister_buffer;
}
void TfLiteAsyncKernelSetSupportedBufferTypes(
TfLiteAsyncKernel* async_kernel,
void (*supported_buffer_types)(const TfLiteAsyncKernel* async_kernel,
TfLiteIoType io_type,
const char* const** types,
size_t* n_types)) {
if (!async_kernel) return;
async_kernel->supported_buffer_types = supported_buffer_types;
}
void TfLiteAsyncKernelSetSupportedSynchronizations(
TfLiteAsyncKernel* async_kernel,
void (*supported_synchronizations)(const TfLiteAsyncKernel* async_kernel,
TfLiteIoType io_type,
const char* const** types,
size_t* n_types)) {
if (!async_kernel) return;
async_kernel->supported_synchronizations = supported_synchronizations;
}
void TfLiteAsyncKernelSetReconcileRestrictions(
TfLiteAsyncKernel* async_kernel,
bool (*reconcile_restrictions)(
const TfLiteAsyncKernel* async_kernel,
const TfLiteOpaqueContext* context, const TfLiteOpaqueNode* node,
int tensor_index, const TfLiteAttributeMap* user_provided_attributes,
TfLiteAttributeMap* merged, TfLiteAttributeMap* conflict)) {
if (!async_kernel) return;
async_kernel->reconcile_restrictions = reconcile_restrictions;
}
void TfLiteAsyncKernelSetSetAttributes(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*set_attributes)(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context,
TfLiteOpaqueNode* node, int tensor_index,
const TfLiteAttributeMap* attrs)) {
if (!async_kernel) return;
async_kernel->set_attributes = set_attributes;
}
void TfLiteAsyncKernelSetSetBufferAttributes(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*set_buffer_attributes)(TfLiteAsyncKernel* async_kernel,
const TfLiteBackendBuffer* buffer,
const TfLiteAttributeMap* attrs)) {
if (!async_kernel) return;
async_kernel->set_buffer_attributes = set_buffer_attributes;
}
void TfLiteAsyncKernelSetGetBufferAttributes(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*get_buffer_attributes)(TfLiteAsyncKernel* async_kernel,
const TfLiteBackendBuffer* buffer,
TfLiteAttributeMap* attrs)) {
if (!async_kernel) return;
async_kernel->get_buffer_attributes = get_buffer_attributes;
};
void TfLiteAsyncKernelSetPrepare(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*prepare)(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context,
TfLiteOpaqueNode* node)) {
if (!async_kernel) return;
async_kernel->prepare = prepare;
}
void TfLiteAsyncKernelSetEval(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*eval)(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context, TfLiteOpaqueNode* node,
TfLiteExecutionTask* task)) {
if (!async_kernel) return;
async_kernel->eval = eval;
}
void TfLiteAsyncKernelSetWait(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*wait)(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context,
TfLiteExecutionTask* task)) {
if (!async_kernel) return;
async_kernel->wait = wait;
}
void TfLiteAsyncKernelSetFinish(
TfLiteAsyncKernel* async_kernel,
TfLiteStatus (*finish)(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context,
TfLiteExecutionTask* task)) {
if (!async_kernel) return;
async_kernel->finish = finish;
}
void TfLiteAsyncKernelDelete(TfLiteAsyncKernel* async_kernel) {
delete async_kernel;
}