diff options
author | A. Unique TensorFlower <gardener@tensorflow.org> | 2017-06-16 16:34:56 -0700 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-06-16 16:39:07 -0700 |
commit | 8e7c2c180c4b75768c707d66c9080ee06ee72773 (patch) | |
tree | 857ce3bacdec575629c78fc7879eb3645be42b59 /tensorflow/contrib/hvx | |
parent | 2473505b70f03838fef4ae6108387ba66d443d62 (diff) |
Cleanup and build fix of hexagon controller
PiperOrigin-RevId: 159291812
Diffstat (limited to 'tensorflow/contrib/hvx')
4 files changed, 107 insertions, 138 deletions
diff --git a/tensorflow/contrib/hvx/hexagon_controller/src_impl/graph_functions_wrapper.c b/tensorflow/contrib/hvx/hexagon_controller/src_impl/graph_functions_wrapper.c index d83b58dc6b..f6a38fe8a9 100644 --- a/tensorflow/contrib/hvx/hexagon_controller/src_impl/graph_functions_wrapper.c +++ b/tensorflow/contrib/hvx/hexagon_controller/src_impl/graph_functions_wrapper.c @@ -52,21 +52,21 @@ static enum InceptionVersion s_inception_version = INCEPTION_V3; ///////////////////////////////////////////////// // file local functions -static const char *ConvertGraphInfoIdToName(unsigned int id) { +static const char* ConvertGraphInfoIdToName(unsigned int id) { // TODO(satok): implement return "?"; } -static const char *ConvertGraphInfoIdToOpName(unsigned int id) { +static const char* ConvertGraphInfoIdToOpName(unsigned int id) { // TODO(satok): implement return "?"; } ///////////////////////////////////////////////// // file local utilities -static uint32_t FindMaxIdxWithExcludeList( - const float *data, uint32_t entries, const int exclude_size, - const int* exclude_idx) { +static uint32_t FindMaxIdxWithExcludeList(const float* data, uint32_t entries, + const int exclude_size, + const int* exclude_idx) { int i; float maxval = data[0]; int maxidx = 0; @@ -94,7 +94,7 @@ static uint32_t FindMaxIdx(const float* data, uint32_t entries) { } void hexagon_controller_PrintMaxNIdx(const float* data, const uint32_t entries, - const int n, int* out_ranking) { + const int n, int* out_ranking) { if (DUMP_OUTPUT) { for (int i = 0; i < entries; ++i) { TFMLOGD("%d: val = %f", i, data[i]); @@ -123,9 +123,9 @@ static inline unsigned long long int GetCounter(hexagon_nn_perfinfo s) { return ret; } -static int CompareCycle(const void *va, const void *vb) { - const hexagon_nn_perfinfo *a = va; - const hexagon_nn_perfinfo *b = vb; +static int CompareCycle(const void* va, const void* vb) { + const hexagon_nn_perfinfo* a = va; + const hexagon_nn_perfinfo* b = vb; unsigned long long int acount = GetCounter(*a); unsigned long long int bcount = GetCounter(*b); if (acount < bcount) { @@ -142,8 +142,6 @@ static int CompareCycle(const void *va, const void *vb) { uint32_t hexagon_controller_InstantiateGraph() { const uint32_t nn_id = hexagon_nn_init(); - // set debug level to 99 for now - //hexagon_nn_set_debug_level(nn_id, 99); // TODO(satok): make this as argument hexagon_nn_set_debug_level(nn_id, 0); return nn_id; @@ -170,7 +168,7 @@ bool hexagon_controller_ConstructGraph(uint32_t nn_id) { int err; if ((err = hexagon_nn_prepare(nn_id)) != 0) { TFMLOGE("Prepare failed! returned 0x%x\n", err); - hexagon_controller_PrintLog(nn_id); + DumpNNId(nn_id); return false; } else { TFMLOGD("Prepare success!\n"); @@ -178,7 +176,7 @@ bool hexagon_controller_ConstructGraph(uint32_t nn_id) { } } -uint32_t hexagon_controller_SetupGraph(int version) { +uint32_t hexagon_controller_SetupGraph(int version) { const uint32_t nn_id = hexagon_controller_InstantiateGraph(); hexagon_controller_InitGraph(version, nn_id); hexagon_controller_ConstructGraph(nn_id); @@ -200,7 +198,7 @@ bool hexagon_controller_ExecuteGraphWithMultipleInOut( if (DBG_EXECUTION) { LogDHexagon("Execution failed!"); TFMLOGE("execute got err: %d\n", err); - hexagon_controller_PrintLog(nn_id); + DumpNNId(nn_id); } return false; } else { @@ -212,24 +210,15 @@ bool hexagon_controller_ExecuteGraphWithMultipleInOut( } bool hexagon_controller_ExecuteGraph( - const uint32_t nn_id, - const uint32_t batches, - const uint32_t height, - const uint32_t width, - const uint32_t depth, - uint8_t* int_data, - const uint32_t int_data_size, - uint32_t* out_batches, - uint32_t* out_height, - uint32_t* out_width, - uint32_t* out_depth, - uint8_t* out_vals, - const uint32_t output_val_byte_size, - uint32_t* out_data_byte_size) { + const uint32_t nn_id, const uint32_t batches, const uint32_t height, + const uint32_t width, const uint32_t depth, uint8_t* int_data, + const uint32_t int_data_size, uint32_t* out_batches, uint32_t* out_height, + uint32_t* out_width, uint32_t* out_depth, uint8_t* out_vals, + const uint32_t output_val_byte_size, uint32_t* out_data_byte_size) { if (DBG_EXECUTION) { TFMLOGD("Preparing to execute..."); - TFMLOGD("Input: %d, %d, %d, %d, %d, %d", - batches, height, width, depth, int_data[0], int_data_size); + TFMLOGD("Input: %d, %d, %d, %d, %d, %d", batches, height, width, depth, + int_data[0], int_data_size); TFMLOGD("Output: %d, %p", output_val_byte_size, out_vals); LogDHexagon("Execute graph!"); } @@ -273,27 +262,21 @@ bool hexagon_controller_ExecuteInceptionDummyData(uint32_t nn_id) { const bool success = hexagon_controller_ExecuteGraph( nn_id, INCEPTION_PARAM_BATCHES, INCEPTION_PARAM_HEIGHT_V3, INCEPTION_PARAM_WIDTH_V3, INCEPTION_PARAM_DEPTH, - (uint8_t *)inception_dummy_int_data_299x299, + (uint8_t*)inception_dummy_int_data_299x299, INCEPTION_PARAM_HEIGHT_V3 * INCEPTION_PARAM_WIDTH_V3 * - INCEPTION_PARAM_DEPTH, + INCEPTION_PARAM_DEPTH, &out_batches, &out_height, &out_width, &out_depth, - (uint8_t *)s_output_values, sizeof(s_output_values), - &out_data_size); + (uint8_t*)s_output_values, sizeof(s_output_values), &out_data_size); if (success) { int out_ranking[OUT_RANKING_SIZE]; hexagon_controller_PrintMaxNIdx( - s_output_values, - out_batches * out_height * out_width * out_depth, + s_output_values, out_batches * out_height * out_width * out_depth, OUT_RANKING_SIZE, out_ranking); - TFMLOGD("%d x %d x %d x %d, size = %d\n", - out_batches, - out_height, - out_width, - out_depth, - out_data_size); - TFMLOGD("max idx: %d\n", FindMaxIdx( - s_output_values, - out_batches * out_height * out_width * out_depth)); + TFMLOGD("%d x %d x %d x %d, size = %d\n", out_batches, out_height, + out_width, out_depth, out_data_size); + TFMLOGD("max idx: %d\n", + FindMaxIdx(s_output_values, + out_batches * out_height * out_width * out_depth)); if (out_ranking[0] == 169 && out_ranking[1] == 7) { return true; } else { @@ -317,25 +300,22 @@ void hexagon_controller_DumpPerf(uint32_t nn_id) { TFMLOGE("perf info failure"); return; } - TFMLOGD("Total %d nodes.",n_nodes); - qsort(info,n_nodes,sizeof(info[0]), CompareCycle); + TFMLOGD("Total %d nodes.", n_nodes); + qsort(info, n_nodes, sizeof(info[0]), CompareCycle); for (i = 0; i < n_nodes; i++) { total_cycles += GetCounter(info[i]); } - TFMLOGD("Total %lld cycles.",total_cycles); + TFMLOGD("Total %lld cycles.", total_cycles); for (i = 0; i < n_nodes; i++) { counter = GetCounter(info[i]); cum_cycles += counter; - TFMLOGD("node,0x%x,%s,%s,executions,%d,cycles,%lld,%f %%," - "cum_cycles,%lld,%f %%\n", - info[i].node_id, - ConvertGraphInfoIdToName(info[i].node_id), - ConvertGraphInfoIdToOpName(info[i].node_id), - info[i].executions, - counter, - 100*((double)counter)/total_cycles, - cum_cycles, - 100*((double)cum_cycles)/total_cycles); + TFMLOGD( + "node,0x%x,%s,%s,executions,%d,cycles,%lld,%f %%," + "cum_cycles,%lld,%f %%\n", + info[i].node_id, ConvertGraphInfoIdToName(info[i].node_id), + ConvertGraphInfoIdToOpName(info[i].node_id), info[i].executions, + counter, 100 * ((double)counter) / total_cycles, cum_cycles, + 100 * ((double)cum_cycles) / total_cycles); } #ifdef ENABLE_HVX_FULL_DEBUG DumpAllPerf(nn_id); @@ -356,7 +336,7 @@ void hexagon_controller_DumpNodeName(uint32_t nn_id) { TFMLOGD("perf info failure"); return; } - TFMLOGD("Total %d nodes.",node_count); + TFMLOGD("Total %d nodes.", node_count); qsort(info, node_count, sizeof(info[0]), CompareCycle); for (i = 0; i < node_count; i++) { total_cycles += GetCounter(info[i]); @@ -365,19 +345,14 @@ void hexagon_controller_DumpNodeName(uint32_t nn_id) { for (i = 0; i < node_count; i++) { counter = GetCounter(info[i]); cum_cycles += counter; - TFMLOGD("node,0x%x,%s,%s,executions,%d,cycles,%lld,%f %%," - "cum_cycles,%lld,%f %%", - info[i].node_id, - ConvertGraphInfoIdToName(info[i].node_id), - ConvertGraphInfoIdToOpName(info[i].node_id), - info[i].executions, - counter, - 100*((double)counter)/total_cycles, - cum_cycles, - 100*((double)cum_cycles)/total_cycles); + TFMLOGD( + "node,0x%x,%s,%s,executions,%d,cycles,%lld,%f %%," + "cum_cycles,%lld,%f %%", + info[i].node_id, ConvertGraphInfoIdToName(info[i].node_id), + ConvertGraphInfoIdToOpName(info[i].node_id), info[i].executions, + counter, 100 * ((double)counter) / total_cycles, cum_cycles, + 100 * ((double)cum_cycles) / total_cycles); } } -void hexagon_controller_Teardown(uint32_t nn_id) { - hexagon_nn_teardown(nn_id); -} +void hexagon_controller_Teardown(uint32_t nn_id) { hexagon_nn_teardown(nn_id); } diff --git a/tensorflow/contrib/hvx/hexagon_controller/src_impl/hexagon_controller.c b/tensorflow/contrib/hvx/hexagon_controller/src_impl/hexagon_controller.c index ba50da6abd..6a5d982dc8 100644 --- a/tensorflow/contrib/hvx/hexagon_controller/src_impl/hexagon_controller.c +++ b/tensorflow/contrib/hvx/hexagon_controller/src_impl/hexagon_controller.c @@ -24,7 +24,8 @@ limitations under the License. #include "adspmsgd.h" #include "dspCV.h" -#include "rpcmem.h" // helper API's for shared buffer allocation +#include "node_data_float.h" +#include "rpcmem.h" // helper API's for shared buffer allocation #include "soc_interface.h" #include "tfm_log.h" @@ -86,7 +87,8 @@ static bool SetInputTensorDef(int port, hexagon_nn_tensordef* tensordef) { TFMLOGE("Error exceeds input count."); return false; } - NodeDataFloat* input_node_data_buffer = &s_input_node_data_buffer[port]; + struct NodeDataFloat* input_node_data_buffer = + &s_input_node_data_buffer[port]; tensordef->batches = input_node_data_buffer->x; tensordef->height = input_node_data_buffer->y; tensordef->width = input_node_data_buffer->z; @@ -142,19 +144,19 @@ void hexagon_controller_InitInputNodeDataToInceptionDummyData(int version) { } hexagon_controller_CopyByteNodeData( 0, INCEPTION_PARAM_BATCHES, INCEPTION_PARAM_HEIGHT_V1, - INCEPTION_PARAM_WIDTH_V1, INCEPTION_PARAM_DEPTH, - 1, inception_dummy_int_data_224x224); + INCEPTION_PARAM_WIDTH_V1, INCEPTION_PARAM_DEPTH, 1, + inception_dummy_int_data_224x224); } else if (version == 3) { if (USE_FLOAT_DATA) { hexagon_controller_CopyByteNodeData( 0, INCEPTION_PARAM_BATCHES, INCEPTION_PARAM_HEIGHT_V3, - INCEPTION_PARAM_WIDTH_V3, INCEPTION_PARAM_DEPTH, - sizeof(float), (uint8_t*)inception_dummy_float_data_299x299); + INCEPTION_PARAM_WIDTH_V3, INCEPTION_PARAM_DEPTH, sizeof(float), + (uint8_t*)inception_dummy_float_data_299x299); } else { hexagon_controller_CopyByteNodeData( 0, INCEPTION_PARAM_BATCHES, INCEPTION_PARAM_HEIGHT_V3, - INCEPTION_PARAM_WIDTH_V3, INCEPTION_PARAM_DEPTH, - 1, inception_dummy_int_data_299x299); + INCEPTION_PARAM_WIDTH_V3, INCEPTION_PARAM_DEPTH, 1, + inception_dummy_int_data_299x299); } } } @@ -188,7 +190,7 @@ bool hexagon_controller_ExecuteGraphWithBuffer(uint32_t nn_id, if (!success) { TFMLOGE("Execution failed"); - hexagon_controller_PrintLog(nn_id); + DumpNNId(nn_id); return false; } else if (!show_ranking) { return true; @@ -217,9 +219,7 @@ bool hexagon_controller_ExecuteGraphWithBuffer(uint32_t nn_id, return true; } -uint32_t hexagon_controller_GetTargetGraphId() { - return s_target_graph_id; -} +uint32_t hexagon_controller_GetTargetGraphId() { return s_target_graph_id; } void hexagon_controller_SetTargetGraphId(uint32_t graph_id) { s_target_graph_id = graph_id; @@ -305,7 +305,8 @@ bool hexagon_controller_AllocateNodeDataBuffers(int input_size, } bool hexagon_controller_ReleaseInputNodeDataBuffersWithPort(int port) { - NodeDataFloat* input_node_data_buffer = &s_input_node_data_buffer[port]; + struct NodeDataFloat* input_node_data_buffer = + &s_input_node_data_buffer[port]; if (input_node_data_buffer->max_buf_byte_size == 0) { TFMLOGE("ERROR! input buffer has not been allocated yet!!"); return false; @@ -346,15 +347,14 @@ bool hexagon_controller_CopyByteNodeData(int port, int x, int y, int z, int d, int array_byte_size = x * y * z * d * type_byte_size; TFMLOGD("--- %d, %d, %d, %d, %d, %d", x, y, z, d, type_byte_size, array_byte_size); - NodeDataFloat* input_node_data_buffer = s_input_node_data_buffer[0]; + struct NodeDataFloat* input_node_data_buffer = &s_input_node_data_buffer[0]; if (input_node_data_buffer->max_buf_byte_size < array_byte_size) { TFMLOGE("ERROR! input buffer size is too small! %d < %d", input_node_data_buffer->max_buf_byte_size, array_byte_size); return false; } - memcpy(input_node_data_buffer->byte_array_data, array_data, - array_byte_size); + memcpy(input_node_data_buffer->byte_array_data, array_data, array_byte_size); input_node_data_buffer->array_byte_size = array_byte_size; input_node_data_buffer->x = x; input_node_data_buffer->y = y; @@ -363,8 +363,9 @@ bool hexagon_controller_CopyByteNodeData(int port, int x, int y, int z, int d, return true; } -int hexagon_controller_InitHexagonWithMaxAttributes( - int enable_dcvs, int bus_usage, int version) { +int hexagon_controller_InitHexagonWithMaxAttributes(int enable_dcvs, + int bus_usage, + int version) { TFMLOGI("Init hexagon with max attributes (Controller version = %d)", HEXAGON_CONTROLLER_VERSION); const int MCPS = 1000; @@ -373,17 +374,17 @@ int hexagon_controller_InitHexagonWithMaxAttributes( adspmsgd_start(0, RPCMEM_HEAP_DEFAULT, 4096); dspCV_Attribute attrib[] = { - // The below values will result in the maximum aDSP performance, - // at Turbo voltage. - // Slightly more MCPS than are available on current targets - {DSP_TOTAL_MCPS, MCPS}, - // drive the clock to MAX on known targets - {DSP_MCPS_PER_THREAD, MCPS / 2}, - // 12 GB/sec is slightly higher than the max realistic - // max BW on existing targets. - {PEAK_BUS_BANDWIDTH_MBPS, MBPS}, - // This app is non-real time, and constantly reading/writing memory - {BUS_USAGE_PERCENT, bus_usage}, + // The below values will result in the maximum aDSP performance, + // at Turbo voltage. + // Slightly more MCPS than are available on current targets + {DSP_TOTAL_MCPS, MCPS}, + // drive the clock to MAX on known targets + {DSP_MCPS_PER_THREAD, MCPS / 2}, + // 12 GB/sec is slightly higher than the max realistic + // max BW on existing targets. + {PEAK_BUS_BANDWIDTH_MBPS, MBPS}, + // This app is non-real time, and constantly reading/writing memory + {BUS_USAGE_PERCENT, bus_usage}, }; int retval = 0; if (!enable_dcvs) { @@ -414,9 +415,7 @@ int hexagon_controller_DeInitHexagon() { return retval; } -void hexagon_controller_GrowMemorySize() { - hexagon_nn_config(); -} +void hexagon_controller_GrowMemorySize() { hexagon_nn_config(); } struct NodeDataFloat* hexagon_controller_GetInputNodeDataBuffer(int port) { if (port >= GetInputNodeCount()) { @@ -435,16 +434,17 @@ uint8_t* hexagon_controller_GetOutputNodeDataBuffer(int port, } // Append const node to the graph -int hexagon_controller_AppendConstNode( - const char* const name, int graph_id, int node_id, - int batch, int height, int width, int depth, - const uint8_t* const data, int data_length) { +int hexagon_controller_AppendConstNode(const char* const name, int graph_id, + int node_id, int batch, int height, + int width, int depth, + const uint8_t* const data, + int data_length) { if (DBG_SHOW_ID) { - TFMLOGV("---(CONST) %s, %d, %d, %d, %d, %d, %d", - name, node_id, batch, height, width, depth, data_length); + TFMLOGV("---(CONST) %s, %d, %d, %d, %d, %d, %d", name, node_id, batch, + height, width, depth, data_length); } else { - TFMLOGV("---(CONST) %s, %d, %d, %d, %d, %d", - name, batch, height, width, depth, data_length); + TFMLOGV("---(CONST) %s, %d, %d, %d, %d, %d", name, batch, height, width, + depth, data_length); } const int retval = hexagon_nn_append_const_node( graph_id, node_id, batch, height, width, depth, data, data_length); @@ -456,11 +456,12 @@ int hexagon_controller_AppendConstNode( } // Append node to the graph -int hexagon_controller_AppendNode( - const char* const name, int graph_id, int node_id, int ops_id, - int padding_id, const hexagon_nn_input* const inputs, - int inputs_count, const hexagon_nn_output* const outputs, - int outputs_count) { +int hexagon_controller_AppendNode(const char* const name, int graph_id, + int node_id, int ops_id, int padding_id, + const hexagon_nn_input* const inputs, + int inputs_count, + const hexagon_nn_output* const outputs, + int outputs_count) { char input_param_buf[OUTPUT_PARAM_MAX_LINE_SIZE]; memset(input_param_buf, 0, OUTPUT_PARAM_MAX_LINE_SIZE); int pos = 0; @@ -470,8 +471,8 @@ int hexagon_controller_AppendNode( pos += snprintf(&input_param_buf[pos], 500, "(%d, %d), ", inputs[i].src_id, inputs[i].output_idx); } else { - pos += snprintf(&input_param_buf[pos], 500, "(%d), ", - inputs[i].output_idx); + pos += + snprintf(&input_param_buf[pos], 500, "(%d), ", inputs[i].output_idx); } } @@ -484,18 +485,16 @@ int hexagon_controller_AppendNode( } if (DBG_SHOW_ID) { - TFMLOGV("---(OP) %s, %d, %d, %d, %d, %d, %s, %s", name, node_id, - ops_id, padding_id, inputs_count, outputs_count, input_param_buf, + TFMLOGV("---(OP) %s, %d, %d, %d, %d, %d, %s, %s", name, node_id, ops_id, + padding_id, inputs_count, outputs_count, input_param_buf, output_param_buf); } else { - TFMLOGV("---(OP) %s, %d, %d, %d, %d, %s, %s", name, - ops_id, padding_id, inputs_count, outputs_count, input_param_buf, - output_param_buf); + TFMLOGV("---(OP) %s, %d, %d, %d, %d, %s, %s", name, ops_id, padding_id, + inputs_count, outputs_count, input_param_buf, output_param_buf); } - const int retval = hexagon_nn_append_node( - graph_id, node_id, ops_id, padding_id, - inputs, inputs_count, - outputs, outputs_count); + const int retval = + hexagon_nn_append_node(graph_id, node_id, ops_id, padding_id, inputs, + inputs_count, outputs, outputs_count); if (retval != 0) { TFMLOGE("Failed to append const node %d", node_id); return retval; @@ -510,11 +509,3 @@ void hexagon_controller_EnableDbgUseInceptionDummyData(bool enable) { bool hexagon_controller_IsDbgUseInceptionDummyDataEnabled() { return s_dbg_use_inception_dummy_data; } - -void hexagon_controller_PrintLog(uint32_t nn_id) { - unsigned char* buf = NULL; - posix_memalign((void**)&buf, 128, PRINT_BUFSIZE); - hexagon_nn_getlog(nn_id, buf, PRINT_BUFSIZE); - TFMLOGE("DUMP HEXAGON LOG: %s", buf); - free(buf); -} diff --git a/tensorflow/contrib/hvx/hexagon_controller/src_impl/include/hexagon_controller.h b/tensorflow/contrib/hvx/hexagon_controller/src_impl/include/hexagon_controller.h index d23048c116..fc921ff8b9 100644 --- a/tensorflow/contrib/hvx/hexagon_controller/src_impl/include/hexagon_controller.h +++ b/tensorflow/contrib/hvx/hexagon_controller/src_impl/include/hexagon_controller.h @@ -142,8 +142,6 @@ void hexagon_controller_EnableDbgUseInceptionDummyData(bool enable); bool hexagon_controller_IsDbgUseInceptionDummyDataEnabled(); -void hexagon_controller_PrintLog(uint32_t nn_id); - #ifdef __cplusplus } #endif // __cplusplus diff --git a/tensorflow/contrib/hvx/hexagon_controller/src_log/include/tfm_log.h b/tensorflow/contrib/hvx/hexagon_controller/src_log/include/tfm_log.h index 91bd15d383..8d11ee4a34 100644 --- a/tensorflow/contrib/hvx/hexagon_controller/src_log/include/tfm_log.h +++ b/tensorflow/contrib/hvx/hexagon_controller/src_log/include/tfm_log.h @@ -74,4 +74,9 @@ static inline void LogDHexagon(const char* fmt, ...) { va_end(ap); } +static inline void DumpNNId(uint32_t nn_id) { + // TODO(satok): Dump more information + TFMLOGI("NN Id = %d", nn_id); +} + #endif |