diff --git a/mace/benchmark/BUILD b/mace/benchmark/BUILD index 70738ddcc0ed25e03f7637d6ed33101195d1cc4e..d38448ec5cea4381646d0e5fb57bfe4a4e411011 100644 --- a/mace/benchmark/BUILD +++ b/mace/benchmark/BUILD @@ -34,7 +34,7 @@ cc_binary( ":statistics", "//external:gflags_nothreads", "//mace/codegen:generated_models", - "//mace/codegen:generated_mace_engine_creator", + "//mace/codegen:generated_mace_engine_factory", ], ) diff --git a/mace/benchmark/benchmark_model.cc b/mace/benchmark/benchmark_model.cc index 9332727ebce6041666736369d0c63914e5de60c9..07a92d2efdd133ecb77c13b2297dac0ee5586e26 100644 --- a/mace/benchmark/benchmark_model.cc +++ b/mace/benchmark/benchmark_model.cc @@ -25,6 +25,7 @@ #include "mace/public/mace_runtime.h" #include "mace/utils/logging.h" #include "mace/benchmark/statistics.h" +#include "mace/codegen/engine/mace_engine_factory.h" namespace mace { namespace benchmark { @@ -174,7 +175,7 @@ bool Run(const std::string &title, return true; } -DEFINE_string(model_tag, "", "model tag"); +DEFINE_string(model_name, "", "model name in yaml"); DEFINE_string(device, "CPU", "Device [CPU|GPU|DSP]"); DEFINE_string(input_node, "input_node0,input_node1", "input nodes, separated by comma"); @@ -200,7 +201,7 @@ int Main(int argc, char **argv) { gflags::SetUsageMessage("some usage message"); gflags::ParseCommandLineFlags(&argc, &argv, true); - LOG(INFO) << "Model tag: [" << FLAGS_model_tag << "]"; + LOG(INFO) << "Model name: [" << FLAGS_model_name << "]"; LOG(INFO) << "Device: [" << FLAGS_device << "]"; LOG(INFO) << "gpu_perf_hint: [" << FLAGS_gpu_perf_hint << "]"; LOG(INFO) << "gpu_priority_hint: [" << FLAGS_gpu_priority_hint << "]"; @@ -254,22 +255,39 @@ int Main(int argc, char **argv) { } #endif // MACE_ENABLE_OPENCL - const char *kernel_path = getenv("MACE_CL_PROGRAM_PATH"); + const char *kernel_path = getenv("MACE_INTERNAL_STORAGE_PATH"); const std::string kernel_file_path = std::string(kernel_path == nullptr ? - "/data/local/tmp/mace_run/cl_program" : kernel_path); + "/data/local/tmp/mace_run/interior" : kernel_path); std::shared_ptr storage_factory( new FileStorageFactory(kernel_file_path)); SetKVStorageFactory(storage_factory); // Create Engine - std::unique_ptr engine_ptr = - CreateMaceEngine(FLAGS_model_tag, - input_names, - output_names, - FLAGS_model_data_file.c_str(), - device_type); + std::shared_ptr engine; + MaceStatus create_engine_status; + // Create Engine + if (FLAGS_model_data_file.empty()) { + create_engine_status = + CreateMaceEngine(FLAGS_model_name.c_str(), + nullptr, + input_names, + output_names, + device_type, + &engine); + } else { + create_engine_status = + CreateMaceEngine(FLAGS_model_name.c_str(), + FLAGS_model_data_file.c_str(), + input_names, + output_names, + device_type, + &engine); + } + if (create_engine_status != MaceStatus::MACE_SUCCESS) { + LOG(FATAL) << "Create engine error, please check the arguments"; + } std::map inputs; std::map outputs; @@ -309,7 +327,7 @@ int Main(int argc, char **argv) { int64_t num_warmup_runs = 0; if (FLAGS_warmup_runs > 0) { bool status = - Run("Warm Up", engine_ptr.get(), inputs, &outputs, + Run("Warm Up", engine.get(), inputs, &outputs, FLAGS_warmup_runs, -1.0, &warmup_time_us, &num_warmup_runs, nullptr); if (!status) { @@ -320,7 +338,7 @@ int Main(int argc, char **argv) { int64_t no_stat_time_us = 0; int64_t no_stat_runs = 0; bool status = - Run("Run without statistics", engine_ptr.get(), inputs, &outputs, + Run("Run without statistics", engine.get(), inputs, &outputs, FLAGS_max_num_runs, max_benchmark_time_seconds, &no_stat_time_us, &no_stat_runs, nullptr); if (!status) { @@ -329,7 +347,7 @@ int Main(int argc, char **argv) { int64_t stat_time_us = 0; int64_t stat_runs = 0; - status = Run("Run with statistics", engine_ptr.get(), inputs, &outputs, + status = Run("Run with statistics", engine.get(), inputs, &outputs, FLAGS_max_num_runs, max_benchmark_time_seconds, &stat_time_us, &stat_runs, statistician.get()); if (!status) { diff --git a/mace/codegen/BUILD b/mace/codegen/BUILD index fde3ebdde957c07129422709cc18c652bd19ae02..be0978a72ad03235e53ab7e176b34e5081583bf4 100644 --- a/mace/codegen/BUILD +++ b/mace/codegen/BUILD @@ -35,12 +35,9 @@ cc_library( ) cc_library( - name = "generated_mace_engine_creator", - srcs = ["engine/mace_engine_creator.cc"], - linkstatic = 1, + name = "generated_mace_engine_factory", + hdrs = ["engine/mace_engine_factory.h"], deps = [ - ":generated_models", "//mace/public", - "//mace/utils", ], ) diff --git a/mace/examples/BUILD b/mace/examples/BUILD index d572e11d319c3da42599055583ead80bd534e65e..0355575aed874fd7da507ef023a27a7de1e7429b 100644 --- a/mace/examples/BUILD +++ b/mace/examples/BUILD @@ -9,5 +9,6 @@ cc_binary( deps = [ "//external:gflags_nothreads", "//mace/codegen:generated_models", + "//mace/codegen:generated_mace_engine_factory", ], ) diff --git a/mace/examples/example.cc b/mace/examples/example.cc index 97520b15b63feba5e9e1be91bbb93bd96a7b9bde..d1beceb4b3f4f4c819252c519d9b83a57a9d62f7 100644 --- a/mace/examples/example.cc +++ b/mace/examples/example.cc @@ -34,6 +34,8 @@ #include "gflags/gflags.h" #include "mace/public/mace.h" #include "mace/public/mace_runtime.h" +// if convert model to code. +#include "mace/codegen/engine/mace_engine_factory.h" #include "mace/utils/env_time.h" #include "mace/utils/logging.h" @@ -94,9 +96,9 @@ DeviceType ParseDeviceType(const std::string &device_str) { } -DEFINE_string(model_tag, +DEFINE_string(model_name, "", - "model tag in yaml file"); + "model name in yaml file"); DEFINE_string(input_node, "input_node0,input_node1", "input nodes, separated by comma"); @@ -149,22 +151,38 @@ bool RunModel(const std::vector &input_names, // DO NOT USE tmp directory. // Please use APP's own directory and make sure the directory exists. // Just call once - const std::string kernel_file_path = - "/data/local/tmp/mace_run/cl"; + const std::string internal_storage_path = + "/data/local/tmp/mace_run/interior"; // Config internal kv storage factory. std::shared_ptr storage_factory( - new FileStorageFactory(kernel_file_path)); + new FileStorageFactory(internal_storage_path)); SetKVStorageFactory(storage_factory); // Create Engine - std::unique_ptr engine = - CreateMaceEngine(FLAGS_model_tag, - input_names, - output_names, - FLAGS_model_data_file.c_str(), - device_type); - + std::shared_ptr engine; + MaceStatus create_engine_status; + // Create Engine + if (FLAGS_model_data_file.empty()) { + create_engine_status = + CreateMaceEngine(FLAGS_model_name.c_str(), + nullptr, + input_names, + output_names, + device_type, + &engine); + } else { + create_engine_status = + CreateMaceEngine(FLAGS_model_name.c_str(), + FLAGS_model_data_file.c_str(), + input_names, + output_names, + device_type, + &engine); + } + if (create_engine_status != MaceStatus::MACE_SUCCESS) { + LOG(FATAL) << "Create engine error, please check the arguments"; + } const size_t input_count = input_names.size(); const size_t output_count = output_names.size(); diff --git a/mace/public/mace.h b/mace/public/mace.h index c2a387d0088a7add9ef257bc78ca1a8b3684a10e..02d903fd1a7a9f40395452e40ab91ef74b5ca9be 100644 --- a/mace/public/mace.h +++ b/mace/public/mace.h @@ -28,7 +28,7 @@ namespace mace { const char *MaceVersion(); -enum DeviceType { CPU = 0, GPU = 2, HEXAGON = 3, AUTO = 4 }; +enum DeviceType { CPU = 0, GPU = 2, HEXAGON = 3 }; enum MaceStatus { MACE_SUCCESS = 0, MACE_INVALID_ARGS = 1 }; @@ -82,13 +82,6 @@ class MaceEngine { MaceEngine &operator=(const MaceEngine &) = delete; }; -std::unique_ptr CreateMaceEngine( - const std::string &model_tag, - const std::vector &input_nodes, - const std::vector &output_nodes, - const char *model_data_file = nullptr, - const DeviceType device_type = DeviceType::AUTO); - } // namespace mace #endif // MACE_PUBLIC_MACE_H_ diff --git a/mace/python/tools/mace_engine_creator.jinja2 b/mace/python/tools/mace_engine_factory.h.jinja2 similarity index 84% rename from mace/python/tools/mace_engine_creator.jinja2 rename to mace/python/tools/mace_engine_factory.h.jinja2 index 9863b6bbd56eb3cf39e26c0310cf7db3319c4e6e..3b4994699ebe85e988f0909832a7e5bf37bafb09 100644 --- a/mace/python/tools/mace_engine_creator.jinja2 +++ b/mace/python/tools/mace_engine_factory.h.jinja2 @@ -21,7 +21,6 @@ #include "mace/public/mace.h" #include "mace/public/mace_runtime.h" -#include "mace/utils/logging.h" namespace mace { {% for tag in model_tags %} @@ -42,30 +41,33 @@ extern const std::string ModelBuildOptions(); {% endfor %} namespace { -std::map model_tag_map { +std::map model_name_map { {% for i in range(model_tags |length) %} std::make_pair({{ model_tags[i]|tojson }}, {{ i }}), {% endfor %} }; } // namespace -std::unique_ptr CreateMaceEngine( - const std::string &model_tag, +MaceStatus CreateMaceEngine( + const char *model_name, + const char *model_data_file, const std::vector &input_nodes, const std::vector &output_nodes, - const char *model_data_file, - const DeviceType device_type) { + const DeviceType device_type, + std::shared_ptr *engine) { // load model - std::unique_ptr engine; + if (engine == nullptr) { + return MaceStatus::MACE_INVALID_ARGS; + } const unsigned char * model_data = nullptr; NetDef net_def; - switch (model_tag_map[model_tag]) { + switch (model_name_map[model_name]) { {% for i in range(model_tags |length) %} case {{ i }}: model_data = mace::{{model_tags[i]}}::LoadModelData(model_data_file); net_def = mace::{{model_tags[i]}}::CreateNet(model_data); - engine.reset( + engine->reset( new mace::MaceEngine(&net_def, device_type, input_nodes, output_nodes)); if (device_type == DeviceType::GPU || device_type == DeviceType::HEXAGON) { mace::{{model_tags[i]}}::UnloadModelData(model_data); @@ -73,10 +75,10 @@ std::unique_ptr CreateMaceEngine( break; {% endfor %} default: - LOG(FATAL) << "There is no model named " << model_tag; + return MaceStatus::MACE_INVALID_ARGS; } - return engine; + return MaceStatus::MACE_SUCCESS; } } // namespace mace diff --git a/mace/python/tools/mace_engine_generator.py b/mace/python/tools/mace_engine_factory_codegen.py similarity index 89% rename from mace/python/tools/mace_engine_generator.py rename to mace/python/tools/mace_engine_factory_codegen.py index d2f85f4682fd78f12f34b887f1d1ef92d7a88bba..e74c0952e0583a5b9eab2c4404b339e5693d20c6 100644 --- a/mace/python/tools/mace_engine_generator.py +++ b/mace/python/tools/mace_engine_factory_codegen.py @@ -20,17 +20,17 @@ from jinja2 import Environment, FileSystemLoader FLAGS = None -def gen_mace_engine_creator(model_tags, template_dir, output_dir): +def gen_mace_engine_factory(model_tags, template_dir, output_dir): # Create the jinja2 environment. j2_env = Environment( loader=FileSystemLoader(template_dir), trim_blocks=True) # generate mace_run BUILD file print model_tags - template_name = 'mace_engine_creator.jinja2' + template_name = 'mace_engine_factory.h.jinja2' source = j2_env.get_template(template_name).render( model_tags=model_tags, ) - with open(output_dir + '/mace_engine_creator.cc', "wb") as f: + with open(output_dir + '/mace_engine_factory.h', "wb") as f: f.write(source) diff --git a/mace/tools/validation/BUILD b/mace/tools/validation/BUILD index 7282155ec1749283368ed4a75c5e03bee8550735..0406c7e0bc06b9bfecd60b19e4609c9b2f754211 100644 --- a/mace/tools/validation/BUILD +++ b/mace/tools/validation/BUILD @@ -10,7 +10,7 @@ cc_binary( deps = [ "//external:gflags_nothreads", "//mace/codegen:generated_models", - "//mace/codegen:generated_mace_engine_creator", + "//mace/codegen:generated_mace_engine_factory", "//mace/core:core", ], ) diff --git a/mace/tools/validation/mace_run.cc b/mace/tools/validation/mace_run.cc index a1583ee02150a53b0f172f065f5c62cfd6717010..0fa474a24caa0744dd4a5e0545c5dbacdcb4d797 100644 --- a/mace/tools/validation/mace_run.cc +++ b/mace/tools/validation/mace_run.cc @@ -41,6 +41,7 @@ #ifdef MACE_ENABLE_OPENCL #include "mace/core/runtime/opencl/opencl_runtime.h" #endif // MACE_ENABLE_OPENCL +#include "mace/codegen/engine/mace_engine_factory.h" namespace mace { namespace tools { @@ -162,9 +163,9 @@ struct mallinfo LogMallinfoChange(struct mallinfo prev) { return curr; } -DEFINE_string(model_tag, +DEFINE_string(model_name, "", - "model tag in yaml"); + "model name in yaml"); DEFINE_string(input_node, "input_node0,input_node1", "input nodes, separated by comma"); @@ -196,7 +197,7 @@ DEFINE_int32(omp_num_threads, -1, "num of openmp threads"); DEFINE_int32(cpu_affinity_policy, 1, "0:AFFINITY_NONE/1:AFFINITY_BIG_ONLY/2:AFFINITY_LITTLE_ONLY"); -bool RunModel(const std::string &model_tag, +bool RunModel(const std::string &model_name, const std::vector &input_names, const std::vector> &input_shapes, const std::vector &output_names, @@ -214,24 +215,42 @@ bool RunModel(const std::string &model_tag, } #endif // MACE_ENABLE_OPENCL - const char *kernel_path = getenv("MACE_CL_PROGRAM_PATH"); + const char *kernel_path = getenv("MACE_INTERNAL_STORAGE_PATH"); const std::string kernel_file_path = std::string(kernel_path == nullptr ? - "/data/local/tmp/mace_run/cl_program" : kernel_path); + "/data/local/tmp/mace_run/interior" : kernel_path); std::shared_ptr storage_factory( new FileStorageFactory(kernel_file_path)); SetKVStorageFactory(storage_factory); + std::shared_ptr engine; + MaceStatus create_engine_status; // Create Engine int64_t t0 = NowMicros(); - std::unique_ptr engine = - CreateMaceEngine(model_tag, - input_names, - output_names, - FLAGS_model_data_file.c_str(), - device_type); + if (FLAGS_model_data_file.empty()) { + create_engine_status = + CreateMaceEngine(model_name.c_str(), + nullptr, + input_names, + output_names, + device_type, + &engine); + } else { + create_engine_status = + CreateMaceEngine(model_name.c_str(), + FLAGS_model_data_file.c_str(), + input_names, + output_names, + device_type, + &engine); + } int64_t t1 = NowMicros(); + + if (create_engine_status != MaceStatus::MACE_SUCCESS) { + LOG(FATAL) << "Create engine error, please check the arguments"; + } + double init_millis = (t1 - t0) / 1000.0; LOG(INFO) << "Total init latency: " << init_millis << " ms"; @@ -330,6 +349,7 @@ int Main(int argc, char **argv) { gflags::SetUsageMessage("some usage message"); gflags::ParseCommandLineFlags(&argc, &argv, true); + LOG(INFO) << "model name: " << FLAGS_model_name; LOG(INFO) << "mace version: " << MaceVersion(); LOG(INFO) << "input node: " << FLAGS_input_node; LOG(INFO) << "input shape: " << FLAGS_input_shape; @@ -370,7 +390,7 @@ int Main(int argc, char **argv) { for (int i = 0; i < FLAGS_restart_round; ++i) { VLOG(0) << "restart round " << i; ret = - RunModel(FLAGS_model_tag, input_names, input_shape_vec, + RunModel(FLAGS_model_name, input_names, input_shape_vec, output_names, output_shape_vec); } if (ret) { diff --git a/tools/mace_tools.py b/tools/mace_tools.py index 24ebabfb5ce5e6322cd2ac18b8bc6db5ba1dc617..f8a603fb08872d4f19bd8f6885feb18f585aa166 100644 --- a/tools/mace_tools.py +++ b/tools/mace_tools.py @@ -115,16 +115,14 @@ def model_benchmark_stdout_processor(stdout, serialno, model_name, runtime): - metrics = [0] * 5 + metrics = [0] * 3 for line in stdout.split('\n'): line = line.strip() parts = line.split() - if len(parts) == 6 and parts[0].startswith("time"): + if len(parts) == 4 and parts[0].startswith("time"): metrics[0] = str(float(parts[1])) metrics[1] = str(float(parts[2])) metrics[2] = str(float(parts[3])) - metrics[3] = str(float(parts[4])) - metrics[4] = str(float(parts[5])) break device_name = "" @@ -137,22 +135,20 @@ def model_benchmark_stdout_processor(stdout, report_filename = FLAGS.output_dir + "/report.csv" if not os.path.exists(report_filename): with open(report_filename, 'w') as f: - f.write("model_name,device_name,soc,abi,runtime,create_net," - "engine_ctor,init,warmup,run_avg\n") + f.write("model_name,device_name,soc,abi,runtime," + "init,warmup,run_avg\n") data_str = "{model_name},{device_name},{soc},{abi},{runtime}," \ - "{create_net},{engine_ctor},{init},{warmup},{run_avg}\n" \ + "{init},{warmup},{run_avg}\n" \ .format( model_name=model_name, device_name=device_name, soc=target_soc, abi=abi, runtime=runtime, - create_net=metrics[0], - engine_ctor=metrics[1], - init=metrics[2], - warmup=metrics[3], - run_avg=metrics[4] + init=metrics[0], + warmup=metrics[1], + run_avg=metrics[2] ) with open(report_filename, 'a') as f: f.write(data_str) @@ -300,22 +296,36 @@ def merge_libs_and_tuning_results(target_soc, embed_model_data) -def get_model_files(model_file_path, - model_output_dir, - weight_file_path=""): +def download_model_files(model_file_path, + model_output_dir, + weight_file_path=""): model_file = "" weight_file = "" if model_file_path.startswith("http://") or \ model_file_path.startswith("https://"): model_file = model_output_dir + "/model.pb" urllib.urlretrieve(model_file_path, model_file) + + if weight_file_path.startswith("http://") or \ + weight_file_path.startswith("https://"): + weight_file = model_output_dir + "/model.caffemodel" + urllib.urlretrieve(weight_file_path, weight_file) + + +def get_model_files_path(model_file_path, + model_output_dir, + weight_file_path=""): + model_file = "" + weight_file = "" + if model_file_path.startswith("http://") or \ + model_file_path.startswith("https://"): + model_file = model_output_dir + "/model.pb" else: model_file = model_file_path if weight_file_path.startswith("http://") or \ weight_file_path.startswith("https://"): weight_file = model_output_dir + "/model.caffemodel" - urllib.urlretrieve(weight_file_path, weight_file) else: weight_file = weight_file_path @@ -547,6 +557,8 @@ def process_models(project_name, configs, embed_model_data, vlog_level, model_output_dir = "%s/%s_%s/%s" % ( model_output_base_dir, device_name.replace(' ', ''), target_soc, target_abi) + sh_commands.clear_phone_data_dir(serialno, phone_data_dir) + model_output_dirs.append(model_output_dir) if FLAGS.mode == "build" or FLAGS.mode == "all": @@ -554,14 +566,11 @@ def process_models(project_name, configs, embed_model_data, vlog_level, sh.rm("-rf", model_output_dir) os.makedirs(model_output_dir) - model_file_path, weight_file_path = get_model_files( + model_file_path, weight_file_path = get_model_files_path( model_config["model_file_path"], model_output_base_dir, model_config["weight_file_path"]) - sh_commands.clear_phone_data_dir( - target_abi, serialno, phone_data_dir) - if FLAGS.mode == "build" or FLAGS.mode == "run" or \ FLAGS.mode == "validate" or \ FLAGS.mode == "benchmark" or FLAGS.mode == "all": @@ -723,7 +732,7 @@ def main(unused_args): # generate source sh_commands.gen_mace_version() sh_commands.gen_encrypted_opencl_source() - sh_commands.gen_mace_engine_creator_source(configs['models'].keys()) + sh_commands.gen_mace_engine_factory_source(configs['models'].keys()) embed_model_data = configs["embed_model_data"] target_socs = get_target_socs(configs) @@ -751,7 +760,12 @@ def main(unused_args): sh.rm("-rf", model_output_base_dir) os.makedirs(model_output_base_dir) - model_file_path, weight_file_path = get_model_files( + download_model_files( + model_config["model_file_path"], + model_output_base_dir, + model_config["weight_file_path"]) + + model_file_path, weight_file_path = get_model_files_path( model_config["model_file_path"], model_output_base_dir, model_config["weight_file_path"]) diff --git a/tools/sh_commands.py b/tools/sh_commands.py index 97c89ea8febed85b5ece2ba453d41d02d49b9e52..7eda49f7a1ead279c56615ba60b963dd9e1fb8ad 100644 --- a/tools/sh_commands.py +++ b/tools/sh_commands.py @@ -33,7 +33,7 @@ try: from binary_codegen import tuning_param_codegen from generate_data import generate_input_data from validate import validate - from mace_engine_generator import gen_mace_engine_creator + from mace_engine_factory_codegen import gen_mace_engine_factory except Exception as e: print("Import error:\n%s" % e) exit(1) @@ -75,12 +75,11 @@ def is_device_locked(serialno): ################################ # clear data ################################ -def clear_phone_data_dir(abi, serialno, phone_data_dir): - if abi != "host": - sh.adb("-s", - serialno, - "shell", - "rm -rf %s" % phone_data_dir) +def clear_phone_data_dir(serialno, phone_data_dir): + sh.adb("-s", + serialno, + "shell", + "rm -rf %s" % phone_data_dir) def clear_model_codegen(model_codegen_dir="mace/codegen/models"): @@ -369,12 +368,12 @@ def gen_encrypted_opencl_source(codegen_path="mace/codegen"): "mace/codegen/opencl/opencl_encrypt_program.cc") -def gen_mace_engine_creator_source(model_tags, codegen_path="mace/codegen"): +def gen_mace_engine_factory_source(model_tags, codegen_path="mace/codegen"): print("* Genearte mace engine creator source") codegen_tools_dir = "%s/engine" % codegen_path sh.rm("-rf", codegen_tools_dir) sh.mkdir("-p", codegen_tools_dir) - gen_mace_engine_creator( + gen_mace_engine_factory( model_tags, "mace/python/tools", codegen_tools_dir) @@ -384,7 +383,7 @@ def gen_mace_engine_creator_source(model_tags, codegen_path="mace/codegen"): def pull_binaries(abi, serialno, model_output_dirs, cl_built_kernel_file_name, cl_platform_info_file_name): - compiled_opencl_dir = "/data/local/tmp/mace_run/cl_program/" + compiled_opencl_dir = "/data/local/tmp/mace_run/interior/" mace_run_param_file = "mace_run.config" cl_bin_dirs = [] @@ -558,9 +557,10 @@ def update_mace_run_lib(model_output_dir, model_output_dir) -def create_compiled_opencl_dir(serialno): - compiled_opencl_dir = "/data/local/tmp/mace_run/cl_program/" - sh.adb("-s", serialno, "shell", "mkdir", "-p", compiled_opencl_dir) +def create_internal_storage_dir(serialno, phone_data_dir): + internal_storage_dir = "%s/interior/" % phone_data_dir + sh.adb("-s", serialno, "shell", "mkdir", "-p", internal_storage_dir) + return internal_storage_dir def tuning_run(abi, @@ -601,7 +601,7 @@ def tuning_run(abi, "env", "MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level, "%s/mace_run" % model_output_dir, - "--model_tag=%s" % model_tag, + "--model_name=%s" % model_tag, "--input_node=%s" % ",".join(input_nodes), "--output_node=%s" % ",".join(output_nodes), "--input_shape=%s" % ":".join(input_shapes), @@ -626,7 +626,8 @@ def tuning_run(abi, return stdout else: sh.adb("-s", serialno, "shell", "mkdir", "-p", phone_data_dir) - create_compiled_opencl_dir(serialno) + internal_storage_dir = create_internal_storage_dir( + serialno, phone_data_dir) for input_name in input_nodes: formatted_name = common.formatted_file_name(input_file_name, @@ -649,7 +650,7 @@ def tuning_run(abi, "MACE_OUT_OF_RANGE_CHECK=%s" % int(out_of_range_check), "MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level, "MACE_RUN_PARAMETER_PATH=%s/mace_run.config" % phone_data_dir, - "MACE_CL_PROGRAM_PATH=%s/cl_program" % phone_data_dir, + "MACE_INTERNAL_STORAGE_PATH=%s" % internal_storage_dir, "MACE_LIMIT_OPENCL_KERNEL_TIME=%s" % limit_opencl_kernel_time, ] if valgrind: @@ -660,7 +661,7 @@ def tuning_run(abi, ]) adb_cmd.extend([ "%s/mace_run" % phone_data_dir, - "--model_tag=%s" % model_tag, + "--model_name=%s" % model_tag, "--input_node=%s" % ",".join(input_nodes), "--output_node=%s" % ",".join(output_nodes), "--input_shape=%s" % ":".join(input_shapes), @@ -840,16 +841,18 @@ def merge_libs(target_soc, if hexagon_mode: sh.cp("-f", hexagon_lib_file, model_bin_dir) + sh.cp("-f", glob.glob("mace/codegen/engine/*.h"), model_header_dir) + mri_stream = "" if abi == "host": mri_stream += "create %s/libmace_%s.a\n" % \ (model_bin_dir, project_name) mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_opencl.pic.a\n") + "addlib " + "bazel-bin/mace/codegen/libgenerated_opencl.pic.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_tuning_params.pic.a\n") + "addlib " + "bazel-bin/mace/codegen/libgenerated_tuning_params.pic.a\n") mri_stream += ( "addlib " "bazel-bin/mace/codegen/libgenerated_models.pic.a\n") @@ -860,35 +863,35 @@ def merge_libs(target_soc, mri_stream += "create %s/libmace_%s.%s.a\n" % \ (model_bin_dir, project_name, target_soc) mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_opencl.a\n") + "addlib " + "bazel-bin/mace/codegen/libgenerated_opencl.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_tuning_params.a\n") + "addlib " + "bazel-bin/mace/codegen/libgenerated_tuning_params.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_version.a\n") + "addlib " + "bazel-bin/mace/codegen/libgenerated_version.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_models.a\n") + "addlib " + "bazel-bin/mace/codegen/libgenerated_models.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_mace_engine_creator.a\n") + "addlib " + "bazel-bin/mace/codegen/libgenerated_mace_engine_creator.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/core/libcore.a\n") + "addlib " + "bazel-bin/mace/core/libcore.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/kernels/libkernels.a\n") + "addlib " + "bazel-bin/mace/kernels/libkernels.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/utils/libutils.a\n") + "addlib " + "bazel-bin/mace/utils/libutils.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/utils/libutils_prod.a\n") + "addlib " + "bazel-bin/mace/utils/libutils_prod.a\n") mri_stream += ( - "addlib " - "bazel-bin/mace/ops/libops.lo\n") + "addlib " + "bazel-bin/mace/ops/libops.lo\n") for model_output_dir in model_output_dirs: if not embed_model_data: @@ -984,7 +987,7 @@ def benchmark_model(abi, "env", "MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level, "%s/benchmark_model" % model_output_dir, - "--model_tag=%s" % model_tag, + "--model_name=%s" % model_tag, "--input_node=%s" % ",".join(input_nodes), "--output_node=%s" % ",".join(output_nodes), "--input_shape=%s" % ":".join(input_shapes), @@ -1000,7 +1003,8 @@ def benchmark_model(abi, p.wait() else: sh.adb("-s", serialno, "shell", "mkdir", "-p", phone_data_dir) - create_compiled_opencl_dir(serialno) + internal_storage_dir = create_internal_storage_dir( + serialno, phone_data_dir) for input_name in input_nodes: formatted_name = common.formatted_file_name(input_file_name, @@ -1020,9 +1024,10 @@ def benchmark_model(abi, "MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level, "MACE_RUN_PARAMETER_PATH=%s/mace_run.config" % phone_data_dir, + "MACE_INTERNAL_STORAGE_PATH=%s" % internal_storage_dir, "MACE_OPENCL_PROFILING=1", "%s/benchmark_model" % phone_data_dir, - "--model_tag=%s" % model_tag, + "--model_name=%s" % model_tag, "--input_node=%s" % ",".join(input_nodes), "--output_node=%s" % ",".join(output_nodes), "--input_shape=%s" % ":".join(input_shapes),