Home | History | Annotate | Download | only in hexagon_nn_controller
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef HEXAGON_NN_CONTROLLER_H
     18 #define HEXAGON_NN_CONTROLLER_H
     19 
     20 #ifdef __cplusplus
     21 extern "C" {
     22 #endif
     23 
     24 // includes
     25 #include "hexagon_nn_ops.h"
     26 
     27 // hexagon types
     28 
     29 typedef struct hexagon_nn_input {
     30     unsigned int src_id;
     31     unsigned int output_idx;
     32 } hexagon_nn_input;
     33 
     34 typedef struct hexagon_nn_output {
     35     unsigned int rank;
     36     unsigned int max_sizes[8];
     37     unsigned int elementsize;
     38     int zero_offset;
     39     float stepsize;
     40 } hexagon_nn_output;
     41 
     42 typedef struct hexagon_nn_perfinfo {
     43     unsigned int node_id;
     44     unsigned int executions;
     45     unsigned int counter_lo;
     46     unsigned int counter_hi;
     47 } hexagon_nn_perfinfo;
     48 
     49 typedef int hexagon_nn_nn_id;
     50 
     51 typedef enum hexagon_nn_padding_type {
     52     NN_PAD_NA,
     53     NN_PAD_SAME,
     54     NN_PAD_VALID,
     55     NN_PAD_MIRROR_REFLECT,
     56     NN_PAD_MIRROR_SYMMETRIC,
     57     NN_PAD_SAME_CAFFE,
     58     _32BIT_PLACEHOLDER_hexagon_nn_padding_type = 0x7fffffff
     59 } hexagon_nn_padding_type;
     60 
     61 typedef struct hexagon_nn_tensordef {
     62     unsigned int batches;
     63     unsigned int height;
     64     unsigned int width;
     65     unsigned int depth;
     66     unsigned char* data;
     67     int dataLen;
     68     unsigned int data_valid_len;
     69     unsigned int unused;
     70 } hexagon_nn_tensordef;
     71 
     72 // interface types
     73 
     74 typedef int (*hexagon_nn_controller_init_fn)(hexagon_nn_nn_id* g);
     75 
     76 typedef int (*hexagon_nn_controller_getlog_fn)(hexagon_nn_nn_id id, unsigned char* buf,
     77                                                unsigned int length);
     78 
     79 typedef int (*hexagon_nn_controller_snpprint_fn)(hexagon_nn_nn_id id, unsigned char* buf,
     80                                                  unsigned int length);
     81 
     82 typedef int (*hexagon_nn_controller_set_debug_level_fn)(hexagon_nn_nn_id id, int level);
     83 
     84 typedef int (*hexagon_nn_controller_prepare_fn)(hexagon_nn_nn_id id);
     85 
     86 typedef int (*hexagon_nn_controller_append_node_fn)(
     87     hexagon_nn_nn_id id, unsigned int node_id, op_type operation, hexagon_nn_padding_type padding,
     88     const hexagon_nn_input* inputs, unsigned int num_inputs, const hexagon_nn_output* outputs,
     89     unsigned int num_outputs);
     90 
     91 typedef int (*hexagon_nn_controller_append_const_node_fn)(hexagon_nn_nn_id id, unsigned int node_id,
     92                                                           unsigned int batches, unsigned int height,
     93                                                           unsigned int width, unsigned int depth,
     94                                                           const unsigned char* data,
     95                                                           unsigned int data_len);
     96 
     97 typedef int (*hexagon_nn_controller_execute_new_fn)(hexagon_nn_nn_id id,
     98                                                     const hexagon_nn_tensordef* inputs,
     99                                                     unsigned int n_inputs,
    100                                                     hexagon_nn_tensordef* outputs,
    101                                                     unsigned int n_outputs);
    102 
    103 typedef int (*hexagon_nn_controller_execute_fn)(hexagon_nn_nn_id id, unsigned int batches_in,
    104                                                 unsigned int height_in, unsigned int width_in,
    105                                                 unsigned int depth_in, const unsigned char* data_in,
    106                                                 unsigned int data_len_in, unsigned int* batches_out,
    107                                                 unsigned int* height_out, unsigned int* width_out,
    108                                                 unsigned int* depth_out, unsigned char* data_out,
    109                                                 unsigned int data_out_max,
    110                                                 unsigned int* data_out_size);
    111 
    112 typedef int (*hexagon_nn_controller_teardown_fn)(hexagon_nn_nn_id id);
    113 
    114 typedef int (*hexagon_nn_controller_get_perfinfo_fn)(hexagon_nn_nn_id id,
    115                                                      hexagon_nn_perfinfo* info_out,
    116                                                      unsigned int info_out_len,
    117                                                      unsigned int* n_items_out);
    118 
    119 typedef int (*hexagon_nn_controller_reset_perfinfo_fn)(hexagon_nn_nn_id id, unsigned int event);
    120 
    121 typedef int (*hexagon_nn_controller_version_fn)(int* ver);
    122 
    123 typedef int (*hexagon_nn_controller_last_execution_cycles_fn)(hexagon_nn_nn_id id,
    124                                                               unsigned int* cycles_lo,
    125                                                               unsigned int* cycles_hi);
    126 
    127 typedef int (*hexagon_nn_controller_GetHexagonBinaryVersion_fn)(int* ver);
    128 
    129 typedef int (*hexagon_nn_controller_PrintLog_fn)(const unsigned char* data_in,
    130                                                  unsigned int data_in_len);
    131 
    132 typedef int (*hexagon_nn_controller_op_name_to_id_fn)(const char* name, unsigned int* id);
    133 
    134 typedef int (*hexagon_nn_controller_op_id_to_name_fn)(const unsigned int id, char* name,
    135                                                       int name_len);
    136 
    137 typedef int (*hexagon_nn_controller_disable_dcvs_fn)();
    138 
    139 typedef int (*hexagon_nn_controller_set_powersave_level_fn)(unsigned int level);
    140 
    141 typedef int (*hexagon_nn_controller_config_fn)();
    142 
    143 typedef unsigned int (*hexagon_nn_controller_get_dsp_offset_fn)();
    144 
    145 typedef int (*hexagon_nn_controller_boost_fn)(int bus_usage);
    146 
    147 typedef int (*hexagon_nn_controller_slow_fn)();
    148 
    149 #ifdef __cplusplus
    150 }  // extern "C"
    151 #endif
    152 
    153 #endif  // HEXAGON_NN_CONTROLLER_H
    154