forked from OAID/Tengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice.h
129 lines (109 loc) · 4.24 KB
/
device.h
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
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
/*
* Copyright (c) 2021, OPEN AI LAB
* Author: [email protected]
*/
#pragma once
struct tensor;
struct graph;
struct subgraph;
struct options;
struct device;
struct vector;
#include <stddef.h>
/*!
* @struct ir_interface_t
* @brief Abstract neural network runnable device interface struct
*/
typedef struct interface
{
//!< interface of init this neural network device
int (*init)(struct device* device);
//!< interface of prepare runnable subgraph on device
int (*pre_run)(struct device* device, struct subgraph* subgraph, void* options);
//!< interface of run runnable subgraph on device
int (*run)(struct device* device, struct subgraph* subgraph);
//!< interface of post run runnable subgraph on device
int (*post_run)(struct device* device, struct subgraph* subgraph);
//!< interface of async run runnable subgraph on device
int (*async_run)(struct device* device, struct subgraph* subgraph);
//!< interface of async wait runnable subgraph on device
int (*async_wait)(struct device* device, struct subgraph* subgraph, int try_wait);
//!< interface of release runnable subgraph on device
int (*release_graph)(struct device* device, void* device_graph);
//!< interface of release this neural network device
int (*release_device)(struct device* device);
} ir_interface_t;
/*!
* @struct ir_allocator_t
* @brief Abstract neural network runnable device allocator struct
*/
typedef struct allocator
{
//!< interface of describe this neural network device supported operators and precision
int (*describe)(struct device*, struct vector* allowed_ops, struct vector* blocked_ops, struct vector* precision);
//!< interface of evaluation subgraph, and report tensors which need to be changed
int (*evaluation)(struct device*, struct subgraph*, struct vector* tensors, struct vector* nodes);
//!< interface of allocate resources which subgraph needed
int (*allocate)(struct device*, struct subgraph*);
//!< interface of release allocated resources
int (*release)(struct device*, struct subgraph*);
} ir_allocator_t;
/*!
* @struct ir_optimizer_t
* @brief Abstract neural network runnable device expend optimizer
*/
typedef struct optimizer
{
int (*split_graph)(struct graph* ir_graph); //!< interface of split graph delegation
int (*optimize_graph)(struct graph* ir_graph, int precision); //!< interface of optimizing graph delegation
} ir_optimizer_t;
/*!
* @struct nn_device_t
* @brief Abstract neural network runnable device description struct
*/
typedef struct device
{
const char* name;
struct interface* interface; //!< device scheduler operation interface
struct allocator* allocator; //!< device allocation operation interface
struct optimizer* optimizer; //!< device optimizer operation interface
struct scheduler* scheduler; //!< device scheduler
void* privacy; //!< device privacy data
} ir_device_t;
/*!
* @brief Initialize a device.
*
* This function will fill other pointer of ir_device_t to NULL.
*
* @param [in] device: The specific device.
* @param [in] name: The name of the device.
*/
void init_ir_device(ir_device_t* device, const char* name);
/*!
* @brief Size of a device option struct.
*
* This function will return device specific option length.
*
* @param [in] device: The specific device.
*
* @return size of device option struct.
*/
int get_device_option_size(ir_device_t* device);