Open Deep Learning API
Loading...
Searching...
No Matches
odla_compute.h
Go to the documentation of this file.
1//===- odla_compute.h -----------------------------------------------------===//
2//
3// Copyright (C) 2019-2020 Alibaba Group Holding Limited.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16// =============================================================================
17
18#ifndef _ODLA_COMPUTE_H_
19#define _ODLA_COMPUTE_H_
20
21#include <ODLA/odla_common.h>
22#include <ODLA/odla_device.h>
23#include <ODLA/odla_value.h>
24
29#ifdef __cplusplus
30extern "C" {
31#endif
32
34typedef enum {
35 ODLA_COMPUTE_DEFAULT,
36 ODLA_COMPUTE_INFERENCE,
37 ODLA_COMPUTE_TRAINING,
39
41typedef enum {
42 ODLA_DYNAMIC_BATCH,
43 ODLA_MIN_BATCH_SIZE,
44 ODLA_MAX_BATCH_SIZE,
45 ODLA_OPT_BATCH_SIZE,
46 ODLA_RUN_BATCH_SIZE,
47 ODLA_DYNAMIC_SHAPE,
48 ODLA_MIN_SHAPE,
49 ODLA_MAX_SHAPE,
50 ODLA_OPT_SHAPE,
51 ODLA_DYNAMIC_VALUE,
52 ODLA_MIN_VALUE,
53 ODLA_MAX_VALUE,
54 ODLA_OPT_VALUE,
55 ODLA_BF16_MODE,
56 ODLA_FP16_MODE,
57 ODLA_USE_SIM_MODE,
58 ODLA_PROCESSOR_NUM,
59 ODLA_BATCHES_PER_STEP,
60 ODLA_USE_DATA_TYPE,
61 ODLA_LOAD_ENGINE_MODE,
62 ODLA_USE_DLA_CORE,
63 ODLA_QUANT_TABLE,
64 ODLA_QUANT_TABLE_SIZE,
65 ODLA_AGGREGATE_OPS,
66 ODLA_ENABLE_ENGINE_CACHE,
67 ODLA_CACHE_DIR,
68 ODLA_ASYNC_CALLBACK_FUNC,
69 ODLA_ASYNC_CALLBACK_ARG,
71
73typedef enum {
74 BF16_DISABLE,
75 BF16_ACCURACY_MODE,
76 BF16_PERFORMACE_MODE,
77 BF16_AUTO_MODE,
79
81typedef enum {
82 ODLA_LOCATION_PATH, // string of file path
83 ODLA_LOCATION_MEMORY, // memory address of a buffer
84 ODLA_LOCATION_URI, // string of URI
86
88
93typedef struct {
94 odla_resource_location_type location_type;
95 const void* location;
96 odla_size_t size;
98
100typedef struct _odla_computation* odla_computation;
101
103typedef struct _odla_executable* odla_executable;
104
106typedef struct _odla_context* odla_context;
107
109typedef struct _odla_item_value* odla_item_value;
110
112typedef struct _odla_constants_array* odla_constants_array;
113
115
120extern ODLA_API_EXPORT odla_status ODLA_API_CALL
122
124
130extern ODLA_API_EXPORT odla_status ODLA_API_CALL
132 const odla_device device, odla_executable* executable);
133
135
142 odla_resource_location location, odla_computation* computation);
144
151 odla_resource_location location, odla_computation computation);
152
154
159extern ODLA_API_EXPORT odla_status ODLA_API_CALL
161
163
172 const odla_computation computation, const odla_context context,
173 const odla_compute_mode mode, odla_device device);
174
176
185 const odla_computation computation, const odla_context context,
186 const odla_compute_mode mode, odla_device device);
187
189
195extern ODLA_API_EXPORT odla_status ODLA_API_CALL
197 odla_uint32* num_args);
198
200
207extern ODLA_API_EXPORT odla_status ODLA_API_CALL
209 const odla_uint32 arg_idx,
210 odla_value* arg_value);
211
213
219extern ODLA_API_EXPORT odla_status ODLA_API_CALL
221 odla_uint32* num_outputs);
222
224
231extern ODLA_API_EXPORT odla_status ODLA_API_CALL
233 const odla_uint32 output_idx,
234 odla_value* output_value);
235
237
242extern ODLA_API_EXPORT odla_status ODLA_API_CALL
244
246
254 odla_computation computation, odla_item_type type, odla_item_value value);
255
257
265 odla_value value, odla_item_type type, odla_value_shape value_shape);
266
268
276 odla_value value, odla_item_type type, odla_item_value value_input);
277
279
287 odla_context context, odla_value value, odla_value_shape value_shape);
288
290
298 odla_context context, odla_value value, odla_value_shape* value_shape_ptr);
299
301
306extern ODLA_API_EXPORT odla_status ODLA_API_CALL
308
310
317 const odla_char* file_name, odla_constants_array* constants_array);
318
320
327 const odla_char* file_name, const odla_constants_array constants_array);
328
330
335extern ODLA_API_EXPORT odla_status ODLA_API_CALL
337
339
347extern ODLA_API_EXPORT odla_status ODLA_API_CALL
349 odla_executable* executable);
350
352
358extern ODLA_API_EXPORT odla_status ODLA_API_CALL
360
362
368extern ODLA_API_EXPORT odla_status ODLA_API_CALL
370
372
382 const odla_executable executable,
383 const odla_constants_array constants_array, const odla_context context,
384 const odla_compute_mode mode, odla_device device);
385
387
393extern ODLA_API_EXPORT odla_status ODLA_API_CALL
395 odla_uint32* num_args);
396
398
406 const odla_executable executable, const odla_uint32 arg_idx,
407 odla_value* arg_value);
408
410
416extern ODLA_API_EXPORT odla_status ODLA_API_CALL
418 odla_uint32* num_outputs);
419
421
428extern ODLA_API_EXPORT odla_status ODLA_API_CALL
430 const odla_uint32 output_idx,
431 odla_value* output_value);
432
434
439extern ODLA_API_EXPORT odla_status ODLA_API_CALL
441
443
448extern ODLA_API_EXPORT odla_status ODLA_API_CALL
450
452
460 odla_context context, odla_item_type type, odla_item_value value);
461
463
468extern ODLA_API_EXPORT odla_status ODLA_API_CALL
470
472
482 odla_value value, const odla_void* data_ptr, odla_context context);
483
485
494extern ODLA_API_EXPORT odla_status ODLA_API_CALL
495odla_BindToArgumentById(const odla_value_id value_id, const odla_void* data_ptr,
496 odla_context context);
497
498extern ODLA_API_EXPORT odla_status ODLA_API_CALL odla_BindValueToArgumentById(
499 const odla_value_id value_id, odla_value data, odla_context context);
500
502
512extern ODLA_API_EXPORT odla_status ODLA_API_CALL
514
516
527 const odla_value_id value_id, odla_void* data_ptr, odla_context context);
528
529extern ODLA_API_EXPORT odla_status ODLA_API_CALL odla_BindValueToOutputById(
530 const odla_value_id value_id, odla_value data, odla_context context);
531
532extern ODLA_API_EXPORT odla_status ODLA_API_CALL odla_SetRuntimeValueType(
533 odla_context context, odla_value value, odla_value_type value_type);
534
536
544 odla_context context, odla_value value, odla_value_type* value_type_ptr);
545
547
553extern ODLA_API_EXPORT odla_status ODLA_API_CALL
555
557
565 const odla_value value, odla_void* data_ptr, odla_context context);
566
567#ifdef __cplusplus
568} // C extern
569#endif
570
571#endif // _ODLA_COMPUTE_H_
#define ODLA_API_EXPORT
API export directives.
Definition: odla_common.h:172
odla_status
Return status.
Definition: odla_common.h:140
__UINT32_TYPE__ odla_uint32
Definition: odla_common.h:70
char odla_char
char
Definition: odla_common.h:131
__SIZE_TYPE__ odla_size_t
size_t
Definition: odla_common.h:134
void odla_void
void
Definition: odla_common.h:137
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetArgFromExecutableByIdx(const odla_executable executable, const odla_uint32 arg_idx, odla_value *arg_value)
Get the #idx argument value from an executable.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_SetInputValueInfo(odla_value value, odla_item_type type, odla_item_value value_input)
Set the computation arguments shape info with a property item.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_LaunchExecutable(odla_executable executable, odla_context context)
Launch an executable.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_CompileComputation(const odla_computation computation, const odla_device device, odla_executable *executable)
Compile a computation object into executable.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_AsyncLaunchExecutable(const odla_executable executable, const odla_constants_array constants_array, const odla_context context, const odla_compute_mode mode, odla_device device)
Asynchronously launch an executable.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_StoreConstantsArray(const odla_char *file_name, const odla_constants_array constants_array)
Store a constants array into the file system.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_DifferentiateComputation(odla_computation computation)
Differentiate a computation.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetRuntimeValueType(odla_context context, odla_value value, odla_value_type *value_type_ptr)
Get the context runtime value type to an odla_value.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetOutputFromComputationByIdx(const odla_computation computation, const odla_uint32 output_idx, odla_value *output_value)
Get the #idx output value from a computation.
struct _odla_executable * odla_executable
Executable object.
Definition: odla_compute.h:103
odla_compute_mode
Compute mode.
Definition: odla_compute.h:34
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetArgFromComputationByIdx(const odla_computation computation, const odla_uint32 arg_idx, odla_value *arg_value)
Get the #idx argument value from a computation.
odla_resource_location_type
Type of resource location.
Definition: odla_compute.h:81
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_AsyncExecuteComputation(const odla_computation computation, const odla_context context, const odla_compute_mode mode, odla_device device)
Asynchronously execute a computation.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetRuntimeNumOfOutputs(odla_context context, odla_uint32 *num_output_ptr)
Get the context runtime number of outputs.
odla_item_type
Property item type.
Definition: odla_compute.h:41
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetNumOfOutputsFromExecutable(const odla_executable executable, odla_uint32 *num_outputs)
Get the number of outputs from an executable.
struct _odla_context * odla_context
Context object.
Definition: odla_compute.h:106
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_SetValueShapeInfo(odla_value value, odla_item_type type, odla_value_shape value_shape)
Set the computation arguments shape info with a property item.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_StoreComputation(odla_resource_location location, odla_computation computation)
Store a computation object into the file system.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_LoadConstantsArray(const odla_char *file_name, odla_constants_array *constants_array)
Load a constants array from the file system.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_SetContextItem(odla_context context, odla_item_type type, odla_item_value value)
Set the context with a property item.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_LoadExecutable(odla_resource_location location, odla_device device, odla_executable *executable)
Load an executable from the file system.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_BindToOutputById(const odla_value_id value_id, odla_void *data_ptr, odla_context context)
Bind memory to an output value by id.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetNumOfArgsFromExecutable(const odla_executable executable, odla_uint32 *num_args)
Get the number of arguments from an Executable.
struct _odla_computation * odla_computation
Computation object.
Definition: odla_compute.h:100
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_DestroyExecutable(odla_executable executable)
Destroy a created executable.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_StoreExecutable(odla_resource_location, odla_executable executable)
Store an executable object into the file system.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_SetRuntimeShape(odla_context context, odla_value value, odla_value_shape value_shape)
Set the context runtime shapes to an odla_value.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_DestroyConstantsArray(odla_constants_array constants_array)
Destroy a created constants array object.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_ExecuteComputation(const odla_computation computation, const odla_context context, const odla_compute_mode mode, odla_device device)
Execute a computation.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_BindToArgument(odla_value value, const odla_void *data_ptr, odla_context context)
Bind data to an argument.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetRuntimeShape(odla_context context, odla_value value, odla_value_shape *value_shape_ptr)
Get the context runtime shapes.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_LoadComputation(odla_resource_location location, odla_computation *computation)
Load a computation from the file system.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_CreateContext(odla_context *context)
Create a context object.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetValueData(const odla_value value, odla_void *data_ptr, odla_context context)
Get a value data.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_CreateConstantsArray(odla_constants_array *constants_array)
Create a constants array object.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetOutputFromExecutableByIdx(const odla_executable executable, const odla_uint32 output_idx, odla_value *output_value)
Get the #idx output value from an executable.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_BindToOutput(odla_value value, odla_void *data_ptr, odla_context context)
Bind memory to an output value.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_DestroyContext(odla_context context)
Destroy a created context.
odla_bf16_mode
BF16 mode.
Definition: odla_compute.h:73
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_BindToArgumentById(const odla_value_id value_id, const odla_void *data_ptr, odla_context context)
Bind data to an argument by id.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetNumOfArgsFromComputation(const odla_computation computation, odla_uint32 *num_args)
Get the number of arguments from a computation.
struct _odla_item_value * odla_item_value
Property item value object.
Definition: odla_compute.h:109
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_GetNumOfOutputsFromComputation(const odla_computation computation, odla_uint32 *num_outputs)
Get the number of outputs from a computation.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_SetComputationItem(odla_computation computation, odla_item_type type, odla_item_value value)
Set the computation with a property item.
struct _odla_constants_array * odla_constants_array
Constants array object.
Definition: odla_compute.h:112
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_CreateComputation(odla_computation *computation)
Create a computation object.
ODLA_API_EXPORT odla_status ODLA_API_CALL odla_DestroyComputation(odla_computation computation)
Destroy a created computation.
struct _odla_device * odla_device
Device object.
Definition: odla_device.h:98
struct _odla_value_id * odla_value_id
Unique id of each value.
Definition: odla_value.h:74
struct _odla_value * odla_value
Value definition.
Definition: odla_value.h:65
Resource location.
Definition: odla_compute.h:93
Shape of value.
Definition: odla_value.h:51
Type of value.
Definition: odla_value.h:59