diff --git a/mace/benchmark/benchmark_model.cc b/mace/benchmark/benchmark_model.cc index df6e9dbca12184e448e7f315f1d6f13ea3bfca98..c83812df4a3e31a8c357ad9009bbe188bc257d9a 100644 --- a/mace/benchmark/benchmark_model.cc +++ b/mace/benchmark/benchmark_model.cc @@ -280,16 +280,15 @@ int Main(int argc, char **argv) { LOG(FATAL) << "Failed to read file: " << FLAGS_model_file; } create_engine_status = - CreateMaceEngine(FLAGS_model_name.c_str(), - model_data_file_ptr, - input_names, - output_names, - device_type, - &engine, - model_pb_data); + CreateMaceEngineFromPB(model_data_file_ptr, + input_names, + output_names, + device_type, + &engine, + model_pb_data); } else { create_engine_status = - CreateMaceEngine(FLAGS_model_name.c_str(), + CreateMaceEngine(FLAGS_model_name, model_data_file_ptr, input_names, output_names, diff --git a/mace/core/mace.cc b/mace/core/mace.cc index 82118fb66bb0c365b2ab25f53ba04a23c5210f16..ac97fe48795f0e79348b80d8f230ec0c61fa2262 100644 --- a/mace/core/mace.cc +++ b/mace/core/mace.cc @@ -12,12 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include +#include #include +#include +#include +#include #include "mace/core/net.h" #include "mace/core/types.h" #include "mace/public/mace.h" + + #ifdef MACE_ENABLE_OPENCL #include "mace/core/runtime/opencl/opencl_runtime.h" #endif // MACE_ENABLE_OPENCL @@ -269,4 +276,58 @@ MaceStatus MaceEngine::Run(const std::map &inputs, return impl_->Run(inputs, outputs, nullptr); } +namespace { +const unsigned char *LoadModelData(const char *model_data_file) { + int fd = open(model_data_file, O_RDONLY); + MACE_CHECK(fd >= 0, "Failed to open model data file ", + model_data_file, ", error code: ", errno); + + const unsigned char *model_data = + static_cast(mmap(nullptr, 2453764, + PROT_READ, MAP_PRIVATE, fd, 0)); + MACE_CHECK(model_data != MAP_FAILED, "Failed to map model data file ", + model_data_file, ", error code: ", errno); + + int ret = close(fd); + MACE_CHECK(ret == 0, "Failed to close model data file ", + model_data_file, ", error code: ", errno); + + return model_data; +} + +void UnloadModelData(const unsigned char *model_data) { + int ret = munmap(const_cast(model_data), + 2453764); + MACE_CHECK(ret == 0, "Failed to unmap model data file, error code: ", errno); +} +} // namespace + +MaceStatus CreateMaceEngineFromPB(const char *model_data_file, + const std::vector &input_nodes, + const std::vector &output_nodes, + const DeviceType device_type, + std::shared_ptr *engine, + const std::vector model_pb) { + LOG(INFO) << "Create MaceEngine from model pb"; + // load model + if (engine == nullptr) { + return MaceStatus::MACE_INVALID_ARGS; + } + + const unsigned char * model_data = nullptr; + model_data = LoadModelData(model_data_file); + + NetDef net_def; + net_def.ParseFromArray(&model_pb[0], model_pb.size()); + + engine->reset( + new mace::MaceEngine(&net_def, device_type, input_nodes, output_nodes, + model_data)); + + if (device_type == DeviceType::GPU || device_type == DeviceType::HEXAGON) { + UnloadModelData(model_data); + } + return MACE_SUCCESS; +} + } // namespace mace diff --git a/mace/core/operator.h b/mace/core/operator.h index e329c8acd793096360ce5ef5332516dc666e740b..11b1f88981a35ad1b9d0233b21b5554c3940a61f 100644 --- a/mace/core/operator.h +++ b/mace/core/operator.h @@ -108,7 +108,7 @@ class Operator : public OperatorBase { inputs_.push_back(tensor); } - for (size_t i = 0; i < (size_t)operator_def.output_size(); ++i) { + for (int i = 0; i < operator_def.output_size(); ++i) { const std::string output_str = operator_def.output(i); if (ws->HasTensor(output_str)) { outputs_.push_back(ws->GetTensor(output_str)); @@ -120,7 +120,7 @@ class Operator : public OperatorBase { operator_def.output_size(), operator_def.output_type_size()); DataType output_type; - if (i < (size_t)operator_def.output_type_size()) { + if (i < operator_def.output_type_size()) { output_type = operator_def.output_type(i); } else { output_type = DataTypeToEnum::v(); diff --git a/mace/core/runtime/hexagon/hexagon_control_wrapper.cc b/mace/core/runtime/hexagon/hexagon_control_wrapper.cc index 8c06ab3a2c252a9cabe20e0438624319fdeb11d0..7293a0aa42c5079f466a24343ed0c03ae76bd020 100644 --- a/mace/core/runtime/hexagon/hexagon_control_wrapper.cc +++ b/mace/core/runtime/hexagon/hexagon_control_wrapper.cc @@ -134,12 +134,12 @@ bool HexagonControlWrapper::SetupGraph(const NetDef &net_def, for (const OperatorDef &op : net_def.op()) { int op_id = op_map.GetOpId(op.type()); inputs.resize(op.node_input().size()); - for (size_t i = 0; i < (size_t)op.node_input().size(); ++i) { + for (int i = 0; i < op.node_input().size(); ++i) { inputs[i].src_id = node_id(op.node_input()[i].node_id()); inputs[i].output_idx = op.node_input()[i].output_port(); } outputs.resize(op.out_max_byte_size().size()); - for (size_t i = 0; i < (size_t)op.out_max_byte_size().size(); ++i) { + for (int i = 0; i < op.out_max_byte_size().size(); ++i) { outputs[i].max_size = op.out_max_byte_size()[i]; } cached_inputs.push_back(inputs); diff --git a/mace/examples/example.cc b/mace/examples/example.cc index d1beceb4b3f4f4c819252c519d9b83a57a9d62f7..6c4fce304d10737bbfa48a5141a392ef115d759f 100644 --- a/mace/examples/example.cc +++ b/mace/examples/example.cc @@ -120,6 +120,9 @@ DEFINE_string(output_file, DEFINE_string(model_data_file, "", "model data file name, used when EMBED_MODEL_DATA set to 0"); +DEFINE_string(model_file, + "", + "model file name, used when load mace model in pb"); DEFINE_string(device, "GPU", "CPU/GPU/HEXAGON"); DEFINE_int32(round, 1, "round"); DEFINE_int32(restart_round, 1, "restart round"); @@ -163,23 +166,33 @@ bool RunModel(const std::vector &input_names, std::shared_ptr engine; MaceStatus create_engine_status; // Create Engine - if (FLAGS_model_data_file.empty()) { + MaceStatus create_engine_status; + // Create Engine + int64_t t0 = NowMicros(); + const char *model_data_file_ptr = + FLAGS_model_data_file.empty() ? nullptr : FLAGS_model_data_file.c_str(); + if (FLAGS_model_file != "") { + std::vector model_pb_data; + if (!mace::ReadBinaryFile(&model_pb_data, FLAGS_model_file)) { + LOG(FATAL) << "Failed to read file: " << FLAGS_model_file; + } create_engine_status = - CreateMaceEngine(FLAGS_model_name.c_str(), - nullptr, - input_names, - output_names, - device_type, - &engine); + CreateMaceEngineFromPB(model_data_file_ptr, + input_names, + output_names, + device_type, + &engine, + model_pb_data); } else { create_engine_status = - CreateMaceEngine(FLAGS_model_name.c_str(), - FLAGS_model_data_file.c_str(), + CreateMaceEngine(model_name, + model_data_file_ptr, input_names, output_names, device_type, &engine); } + if (create_engine_status != MaceStatus::MACE_SUCCESS) { LOG(FATAL) << "Create engine error, please check the arguments"; } @@ -258,6 +271,7 @@ int Main(int argc, char **argv) { LOG(INFO) << "input_file: " << FLAGS_input_file; LOG(INFO) << "output_file: " << FLAGS_output_file; LOG(INFO) << "model_data_file: " << FLAGS_model_data_file; + LOG(INFO) << "model_file: " << FLAGS_model_file; LOG(INFO) << "device: " << FLAGS_device; LOG(INFO) << "round: " << FLAGS_round; LOG(INFO) << "restart_round: " << FLAGS_restart_round; diff --git a/mace/public/mace.h b/mace/public/mace.h index 68f24dca1a44b1cc3e00c653c4ff52505dd5587f..7b238aa2fb8359e138a6cb30ebdf0efe23382e32 100644 --- a/mace/public/mace.h +++ b/mace/public/mace.h @@ -56,8 +56,6 @@ class RunMetadata { const char *MaceVersion(); -// enum DeviceType { CPU = 0, GPU = 2, HEXAGON = 3 }; - enum MaceStatus { MACE_SUCCESS = 0, MACE_INVALID_ARGS = 1 }; // MACE input/output tensor @@ -108,6 +106,13 @@ class MaceEngine { MaceEngine &operator=(const MaceEngine &) = delete; }; +MaceStatus CreateMaceEngineFromPB(const char *model_data_file, + const std::vector &input_nodes, + const std::vector &output_nodes, + const DeviceType device_type, + std::shared_ptr *engine, + const std::vector model_pb); + } // namespace mace #endif // MACE_PUBLIC_MACE_H_ diff --git a/mace/python/tools/mace_engine_factory.h.jinja2 b/mace/python/tools/mace_engine_factory.h.jinja2 index d9eea4ca8d27d227904f2fa10c869136c2867d41..1042f6975e27edeb93aab1ebe71ea6c3c4fe8f46 100644 --- a/mace/python/tools/mace_engine_factory.h.jinja2 +++ b/mace/python/tools/mace_engine_factory.h.jinja2 @@ -19,11 +19,13 @@ #include #include +#include "mace/core/macros.h" #include "mace/public/mace.h" #include "mace/public/mace_runtime.h" namespace mace { +{% if model_type == 'source' %} {% for tag in model_tags %} namespace {{tag}} { @@ -50,13 +52,12 @@ std::map model_name_map { } // namespace MaceStatus CreateMaceEngine( - const char *model_name, + const std::string &model_name, const char *model_data_file, const std::vector &input_nodes, const std::vector &output_nodes, const DeviceType device_type, - std::shared_ptr *engine, - const std::vector model_pb = {}) { + std::shared_ptr *engine) { // load model if (engine == nullptr) { return MaceStatus::MACE_INVALID_ARGS; @@ -68,7 +69,7 @@ MaceStatus CreateMaceEngine( case {{ i }}: model_data = mace::{{model_tags[i]}}::LoadModelData(model_data_file); - net_def = mace::{{model_tags[i]}}::CreateNet(model_pb); + net_def = mace::{{model_tags[i]}}::CreateNet(); engine->reset( new mace::MaceEngine(&net_def, device_type, input_nodes, output_nodes, @@ -84,5 +85,22 @@ MaceStatus CreateMaceEngine( return MaceStatus::MACE_SUCCESS; } +{% else %} +MaceStatus CreateMaceEngine( + const std::string &model_name, + const char *model_data_file, + const std::vector &input_nodes, + const std::vector &output_nodes, + const DeviceType device_type, + std::shared_ptr *engine) { + MACE_UNUSED(model_name); + MACE_UNUSED(model_data_file); + MACE_UNUSED(input_nodes); + MACE_UNUSED(output_nodes); + MACE_UNUSED(device_type); + MACE_UNUSED(engine); + return MaceStatus::MACE_INVALID_ARGS; +} +{% endif %} } // namespace mace diff --git a/mace/python/tools/mace_engine_factory_codegen.py b/mace/python/tools/mace_engine_factory_codegen.py index 1111eb329c7219600a8b234ab0673d8fed06c34d..c744069a5db3209006b89dd88403effa24d6182f 100644 --- a/mace/python/tools/mace_engine_factory_codegen.py +++ b/mace/python/tools/mace_engine_factory_codegen.py @@ -20,7 +20,7 @@ from jinja2 import Environment, FileSystemLoader FLAGS = None -def gen_mace_engine_factory(model_tags, template_dir, output_dir): +def gen_mace_engine_factory(model_tags, template_dir, model_type, output_dir): # Create the jinja2 environment. j2_env = Environment( loader=FileSystemLoader(template_dir), trim_blocks=True) @@ -29,6 +29,7 @@ def gen_mace_engine_factory(model_tags, template_dir, output_dir): template_name = 'mace_engine_factory.h.jinja2' source = j2_env.get_template(template_name).render( model_tags=model_tags, + model_type=model_type, ) with open(output_dir + '/mace_engine_factory.h', "wb") as f: f.write(source) @@ -46,10 +47,15 @@ def parse_args(): "--template_dir", type=str, default="", help="template path") parser.add_argument( "--output_dir", type=str, default="", help="output path") + parser.add_argument( + "--model_type", + type=str, + default="", + help="[source|pb] model load type") return parser.parse_known_args() if __name__ == '__main__': FLAGS, unparsed = parse_args() gen_mace_engine_creator(FLAGS.model_tag, FLAGS.template_dir, - FLAGS.output_dir) + FLAGS.model_type, FLAGS.output_dir) diff --git a/mace/python/tools/source_converter_lib.py b/mace/python/tools/source_converter_lib.py index 65989940d56dc3c708a994fc86a2e3a7ee5555c1..81ebef0de513724e6fdb39df470e880b32f62539 100644 --- a/mace/python/tools/source_converter_lib.py +++ b/mace/python/tools/source_converter_lib.py @@ -184,20 +184,21 @@ def convert_to_source(net_def, model_checksum, weight_checksum, template_dir, model_data.extend(tensor_info.data) offset += len(tensor_info.data) - # generate tensor data - template_name = 'tensor_data.jinja2' - source = j2_env.get_template(template_name).render( - tag=model_tag, - embed_model_data=embed_model_data, - model_data_size=offset, - model_data=model_data) - with open(output_dir + 'tensor_data' + '.cc', "wb") as f: - f.write(source) if not embed_model_data: with open(output_dir + model_tag + '.data', "wb") as f: f.write(bytearray(model_data)) if model_load_type == 'source': + # generate tensor data + template_name = 'tensor_data.jinja2' + source = j2_env.get_template(template_name).render( + tag=model_tag, + embed_model_data=embed_model_data, + model_data_size=offset, + model_data=model_data) + with open(output_dir + 'tensor_data' + '.cc', "wb") as f: + f.write(source) + # generate op source files template_name = 'operator.jinja2' counter = 0 @@ -214,35 +215,35 @@ def convert_to_source(net_def, model_checksum, weight_checksum, template_dir, f.write(source) counter += 1 - # generate model source files - build_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') - template_name = 'model.jinja2' - tensors = [ - TensorInfo(i, net_def.tensors[i], runtime) - for i in range(len(net_def.tensors)) - ] - checksum = model_checksum - if weight_checksum is not None: - checksum = "{},{}".format(model_checksum, weight_checksum) - source = j2_env.get_template(template_name).render( - tensors=tensors, - net=net_def, - tag=model_tag, - runtime=runtime, - obfuscate=obfuscate, - embed_model_data=embed_model_data, - winograd_conv=winograd_conv, - checksum=checksum, - build_time=build_time, - model_type=model_load_type) - with open(output, "wb") as f: - f.write(source) - - # generate model header file - template_name = 'model_header.jinja2' - source = j2_env.get_template(template_name).render(tag=model_tag, ) - with open(output_dir + model_tag + '.h', "wb") as f: - f.write(source) + # generate model source files + build_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + template_name = 'model.jinja2' + tensors = [ + TensorInfo(i, net_def.tensors[i], runtime) + for i in range(len(net_def.tensors)) + ] + checksum = model_checksum + if weight_checksum is not None: + checksum = "{},{}".format(model_checksum, weight_checksum) + source = j2_env.get_template(template_name).render( + tensors=tensors, + net=net_def, + tag=model_tag, + runtime=runtime, + obfuscate=obfuscate, + embed_model_data=embed_model_data, + winograd_conv=winograd_conv, + checksum=checksum, + build_time=build_time, + model_type=model_load_type) + with open(output, "wb") as f: + f.write(source) + + # generate model header file + template_name = 'model_header.jinja2' + source = j2_env.get_template(template_name).render(tag=model_tag, ) + with open(output_dir + model_tag + '.h', "wb") as f: + f.write(source) for t in net_def.tensors: if t.data_type == mace_pb2.DT_FLOAT: diff --git a/mace/tools/validation/mace_run.cc b/mace/tools/validation/mace_run.cc index fb40ffd3bf348fe6225d2c3245294b1646d27caf..553647f8821e84a52fafd37a5cb37769b7b3e54d 100644 --- a/mace/tools/validation/mace_run.cc +++ b/mace/tools/validation/mace_run.cc @@ -239,16 +239,15 @@ bool RunModel(const std::string &model_name, LOG(FATAL) << "Failed to read file: " << FLAGS_model_file; } create_engine_status = - CreateMaceEngine(model_name.c_str(), - model_data_file_ptr, - input_names, - output_names, - device_type, - &engine, - model_pb_data); + CreateMaceEngineFromPB(model_data_file_ptr, + input_names, + output_names, + device_type, + &engine, + model_pb_data); } else { create_engine_status = - CreateMaceEngine(model_name.c_str(), + CreateMaceEngine(model_name, model_data_file_ptr, input_names, output_names, diff --git a/tools/mace_tools.py b/tools/mace_tools.py index b160084eb9e1e0eeb3bf2410a6b3dc0b91e1bbf5..c68ea22532d00da22de0aaca6dcfa7953112fd7d 100644 --- a/tools/mace_tools.py +++ b/tools/mace_tools.py @@ -205,8 +205,8 @@ def tuning_run(target_abi, stdout, target_abi, serialno, model_name, device_type) -def build_mace_run_prod(hexagon_mode, runtime, target_abi, - serialno, vlog_level, embed_model_data, +def build_mace_run_prod(hexagon_mode, runtime, target_abi, serialno, + vlog_level, embed_model_data, model_load_type, model_output_dir, input_nodes, output_nodes, input_shapes, output_shapes, mace_model_dir, model_name, device_type, running_round, restart_round, @@ -228,7 +228,7 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi, hexagon_mode=hexagon_mode, enable_openmp=enable_openmp ) - sh_commands.update_mace_run_lib(model_output_dir, + sh_commands.update_mace_run_lib(model_output_dir, model_load_type, model_name, embed_model_data) device_type = parse_device_type("gpu") @@ -250,7 +250,7 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi, debug=debug, enable_openmp=enable_openmp ) - sh_commands.update_mace_run_lib(model_output_dir, + sh_commands.update_mace_run_lib(model_output_dir, model_load_type, model_name, embed_model_data) else: gen_opencl_and_tuning_code(target_abi, serialno, [], False) @@ -263,7 +263,7 @@ def build_mace_run_prod(hexagon_mode, runtime, target_abi, debug=debug, enable_openmp=enable_openmp ) - sh_commands.update_mace_run_lib(model_output_dir, + sh_commands.update_mace_run_lib(model_output_dir, model_load_type, model_name, embed_model_data) @@ -274,11 +274,12 @@ def merge_libs_and_tuning_results(target_soc, output_dir, model_output_dirs, mace_model_dirs_kv, + model_load_type, hexagon_mode, embed_model_data): gen_opencl_and_tuning_code( target_abi, serialno, model_output_dirs, False) - sh_commands.build_production_code(target_abi) + sh_commands.build_production_code(model_load_type, target_abi) sh_commands.merge_libs(target_soc, target_abi, @@ -286,6 +287,7 @@ def merge_libs_and_tuning_results(target_soc, output_dir, model_output_dirs, mace_model_dirs_kv, + model_load_type, hexagon_mode, embed_model_data) @@ -370,6 +372,9 @@ def parse_model_configs(): print("CONFIG ERROR:") print("embed_model_data must be integer in range [0, 1]") exit(1) + elif FLAGS.model_load_type == "pb": + configs["embed_model_data"] = 0 + print("emebed_model_data is set 0") model_names = configs.get("models", "") if not model_names: @@ -599,6 +604,7 @@ def process_models(project_name, configs, embed_model_data, vlog_level, serialno, vlog_level, embed_model_data, + model_load_type, model_output_dir, model_config["input_nodes"], model_config["output_nodes"], @@ -688,6 +694,7 @@ def process_models(project_name, configs, embed_model_data, vlog_level, FLAGS.output_dir, model_output_dirs, mace_model_dirs_kv, + model_load_type, hexagon_mode, embed_model_data) @@ -748,7 +755,8 @@ def main(unused_args): # generate source sh_commands.gen_mace_version() sh_commands.gen_encrypted_opencl_source() - sh_commands.gen_mace_engine_factory_source(configs['models'].keys()) + sh_commands.gen_mace_engine_factory_source(configs['models'].keys(), + FLAGS.model_load_type) embed_model_data = configs["embed_model_data"] target_socs = get_target_socs(configs) diff --git a/tools/sh_commands.py b/tools/sh_commands.py index 9ab3dd00b8715763247a31e9bc9e9e36af7c2807..535fcf706989353f452726676044f5c75c917afb 100644 --- a/tools/sh_commands.py +++ b/tools/sh_commands.py @@ -370,6 +370,7 @@ def gen_encrypted_opencl_source(codegen_path="mace/codegen"): def gen_mace_engine_factory_source(model_tags, + model_load_type, codegen_path="mace/codegen"): print("* Genearte mace engine creator source") codegen_tools_dir = "%s/engine" % codegen_path @@ -378,6 +379,7 @@ def gen_mace_engine_factory_source(model_tags, gen_mace_engine_factory( model_tags, "mace/python/tools", + model_load_type, codegen_tools_dir) print("Genearte mace engine creator source done!\n") @@ -547,6 +549,7 @@ def gen_random_input(model_output_dir, def update_mace_run_lib(model_output_dir, + model_load_type, model_tag, embed_model_data): mace_run_filepath = model_output_dir + "/mace_run" @@ -558,8 +561,9 @@ def update_mace_run_lib(model_output_dir, sh.cp("-f", "mace/codegen/models/%s/%s.data" % (model_tag, model_tag), model_output_dir) - sh.cp("-f", "mace/codegen/models/%s/%s.h" % (model_tag, model_tag), - model_output_dir) + if model_load_type == "source": + sh.cp("-f", "mace/codegen/models/%s/%s.h" % (model_tag, model_tag), + model_output_dir) def create_internal_storage_dir(serialno, phone_data_dir): @@ -833,13 +837,17 @@ def validate_model(abi, print("Validation done!\n") -def build_production_code(abi): +def build_production_code(model_load_type, abi): bazel_build("//mace/codegen:generated_opencl", abi=abi) bazel_build("//mace/codegen:generated_tuning_params", abi=abi) if abi == 'host': - bazel_build( - "//mace/codegen:generated_models", - abi=abi) + if model_load_type == "source": + bazel_build( + "//mace/codegen:generated_models", + abi=abi) + else: + bazel_build("//mace/core:core", abi=abi) + bazel_build("//mace/ops:ops", abi=abi) def merge_libs(target_soc, @@ -848,6 +856,7 @@ def merge_libs(target_soc, libmace_output_dir, model_output_dirs, mace_model_dirs_kv, + model_load_type, hexagon_mode, embed_model_data): print("* Merge mace lib") @@ -879,12 +888,24 @@ def merge_libs(target_soc, mri_stream += ( "addlib " "bazel-bin/mace/codegen/libgenerated_tuning_params.pic.a\n") - mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_models.pic.a\n") + if model_load_type == "source": + mri_stream += ( + "addlib " + "bazel-bin/mace/codegen/libgenerated_models.pic.a\n") + else: + mri_stream += ( + "addlib " + "bazel-bin/mace/core/libcore.pic.a\n") + mri_stream += ( + "addlib " + "bazel-bin/mace/ops/libops.pic.lo\n") else: mri_stream += "create %s/libmace_%s.%s.a\n" % \ (model_bin_dir, project_name, target_soc) + if model_load_type == "source": + mri_stream += ( + "addlib " + "bazel-bin/mace/codegen/libgenerated_models.a\n") mri_stream += ( "addlib " "bazel-bin/mace/codegen/libgenerated_opencl.a\n") @@ -894,9 +915,6 @@ def merge_libs(target_soc, mri_stream += ( "addlib " "bazel-bin/mace/codegen/libgenerated_version.a\n") - mri_stream += ( - "addlib " - "bazel-bin/mace/codegen/libgenerated_models.a\n") mri_stream += ( "addlib " "bazel-bin/mace/core/libcore.a\n") @@ -909,6 +927,12 @@ def merge_libs(target_soc, mri_stream += ( "addlib " "bazel-bin/mace/utils/libutils_prod.a\n") + mri_stream += ( + "addlib " + "bazel-bin/mace/proto/libmace_cc.a\n") + mri_stream += ( + "addlib " + "bazel-bin/external/com_google_protobuf/libprotobuf_lite.a\n") mri_stream += ( "addlib " "bazel-bin/mace/ops/libops.lo\n") @@ -917,7 +941,8 @@ def merge_libs(target_soc, if not embed_model_data: sh.cp("-f", glob.glob("%s/*.data" % model_output_dir), model_data_dir) - sh.cp("-f", glob.glob("%s/*.h" % model_output_dir), model_header_dir) + if model_load_type == "source": + sh.cp("-f", glob.glob("%s/*.h" % model_output_dir), model_header_dir) for model_name in mace_model_dirs_kv: sh.cp("-f", "%s/%s.pb" % (mace_model_dirs_kv[model_name], model_name),