提交 cdf5d030 编写于 作者: 叶剑武

Merge branch 'capability' into 'master'

Feature: Add capability information for mace_run

See merge request !1001
...@@ -7,6 +7,7 @@ mace { ...@@ -7,6 +7,7 @@ mace {
*CreateMaceEngineFromProto*; *CreateMaceEngineFromProto*;
*GetBigLittleCoreIDs*; *GetBigLittleCoreIDs*;
*MaceVersion*; *MaceVersion*;
*GetCapability*;
# api for static library of models # api for static library of models
*mace*logging*LogMessage*; *mace*logging*LogMessage*;
......
...@@ -102,7 +102,7 @@ class RunMetadata { ...@@ -102,7 +102,7 @@ class RunMetadata {
/// Consistent with Android NNAPI /// Consistent with Android NNAPI
struct PerformanceInfo { struct PerformanceInfo {
// Time of executing some workload. // Time of executing some workload(millisecond).
// negative value for unsupported. // negative value for unsupported.
float exec_time; float exec_time;
}; };
......
...@@ -123,39 +123,16 @@ TFOpType = Enum('TFOpType', [(op, op) for op in TFSupportedOps], type=str) ...@@ -123,39 +123,16 @@ TFOpType = Enum('TFOpType', [(op, op) for op in TFSupportedOps], type=str)
TFSupportedOps = [six.b(op) for op in TFSupportedOps] TFSupportedOps = [six.b(op) for op in TFSupportedOps]
TFTransformGraphOptions = { TFTransformGraphOptions = [
base_converter.DeviceType.CPU.value: [ 'strip_unused_nodes',
'strip_unused_nodes', 'remove_nodes(op=Identity, op=CheckNumerics)',
'remove_nodes(op=Identity, op=CheckNumerics)', 'fold_constants(ignore_errors=true)',
'fold_constants(ignore_errors=true)', 'fold_batch_norms',
'fold_batch_norms', 'fold_old_batch_norms',
'fold_old_batch_norms', 'remove_control_dependencies',
'remove_control_dependencies', 'strip_unused_nodes',
'strip_unused_nodes', 'sort_by_execution_order'
'sort_by_execution_order' ]
],
base_converter.DeviceType.GPU.value: [
'strip_unused_nodes',
'remove_nodes(op=Identity, op=CheckNumerics)',
'fold_constants(ignore_errors=true)',
'flatten_atrous_conv',
'fold_batch_norms',
'fold_old_batch_norms',
'remove_control_dependencies',
'strip_unused_nodes',
'sort_by_execution_order'
],
base_converter.DeviceType.HEXAGON.value: [
'strip_unused_nodes',
'remove_nodes(op=Identity, op=CheckNumerics)',
'fold_constants(ignore_errors=true)',
'fold_batch_norms',
'fold_old_batch_norms',
'remove_control_dependencies',
'strip_unused_nodes',
'sort_by_execution_order'
]
}
class TensorflowConverter(base_converter.ConverterInterface): class TensorflowConverter(base_converter.ConverterInterface):
...@@ -289,15 +266,13 @@ class TensorflowConverter(base_converter.ConverterInterface): ...@@ -289,15 +266,13 @@ class TensorflowConverter(base_converter.ConverterInterface):
self._placeholders = {} self._placeholders = {}
print("Run transform_graph: %s" % TFTransformGraphOptions[ print("Run transform_graph: %s" % TFTransformGraphOptions)
option.device])
try: try:
print("output keys: ", option.output_nodes.keys()) print("output keys: ", option.output_nodes.keys())
transformed_graph_def = TransformGraph(tf_graph_def, transformed_graph_def = TransformGraph(tf_graph_def,
option.input_nodes.keys(), option.input_nodes.keys(),
option.output_nodes.keys(), option.output_nodes.keys(),
TFTransformGraphOptions[ TFTransformGraphOptions)
option.device])
except Exception as ex: except Exception as ex:
print("Failed to transform graph using tf tool: %s" % ex) print("Failed to transform graph using tf tool: %s" % ex)
transformed_graph_def = tf_graph_def transformed_graph_def = tf_graph_def
......
...@@ -225,7 +225,8 @@ bool RunModel(const std::string &model_name, ...@@ -225,7 +225,8 @@ bool RunModel(const std::string &model_name,
const std::vector<DataFormat> &input_data_formats, const std::vector<DataFormat> &input_data_formats,
const std::vector<std::string> &output_names, const std::vector<std::string> &output_names,
const std::vector<std::vector<int64_t>> &output_shapes, const std::vector<std::vector<int64_t>> &output_shapes,
const std::vector<DataFormat> &output_data_formats) { const std::vector<DataFormat> &output_data_formats,
float cpu_capability) {
DeviceType device_type = ParseDeviceType(FLAGS_device); DeviceType device_type = ParseDeviceType(FLAGS_device);
int64_t t0 = NowMicros(); int64_t t0 = NowMicros();
...@@ -446,11 +447,11 @@ bool RunModel(const std::string &model_name, ...@@ -446,11 +447,11 @@ bool RunModel(const std::string &model_name,
} }
// Metrics reporting tools depends on the format, keep in consistent // Metrics reporting tools depends on the format, keep in consistent
printf("========================================\n"); printf("========================================================\n");
printf(" init warmup run_avg\n"); printf(" capability(CPU) init warmup run_avg\n");
printf("========================================\n"); printf("========================================================\n");
printf("time %11.3f %11.3f %11.3f\n", printf("time %15.3f %11.3f %11.3f %11.3f\n",
init_millis, warmup_millis, model_run_millis); cpu_capability, init_millis, warmup_millis, model_run_millis);
for (size_t i = 0; i < output_count; ++i) { for (size_t i = 0; i < output_count; ++i) {
...@@ -532,13 +533,16 @@ int Main(int argc, char **argv) { ...@@ -532,13 +533,16 @@ int Main(int argc, char **argv) {
} }
// get cpu capability
Capability cpu_capability = GetCapability(DeviceType::CPU);
bool ret = false; bool ret = false;
for (int i = 0; i < FLAGS_restart_round; ++i) { for (int i = 0; i < FLAGS_restart_round; ++i) {
VLOG(0) << "restart round " << i; VLOG(0) << "restart round " << i;
ret = ret = RunModel(FLAGS_model_name,
RunModel(FLAGS_model_name, input_names, input_shape_vec, input_data_formats,
input_names, input_shape_vec, input_data_formats, output_names, output_shape_vec, output_data_formats,
output_names, output_shape_vec, output_data_formats); cpu_capability.float32_performance.exec_time);
} }
if (ret) { if (ret) {
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册