1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef GEMM_WRAPPER_H 17 #define GEMM_WRAPPER_H 18 19 #include <stdbool.h> 20 #include <stdlib.h> 21 22 #include "hexagon_nn.h" 23 #include "node_data_float.h" 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif // __cplusplus 28 29 #define INCEPTION_PARAM_BATCHES 1 30 #define INCEPTION_PARAM_HEIGHT_V1 224 31 #define INCEPTION_PARAM_WIDTH_V1 224 32 #define INCEPTION_PARAM_HEIGHT_V3 299 33 #define INCEPTION_PARAM_WIDTH_V3 299 34 #define INCEPTION_PARAM_DEPTH 3 35 36 // General functions 37 void hexagon_controller_PrintGraph(uint32_t nn_id); 38 39 int hexagon_controller_GetWrapperVersion(); 40 41 int hexagon_controller_GetHexagonBinaryVersion(); 42 43 // Buffer operations 44 bool hexagon_controller_SetAllInputTensorDef(int node_count, 45 hexagon_nn_tensordef* tensordef); 46 47 bool hexagon_controller_SetAllInputTensorDef(int node_count, 48 hexagon_nn_tensordef* tensordef); 49 50 // Hexagon perf functions 51 int hexagon_controller_InitHexagonWithMaxAttributes(int enable_dcvs, 52 int bus_usage, int version); 53 54 bool hexagon_controller_AllocateInputNodeDataBuffersWithPort(int port, 55 int input_size); 56 57 bool hexagon_controller_AllocateOutNodeDataBuffersWithPort(int port, 58 int output_size); 59 60 bool hexagon_controller_AllocateNodeDataBuffers(int input_size, 61 int output_size); 62 63 bool hexagon_controller_AllocateMultipleNodeDataBuffers(int input_count, 64 int* input_sizes, 65 int output_count, 66 int* output_sizes); 67 68 bool hexagon_controller_ReleaseInputNodeDataBuffersWithPort(int port); 69 bool hexagon_controller_ReleaseOutputNodeDataBuffersWithPort(int port); 70 71 bool hexagon_controller_ReleaseNodeDataBuffers(); 72 73 bool hexagon_controller_CopyByteNodeData(int port, int x, int y, int z, int d, 74 int type_byte_size, 75 uint8_t* array_data); 76 77 int hexagon_controller_DeInitHexagon(); 78 79 uint32_t hexagon_controller_GetTargetGraphId(); 80 81 void hexagon_controller_SetTargetGraphId(uint32_t graph_id); 82 83 // Hexagon config functions 84 void hexagon_controller_GrowMemorySize(); 85 86 // Graph data transfer functions 87 struct NodeDataFloat* hexagon_controller_GetInputNodeDataBuffer(int port); 88 89 uint8_t* hexagon_controller_GetOutputNodeDataBuffer(int port, 90 int* out_array_byte_size); 91 92 // Graph functions 93 uint32_t hexagon_controller_InstantiateGraph(); 94 95 void hexagon_controller_InitGraph(int version, uint32_t nn_id); 96 97 bool hexagon_controller_ConstructGraph(uint32_t nn_id); 98 99 uint32_t hexagon_controller_SetupGraph(int version); 100 101 bool hexagon_controller_ExecuteInceptionDummyData(uint32_t nn_id); 102 103 bool hexagon_controller_ExecuteGraphWithMultipleInOut( 104 const uint32_t nn_id, const int input_count, hexagon_nn_tensordef* inputs, 105 const int output_count, hexagon_nn_tensordef* outputs); 106 107 bool hexagon_controller_ExecuteGraph( 108 const uint32_t nn_id, const uint32_t batches, const uint32_t height, 109 const uint32_t width, const uint32_t depth, uint8_t* int_data, 110 const uint32_t int_data_size, uint32_t* out_batches, uint32_t* out_height, 111 uint32_t* out_width, uint32_t* out_depth, uint8_t* out_vals, 112 const uint32_t output_val_byte_size, uint32_t* out_data_byte_size); 113 114 bool hexagon_controller_ExecuteGraphWithBuffer(uint32_t nn_id, 115 bool show_ranking); 116 117 void hexagon_controller_DumpPerf(uint32_t nn_id); 118 119 void hexagon_controller_DumpNodeName(uint32_t nn_id); 120 121 void hexagon_controller_Teardown(uint32_t nn_id); 122 123 void hexagon_controller_PrintMaxNIdx(const float* data, const uint32_t entries, 124 const int n, int* out_ranking); 125 126 void hexagon_controller_InitInputNodeDataToInceptionDummyData(int version); 127 128 int hexagon_controller_AppendNode(const char* const name, int graph_id, 129 int node_id, int op_id, int padding_id, 130 const hexagon_nn_input* const inputs, 131 int inputs_count, 132 const hexagon_nn_output* const outputs, 133 int outputs_count); 134 135 int hexagon_controller_AppendConstNode(const char* const name, int graph_id, 136 int node_id, int batch, int height, 137 int width, int depth, 138 const uint8_t* const data, 139 int data_length); 140 141 void hexagon_controller_EnableDbgUseInceptionDummyData(bool enable); 142 143 bool hexagon_controller_IsDbgUseInceptionDummyDataEnabled(); 144 145 #ifdef __cplusplus 146 } 147 #endif // __cplusplus 148 149 #endif // GEMM_WRAPPER_H 150