hexagon_nn.h 8.4 KB
Newer Older
李寅 已提交
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
/*
 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted (subject to the limitations in the
 * disclaimer below) provided that the following conditions are met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *    * Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *
 *    * Neither the name of The Linux Foundation nor the names of its
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
 * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
 * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

L
Liangliang He 已提交
36 37
#ifndef THIRD_PARTY_NNLIB_HEXAGON_NN_H_
#define THIRD_PARTY_NNLIB_HEXAGON_NN_H_
李寅 已提交
38 39
#ifndef __QAIC_HEADER
#define __QAIC_HEADER(ff) ff
李寅 已提交
40
#endif  //__QAIC_HEADER
李寅 已提交
41 42 43

#ifndef __QAIC_HEADER_EXPORT
#define __QAIC_HEADER_EXPORT
44
#endif  // __QAIC_HEADER_EXPORT
李寅 已提交
45 46 47

#ifndef __QAIC_HEADER_ATTRIBUTE
#define __QAIC_HEADER_ATTRIBUTE
48
#endif  // __QAIC_HEADER_ATTRIBUTE
李寅 已提交
49 50 51

#ifndef __QAIC_IMPL
#define __QAIC_IMPL(ff) ff
李寅 已提交
52
#endif  //__QAIC_IMPL
李寅 已提交
53 54 55

#ifndef __QAIC_IMPL_EXPORT
#define __QAIC_IMPL_EXPORT
56
#endif  // __QAIC_IMPL_EXPORT
李寅 已提交
57 58 59

#ifndef __QAIC_IMPL_ATTRIBUTE
#define __QAIC_IMPL_ATTRIBUTE
60
#endif  // __QAIC_IMPL_ATTRIBUTE
李寅 已提交
61 62 63 64 65 66 67
#ifdef __cplusplus
extern "C" {
#endif
#if !defined(__QAIC_STRING1_OBJECT_DEFINED__) && !defined(__STRING1_OBJECT__)
#define __QAIC_STRING1_OBJECT_DEFINED__
#define __STRING1_OBJECT__
typedef struct _cstring1_s {
68 69
  char *data;
  int dataLen;
李寅 已提交
70 71 72 73 74
} _cstring1_t;

#endif /* __QAIC_STRING1_OBJECT_DEFINED__ */
typedef struct hexagon_nn_input hexagon_nn_input;
struct hexagon_nn_input {
75 76
  unsigned int src_id;
  unsigned int output_idx;
李寅 已提交
77 78 79
};
typedef struct hexagon_nn_output hexagon_nn_output;
struct hexagon_nn_output {
80 81 82 83 84
  unsigned int rank;
  unsigned int max_sizes[8];
  unsigned int elementsize;
  int zero_offset;
  float stepsize;
李寅 已提交
85 86 87
};
typedef struct hexagon_nn_perfinfo hexagon_nn_perfinfo;
struct hexagon_nn_perfinfo {
88 89 90 91 92 93
  unsigned int node_id;
  unsigned int node_type;
  unsigned int executions;
  unsigned int unused;
  unsigned int counter_lo;
  unsigned int counter_hi;
李寅 已提交
94 95 96
};
typedef int hexagon_nn_nn_id;
enum hexagon_nn_padding_type {
97 98 99 100 101 102 103
  NN_PAD_NA,
  NN_PAD_SAME,
  NN_PAD_VALID,
  NN_PAD_MIRROR_REFLECT,
  NN_PAD_MIRROR_SYMMETRIC,
  NN_PAD_SAME_CAFFE,
  _32BIT_PLACEHOLDER_hexagon_nn_padding_type = 0x7fffffff
李寅 已提交
104 105 106 107
};
typedef enum hexagon_nn_padding_type hexagon_nn_padding_type;
typedef struct hexagon_nn_tensordef hexagon_nn_tensordef;
struct hexagon_nn_tensordef {
108 109 110 111 112 113 114 115
  unsigned int batches;
  unsigned int height;
  unsigned int width;
  unsigned int depth;
  unsigned char *data;
  int dataLen;
  unsigned int data_valid_len;
  unsigned int unused;
李寅 已提交
116 117 118
};
typedef struct hexagon_nn_op_node hexagon_nn_op_node;
struct hexagon_nn_op_node {
119 120 121 122 123 124 125
  unsigned int node_id;
  unsigned int operation;
  hexagon_nn_padding_type padding;
  hexagon_nn_input *inputs;
  int inputsLen;
  hexagon_nn_output *outputs;
  int outputsLen;
李寅 已提交
126 127 128
};
typedef struct hexagon_nn_const_node hexagon_nn_const_node;
struct hexagon_nn_const_node {
129 130
  unsigned int node_id;
  hexagon_nn_tensordef tensor;
李寅 已提交
131
};
132 133
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_config)(void)
    __QAIC_HEADER_ATTRIBUTE;
李寅 已提交
134
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_init)(hexagon_nn_nn_id *g)
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
    __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_debug_level)(
    hexagon_nn_nn_id id, int level) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_graph_mode)(
    hexagon_nn_nn_id id, int mode) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_snpprint)(hexagon_nn_nn_id id,
                                                            unsigned char *buf,
                                                            int bufLen)
    __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_getlog)(hexagon_nn_nn_id id,
                                                          unsigned char *buf,
                                                          int bufLen)
    __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_node)(
    hexagon_nn_nn_id id,
    unsigned int node_id,
    unsigned int operation,
    hexagon_nn_padding_type padding,
    const hexagon_nn_input *inputs,
    int inputsLen,
    const hexagon_nn_output *outputs,
    int outputsLen) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_node_list)(
    hexagon_nn_nn_id id,
    const hexagon_nn_op_node *ops,
    int opsLen) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_const_node)(
    hexagon_nn_nn_id id,
    unsigned int node_id,
    unsigned int batches,
    unsigned int height,
    unsigned int width,
    unsigned int depth,
    const unsigned char *data,
    int dataLen) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_append_const_node_list)(
    hexagon_nn_nn_id id,
    const hexagon_nn_const_node *consts,
    int constsLen) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_prepare)(hexagon_nn_nn_id id)
    __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute)(
    hexagon_nn_nn_id id,
    unsigned int batches_in,
    unsigned int height_in,
    unsigned int width_in,
    unsigned int depth_in,
    const unsigned char *data_in,
    int data_inLen,
    unsigned int *batches_out,
    unsigned int *height_out,
    unsigned int *width_out,
    unsigned int *depth_out,
    unsigned char *data_out,
    int data_outLen,
    unsigned int *data_len_out) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_teardown)(hexagon_nn_nn_id id)
    __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_set_powersave_level)(
    unsigned int level) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_get_perfinfo)(
    hexagon_nn_nn_id id,
    hexagon_nn_perfinfo *info_out,
    int info_outLen,
    unsigned int *n_items) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_reset_perfinfo)(
    hexagon_nn_nn_id id, unsigned int event) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_last_execution_cycles)(
    hexagon_nn_nn_id id,
    unsigned int *cycles_lo,
    unsigned int *cycles_hi) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_version)(int *ver)
    __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_op_name_to_id)(
    const char *name, unsigned int *node_id) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_op_id_to_name)(
    unsigned int node_id, char *name, int nameLen) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_disable_dcvs)(void)
    __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_GetHexagonBinaryVersion)(
    int *ver) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_PrintLog)(
    const unsigned char *buf, int bufLen) __QAIC_HEADER_ATTRIBUTE;
__QAIC_HEADER_EXPORT int __QAIC_HEADER(hexagon_nn_execute_new)(
    hexagon_nn_nn_id id,
    const hexagon_nn_tensordef *inputs,
    int inputsLen,
    hexagon_nn_tensordef *outputs,
    int outputsLen) __QAIC_HEADER_ATTRIBUTE;
李寅 已提交
224 225
__QAIC_HEADER_EXPORT unsigned int __QAIC_HEADER(hexagon_nn_get_dsp_offset)(void)
    __QAIC_HEADER_ATTRIBUTE;
李寅 已提交
226 227 228
#ifdef __cplusplus
}
#endif
L
Liangliang He 已提交
229
#endif  // THIRD_PARTY_NNLIB_HEXAGON_NN_H_