├── .bazelrc ├── .bazelversion ├── .clang-format ├── .gitignore ├── .gitlab-ci-new.yml ├── .gitlab-ci.yml ├── .gitmodules ├── .travis.yml ├── BUILD.bazel ├── CMakeLists.txt ├── ISSUE_TEMPLATE.md ├── JOBS.md ├── LICENSE ├── README.md ├── README_zh.md ├── RELEASE.md ├── ROADMAP.md ├── WORKSPACE ├── cmake └── toolchains │ ├── aarch64-linux-gnu.cmake │ ├── arm-linux-gnueabi.cmake │ ├── arm-linux-gnueabihf.cmake │ └── ios.toolchain.cmake ├── docker ├── gitlab-runner │ └── Dockerfile ├── mace-dev-lite │ └── Dockerfile ├── mace-dev │ └── Dockerfile ├── mace-dev2.dockerfile ├── mace-micro-dev │ └── mace-micro-dev.dockerfile └── update_images.sh ├── docs ├── Makefile ├── README ├── chinese.rst ├── conf.py ├── development │ ├── adding_a_new_op.md │ ├── contributing.md │ ├── data_format.md │ ├── dynamic_lstm.rst │ ├── how_to_debug.rst │ ├── how_to_run_tests.md │ ├── imgs │ │ ├── DynamicLSTM.png │ │ └── FuseLSTM.png │ └── memory_layout.rst ├── faq.md ├── index.rst ├── installation │ ├── env_requirement.rst │ ├── manual_setup.rst │ └── using_docker.rst ├── introduction.rst ├── mace-arch.png ├── mace-logo.png ├── mace-work-flow-zh.png ├── mace-work-flow.png ├── micro-controllers │ ├── basic_usage.rst │ ├── deploy.rst │ └── op_lists.rst ├── user_guide │ ├── advanced_usage.rst │ ├── advanced_usage_cmake.rst │ ├── basic_usage.rst │ ├── basic_usage_cmake.rst │ ├── benchmark.rst │ ├── devices │ │ └── demo_device_nanopi.yml │ ├── models │ │ ├── demo_models.yml │ │ ├── demo_models_caffe.yml │ │ ├── demo_models_cmake.yml │ │ ├── demo_models_onnx.yml │ │ └── demo_models_tf.yml │ ├── op_lists.rst │ └── quantization_usage.rst └── zh │ ├── installation │ └── env_requirement.rst │ └── user_guide │ └── basic_usage.rst ├── examples └── android │ ├── .gitignore │ ├── README.md │ ├── app │ ├── .gitignore │ ├── build.gradle │ ├── mace_demo.jks │ └── src │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── assets │ │ └── cacheLabel.txt │ │ ├── java │ │ └── com │ │ │ └── xiaomi │ │ │ └── mace │ │ │ └── demo │ │ │ ├── AppModel.java │ │ │ ├── CameraActivity.java │ │ │ ├── CameraFactory.java │ │ │ ├── Constant.java │ │ │ ├── MaceApp.java │ │ │ ├── camera │ │ │ ├── CameraApiLessM.java │ │ │ ├── CameraApiMoreM.java │ │ │ ├── CameraEngage.java │ │ │ ├── CameraTextureView.java │ │ │ ├── ContextMenuDialog.java │ │ │ ├── ItemAdapter.java │ │ │ ├── MessageEvent.java │ │ │ └── MobilenetResultCallback.java │ │ │ └── result │ │ │ ├── InitData.java │ │ │ ├── LabelCache.java │ │ │ └── ResultData.java │ │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_camera.xml │ │ ├── layout_dialog.xml │ │ └── layout_item.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ ├── build.gradle │ ├── build.sh │ ├── gradle.properties │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── macelibrary │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.gradle │ ├── proguard-rules.pro │ ├── src │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── cpp │ │ │ ├── image_classify.cc │ │ │ └── image_classify.h │ │ │ ├── java │ │ │ └── com │ │ │ │ └── xiaomi │ │ │ │ └── mace │ │ │ │ └── JniMaceUtils.java │ │ │ └── res │ │ │ └── values │ │ │ └── strings.xml │ └── version_script.lds │ ├── mobilenet.yml │ └── settings.gradle ├── include ├── BUILD.bazel ├── CMakeLists.txt └── mace │ ├── port │ ├── env.h │ ├── file_system.h │ ├── logger.h │ ├── port-arch.h │ └── port.h │ ├── public │ └── mace.h │ └── utils │ ├── logging.h │ ├── mace_engine_config.h │ ├── macros.h │ ├── memory.h │ └── string_util.h ├── mace ├── BUILD.bazel ├── CMakeLists.txt ├── codegen │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── model_version_script.lds │ └── tools │ │ └── gen_version_source.sh ├── core │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── bfloat16.h │ ├── flow │ │ ├── base_flow.cc │ │ ├── base_flow.h │ │ ├── common_fp32_flow.cc │ │ ├── common_fp32_flow.h │ │ ├── flow_registry.cc │ │ └── flow_registry.h │ ├── fp16.h │ ├── future.h │ ├── kv_storage.cc │ ├── kv_storage.h │ ├── mace_tensor_impl.h │ ├── memory │ │ ├── allocator.h │ │ ├── buffer.h │ │ ├── general_memory_manager.cc │ │ ├── general_memory_manager.h │ │ ├── memory_manager.h │ │ ├── rpcmem │ │ │ ├── rpcmem.cc │ │ │ └── rpcmem.h │ │ └── slice.h │ ├── net │ │ ├── allocate_opt_strategy.cc │ │ ├── allocate_ref_strategy.cc │ │ ├── allocate_strategy.h │ │ ├── base_net.h │ │ ├── serial_net.cc │ │ └── serial_net.h │ ├── net_def_adapter.cc │ ├── net_def_adapter.h │ ├── net_optimizer.cc │ ├── net_optimizer.h │ ├── ops │ │ ├── op_condition_builder.cc │ │ ├── op_condition_builder.h │ │ ├── op_condition_context.cc │ │ ├── op_condition_context.h │ │ ├── op_construct_context.cc │ │ ├── op_construct_context.h │ │ ├── op_context.cc │ │ ├── op_context.h │ │ ├── op_delegator.h │ │ ├── op_init_context.cc │ │ ├── op_init_context.h │ │ ├── operator.cc │ │ ├── operator.h │ │ ├── ops_utils.cc │ │ └── ops_utils.h │ ├── proto │ │ ├── arg_helper.cc │ │ ├── arg_helper.h │ │ ├── net_def_helper.cc │ │ └── net_def_helper.h │ ├── quantize.cc │ ├── quantize.h │ ├── registry │ │ ├── op_delegator_registry.cc │ │ ├── op_delegator_registry.h │ │ ├── op_registration_info.cc │ │ ├── op_registration_info.h │ │ ├── ops_registry.cc │ │ └── ops_registry.h │ ├── runtime │ │ ├── runtime.cc │ │ ├── runtime.h │ │ ├── runtime_context.h │ │ ├── runtime_registry.cc │ │ └── runtime_registry.h │ ├── runtime_failure_mock.cc │ ├── runtime_failure_mock.h │ ├── tensor.cc │ ├── tensor.h │ ├── types.cc │ ├── types.h │ ├── workspace.cc │ └── workspace.h ├── flows │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── apu │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── apu_ref_flow.cc │ │ └── apu_ref_flow.h │ ├── cpu │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── cpu_bf16_flow.cc │ │ ├── cpu_bf16_flow.h │ │ ├── cpu_fp16_flow.cc │ │ ├── cpu_fp16_flow.h │ │ ├── cpu_ref_flow.cc │ │ ├── cpu_ref_flow.h │ │ ├── transpose_const.cc │ │ └── transpose_const.h │ ├── flow_registry.cc │ ├── hexagon │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── hexagon_ref_flow.cc │ │ └── hexagon_ref_flow.h │ ├── opencl │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── opencl_ref_flow.cc │ │ └── opencl_ref_flow.h │ └── qnn │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── qnn_ref_flow.cc │ │ └── qnn_ref_flow.h ├── libmace │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── capability.cc │ ├── combine_static_libs.sh │ ├── engines │ │ ├── base_engine.cc │ │ ├── base_engine.h │ │ ├── engine_registry.cc │ │ ├── engine_registry.h │ │ ├── serial_engine.cc │ │ ├── serial_engine.h │ │ ├── single_flow_engine.cc │ │ └── single_flow_engine.h │ ├── gpu_context_builder.cc │ ├── mace.mri.in │ ├── mace_engine.cc │ ├── mace_engine_config.cc │ ├── mace_tensor.cc │ └── mace_version_script.lds ├── mace.bzl ├── ops │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── activation.cc │ ├── activation.h │ ├── addn.cc │ ├── argmax.cc │ ├── arm │ │ ├── README │ │ ├── base │ │ │ ├── activation.cc │ │ │ ├── activation.h │ │ │ ├── bias_add.cc │ │ │ ├── bias_add.h │ │ │ ├── common_neon.h │ │ │ ├── conv_2d.cc │ │ │ ├── conv_2d.h │ │ │ ├── conv_2d_1x1.cc │ │ │ ├── conv_2d_1x1.h │ │ │ ├── conv_2d_1xn.cc │ │ │ ├── conv_2d_1xn.h │ │ │ ├── conv_2d_3x3.cc │ │ │ ├── conv_2d_3x3.h │ │ │ ├── conv_2d_3x3_winograd.cc │ │ │ ├── conv_2d_3x3_winograd.h │ │ │ ├── conv_2d_5x5.cc │ │ │ ├── conv_2d_5x5.h │ │ │ ├── conv_2d_7x7.cc │ │ │ ├── conv_2d_7x7.h │ │ │ ├── conv_2d_general.cc │ │ │ ├── conv_2d_general.h │ │ │ ├── conv_2d_mxn.h │ │ │ ├── deconv_2d.cc │ │ │ ├── deconv_2d.h │ │ │ ├── deconv_2d_2x2.cc │ │ │ ├── deconv_2d_2x2.h │ │ │ ├── deconv_2d_3x3.cc │ │ │ ├── deconv_2d_3x3.h │ │ │ ├── deconv_2d_4x4.cc │ │ │ ├── deconv_2d_4x4.h │ │ │ ├── deconv_2d_general.cc │ │ │ ├── deconv_2d_general.h │ │ │ ├── deconv_2d_mxn.h │ │ │ ├── depthwise_conv_2d_3x3.cc │ │ │ ├── depthwise_conv_2d_3x3.h │ │ │ ├── depthwise_conv_2d_mxn.h │ │ │ ├── depthwise_deconv_2d_3x3.cc │ │ │ ├── depthwise_deconv_2d_3x3.h │ │ │ ├── depthwise_deconv_2d_4x4.cc │ │ │ ├── depthwise_deconv_2d_4x4.h │ │ │ ├── depthwise_deconv_2d_general.cc │ │ │ ├── depthwise_deconv_2d_general.h │ │ │ ├── depthwise_deconv_2d_mxn.h │ │ │ ├── gemm.cc │ │ │ ├── gemm.h │ │ │ ├── gemv.cc │ │ │ └── gemv.h │ │ ├── bf16 │ │ │ ├── conv_2d_3x3.cc │ │ │ └── gemm.cc │ │ ├── fp16 │ │ │ ├── conv_2d_3x3.cc │ │ │ ├── depthwise_conv_2d_3x3.cc │ │ │ ├── gemm.cc │ │ │ └── gemv.h │ │ ├── fp32 │ │ │ ├── conv_2d_1xn.cc │ │ │ ├── conv_2d_3x3.cc │ │ │ ├── conv_2d_5x5.cc │ │ │ ├── conv_2d_7x7.cc │ │ │ ├── deconv_2d_2x2.cc │ │ │ ├── deconv_2d_3x3.cc │ │ │ ├── deconv_2d_4x4.cc │ │ │ ├── depthwise_deconv_2d_3x3.cc │ │ │ ├── depthwise_deconv_2d_4x4.cc │ │ │ ├── gemm.cc │ │ │ └── gemv.cc │ │ └── q8 │ │ │ ├── activation.cc │ │ │ ├── bias_add.cc │ │ │ ├── eltwise.cc │ │ │ ├── gemv.cc │ │ │ ├── gemv.h │ │ │ ├── quantization_util.cc │ │ │ ├── quantization_util.h │ │ │ └── quantize.cc │ ├── batch_norm.cc │ ├── batch_to_space.cc │ ├── bias_add.cc │ ├── cast.cc │ ├── channel_shuffle.cc │ ├── common │ │ ├── activation_type.h │ │ ├── conv_pool_2d_util.cc │ │ ├── conv_pool_2d_util.h │ │ ├── coordinate_transformation_mode.h │ │ ├── eltwise_type.h │ │ ├── gemmlowp_util.h │ │ ├── lstm.h │ │ ├── matrix.h │ │ ├── pad_type.h │ │ ├── pooling_type.h │ │ ├── reduce_type.h │ │ ├── utils.cc │ │ └── utils.h │ ├── concat.cc │ ├── conv_2d.cc │ ├── conv_pool_2d_base.h │ ├── crop.cc │ ├── cumsum.cc │ ├── deconv_2d.cc │ ├── deconv_2d.h │ ├── delegator │ │ ├── activation.h │ │ ├── bias_add.h │ │ ├── conv_2d.h │ │ ├── deconv_2d.h │ │ ├── depthwise_conv_2d.h │ │ ├── depthwise_deconv_2d.h │ │ ├── eltwise.h │ │ ├── gemm.h │ │ └── gemv.h │ ├── depth_to_space.cc │ ├── depthwise_conv2d.cc │ ├── depthwise_deconv2d.cc │ ├── detection_output.cc │ ├── dynamic_lstm.cc │ ├── eltwise.cc │ ├── eltwise.h │ ├── expand_dims.cc │ ├── extract_image_patches.cc │ ├── extract_pooling.cc │ ├── fill.cc │ ├── fixpoint.h │ ├── fully_connected.cc │ ├── gather.cc │ ├── group_norm.cc │ ├── identity.cc │ ├── ifdefined.cc │ ├── infer_conv2d_shape.cc │ ├── instance_norm.cc │ ├── kaldi_batch_norm.cc │ ├── local_response_norm.cc │ ├── lpnorm.cc │ ├── lstm_nonlinear.cc │ ├── matmul.cc │ ├── mvnorm.cc │ ├── nonlocal_reshape.cc │ ├── one_hot.cc │ ├── opencl │ │ ├── activation.h │ │ ├── addn.h │ │ ├── batch_norm.h │ │ ├── batch_to_space.h │ │ ├── bias_add.h │ │ ├── buffer │ │ │ ├── conv_2d.cc │ │ │ ├── conv_2d.h │ │ │ ├── conv_2d_1x1.cc │ │ │ ├── conv_2d_general.cc │ │ │ ├── depthwise_conv2d.cc │ │ │ ├── depthwise_conv2d.h │ │ │ ├── pooling.cc │ │ │ ├── pooling.h │ │ │ ├── reshape.cc │ │ │ ├── reshape.h │ │ │ ├── softmax.cc │ │ │ ├── softmax.h │ │ │ ├── transpose.cc │ │ │ ├── transpose.h │ │ │ ├── utils.cc │ │ │ └── utils.h │ │ ├── buffer_transform.cc │ │ ├── channel_shuffle.h │ │ ├── cl │ │ │ ├── activation.cl │ │ │ ├── addn.cl │ │ │ ├── batch_norm.cl │ │ │ ├── batch_to_space.cl │ │ │ ├── bias_add.cl │ │ │ ├── buffer_to_image.cl │ │ │ ├── buffer_transform.cl │ │ │ ├── channel_shuffle.cl │ │ │ ├── common.h │ │ │ ├── concat.cl │ │ │ ├── conv_2d.cl │ │ │ ├── conv_2d_1x1.cl │ │ │ ├── conv_2d_1x1_buffer.cl │ │ │ ├── conv_2d_3x3.cl │ │ │ ├── conv_2d_buffer.cl │ │ │ ├── crop.cl │ │ │ ├── deconv_2d.cl │ │ │ ├── depth_to_space.cl │ │ │ ├── depthwise_conv2d.cl │ │ │ ├── depthwise_conv2d_buffer.cl │ │ │ ├── depthwise_deconv2d.cl │ │ │ ├── eltwise.cl │ │ │ ├── extract_image_patches.cl │ │ │ ├── fully_connected.cl │ │ │ ├── instance_norm.cl │ │ │ ├── lpnorm.cl │ │ │ ├── lstmcell.cl │ │ │ ├── matmul.cl │ │ │ ├── mvnorm.cl │ │ │ ├── pad.cl │ │ │ ├── pooling.cl │ │ │ ├── pooling_buffer.cl │ │ │ ├── reduce.cl │ │ │ ├── resize_bicubic.cl │ │ │ ├── resize_bilinear.cl │ │ │ ├── resize_nearest_neighbor.cl │ │ │ ├── softmax.cl │ │ │ ├── softmax_buffer.cl │ │ │ ├── space_to_batch.cl │ │ │ ├── space_to_depth.cl │ │ │ ├── split.cl │ │ │ ├── sqrdiff_mean.cl │ │ │ ├── transpose.cl │ │ │ └── winograd_transform.cl │ │ ├── concat.h │ │ ├── conv_2d.h │ │ ├── crop.h │ │ ├── deconv_2d.h │ │ ├── depth_to_space.h │ │ ├── depthwise_conv2d.h │ │ ├── depthwise_deconv2d.h │ │ ├── eltwise.h │ │ ├── extract_image_patches.h │ │ ├── fully_connected.h │ │ ├── image │ │ │ ├── activation.cc │ │ │ ├── activation.h │ │ │ ├── addn.cc │ │ │ ├── addn.h │ │ │ ├── batch_norm.cc │ │ │ ├── batch_norm.h │ │ │ ├── batch_to_space.cc │ │ │ ├── batch_to_space.h │ │ │ ├── bias_add.cc │ │ │ ├── bias_add.h │ │ │ ├── channel_shuffle.cc │ │ │ ├── channel_shuffle.h │ │ │ ├── concat.cc │ │ │ ├── concat.h │ │ │ ├── conv_2d.cc │ │ │ ├── conv_2d.h │ │ │ ├── conv_2d_1x1.cc │ │ │ ├── conv_2d_3x3.cc │ │ │ ├── conv_2d_general.cc │ │ │ ├── crop.cc │ │ │ ├── crop.h │ │ │ ├── deconv_2d.cc │ │ │ ├── deconv_2d.h │ │ │ ├── depth_to_space.cc │ │ │ ├── depth_to_space.h │ │ │ ├── depthwise_conv2d.cc │ │ │ ├── depthwise_conv2d.h │ │ │ ├── depthwise_deconv2d.cc │ │ │ ├── depthwise_deconv2d.h │ │ │ ├── eltwise.cc │ │ │ ├── eltwise.h │ │ │ ├── extract_image_patches.cc │ │ │ ├── extract_image_patches.h │ │ │ ├── fully_connected.cc │ │ │ ├── fully_connected.h │ │ │ ├── instance_norm.cc │ │ │ ├── instance_norm.h │ │ │ ├── lpnorm.cc │ │ │ ├── lpnorm.h │ │ │ ├── lstm_cell.cc │ │ │ ├── lstm_cell.h │ │ │ ├── matmul.cc │ │ │ ├── matmul.h │ │ │ ├── mvnorm.cc │ │ │ ├── mvnorm.h │ │ │ ├── pad.cc │ │ │ ├── pad.h │ │ │ ├── pooling.cc │ │ │ ├── pooling.h │ │ │ ├── reduce.cc │ │ │ ├── reduce.h │ │ │ ├── reshape.cc │ │ │ ├── reshape.h │ │ │ ├── resize_bicubic.cc │ │ │ ├── resize_bicubic.h │ │ │ ├── resize_bilinear.cc │ │ │ ├── resize_bilinear.h │ │ │ ├── resize_nearest_neighbor.cc │ │ │ ├── resize_nearest_neighbor.h │ │ │ ├── softmax.cc │ │ │ ├── softmax.h │ │ │ ├── space_to_batch.cc │ │ │ ├── space_to_batch.h │ │ │ ├── space_to_depth.cc │ │ │ ├── space_to_depth.h │ │ │ ├── split.cc │ │ │ ├── split.h │ │ │ ├── sqrdiff_mean.cc │ │ │ ├── sqrdiff_mean.h │ │ │ └── winograd_conv2d.cc │ │ ├── instance_norm.h │ │ ├── lpnorm.h │ │ ├── lstm_cell.cc │ │ ├── lstm_cell.h │ │ ├── matmul.h │ │ ├── mvnorm.h │ │ ├── pad.h │ │ ├── pooling.h │ │ ├── reduce.h │ │ ├── reshape.h │ │ ├── resize_bicubic.h │ │ ├── resize_bilinear.h │ │ ├── resize_nearest_neighbor.h │ │ ├── softmax.h │ │ ├── space_to_batch.h │ │ ├── space_to_depth.h │ │ ├── split.h │ │ ├── sqrdiff_mean.h │ │ └── transpose.h │ ├── pad.cc │ ├── pad_context.cc │ ├── pnorm.cc │ ├── pooling.cc │ ├── prior_box.cc │ ├── reduce.cc │ ├── ref │ │ ├── activation.cc │ │ ├── bias_add.cc │ │ ├── conv_2d.cc │ │ ├── deconv_2d.cc │ │ ├── depthwise_conv_2d.cc │ │ ├── depthwise_deconv_2d.cc │ │ ├── gemm.cc │ │ ├── gemv.cc │ │ └── q8 │ │ │ ├── eltwise.cc │ │ │ └── gemv.cc │ ├── registry │ │ ├── op_delegators_registry.cc │ │ ├── ops_registry.cc │ │ └── registry.h │ ├── replace_index.cc │ ├── reshape.cc │ ├── resize_bicubic.cc │ ├── resize_bilinear.cc │ ├── resize_nearest_neighbor.cc │ ├── reverse.cc │ ├── scalar_math.cc │ ├── select.cc │ ├── shape.cc │ ├── slice.cc │ ├── softmax.cc │ ├── space_to_batch.cc │ ├── space_to_depth.cc │ ├── splice.cc │ ├── split.cc │ ├── sqrdiff_mean.cc │ ├── squeeze.cc │ ├── stack.cc │ ├── strided_slice.cc │ ├── subsample.cc │ ├── sum_group.cc │ ├── target_rms_norm.cc │ ├── tile.cc │ ├── transpose.cc │ ├── unsqueeze.cc │ ├── unstack.cc │ └── where.cc ├── port │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── README.md │ ├── android │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── env.cc │ │ ├── env.h │ │ ├── logger.cc │ │ ├── logger.h │ │ ├── malloc_logger.cc │ │ └── malloc_logger.h │ ├── darwin │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── ar_merge_on_darwin.sh │ │ ├── env.cc │ │ └── env.h │ ├── env.cc │ ├── file_system.cc │ ├── linux │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── env.cc │ │ └── env.h │ ├── linux_base │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── env.cc │ │ └── env.h │ ├── logger.cc │ ├── posix │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── backtrace.h │ │ ├── file_system.cc │ │ ├── file_system.h │ │ └── time.h │ └── windows │ │ ├── CMakeLists.txt │ │ ├── env.cc │ │ ├── env.h │ │ ├── file_system.cc │ │ └── file_system.h ├── proto │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── mace.proto │ ├── micro_mem.proto │ └── qnn_cache.proto ├── python │ └── tools │ │ ├── BUILD.bazel │ │ ├── __init__.py │ │ ├── archive_static_lib.py │ │ ├── encrypt_opencl_codegen.py │ │ ├── file_binary.cc.jinja2 │ │ ├── mace_engine_factory.h.jinja2 │ │ ├── mace_engine_factory_codegen.py │ │ ├── opencl_binary_codegen.py │ │ ├── operator.jinja2 │ │ ├── str2vec_maps.cc.jinja2 │ │ └── str2vec_maps.h.jinja2 ├── rpcmems │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── dmabufheap │ │ ├── dma_buf_heap_rpcmem.cc │ │ ├── dma_buf_heap_rpcmem.h │ │ ├── dma_buf_heap_wrapper.cc │ │ └── dma_buf_heap_wrapper.h │ ├── mtk │ │ ├── mtk_ion_wrapper.cc │ │ ├── mtk_ion_wrapper.h │ │ ├── mtk_rpcmem.cc │ │ └── mtk_rpcmem.h │ ├── qualcomm │ │ ├── qualcomm_rpcmem.cc │ │ └── qualcomm_rpcmem.h │ └── rpcmem_factory.cc ├── runtimes │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── apu │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── apu_runtime.cc │ │ ├── apu_runtime.h │ │ ├── ion │ │ │ ├── apu_ion_runtime.cc │ │ │ └── apu_ion_runtime.h │ │ ├── v1v2v3 │ │ │ ├── apu_wrapper.h │ │ │ ├── v1 │ │ │ │ └── apu_wrapper.cc │ │ │ └── v2v3 │ │ │ │ └── apu_wrapper.cc │ │ └── v4 │ │ │ ├── apu_wrapper.cc │ │ │ ├── apu_wrapper.h │ │ │ ├── neuron_delegate_builder.h │ │ │ ├── neuron_delegate_kernel.cc │ │ │ ├── neuron_delegate_kernel.h │ │ │ ├── neuron_implementation.cc │ │ │ └── neuron_implementation.h │ ├── cpu │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── cpu_ref_allocator.cc │ │ ├── cpu_ref_allocator.h │ │ ├── cpu_ref_runtime.cc │ │ ├── cpu_ref_runtime.h │ │ ├── cpu_runtime.cc │ │ ├── cpu_runtime.h │ │ └── ion │ │ │ ├── cpu_ion_allocator.cc │ │ │ ├── cpu_ion_allocator.h │ │ │ ├── cpu_ion_runtime.cc │ │ │ └── cpu_ion_runtime.h │ ├── hexagon │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── dsp │ │ │ ├── hexagon_dsp_ops.h │ │ │ ├── hexagon_dsp_runtime.cc │ │ │ ├── hexagon_dsp_runtime.h │ │ │ ├── hexagon_dsp_wrapper.cc │ │ │ └── hexagon_dsp_wrapper.h │ │ ├── hexagon_base_runtime.cc │ │ ├── hexagon_base_runtime.h │ │ ├── hexagon_control_wrapper.h │ │ └── hta │ │ │ ├── hexagon_hta_ops.h │ │ │ ├── hexagon_hta_runtime.cc │ │ │ ├── hexagon_hta_runtime.h │ │ │ ├── hexagon_hta_transformer.cc │ │ │ ├── hexagon_hta_transformer.h │ │ │ ├── hexagon_hta_wrapper.cc │ │ │ ├── hexagon_hta_wrapper.h │ │ │ └── opencl │ │ │ ├── hexagon_hta_opencl_runtime.cc │ │ │ └── hexagon_hta_opencl_runtime.h │ ├── opencl │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── core │ │ │ ├── cl2_header.h │ │ │ ├── opencl_context.cc │ │ │ ├── opencl_context.h │ │ │ ├── opencl_executor.cc │ │ │ ├── opencl_executor.h │ │ │ ├── opencl_extension.h │ │ │ ├── opencl_helper.cc │ │ │ ├── opencl_helper.h │ │ │ ├── opencl_util.cc │ │ │ ├── opencl_util.h │ │ │ └── opencl_wrapper.cc │ │ ├── mtk_ion │ │ │ ├── opencl_base_mtk_ion_allocator.cc │ │ │ ├── opencl_base_mtk_ion_allocator.h │ │ │ ├── opencl_buffer_mtk_ion_allocator.cc │ │ │ ├── opencl_buffer_mtk_ion_allocator.h │ │ │ ├── opencl_image_mtk_ion_allocator.cc │ │ │ ├── opencl_image_mtk_ion_allocator.h │ │ │ ├── opencl_mtk_ion_executor.cc │ │ │ ├── opencl_mtk_ion_executor.h │ │ │ ├── opencl_mtk_ion_runtime.cc │ │ │ └── opencl_mtk_ion_runtime.h │ │ ├── opencl_buffer_allocator.cc │ │ ├── opencl_buffer_allocator.h │ │ ├── opencl_image_allocator.cc │ │ ├── opencl_image_allocator.h │ │ ├── opencl_image_manager.cc │ │ ├── opencl_image_manager.h │ │ ├── opencl_ref_runtime.cc │ │ ├── opencl_ref_runtime.h │ │ ├── opencl_runtime.cc │ │ ├── opencl_runtime.h │ │ ├── qc_ion │ │ │ ├── opencl_base_qc_ion_allocator.cc │ │ │ ├── opencl_base_qc_ion_allocator.h │ │ │ ├── opencl_buffer_qc_ion_allocator.cc │ │ │ ├── opencl_buffer_qc_ion_allocator.h │ │ │ ├── opencl_image_qc_ion_allocator.cc │ │ │ ├── opencl_image_qc_ion_allocator.h │ │ │ ├── opencl_qc_ion_executor.cc │ │ │ ├── opencl_qc_ion_executor.h │ │ │ ├── opencl_qc_ion_runtime.cc │ │ │ └── opencl_qc_ion_runtime.h │ │ └── transform │ │ │ ├── buffer_to_image.cc │ │ │ ├── buffer_to_image.h │ │ │ ├── buffer_transform.cc │ │ │ ├── buffer_transform.h │ │ │ ├── buffer_transform_kernel.h │ │ │ ├── buffer_transformer.cc │ │ │ ├── buffer_transformer.h │ │ │ ├── buffer_type_transform.cc │ │ │ ├── image_to_buffer.cc │ │ │ └── image_to_buffer.h │ ├── qnn │ │ ├── BUILD.bazel │ │ ├── CMakeLists.txt │ │ ├── common.h │ │ ├── op_builder.cc │ │ ├── op_builder.h │ │ ├── opencl │ │ │ ├── qnn_opencl_runtime.cc │ │ │ └── qnn_opencl_runtime.h │ │ ├── ops │ │ │ ├── activation_op_builder.cc │ │ │ ├── argmax_op_builder.cc │ │ │ ├── batch_norm_op_builder.cc │ │ │ ├── cast_op_builder.cc │ │ │ ├── concat_op_builder.cc │ │ │ ├── conv2d_op_builder.cc │ │ │ ├── conv_pool_2d_util.cc │ │ │ ├── conv_pool_2d_util.h │ │ │ ├── deconv2d_op_builder.cc │ │ │ ├── depth_to_space_op_builder.cc │ │ │ ├── eltwise_op_builder.cc │ │ │ ├── expand_dims_op_builder.cc │ │ │ ├── fully_connected_op_builder.cc │ │ │ ├── gather_op_builder.cc │ │ │ ├── instance_norm_op_builder.cc │ │ │ ├── matmul_op_builder.cc │ │ │ ├── moments_op_builder.cc │ │ │ ├── pack_op_builder.cc │ │ │ ├── pad_op_builder.cc │ │ │ ├── pooling_op_builder.cc │ │ │ ├── quantize_op_builder.cc │ │ │ ├── reduce_op_builder.cc │ │ │ ├── reshape_op_builder.cc │ │ │ ├── resize_op_builder.cc │ │ │ ├── softmax_op_builder.cc │ │ │ ├── space_to_depth_op_builder.cc │ │ │ ├── split_op_builder.cc │ │ │ ├── squeeze_op_builder.cc │ │ │ ├── strided_slice_op_builder.cc │ │ │ ├── tile_op_builder.cc │ │ │ └── transpose_op_builder.cc │ │ ├── qnn_base_runtime.cc │ │ ├── qnn_base_runtime.h │ │ ├── qnn_performance.cc │ │ ├── qnn_performance.h │ │ ├── qnn_runtime.cc │ │ ├── qnn_runtime.h │ │ ├── qnn_wrapper.cc │ │ └── qnn_wrapper.h │ └── runtime_registry.cc ├── tools │ ├── BUILD.bazel │ ├── CMakeLists.txt │ └── mace_run.cc └── utils │ ├── BUILD.bazel │ ├── CMakeLists.txt │ ├── conf_util.h │ ├── count_down_latch.h │ ├── math.h │ ├── rwlock.h │ ├── spinlock.h │ ├── statistics.cc │ ├── statistics.h │ ├── status.cc │ ├── stl_util.h │ ├── string_util.cc │ ├── thread_pool.cc │ ├── thread_pool.h │ ├── timer.h │ ├── transpose.h │ └── tuner.h ├── micro ├── CMakeLists.txt ├── base │ ├── CMakeLists.txt │ ├── logger.cc │ ├── logger.h │ ├── logging.h │ ├── serialize.cc │ ├── serialize.h │ ├── serialize_type.h │ ├── types.h │ ├── utils.cc │ ├── utils.h │ ├── value_to_str.cc │ └── value_to_str.h ├── cmake │ ├── config_gcc_arm.cmake │ ├── find_hexagon_sdk.cmake │ └── toolchain │ │ ├── gcc-arm-none-eabi.cmake │ │ ├── hexagon6.toolchain.cmake │ │ ├── hexagon8.toolchain.cmake │ │ └── xcc.cmake ├── codegen │ └── CMakeLists.txt ├── examples │ ├── CMakeLists.txt │ ├── classifier │ │ ├── .gitignore │ │ ├── .mbed │ │ ├── CMakeLists.txt │ │ ├── main.cc │ │ └── mbed-os.lib │ ├── data │ │ ├── data.h │ │ ├── har.h │ │ ├── kws.h │ │ └── mnist.h │ └── runtime_load_model │ │ ├── CMakeLists.txt │ │ └── main.cc ├── framework │ ├── CMakeLists.txt │ ├── graph.cc │ ├── graph.h │ ├── micro_engine.cc │ ├── op_context.cc │ ├── op_context.h │ ├── operator.cc │ ├── operator.h │ ├── scratch_buffer.cc │ └── scratch_buffer.h ├── include │ ├── CMakeLists.txt │ ├── port │ │ └── define.h │ ├── public │ │ └── micro.h │ └── utils │ │ ├── bfloat16.h │ │ └── macros.h ├── model │ ├── CMakeLists.txt │ ├── argument.cc │ ├── argument.h │ ├── const_tensor.cc │ ├── const_tensor.h │ ├── input_output_info.cc │ ├── input_output_info.h │ ├── net_def.cc │ ├── net_def.h │ ├── operator_def.cc │ ├── operator_def.h │ ├── output_shape.cc │ └── output_shape.h ├── ops │ ├── CMakeLists.txt │ ├── activation.cc │ ├── activation.h │ ├── argmax.h │ ├── bias_add.cc │ ├── bias_add.h │ ├── cast.h │ ├── cmsis_nn │ │ ├── CMakeLists.txt │ │ ├── arm_conv_2d_int8.cc │ │ ├── arm_conv_2d_int8.h │ │ ├── arm_depthwise_conv_2d_int8.cc │ │ ├── arm_depthwise_conv_2d_int8.h │ │ ├── arm_eltwise_int8.cc │ │ ├── arm_eltwise_int8.h │ │ ├── arm_mat_mul_int8.cc │ │ ├── arm_mat_mul_int8.h │ │ ├── arm_pooling_int8.cc │ │ ├── arm_pooling_int8.h │ │ ├── arm_softmax_int8.cc │ │ ├── arm_softmax_int8.h │ │ ├── dequantize.cc │ │ ├── dequantize.h │ │ ├── quantize.cc │ │ ├── quantize.h │ │ ├── utilities.cc │ │ └── utilities.h │ ├── concat.h │ ├── eltwise.cc │ ├── eltwise.h │ ├── expand_dims.cc │ ├── expand_dims.h │ ├── matmul.cc │ ├── matmul.h │ ├── nhwc │ │ ├── CMakeLists.txt │ │ ├── base │ │ │ ├── conv_2d_base.cc │ │ │ ├── conv_2d_base.h │ │ │ ├── depthwise_conv_2d_base.cc │ │ │ ├── depthwise_conv_2d_base.h │ │ │ ├── filter_op_base.cc │ │ │ ├── filter_op_base.h │ │ │ ├── pooling_base.cc │ │ │ └── pooling_base.h │ │ ├── batch_norm.cc │ │ ├── batch_norm.h │ │ ├── conv_2d_c2_s4.cc │ │ ├── conv_2d_c2_s4.h │ │ ├── conv_2d_c3_s4.cc │ │ ├── conv_2d_c3_s4.h │ │ ├── conv_2d_c4_s4.cc │ │ ├── conv_2d_c4_s4.h │ │ ├── conv_2d_ref.cc │ │ ├── conv_2d_ref.h │ │ ├── depthwise_conv_2d_kb1_s4.cc │ │ ├── depthwise_conv_2d_kb1_s4.h │ │ ├── depthwise_conv_2d_kb2_s4.cc │ │ ├── depthwise_conv_2d_kb2_s4.h │ │ ├── depthwise_conv_2d_kb3_s4.cc │ │ ├── depthwise_conv_2d_kb3_s4.h │ │ ├── depthwise_conv_2d_kb4_s4.cc │ │ ├── depthwise_conv_2d_kb4_s4.h │ │ ├── depthwise_conv_2d_ref.cc │ │ ├── depthwise_conv_2d_ref.h │ │ ├── pooling_ref.cc │ │ ├── pooling_ref.h │ │ ├── pooling_s4.cc │ │ └── pooling_s4.h │ ├── reduce.cc │ ├── reduce.h │ ├── reshape.h │ ├── shape.cc │ ├── shape.h │ ├── softmax.cc │ ├── softmax.h │ ├── squeeze.cc │ ├── squeeze.h │ ├── stack.h │ ├── strided_slice.h │ ├── utils │ │ ├── activation.cc │ │ ├── activation.h │ │ ├── crumb_utils.cc │ │ ├── crumb_utils.h │ │ ├── gemm.cc │ │ ├── gemm.h │ │ ├── gemv.cc │ │ ├── gemv.h │ │ └── matrix.h │ └── xtensa │ │ ├── CMakeLists.txt │ │ ├── conv_2d_xtensa.cc │ │ ├── conv_2d_xtensa.h │ │ ├── depthwise_conv_2d_xtensa.cc │ │ ├── depthwise_conv_2d_xtensa.h │ │ ├── matmul_xtensa.cc │ │ └── matmul_xtensa.h ├── port │ ├── CMakeLists.txt │ ├── api.cc │ └── api.h ├── pretrained_models │ ├── har-cnn │ │ ├── har-cnn-bf16.yml │ │ └── har-cnn.yml │ ├── keras │ │ ├── README.md │ │ ├── har │ │ │ ├── har-int8.yml │ │ │ └── har.yml │ │ └── mnist │ │ │ ├── mnist-hifi4.yml │ │ │ ├── mnist-int8.yml │ │ │ ├── mnist.yml │ │ │ └── mnist_keras.py │ └── tensorflow │ │ ├── README.md │ │ └── kws │ │ ├── kws-tc_resnet8-bf16.yml │ │ ├── kws-tc_resnet8-hifi4.yml │ │ └── kws-tc_resnet8.yml ├── test │ ├── CMakeLists.txt │ ├── ccbaseline │ │ ├── CMakeLists.txt │ │ ├── macemc │ │ │ └── rpc │ │ │ │ ├── macemc.idl │ │ │ │ ├── skel │ │ │ │ ├── macemc.cc │ │ │ │ └── micro_tester.cc │ │ │ │ └── stub │ │ │ │ ├── macemc.cc │ │ │ │ └── macemc.h │ │ └── test_baseline_main.cc │ ├── ccbenchmark │ │ ├── CMakeLists.txt │ │ └── micro │ │ │ ├── benchmark_utils │ │ │ ├── test_benchmark.cc │ │ │ └── test_benchmark.h │ │ │ ├── ops │ │ │ ├── activation_benchmark.cc │ │ │ ├── bias_add_benchmark.cc │ │ │ ├── eltwise_benchmark.cc │ │ │ ├── matmul_benchmark.cc │ │ │ ├── nhwc │ │ │ │ ├── batch_norm_benchmark.cc │ │ │ │ ├── conv_2d_benchmark.cc │ │ │ │ ├── conv_2d_opt_benchmark.cc │ │ │ │ ├── depthwise_conv_2d_benchmark.cc │ │ │ │ ├── depthwise_conv_2d_opt_benchmark.cc │ │ │ │ └── pooling_benchmark.cc │ │ │ ├── reduce_benchmark.cc │ │ │ └── softmax_benchmark.cc │ │ │ ├── rpc │ │ │ ├── benchmark.idl │ │ │ ├── skel │ │ │ │ └── benchmark.c │ │ │ └── stub │ │ │ │ ├── benchmark.cc │ │ │ │ └── benchmark.h │ │ │ └── test_benchmark_main.cc │ ├── ccunit │ │ ├── CMakeLists.txt │ │ └── micro │ │ │ ├── codegen │ │ │ └── engine_test.cc │ │ │ ├── framework │ │ │ └── graph_test.cc │ │ │ ├── model │ │ │ └── net_def_test.cc │ │ │ └── ops │ │ │ ├── activation_test.cc │ │ │ ├── argmax_test.cc │ │ │ ├── bias_add_test.cc │ │ │ ├── concat_test.cc │ │ │ ├── eltwise_test.cc │ │ │ ├── expand_dims_test.cc │ │ │ ├── matmul_test.cc │ │ │ ├── nhwc │ │ │ ├── batch_norm_test.cc │ │ │ ├── conv_2d_opt_test.cc │ │ │ ├── conv_2d_test.cc │ │ │ ├── depthwise_conv_2d_opt_test.cc │ │ │ ├── depthwise_conv_2d_test.cc │ │ │ └── pooling_test.cc │ │ │ ├── reduce_test.cc │ │ │ ├── reshape_test.cc │ │ │ ├── shape_test.cc │ │ │ ├── softmax_test.cc │ │ │ ├── squeeze_test.cc │ │ │ ├── stack_test.cc │ │ │ └── strided_slice_test.cc │ └── ccutils │ │ ├── CMakeLists.txt │ │ ├── micro │ │ ├── common │ │ │ ├── global_buffer.cc │ │ │ └── global_buffer.h │ │ └── ops │ │ │ ├── gtest_utils.h │ │ │ ├── operator.test.cc │ │ │ ├── substitute_op.cc │ │ │ ├── substitute_op.h │ │ │ ├── test_quantize_utils.h │ │ │ ├── test_utils.cc │ │ │ └── test_utils.h │ │ └── rpc │ │ ├── qaic.sh │ │ ├── skel │ │ ├── base_func.cc │ │ └── base_func.h │ │ └── stub │ │ ├── base_handle.cc │ │ └── base_handle.h └── tools │ ├── CMakeLists.txt │ ├── build_docker.sh │ ├── ci │ ├── build_mbed_example.sh │ ├── cross_build.sh │ ├── host_build_and_run_examples.sh │ ├── host_build_and_run_tests.sh │ └── model_convert.sh │ ├── cmake │ ├── cmake-build-arm64-v8a-hexagon-stub.sh │ ├── cmake-build-gcc-arm-none-eabi.sh │ ├── cmake-build-hexagon6.sh │ ├── cmake-build-hexagon8.sh │ ├── cmake-build-host.sh │ └── cmake-build-xcc.sh │ ├── combine_static_libs.sh │ └── micro_run.cc ├── repository ├── git │ ├── BUILD.bazel │ ├── BUILD.bazel.tpl │ └── git_configure.bzl └── opencl-kernel │ ├── BUILD.bazel │ ├── BUILD.bazel.tpl │ └── opencl_kernel_configure.bzl ├── setup ├── optionals.txt └── requirements.txt ├── test ├── CMakeLists.txt ├── ccbenchmark │ ├── BUILD.bazel │ ├── CMakeLists.txt │ └── mace │ │ ├── benchmark_utils │ │ ├── test_benchmark.cc │ │ ├── test_benchmark.h │ │ └── test_benchmark_main.cc │ │ └── ops │ │ ├── activation_benchmark.cc │ │ ├── addn_benchmark.cc │ │ ├── batch_norm_benchmark.cc │ │ ├── batch_to_space_benchmark.cc │ │ ├── bias_add_benchmark.cc │ │ ├── buffer_to_image_benchmark.cc │ │ ├── channel_shuffle_benchmark.cc │ │ ├── concat_benchmark.cc │ │ ├── conv_2d_benchmark.cc │ │ ├── crop_benchmark.cc │ │ ├── cumsum_benchmark.cc │ │ ├── deconv_2d_benchmark.cc │ │ ├── depth_to_space_benchmark.cc │ │ ├── depthwise_conv2d_benchmark.cc │ │ ├── depthwise_deconv2d_benchmark.cc │ │ ├── dynamic_lstm_benchmark.cc │ │ ├── eltwise_benchmark.cc │ │ ├── extract_pooling_benchmark.cc │ │ ├── fully_connected_benchmark.cc │ │ ├── gather_benchmark.cc │ │ ├── kaldi_batch_norm_benchmark.cc │ │ ├── local_response_norm_benchmark.cc │ │ ├── lstm_nonlinear_benchmark.cc │ │ ├── lstmcell_benchmark.cc │ │ ├── matmul_benchmark.cc │ │ ├── memory_benchmark.cc │ │ ├── one_hot_benchmark.cc │ │ ├── pad_benchmark.cc │ │ ├── pad_context_benchmark.cc │ │ ├── pnorm_benchmark.cc │ │ ├── pooling_benchmark.cc │ │ ├── prior_box_benchmark.cc │ │ ├── quantize_benchmark.cc │ │ ├── reduce_benchmark.cc │ │ ├── resize_bicubic_benchmark.cc │ │ ├── resize_bilinear_benchmark.cc │ │ ├── resize_nearest_neighbor_benchmark.cc │ │ ├── reverse_benchmark.cc │ │ ├── slice_benchmark.cc │ │ ├── softmax_benchmark.cc │ │ ├── space_to_batch_benchmark.cc │ │ ├── space_to_depth_benchmark.cc │ │ ├── splice_benchmark.cc │ │ ├── split_benchmark.cc │ │ ├── sqrdiff_mean_benchmark.cc │ │ ├── sum_group_benchmark.cc │ │ ├── target_rms_norm_benchmark.cc │ │ ├── thread_pool_benchmark.cc │ │ ├── tile_benchmark.cc │ │ └── transpose_benchmark.cc ├── ccunit │ ├── BUILD.bazel │ ├── CMakeLists.txt │ └── mace │ │ ├── core │ │ └── runtime │ │ │ └── hexagon │ │ │ └── hta_transform_test.cc │ │ ├── libmace │ │ ├── device_capability_api_test.cc │ │ ├── mace_api_exception_test.cc │ │ ├── mace_api_mt_test.cc │ │ ├── mace_api_test.cc │ │ └── mace_api_test.h │ │ ├── ops │ │ ├── activation_test.cc │ │ ├── addn_test.cc │ │ ├── argmax_test.cc │ │ ├── arm │ │ │ ├── arm82 │ │ │ │ └── gemm_test.cc │ │ │ ├── bf16 │ │ │ │ └── gemm_test.cc │ │ │ ├── fp32 │ │ │ │ ├── gemm_test.cc │ │ │ │ └── gemv_test.cc │ │ │ └── q8 │ │ │ │ └── gemv_test.cc │ │ ├── batch_norm_test.cc │ │ ├── bias_add_test.cc │ │ ├── buffer_to_image_test.cc │ │ ├── buffer_transform_test.cc │ │ ├── cast_test.cc │ │ ├── channel_shuffle_test.cc │ │ ├── concat_test.cc │ │ ├── conv_2d_test.cc │ │ ├── crop_test.cc │ │ ├── cumsum_test.cc │ │ ├── deconv_2d_test.cc │ │ ├── depth_to_space_test.cc │ │ ├── depthwise_conv2d_test.cc │ │ ├── depthwise_deconv2d_test.cc │ │ ├── detection_output_test.cc │ │ ├── eltwise_test.cc │ │ ├── expand_dims_test.cc │ │ ├── extract_image_patches_test.cc │ │ ├── extract_pooling_test.cc │ │ ├── fill_test.cc │ │ ├── fixpoint_test.cc │ │ ├── folded_batch_norm_test.cc │ │ ├── fully_connected_test.cc │ │ ├── gather_test.cc │ │ ├── group_norm_test.cc │ │ ├── identity_test.cc │ │ ├── infer_conv2d_shape_test.cc │ │ ├── instance_norm_test.cc │ │ ├── kaldi_batch_norm_test.cc │ │ ├── local_response_norm_test.cc │ │ ├── lpnorm_test.cc │ │ ├── lstmcell_test.cc │ │ ├── matmul_test.cc │ │ ├── mvnorm_test.cc │ │ ├── one_hot_test.cc │ │ ├── opencl │ │ │ └── out_of_range_check_test.cc │ │ ├── pad_context_test.cc │ │ ├── pad_test.cc │ │ ├── pnorm_test.cc │ │ ├── pooling_test.cc │ │ ├── prior_box_test.cc │ │ ├── quantize_test.cc │ │ ├── reduce_test.cc │ │ ├── reshape_test.cc │ │ ├── resize_bicubic_test.cc │ │ ├── resize_bilinear_test.cc │ │ ├── resize_nearest_neighbor_test.cc │ │ ├── reverse_test.cc │ │ ├── scalar_math_test.cc │ │ ├── select_test.cc │ │ ├── shape_test.cc │ │ ├── slice_test.cc │ │ ├── softmax_test.cc │ │ ├── space_to_batch_test.cc │ │ ├── space_to_depth_test.cc │ │ ├── splice_test.cc │ │ ├── split_test.cc │ │ ├── sqrdiff_mean_test.cc │ │ ├── squeeze_test.cc │ │ ├── stack_test.cc │ │ ├── strided_slice_test.cc │ │ ├── sum_group_test.cc │ │ ├── target_rms_norm_test.cc │ │ ├── tile_test.cc │ │ ├── transpose_test.cc │ │ ├── unstack_test.cc │ │ └── where_test.cc │ │ ├── port │ │ ├── env_test.cc │ │ └── logger_test.cc │ │ └── utils │ │ ├── count_down_latch_test.cc │ │ ├── logging_test.cc │ │ ├── spinlock_test.cc │ │ ├── string_util_test.cc │ │ ├── thread_pool_test.cc │ │ └── tuner_test.cc ├── ccutils │ ├── BUILD.bazel │ ├── CMakeLists.txt │ └── mace │ │ └── ops │ │ ├── lstmcell_test_util.h │ │ ├── ops_test_util.cc │ │ ├── ops_test_util.h │ │ └── testing │ │ └── test_utils.h └── ci-mace-models │ ├── onnx-models │ └── pytorch2onnx │ │ ├── reduce_test │ │ ├── reduce_test_max_channel_103 │ │ │ └── reduce_test.gpu.fp16.speedupDownload.yml │ │ ├── reduce_test_mean_channel_1003 │ │ │ └── reduce_test.gpu.fp32.speedupDownload.yml │ │ ├── reduce_test_mean_channel_1024 │ │ │ └── reduce_test.gpu.fp32.speedupDownload.yml │ │ ├── reduce_test_min_channel_1003 │ │ │ └── reduce_test.gpu.fp16.speedupDownload.yml │ │ ├── reduce_test_prod_channel_101 │ │ │ └── reduce_test.gpu.fp32.speedupDownload.yml │ │ ├── reduce_test_prod_channel_102 │ │ │ └── reduce_test.gpu.fp32.speedupDownload.yml │ │ └── reduce_test_sum_channel_1003 │ │ │ └── reduce_test.gpu.fp32.speedupDownload.yml │ │ └── test_const_input │ │ ├── test_const_input.cpu.yml │ │ ├── test_const_input.gpu.fp16.yml │ │ └── test_const_input.gpu.fp32.yml │ ├── run-ci-test-model.sh │ └── tf-models │ └── test_const_input │ ├── test_const_input.cpu.yml │ ├── test_const_input.gpu.fp16.yml │ └── test_const_input.gpu.fp32.yml ├── third_party ├── apu │ ├── BUILD │ ├── LICENSE │ ├── android_Q │ │ ├── mt67xx │ │ │ ├── ApuFrontend.h │ │ │ ├── libapu-frontend.so │ │ │ ├── mt6779 │ │ │ │ └── libapu-platform.so │ │ │ └── mt6785 │ │ │ │ └── libapu-platform.so │ │ └── mt68xx │ │ │ ├── libapu-frontend.so │ │ │ ├── mt6853 │ │ │ ├── libapu-frontend.so │ │ │ └── libapu-platform.so │ │ │ ├── mt6873 │ │ │ ├── libapu-frontend.so │ │ │ └── libapu-platform.so │ │ │ └── mt6885 │ │ │ ├── libapu-frontend.so │ │ │ └── libapu-platform.so │ ├── android_R │ │ ├── ApuFrontend.h │ │ ├── libapu-apuwareapusys.mtk.so │ │ ├── libapu-apuwareutils.mtk.so │ │ ├── libapu-apuwarexrp.mtk.so │ │ ├── libapu-frontend.so │ │ └── libapu-platform.so │ ├── android_R2 │ │ └── neuron_types.h │ └── apu.cmake ├── caffe │ ├── BUILD.bazel │ ├── Dockerfile │ ├── LICENSE │ ├── caffe.cmake │ └── caffe.proto ├── compilers │ ├── aarch64_compiler.BUILD │ └── arm_compiler.BUILD ├── dmabufheap │ ├── BUILD.bazel │ ├── dmabufheap.cmake │ └── include │ │ ├── BufferAllocatorWrapper.h │ │ └── dmabufheap-defs.h ├── eigen3 │ ├── BUILD.bazel │ ├── Eigen │ │ ├── Cholesky │ │ ├── Core │ │ ├── Eigenvalues │ │ ├── LU │ │ ├── QR │ │ └── SVD │ ├── LICENSE │ ├── eigen.BUILD │ ├── eigen3.cmake │ └── unsupported │ │ └── Eigen │ │ ├── CXX11 │ │ ├── Core │ │ ├── FixedPoint │ │ ├── NeuralNetworks │ │ ├── Tensor │ │ ├── ThreadPool │ │ └── src │ │ │ ├── FixedPoint │ │ │ ├── FixedPointTypes.h │ │ │ ├── MatMatProduct.h │ │ │ ├── MatMatProductAVX2.h │ │ │ ├── MatMatProductNEON.h │ │ │ ├── MatVecProduct.h │ │ │ ├── PacketMathAVX2.h │ │ │ ├── PacketMathAVX512.h │ │ │ ├── TypeCastingAVX2.h │ │ │ └── TypeCastingAVX512.h │ │ │ └── NeuralNetworks │ │ │ ├── Activations.h │ │ │ ├── Attention.h │ │ │ ├── BackwardCuboidConvolutions.h │ │ │ ├── BackwardSpatialConvolutions.h │ │ │ ├── CuboidConvolution.h │ │ │ ├── Patch3d.h │ │ │ ├── Pooling.h │ │ │ ├── SoftMax.h │ │ │ ├── SpatialConvolutions.h │ │ │ └── TensorConvolutionByFFT.h │ │ └── SpecialFunctions ├── gemmlowp │ ├── LICENSE │ └── gemmlowp.cmake ├── gflags │ ├── COPYING.txt │ └── gflags.cmake ├── googletest │ ├── LICENSE │ ├── googletest.BUILD │ └── googletest.cmake ├── half │ ├── LICENSE.txt │ ├── half.BUILD │ └── half.cmake ├── hexagon │ ├── hexagon_sdk.BUILD │ └── hexagon_tools.BUILD ├── mtk_rpcmem │ ├── BUILD.bazel │ ├── includes │ │ ├── libion │ │ │ └── ion.h │ │ ├── libion_mtk │ │ │ └── ion.h │ │ └── linux │ │ │ └── ion_drv.h │ ├── libs │ │ └── arm64-v8a │ │ │ ├── libion.so │ │ │ └── libion_mtk.so │ └── mtk_rpcmem.cmake ├── nnlib │ ├── BUILD.bazel │ ├── arm64-v8a │ │ ├── libcdsprpc.so │ │ └── libhexagon_controller.so │ ├── armeabi-v7a │ │ └── libhexagon_controller.so │ ├── hexagon_nn.h │ ├── hexnn_dsp_controller.h │ ├── license.txt │ ├── nnlib.cmake │ ├── ops.h │ ├── v60 │ │ └── libhexagon_nn_skel.so │ ├── v65 │ │ └── libhexagon_nn_skel.so │ └── v66 │ │ └── libhexagon_nn_skel.so ├── opencl-clhpp │ ├── LICENSE.txt │ ├── opencl-clhpp.BUILD │ └── opencl-clhpp.cmake ├── opencl-headers │ ├── LICENSE │ ├── opencl-headers.BUILD │ └── opencl-headers.cmake ├── protobuf │ ├── LICENSE │ └── protobuf.cmake ├── rpcmem │ ├── BUILD.bazel │ ├── arm64-v8a │ │ └── rpcmem.a │ ├── armeabi-v7a │ │ └── rpcmem.a │ ├── license.txt │ ├── rpcmem.cmake │ └── rpcmem.h ├── six │ ├── LICENSE │ └── six.BUILD ├── tflite │ ├── LICENSE │ └── tflite.cmake └── third_party.cmake └── tools ├── aarch64_compiler ├── BUILD.bazel ├── CROSSTOOL └── linaro_linux_gcc │ ├── BUILD.bazel │ ├── aarch64-linux-gnu-ar │ ├── aarch64-linux-gnu-as │ ├── aarch64-linux-gnu-gcc │ ├── aarch64-linux-gnu-gcov │ ├── aarch64-linux-gnu-ld │ ├── aarch64-linux-gnu-nm │ ├── aarch64-linux-gnu-objcopy │ ├── aarch64-linux-gnu-objdump │ └── aarch64-linux-gnu-strip ├── accuracy_validator.py ├── arm_compiler ├── BUILD.bazel ├── CROSSTOOL └── linaro_linux_gcc │ ├── BUILD.bazel │ ├── arm-linux-gnueabihf-ar │ ├── arm-linux-gnueabihf-as │ ├── arm-linux-gnueabihf-gcc │ ├── arm-linux-gnueabihf-gcov │ ├── arm-linux-gnueabihf-ld │ ├── arm-linux-gnueabihf-nm │ ├── arm-linux-gnueabihf-objcopy │ ├── arm-linux-gnueabihf-objdump │ └── arm-linux-gnueabihf-strip ├── bazel.rc ├── bazel_adb_run.py ├── bazel_build_standalone_lib.sh ├── clear_workspace.sh ├── cmake ├── cmake-build-aarch64-linux-gnu.sh ├── cmake-build-arm-linux-gnueabihf.sh ├── cmake-build-arm64-v8a.sh ├── cmake-build-armeabi-v7a.sh ├── cmake-build-host.sh └── cmake-generate-proto-py-host.sh ├── common.py ├── converter.py ├── cpplint.sh ├── dana ├── __init__.py ├── dana_cli.py └── dana_util.py ├── device.py ├── extract_pooling.py ├── generate_data.py ├── hexagon_compiler ├── BUILD.bazel ├── CROSSTOOL └── hexagon_gcc │ ├── BUILD.bazel │ ├── hexagon-qualcomm-ar │ ├── hexagon-qualcomm-as │ ├── hexagon-qualcomm-gcc │ ├── hexagon-qualcomm-gcov │ ├── hexagon-qualcomm-ld │ ├── hexagon-qualcomm-nm │ ├── hexagon-qualcomm-objcopy │ ├── hexagon-qualcomm-objdump │ └── hexagon-qualcomm-strip ├── image ├── image_to_tensor.py └── tensor_to_image.py ├── layers_validate.py ├── onnx_optimizer.py ├── python ├── CMakeLists.txt ├── __init__.py ├── apu_utils.py ├── config │ └── model │ │ └── model-template.yaml ├── convert.py ├── encrypt.py ├── gen_opencl.py ├── hexagon_soc_defines.py ├── layers_validate.py ├── micro │ ├── __init__.py │ ├── graph_builder.py │ ├── jinja2_files │ │ ├── CMakeLists.txt.jinja2 │ │ ├── micro_engine_c_interface.cc.jinja2 │ │ ├── micro_engine_c_interface.h.jinja2 │ │ ├── micro_engine_config.cc.jinja2 │ │ ├── micro_engine_factory.cc.jinja2 │ │ ├── micro_engine_factory.h.jinja2 │ │ ├── micro_graph_data.h.jinja2 │ │ ├── micro_model_data.h.jinja2 │ │ ├── micro_net_def.h.jinja2 │ │ └── micro_ops_list.h.jinja2 │ ├── mem_computer.py │ ├── micro_codegen.py │ ├── micro_io_converter.py │ ├── micro_op_converter.py │ ├── micro_op_resolver_cmsis_rules.py │ ├── micro_op_resolver_rules.py │ ├── micro_op_resolver_xtensa_rules.py │ ├── micro_support_ops.py │ ├── proto_to_bytes.py │ └── scratch_computer.py ├── micro_converter.py ├── py_proto │ └── __init__.py ├── quantize │ ├── __init__.py │ ├── quantize_stat.py │ ├── quantize_util.py │ └── quantize_util_test.py ├── run_micro.py ├── run_model.py ├── run_target.py ├── template │ ├── file_binary.cc.jinja2 │ ├── graph.jinja2 │ ├── mace_engine_factory.h.jinja2 │ ├── model.jinja2 │ ├── model_header.jinja2 │ ├── operator.jinja2 │ ├── tensor_data.jinja2 │ └── tensor_source.jinja2 ├── transform │ ├── __init__.py │ ├── apu_converter.py │ ├── base_converter.py │ ├── caffe_converter.py │ ├── hexagon_converter.py │ ├── keras_converter.py │ ├── megengine_converter.py │ ├── onnx_converter.py │ ├── pytorch_converter.py │ ├── shape_inference.py │ ├── tensorflow_converter.py │ └── transformer.py ├── utils │ ├── __init__.py │ ├── config_parser.py │ ├── convert_util.py │ ├── device.py │ ├── net_util.py │ ├── target.py │ └── util.py ├── validate.py └── visualize │ ├── __init__.py │ ├── index.html │ └── visualize_model.py ├── sh_commands.py ├── validate.py └── wino_conv.py /.bazelrc: -------------------------------------------------------------------------------- 1 | # To support new bazelrc file list: 2 | # https://github.com/bazelbuild/bazel/issues/4502 3 | import %workspace%/tools/bazel.rc 4 | -------------------------------------------------------------------------------- /.bazelversion: -------------------------------------------------------------------------------- 1 | 0.13.0 -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: google 2 | MaxEmptyLinesToKeep: 3 3 | DerivePointerAlignment: false 4 | PointerAlignment: Right 5 | BinPackParameters: false 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | build/* 3 | cmake-build/ 4 | cmake-build-debug/ 5 | docs/_build/ 6 | 7 | .idea/ 8 | .vscode/ 9 | tags 10 | 11 | \.project/ 12 | *swp 13 | *~ 14 | *.pyc 15 | .python-version 16 | 17 | mace/codegen/models/ 18 | mace/codegen/opencl/ 19 | mace/codegen/opencl_bin/ 20 | mace/codegen/tuning/ 21 | mace/codegen/version/ 22 | mace/codegen/engine/ 23 | mace/codegen/lib/ 24 | 25 | examples/android/macelibrary/src/main/cpp/mace/ 26 | examples/android/macelibrary/src/main/cpp/include/ 27 | examples/android/macelibrary/src/main/cpp/lib/arm64-v8a/ 28 | examples/android/macelibrary/src/main/jniLibs/arm64-v8a/ 29 | 30 | tools/python/py_proto/*_pb2.py 31 | 32 | micro/codegen/** 33 | micro/examples/micro 34 | micro/build 35 | 36 | mace-models 37 | 38 | __pycache__ 39 | *.egg-info 40 | .mace_run 41 | .model 42 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "micro/third_party/CMSIS_5"] 2 | path = micro/third_party/CMSIS_5 3 | url = https://github.com/ARM-software/CMSIS_5.git 4 | shallow = true 5 | [submodule "micro/third_party/googletest"] 6 | path = micro/third_party/googletest 7 | url = https://github.com/google/googletest.git 8 | shallow = true 9 | [submodule "micro/third_party/gflags"] 10 | path = micro/third_party/gflags 11 | url = https://github.com/gflags/gflags.git 12 | shallow = true 13 | -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/BUILD.bazel -------------------------------------------------------------------------------- /JOBS.md: -------------------------------------------------------------------------------- 1 | ## Join Us 2 | We are hiring talents (full-time or interns) with the following skills: 3 | 4 | * Solid C++ skills (required) 5 | * Heterogeneous computing (NEON, OpenCL, CUDA, HVX, TVM, MLIR etc.) 6 | * Model compression and quantization 7 | * Large scale distributed system 8 | * Computer vision, image processing and/or autonomous driving 9 | 10 | Contacts: please find email from the commit log. 11 | 12 | ## 加入我们 13 | 欢迎加入我们 (全职或实习生): 14 | 15 | * 扎实的C++编程基础与良好的工程习惯 (必须) 16 | * 异构计算 (NEON, OpenCL, CUDA, HVX, TVM, MLIR等) 17 | * 神经网络模型压缩与量化 18 | * 大规模分布式系统 19 | * 计算机视觉,图像处理,自动驾驶 20 | 21 | 联系方式:提交记录中的email。 22 | -------------------------------------------------------------------------------- /ROADMAP.md: -------------------------------------------------------------------------------- 1 | Roadmap 2 | ======= 3 | 4 | * CUDA support 5 | * Mixed-precision inference 6 | * Improved host/x86 performance 7 | 8 | *Last updated: April 15, 2019* 9 | -------------------------------------------------------------------------------- /cmake/toolchains/aarch64-linux-gnu.cmake: -------------------------------------------------------------------------------- 1 | # Tested with gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu 2 | # https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/ 3 | 4 | set(CMAKE_SYSTEM_NAME Linux) 5 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 6 | 7 | set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/aarch64-linux-gnu-gcc") 8 | set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/aarch64-linux-gnu-g++") 9 | 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 13 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 14 | 15 | set(CMAKE_CXX_FLAGS "-march=armv8-a ${CMAKE_CXX_FLAGS}") 16 | -------------------------------------------------------------------------------- /cmake/toolchains/arm-linux-gnueabi.cmake: -------------------------------------------------------------------------------- 1 | # Tested with gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi 2 | # https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/ 3 | 4 | set(CMAKE_SYSTEM_NAME Linux) 5 | set(CMAKE_SYSTEM_PROCESSOR arm) 6 | 7 | set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabi-gcc") 8 | set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabi-g++") 9 | 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 13 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 14 | 15 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}") 16 | -------------------------------------------------------------------------------- /cmake/toolchains/arm-linux-gnueabihf.cmake: -------------------------------------------------------------------------------- 1 | # Tested with gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf 2 | # https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/ 3 | 4 | set(CMAKE_SYSTEM_NAME Linux) 5 | set(CMAKE_SYSTEM_PROCESSOR arm) 6 | 7 | set(CMAKE_C_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabihf-gcc") 8 | set(CMAKE_CXX_COMPILER "${CROSSTOOL_ROOT}/bin/arm-linux-gnueabihf-g++") 9 | 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 13 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 14 | 15 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 ${CMAKE_CXX_FLAGS}") 16 | -------------------------------------------------------------------------------- /docker/gitlab-runner/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev:latest 2 | 3 | # Update source 4 | RUN apt-get update -y 5 | 6 | # Install gitlab runner 7 | RUN curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.deb.sh | bash 8 | RUN apt-get install gitlab-ci-multi-runner 9 | 10 | # set timezone 11 | RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 12 | 13 | ENTRYPOINT gitlab-runner run 14 | -------------------------------------------------------------------------------- /docker/mace-micro-dev/mace-micro-dev.dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | RUN apt-get update --fix-missing 4 | RUN apt-get install -y wget 5 | 6 | RUN wget https://github.com/Kitware/CMake/releases/download/v3.18.4/cmake-3.18.4-Linux-x86_64.sh && chmod +x cmake-3.18.4-Linux-x86_64.sh && ./cmake-3.18.4-Linux-x86_64.sh --skip-license --prefix=/usr 7 | 8 | RUN apt-get install -y g++-5 gcc-5 9 | RUN apt-get install -y gcc-arm-none-eabi 10 | RUN apt-get install -y git mercurial 11 | RUN apt-get install -y python python-pip 12 | RUN apt-get install -y python3 python3-pip 13 | 14 | RUN python -m pip install -U pip 15 | RUN python -m pip install jinja2 pyyaml sh numpy six filelock 16 | RUN python -m pip install tensorflow==1.8.0 17 | 18 | RUN python3 -m pip install -U pip 19 | RUN python3 -m pip install jinja2 pyyaml sh numpy six filelock 20 | RUN python3 -m pip install tensorflow==2.3.0 tensorflow_model_optimization 21 | RUN python3 -m pip install mbed-cli 22 | -------------------------------------------------------------------------------- /docker/update_images.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | BUILD_DIR_NAME="docker" 6 | CURRENT_DIR_NAME=`basename "$PWD"` 7 | 8 | if [ $BUILD_DIR_NAME != $CURRENT_DIR_NAME ]; then 9 | echo "You can run script only in 'mace/docker' directory" 10 | exit 1 11 | fi 12 | 13 | # build images 14 | docker build --network host -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite ./mace-dev-lite 15 | docker build --network host -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev ./mace-dev 16 | docker build --network host -t registry.cn-hangzhou.aliyuncs.com/xiaomimace/gitlab-runner ./gitlab-runner 17 | 18 | if grep -lq registry.cn-hangzhou.aliyuncs.com ~/.docker/config.json; then 19 | # update images to repository 20 | docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev-lite 21 | docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/mace-dev 22 | docker push registry.cn-hangzhou.aliyuncs.com/xiaomimace/gitlab-runner 23 | else 24 | echo "Login docker registry server is needed!" 25 | exit 1 26 | fi 27 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = MACE 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /docs/README: -------------------------------------------------------------------------------- 1 | The documents are based on Sphinx, run the following commands to build the documents: 2 | 3 | pip install sphinx sphinx-autobuild sphinx-rtd-theme 4 | pip install recommonmark 5 | make html 6 | 7 | After building, the generated documents are located in _build. 8 | -------------------------------------------------------------------------------- /docs/chinese.rst: -------------------------------------------------------------------------------- 1 | 中文 2 | ============ 3 | 4 | 简介 5 | ---- 6 | 7 | Mobile AI Compute Engine (MACE) 是一个专为移动端异构计算设备优化的深度学习前向预测框架。 8 | MACE覆盖了常见的移动端计算设备(CPU、GPU、Hexagon DSP、Hexagon HTA、MTK APU),并且提供了完整的工具链和文档,用户借助MACE能够 9 | 很方便地在移动端部署深度学习模型。MACE已经在小米内部广泛使用并且被充分验证具有业界领先的性能和稳定性。 10 | 11 | 框架 12 | ---- 13 | 下图描述了MACE的基本框架。 14 | 15 | .. image:: mace-arch.png 16 | :scale: 40 % 17 | :align: center 18 | 19 | .. toctree:: 20 | :maxdepth: 1 21 | :caption: 安装方法 22 | :name: sec-install-ch 23 | 24 | zh/installation/env_requirement 25 | 26 | .. toctree:: 27 | :maxdepth: 1 28 | :caption: 基本使用 29 | :name: sec-user-ch 30 | 31 | zh/user_guide/basic_usage -------------------------------------------------------------------------------- /docs/development/dynamic_lstm.rst: -------------------------------------------------------------------------------- 1 | Dynamic LSTM 2 | ============ 3 | 4 | 5 | The DynamicLSTM in MACE is implemented for Kaldi's time delay RNN models. 6 | 7 | The following pictures explain how to fuse components into a DynamicLSTMCell. 8 | 9 | Before fusing: 10 | 11 | .. image:: imgs/FuseLSTM.png 12 | :scale: 100 % 13 | :align: center 14 | 15 | 16 | After fusing: 17 | 18 | .. image:: imgs/DynamicLSTM.png 19 | :scale: 100 % 20 | :align: center 21 | 22 | For more details about LSTMNonlinear in Kaldi, 23 | please refer to [LstmNonlinearityComponent](http://kaldi-asr.org/doc/nnet-combined-component_8h_source.html#l00255) 24 | -------------------------------------------------------------------------------- /docs/development/imgs/DynamicLSTM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/docs/development/imgs/DynamicLSTM.png -------------------------------------------------------------------------------- /docs/development/imgs/FuseLSTM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/docs/development/imgs/FuseLSTM.png -------------------------------------------------------------------------------- /docs/mace-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/docs/mace-arch.png -------------------------------------------------------------------------------- /docs/mace-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/docs/mace-logo.png -------------------------------------------------------------------------------- /docs/mace-work-flow-zh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/docs/mace-work-flow-zh.png -------------------------------------------------------------------------------- /docs/mace-work-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/docs/mace-work-flow.png -------------------------------------------------------------------------------- /docs/micro-controllers/op_lists.rst: -------------------------------------------------------------------------------- 1 | Operator lists 2 | =============== 3 | 4 | MACE Micro supported operators 5 | ------------------------------ 6 | 7 | Float32 and bfloat16 operators 8 | 9 | * batch_norm 10 | * conv_2d 11 | * depthwise_conv_2d 12 | * pooling 13 | * activation 14 | * argmax 15 | * bias_add 16 | * cast 17 | * concat 18 | * eltwise 19 | * expand_dims 20 | * matmul 21 | * reduce 22 | * reshape 23 | * softmax 24 | * squeeze 25 | * stack 26 | * stride_slice 27 | 28 | Int8 operators 29 | 30 | * conv_2d 31 | * depthwsie_conv_2d 32 | * eltwise 33 | * mat_mul 34 | * pooling 35 | * softmax 36 | * quantize 37 | * dequantize 38 | 39 | Tensorflow Keras Converter supported layers 40 | 41 | * InputLayer 42 | * Flatten 43 | * Dense 44 | * Conv2D 45 | * MaxPooling2D 46 | * Dropout 47 | * DepthwiseConv2D 48 | * Softmax 49 | * BatchNormalization 50 | * Activation 51 | * ReLU 52 | * Concatenate 53 | * GlobalAveragePooling2D 54 | * Add 55 | * QuantizeLayer 56 | * QuantizeWrapper 57 | -------------------------------------------------------------------------------- /docs/user_guide/devices/demo_device_nanopi.yml: -------------------------------------------------------------------------------- 1 | # one yaml config file can contain multi device info 2 | devices: 3 | # The name of the device 4 | nanopi: 5 | # arm64 or armhf 6 | target_abis: [arm64, armhf] 7 | # device soc, you can get it from device manual 8 | target_socs: RK3399 9 | # device model full name 10 | models: FriendlyElec Nanopi M4 11 | # device ip address 12 | address: 10.0.0.0 13 | # login username 14 | username: user 15 | raspberry: 16 | target_abis: [armv7l] 17 | target_socs: BCM2837 18 | models: Raspberry Pi 3 Model B Plus Rev 1.3 19 | address: 10.0.0.1 20 | username: user 21 | -------------------------------------------------------------------------------- /examples/android/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /examples/android/README.md: -------------------------------------------------------------------------------- 1 | Android Demo 2 | ============= 3 | 4 | How to build 5 | --------------- 6 | 7 | ```sh 8 | cd mace/examples/android 9 | ./build.sh dynamic 10 | # if libmace.a is needed, update `macelibrary/CMakeLists.txt` and run with `./build.sh static`. 11 | ``` 12 | 13 | Install 14 | --------------- 15 | 16 | ```sh 17 | # running after build step and in `mace/exampls/android` directory 18 | adb install ./app/build/outputs/apk/app/release/app-app-release.apk 19 | ``` 20 | 21 | Pre-built APK 22 | -------------- 23 | Pre-built Android APK can be downloaded [here](https://cnbj1.fds.api.xiaomi.com/mace/demo/mace_android_demo.apk). 24 | 25 | Note 26 | -------------- 27 | We use two big cores for CPU inference. 28 | -------------------------------------------------------------------------------- /examples/android/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /examples/android/app/mace_demo.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/mace_demo.jks -------------------------------------------------------------------------------- /examples/android/app/src/main/java/com/xiaomi/mace/demo/Constant.java: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | package com.xiaomi.mace.demo; 16 | 17 | public class Constant { 18 | 19 | public static final int CAMERA_PERMISSION_REQ = 1; 20 | } 21 | -------------------------------------------------------------------------------- /examples/android/app/src/main/java/com/xiaomi/mace/demo/camera/MobilenetResultCallback.java: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | package com.xiaomi.mace.demo.camera; 16 | 17 | public interface MobilenetResultCallback { 18 | void onMaceResult(float[] result, long costTime); 19 | } 20 | -------------------------------------------------------------------------------- /examples/android/app/src/main/res/layout/layout_dialog.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 10 | -------------------------------------------------------------------------------- /examples/android/app/src/main/res/layout/layout_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /examples/android/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /examples/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 识物 3 | 4 | -------------------------------------------------------------------------------- /examples/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/android/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.2.0' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /examples/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | #android.useDeprecatedNdk=true 14 | 15 | # When configured, Gradle will run in incubating parallel model. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | -------------------------------------------------------------------------------- /examples/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/examples/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 12 13:35:24 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip 7 | -------------------------------------------------------------------------------- /examples/android/macelibrary/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /examples/android/macelibrary/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /examples/android/macelibrary/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /examples/android/macelibrary/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | MaceLibrary 3 | 4 | -------------------------------------------------------------------------------- /examples/android/macelibrary/version_script.lds: -------------------------------------------------------------------------------- 1 | VERS_1.0 { 2 | # Export JNI symbols. 3 | global: 4 | Java_*; 5 | JNI_OnLoad; 6 | JNI_OnUnload; 7 | 8 | # Hide everything else. 9 | local: 10 | *; 11 | }; 12 | -------------------------------------------------------------------------------- /examples/android/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':macelibrary' 2 | -------------------------------------------------------------------------------- /include/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | cc_library( 8 | name = "public_headers", 9 | hdrs = glob([ 10 | "mace/public/*.h", 11 | "mace/port/*.h", 12 | "mace/utils/*.h", 13 | ]), 14 | strip_include_prefix = "", 15 | copts = ["-Werror", "-Wextra", "-Wno-missing-field-initializers"], 16 | ) 17 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(DIRECTORY mace DESTINATION include) 2 | -------------------------------------------------------------------------------- /include/mace/port/port-arch.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The MACE 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 | #ifndef MACE_PORT_PORT_ARCH_H_ 16 | #define MACE_PORT_PORT_ARCH_H_ 17 | 18 | #if defined __APPLE__ 19 | # define MACE_OS_MAC 1 20 | # if TARGET_OS_IPHONE 21 | # define MACE_OS_IOS 1 22 | # endif 23 | #elif defined __linux__ 24 | # define MACE_OS_LINUX 1 25 | # if defined(__ANDROID__) || defined(ANDROID) 26 | # define MACE_OS_LINUX_ANDROID 1 27 | # endif 28 | #endif 29 | 30 | #endif // MACE_PORT_PORT_ARCH_H_ 31 | -------------------------------------------------------------------------------- /include/mace/port/port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The MACE 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 | #ifndef MACE_PORT_PORT_H_ 16 | #define MACE_PORT_PORT_H_ 17 | 18 | #include "mace/port/port-arch.h" 19 | #include "mace/public/mace.h" 20 | #include "mace/utils/logging.h" 21 | 22 | #if defined(MACE_OS_LINUX_ANDROID) 23 | #define MACE_THREAD_POOL_USE_SPIN 1 24 | #endif // MACE_OS_LINUX_ANDROID 25 | 26 | #endif // MACE_PORT_PORT_H_ 27 | -------------------------------------------------------------------------------- /mace/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(codegen) 2 | add_subdirectory(core) 3 | add_subdirectory(flows) 4 | add_subdirectory(libmace) 5 | add_subdirectory(ops) 6 | add_subdirectory(port) 7 | add_subdirectory(proto) 8 | add_subdirectory(rpcmems) 9 | add_subdirectory(runtimes) 10 | add_subdirectory(tools) 11 | add_subdirectory(utils) 12 | -------------------------------------------------------------------------------- /mace/codegen/model_version_script.lds: -------------------------------------------------------------------------------- 1 | mace { 2 | global: 3 | *LoadModelData*; 4 | *GetModelSize*; 5 | *CreateNet*; 6 | *ModelName*; 7 | *ModelChecksum*; 8 | *ModelBuildTime*; 9 | *ModelBuildOptions*; 10 | *MaceVersion*; 11 | 12 | local: 13 | *; 14 | }; 15 | -------------------------------------------------------------------------------- /mace/core/mace_tensor_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 MACE_CORE_MACE_TENSOR_IMPL_H_ 17 | #define MACE_CORE_MACE_TENSOR_IMPL_H_ 18 | 19 | #include 20 | #include 21 | 22 | namespace mace { 23 | 24 | // Mace Tensor 25 | class MaceTensor::Impl { 26 | public: 27 | std::vector shape; 28 | std::shared_ptr data; 29 | DataFormat format; 30 | IDataType data_type; 31 | MemoryType mem_type; 32 | int64_t buffer_size; 33 | }; 34 | 35 | } // namespace mace 36 | 37 | 38 | #endif // MACE_CORE_MACE_TENSOR_IMPL_H_ 39 | -------------------------------------------------------------------------------- /mace/core/ops/op_construct_context.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #include "mace/core/ops/op_construct_context.h" 16 | 17 | namespace mace { 18 | 19 | OpConstructContext::OpConstructContext(Workspace *ws) 20 | : operator_def_(nullptr), 21 | ws_(ws), 22 | runtime_(nullptr) {} 23 | 24 | void OpConstructContext::set_operator_def( 25 | std::shared_ptr operator_def) { 26 | operator_def_ = operator_def; 27 | } 28 | 29 | } // namespace mace 30 | -------------------------------------------------------------------------------- /mace/core/runtime_failure_mock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | #ifndef MACE_CORE_RUNTIME_FAILURE_MOCK_H_ 16 | #define MACE_CORE_RUNTIME_FAILURE_MOCK_H_ 17 | 18 | namespace mace { 19 | 20 | bool ShouldMockRuntimeFailure(); 21 | 22 | } // namespace mace 23 | 24 | #endif // MACE_CORE_RUNTIME_FAILURE_MOCK_H_ 25 | -------------------------------------------------------------------------------- /mace/flows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(FLOWS_SRCS flow_registry.cc) 2 | 3 | add_subdirectory(cpu) 4 | 5 | if(MACE_ENABLE_OPENCL) 6 | add_subdirectory(opencl) 7 | endif(MACE_ENABLE_OPENCL) 8 | 9 | if(MACE_ENABLE_HEXAGON) 10 | add_subdirectory(hexagon) 11 | endif(MACE_ENABLE_HEXAGON) 12 | 13 | if(MACE_ENABLE_MTK_APU) 14 | add_subdirectory(apu) 15 | endif(MACE_ENABLE_MTK_APU) 16 | 17 | if(MACE_ENABLE_QNN) 18 | add_subdirectory(qnn) 19 | endif(MACE_ENABLE_QNN) 20 | 21 | add_library(flows STATIC ${FLOWS_SRCS}) 22 | target_link_libraries(flows PRIVATE core cpu_flow) 23 | if(MACE_ENABLE_OPENCL) 24 | target_link_libraries(flows PRIVATE opencl_flow) 25 | endif(MACE_ENABLE_OPENCL) 26 | install(TARGETS flows ARCHIVE DESTINATION lib) 27 | -------------------------------------------------------------------------------- /mace/flows/apu/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load( 8 | "//mace:mace.bzl", 9 | "apu_version_select", 10 | ) 11 | 12 | cc_library( 13 | name = "apu_flows", 14 | srcs = glob([ 15 | "*.cc", 16 | ]), 17 | hdrs = glob([ 18 | "*.h", 19 | ]), 20 | copts = [ 21 | "-Werror", 22 | "-Wextra", 23 | "-Wno-missing-field-initializers", 24 | ] + apu_version_select( 25 | ["-DMACE_MTK_APU_VERSION=1"], 26 | ["-DMACE_MTK_APU_VERSION=2"], 27 | ["-DMACE_MTK_APU_VERSION=3"], 28 | ["-DMACE_MTK_APU_VERSION=4"], 29 | ), 30 | linkopts = ["-ldl"], 31 | deps = [ 32 | "//mace/core", 33 | "//mace/runtimes/apu:apu_runtimes", 34 | ], 35 | ) 36 | -------------------------------------------------------------------------------- /mace/flows/apu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(apu_flow STATIC 2 | apu_ref_flow.cc 3 | ) 4 | 5 | target_link_libraries(apu_flow core ${EXTRA_LINK_LIBS}) 6 | 7 | install(TARGETS apu_flow ARCHIVE DESTINATION lib) 8 | -------------------------------------------------------------------------------- /mace/flows/cpu/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load( 8 | "//mace:mace.bzl", 9 | "if_bfloat16_enabled", 10 | "if_fp16_enabled", 11 | ) 12 | 13 | cc_library( 14 | name = "cpu_flows", 15 | srcs = glob([ 16 | "cpu_ref*.cc", 17 | "transpose_const.cc", 18 | ]) + if_bfloat16_enabled(glob([ 19 | "cpu_bf16*.cc", 20 | ])) + if_fp16_enabled(glob([ 21 | "cpu_fp16*.cc", 22 | ])), 23 | hdrs = glob([ 24 | "cpu_ref*.h", 25 | "transpose_const.h", 26 | ]) + if_bfloat16_enabled(glob([ 27 | "cpu_bf16*.h", 28 | ])) + if_fp16_enabled(glob([ 29 | "cpu_fp16*.h", 30 | ])), 31 | copts = [ 32 | "-Werror", 33 | "-Wextra", 34 | "-Wno-missing-field-initializers", 35 | ] + if_bfloat16_enabled([ 36 | "-DMACE_ENABLE_BFLOAT16", 37 | ]) + if_fp16_enabled([ 38 | "-DMACE_ENABLE_FP16", 39 | "-march=armv8.2-a+fp16", 40 | ]), 41 | linkopts = ["-ldl"], 42 | deps = [ 43 | "//mace/core", 44 | ], 45 | ) 46 | -------------------------------------------------------------------------------- /mace/flows/cpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CPU_SRCS 2 | cpu_ref_flow.cc 3 | transpose_const.cc 4 | ) 5 | 6 | if(MACE_ENABLE_FP16) 7 | set(CPU_SRCS ${CPU_SRCS} cpu_fp16_flow.cc) 8 | endif(MACE_ENABLE_FP16) 9 | 10 | if(MACE_ENABLE_BFLOAT16) 11 | set(CPU_SRCS ${CPU_SRCS} cpu_bf16_flow.cc) 12 | endif(MACE_ENABLE_BFLOAT16) 13 | 14 | add_library(cpu_flow STATIC ${CPU_SRCS}) 15 | target_link_libraries(cpu_flow core) 16 | install(TARGETS cpu_flow ARCHIVE DESTINATION lib) 17 | -------------------------------------------------------------------------------- /mace/flows/cpu/transpose_const.h: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The MACE 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 | #ifndef MACE_FLOWS_CPU_TRANSPOSE_CONST_H_ 16 | #define MACE_FLOWS_CPU_TRANSPOSE_CONST_H_ 17 | 18 | #include "mace/public/mace.h" 19 | #include "mace/utils/thread_pool.h" 20 | 21 | namespace mace { 22 | class Workspace; 23 | MaceStatus TransposeConstForCPU( 24 | mace::utils::ThreadPool *thread_pool, 25 | Workspace *ws, 26 | Runtime *runtime, 27 | NetDef *net_def); 28 | 29 | } // namespace mace 30 | 31 | #endif // MACE_FLOWS_CPU_TRANSPOSE_CONST_H_ 32 | -------------------------------------------------------------------------------- /mace/flows/hexagon/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | cc_library( 8 | name = "hexagon_flows", 9 | srcs = glob([ 10 | "*.cc", 11 | ]), 12 | hdrs = glob([ 13 | "*.h", 14 | ]), 15 | copts = [ 16 | "-Werror", 17 | "-Wextra", 18 | "-Wno-missing-field-initializers", 19 | ], 20 | linkopts = ["-ldl"], 21 | deps = [ 22 | "//mace/core", 23 | "//mace/runtimes/hexagon:hexagon_runtimes", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /mace/flows/hexagon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEXAGON_SRCS 2 | hexagon_ref_flow.cc 3 | ) 4 | 5 | add_library(hexagon_flow STATIC ${HEXAGON_SRCS}) 6 | target_link_libraries(hexagon_flow core) 7 | install(TARGETS hexagon_flow ARCHIVE DESTINATION lib) 8 | -------------------------------------------------------------------------------- /mace/flows/opencl/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | cc_library( 8 | name = "opencl_flows", 9 | srcs = glob([ 10 | "*.cc", 11 | ]), 12 | hdrs = glob([ 13 | "*.h", 14 | ]), 15 | copts = [ 16 | "-Werror", 17 | "-Wextra", 18 | "-Wno-missing-field-initializers", 19 | ], 20 | linkopts = ["-ldl"], 21 | deps = [ 22 | "//mace/core", 23 | "//mace/flows/cpu:cpu_flows", 24 | "//mace/runtimes/opencl:opencl_runtimes", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /mace/flows/opencl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OPENCL_SRCS 2 | opencl_ref_flow.cc 3 | ) 4 | 5 | add_library(opencl_flow STATIC ${OPENCL_SRCS}) 6 | add_dependencies(opencl_flow opencl_clhpp) 7 | 8 | target_link_libraries(opencl_flow core ${EXTRA_LINK_LIBS}) 9 | install(TARGETS opencl_flow ARCHIVE DESTINATION lib) 10 | -------------------------------------------------------------------------------- /mace/flows/qnn/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | cc_library( 8 | name = "qnn_flows", 9 | srcs = glob([ 10 | "*.cc", 11 | ]), 12 | hdrs = glob([ 13 | "*.h", 14 | ]), 15 | copts = [ 16 | "-Werror", 17 | "-Wextra", 18 | "-Wno-missing-field-initializers", 19 | ], 20 | linkopts = ["-ldl"], 21 | deps = [ 22 | "//mace/core", 23 | "//mace/runtimes/qnn:qnn_runtimes", 24 | ], 25 | ) 26 | -------------------------------------------------------------------------------- /mace/flows/qnn/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(QNN_SRCS 2 | qnn_ref_flow.cc 3 | ) 4 | 5 | add_library(qnn_flow STATIC ${QNN_SRCS}) 6 | target_link_libraries(qnn_flow core) 7 | install(TARGETS qnn_flow ARCHIVE DESTINATION lib) 8 | -------------------------------------------------------------------------------- /mace/libmace/combine_static_libs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | output_name=$1 4 | 5 | shift 6 | 7 | for i in "$@" 8 | do 9 | echo "$i" | tr -s ';' ' ' | xargs ar qc $output_name 10 | done -------------------------------------------------------------------------------- /mace/libmace/engines/engine_registry.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #include "mace/libmace/engines/engine_registry.h" 17 | 18 | #include "mace/libmace/engines/serial_engine.h" 19 | #include "mace/utils/memory.h" 20 | 21 | namespace mace { 22 | 23 | std::unique_ptr SmartCreateEngine(const MaceEngineConfig &config) { 24 | return make_unique(config); 25 | } 26 | 27 | } // namespace mace 28 | -------------------------------------------------------------------------------- /mace/libmace/engines/engine_registry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MACE_LIBMACE_ENGINES_ENGINE_REGISTRY_H_ 16 | #define MACE_LIBMACE_ENGINES_ENGINE_REGISTRY_H_ 17 | 18 | #include 19 | 20 | #include "mace/libmace/engines/base_engine.h" 21 | 22 | namespace mace { 23 | 24 | std::unique_ptr SmartCreateEngine(const MaceEngineConfig &config); 25 | 26 | } // namespace mace 27 | 28 | #endif // MACE_LIBMACE_ENGINES_ENGINE_REGISTRY_H_ 29 | -------------------------------------------------------------------------------- /mace/libmace/mace.mri.in: -------------------------------------------------------------------------------- 1 | create @BASE_PATH@/mace/libmace/libmace_static.a 2 | addlib @BASE_PATH@/mace/libmace/libmace_API.a 3 | addlib @BASE_PATH@/mace/ops/libops.a 4 | @FLOW_LIBS_MRI@ 5 | @RUNTIME_LIBS_MRI@ 6 | addlib @BASE_PATH@/mace/core/libcore.a 7 | addlib @BASE_PATH@/mace/utils/libutils.a 8 | addlib @BASE_PATH@/mace/proto/libproto.a 9 | addlib @BASE_PATH@/mace/port/libport_base.a 10 | @PORT_LIBS_MRI@ 11 | addlib @BASE_PATH@/mace/codegen/libgenerated_version.a 12 | addlib @BASE_PATH@/mace/codegen/libgenerated_opencl_kernel.a 13 | addlib @BASE_PATH@/third_party/protobuf/src/protobuf-build/libprotobuf-lite.a 14 | save 15 | end 16 | -------------------------------------------------------------------------------- /mace/libmace/mace_version_script.lds: -------------------------------------------------------------------------------- 1 | mace { 2 | global: 3 | *GPUContextBuilder*; 4 | *MaceEngineConfig*; 5 | *MaceTensor*; 6 | *MaceEngine*; 7 | *CreateMaceEngineFromProto*; 8 | *GetBigLittleCoreIDs*; 9 | *MaceVersion*; 10 | *GetCapability*; 11 | 12 | # api for static library of models 13 | *mace*port**; 14 | *mace*MaceStatus*; 15 | *mace*NetDef*; 16 | *mace*MemoryType*; 17 | *mace*DataType*; 18 | *mace*InputOutputInfo*; 19 | *mace*OutputShape*; 20 | *mace*OperatorDef*; 21 | *mace*ConstTensor*; 22 | *mace*Argument*; 23 | *mace*Split*; 24 | *mace*MemoryBlock*; 25 | *google*protobuf*; 26 | 27 | local: 28 | *; 29 | }; 30 | -------------------------------------------------------------------------------- /mace/ops/arm/README: -------------------------------------------------------------------------------- 1 | # Notes for Contributors and Roadmap 2 | 3 | We are going to refactor and optimize ARM related kernels one step at a time. 4 | 5 | The code structure will be organized as that kernels for each data type are separated. 6 | By this way, they are independent to each other and can be linked and shipped as a submodule, 7 | and it saves us from writing macro boilerplate. The reason we do not use a unified header file for each kernel 8 | is that we are not forcing developers to use exact same interface for kernels of different data types at this level, 9 | although doing this is recommended if convenient to do so. A reference version is put right in `ops` directory to be used 10 | as non-NEON kernels, which are not separated for different data types for simplicity. 11 | 12 | Although interface is kept flexible and can be defined according to demand, 13 | input/output parameters should be of `Tensor` type instead of raw pointer, as 14 | `Tensor` has more information kernel might use. 15 | 16 | -------------------------------------------------------------------------------- /mace/ops/arm/base/conv_2d_5x5.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #include "mace/ops/arm/base/conv_2d_5x5.h" 16 | 17 | namespace mace { 18 | namespace ops { 19 | namespace arm { 20 | 21 | void RegisterConv2dK5x5Delegator(OpDelegatorRegistry *registry) { 22 | MACE_REGISTER_DELEGATOR( 23 | registry, Conv2dK5x5S1, delegator::Conv2dParam, 24 | MACE_DELEGATOR_KEY_EX(Conv2d, RuntimeType::RT_CPU, 25 | float, ImplType::NEON, K5x5S1)); 26 | } 27 | 28 | } // namespace arm 29 | } // namespace ops 30 | } // namespace mace 31 | -------------------------------------------------------------------------------- /mace/ops/arm/base/gemv.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #include "mace/ops/arm/base/gemv.h" 17 | 18 | namespace mace { 19 | namespace ops { 20 | namespace arm { 21 | 22 | void RegisterGemvDelegator(OpDelegatorRegistry *registry) { 23 | MACE_REGISTER_DELEGATOR( 24 | registry, Gemv, DelegatorParam, 25 | MACE_DELEGATOR_KEY(Gemv, RuntimeType::RT_CPU, float, ImplType::NEON)); 26 | } 27 | 28 | } // namespace arm 29 | } // namespace ops 30 | } // namespace mace 31 | -------------------------------------------------------------------------------- /mace/ops/common/activation_type.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | #ifndef MACE_OPS_COMMON_ACTIVATION_TYPE_H_ 16 | #define MACE_OPS_COMMON_ACTIVATION_TYPE_H_ 17 | 18 | namespace mace { 19 | namespace ops { 20 | 21 | enum ActivationType { 22 | NOOP = 0, 23 | RELU = 1, 24 | RELUX = 2, 25 | PRELU = 3, 26 | TANH = 4, 27 | SIGMOID = 5, 28 | LEAKYRELU = 6, 29 | ELU = 7, 30 | HARDSIGMOID = 8, 31 | }; 32 | 33 | } // namespace ops 34 | } // namespace mace 35 | 36 | #endif // MACE_OPS_COMMON_ACTIVATION_TYPE_H_ 37 | -------------------------------------------------------------------------------- /mace/ops/common/pad_type.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | #ifndef MACE_OPS_COMMON_PAD_TYPE_H_ 16 | #define MACE_OPS_COMMON_PAD_TYPE_H_ 17 | 18 | namespace mace { 19 | namespace ops { 20 | 21 | enum PadType { 22 | CONSTANT = 0, 23 | REFLECT = 1, 24 | SYMMETRIC = 2, 25 | }; 26 | 27 | } // namespace ops 28 | } // namespace mace 29 | 30 | #endif // MACE_OPS_COMMON_PAD_TYPE_H_ 31 | -------------------------------------------------------------------------------- /mace/ops/common/pooling_type.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | #ifndef MACE_OPS_COMMON_POOLING_TYPE_H_ 16 | #define MACE_OPS_COMMON_POOLING_TYPE_H_ 17 | 18 | 19 | namespace mace { 20 | enum PoolingType { 21 | AVG = 1, // avg_pool 22 | MAX = 2, // max_pool 23 | }; 24 | } // namespace mace 25 | 26 | #endif // MACE_OPS_COMMON_POOLING_TYPE_H_ 27 | -------------------------------------------------------------------------------- /mace/ops/common/reduce_type.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | #ifndef MACE_OPS_COMMON_REDUCE_TYPE_H_ 16 | #define MACE_OPS_COMMON_REDUCE_TYPE_H_ 17 | 18 | 19 | namespace mace { 20 | enum ReduceType { 21 | MEAN = 0, 22 | MIN = 1, 23 | MAX = 2, 24 | PROD = 3, 25 | SUM = 4, 26 | // SUM_SQR = 4, 27 | // SQR_MEAN = 5, 28 | }; 29 | } // namespace mace 30 | 31 | #endif // MACE_OPS_COMMON_REDUCE_TYPE_H_ 32 | -------------------------------------------------------------------------------- /mace/ops/delegator/depthwise_conv_2d.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 MACE_OPS_DELEGATOR_DEPTHWISE_CONV_2D_H_ 17 | #define MACE_OPS_DELEGATOR_DEPTHWISE_CONV_2D_H_ 18 | 19 | #include "mace/ops/delegator/conv_2d.h" 20 | 21 | namespace mace { 22 | namespace ops { 23 | namespace delegator { 24 | 25 | typedef Conv2dParam DepthwiseConv2dParam; 26 | typedef Conv2d DepthwiseConv2d; 27 | 28 | } // namespace delegator 29 | } // namespace ops 30 | } // namespace mace 31 | 32 | #endif // MACE_OPS_DELEGATOR_DEPTHWISE_CONV_2D_H_ 33 | 34 | -------------------------------------------------------------------------------- /mace/ops/eltwise.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | #ifndef MACE_OPS_ELTWISE_H_ 16 | #define MACE_OPS_ELTWISE_H_ 17 | 18 | #include "mace/ops/common/eltwise_type.h" 19 | 20 | namespace mace { 21 | namespace ops { 22 | 23 | inline bool IsLogicalType(EltwiseType type) { 24 | return type == EQUAL || type == NOT_EQUAL; 25 | } 26 | 27 | template int Sign(T val) { 28 | return (T(0) < val) - (val < T(0)); 29 | } 30 | 31 | } // namespace ops 32 | } // namespace mace 33 | 34 | #endif // MACE_OPS_ELTWISE_H_ 35 | -------------------------------------------------------------------------------- /mace/ops/opencl/cl/addn.cl: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __kernel void addn(OUT_OF_RANGE_PARAMS 4 | GLOBAL_WORK_GROUP_SIZE_DIM2 5 | __read_only image2d_t input0, /* [c%4 * w * c/4, h * b] */ 6 | __read_only image2d_t input1, 7 | #if INPUT_NUM > 2 8 | __read_only image2d_t input2, 9 | #endif 10 | #if INPUT_NUM > 3 11 | __read_only image2d_t input3, 12 | #endif 13 | __write_only image2d_t output) { 14 | const int w = get_global_id(0); 15 | const int hb = get_global_id(1); 16 | 17 | #ifndef NON_UNIFORM_WORK_GROUP 18 | if (w >= global_size_dim0 || hb >= global_size_dim1) return; 19 | #endif 20 | 21 | DATA_TYPE4 in0 = READ_IMAGET(input0, SAMPLER, (int2)(w, hb)); 22 | DATA_TYPE4 in1 = READ_IMAGET(input1, SAMPLER, (int2)(w, hb)); 23 | DATA_TYPE4 out = in0 + in1; 24 | 25 | #if INPUT_NUM > 2 26 | DATA_TYPE4 in2 = READ_IMAGET(input2, SAMPLER, (int2)(w, hb)); 27 | out = out + in2; 28 | #endif 29 | 30 | #if INPUT_NUM > 3 31 | DATA_TYPE4 in3 = READ_IMAGET(input3, SAMPLER, (int2)(w, hb)); 32 | out = out + in3; 33 | #endif 34 | 35 | WRITE_IMAGET(output, (int2)(w, hb), out); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /mace/ops/opencl/cl/bias_add.cl: -------------------------------------------------------------------------------- 1 | #include 2 | // Supported data types: half/float 3 | __kernel void bias_add(OUT_OF_RANGE_PARAMS 4 | GLOBAL_WORK_GROUP_SIZE_DIM3 5 | __private const int input_height, 6 | __read_only image2d_t input, 7 | __read_only image2d_t bias, 8 | __write_only image2d_t output) { 9 | const int ch_blk = get_global_id(0); 10 | const int width_idx = get_global_id(1); 11 | const int hb_idx = get_global_id(2); 12 | 13 | #ifndef NON_UNIFORM_WORK_GROUP 14 | if (ch_blk >= global_size_dim0 || width_idx >= global_size_dim1 15 | || hb_idx >= global_size_dim2) { 16 | return; 17 | } 18 | #endif 19 | const int width = global_size_dim1; 20 | 21 | const int pos = mad24(ch_blk, width, width_idx); 22 | DATA_TYPE4 in = READ_IMAGET(input, SAMPLER, (int2)(pos, hb_idx)); 23 | const int b_idx = select(0, hb_idx / input_height, input_height > 0); 24 | DATA_TYPE4 bias_value = READ_IMAGET(bias, SAMPLER, (int2)(ch_blk, b_idx)); 25 | DATA_TYPE4 out = in + bias_value; 26 | 27 | WRITE_IMAGET(output, (int2)(pos, hb_idx), out); 28 | } 29 | -------------------------------------------------------------------------------- /mace/ops/opencl/cl/split.cl: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | __kernel void split(OUT_OF_RANGE_PARAMS 4 | GLOBAL_WORK_GROUP_SIZE_DIM3 5 | __read_only image2d_t input, 6 | __private const int chan_blk_offset, 7 | __write_only image2d_t output) { 8 | const int chan_blk_idx = get_global_id(0); 9 | const int width_idx = get_global_id(1); 10 | const int hb_idx = get_global_id(2); 11 | 12 | #ifndef NON_UNIFORM_WORK_GROUP 13 | if (chan_blk_idx >= global_size_dim0 || width_idx >= global_size_dim1 14 | || hb_idx >= global_size_dim2) { 15 | return; 16 | } 17 | #endif 18 | const int width = global_size_dim1; 19 | 20 | DATA_TYPE4 data = READ_IMAGET(input, SAMPLER, 21 | (int2)(mad24(chan_blk_idx + chan_blk_offset, 22 | width, width_idx), hb_idx)); 23 | 24 | const int pos = mad24(chan_blk_idx, width, width_idx); 25 | WRITE_IMAGET(output, (int2)(pos, hb_idx), data); 26 | } 27 | -------------------------------------------------------------------------------- /mace/ops/opencl/mvnorm.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | #ifndef MACE_OPS_OPENCL_MVNORM_H_ 16 | #define MACE_OPS_OPENCL_MVNORM_H_ 17 | 18 | #include "mace/public/mace.h" 19 | 20 | namespace mace { 21 | 22 | class OpContext; 23 | class Tensor; 24 | 25 | namespace ops { 26 | class OpenCLMVNormKernel { 27 | public: 28 | virtual MaceStatus Compute( 29 | OpContext *context, 30 | const Tensor *input, 31 | Tensor *output) = 0; 32 | MACE_EMPTY_VIRTUAL_DESTRUCTOR(OpenCLMVNormKernel); 33 | }; 34 | 35 | } // namespace ops 36 | } // namespace mace 37 | 38 | #endif // MACE_OPS_OPENCL_MVNORM_H_ 39 | -------------------------------------------------------------------------------- /mace/ops/registry/registry.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | #ifndef MACE_OPS_REGISTRY_REGISTRY_H_ 16 | #define MACE_OPS_REGISTRY_REGISTRY_H_ 17 | 18 | #include "mace/utils/macros.h" 19 | 20 | namespace mace { 21 | class OpRegistry; 22 | class OpDelegatorRegistry; 23 | 24 | namespace ops { 25 | 26 | void RegisterAllOps(OpRegistry *registry); 27 | void RegisterAllOpDelegators(OpDelegatorRegistry *registry); 28 | 29 | } // namespace ops 30 | } // namespace mace 31 | 32 | #endif // MACE_OPS_REGISTRY_REGISTRY_H_ 33 | -------------------------------------------------------------------------------- /mace/port/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | cc_library( 8 | name = "port", 9 | deps = [ 10 | "//mace/port/android:port_android", 11 | "//mace/port/darwin:port_darwin", 12 | "//mace/port/linux:port_linux", 13 | ], 14 | ) 15 | 16 | cc_library( 17 | name = "port_base", 18 | srcs = [ 19 | "env.cc", 20 | "logger.cc", 21 | "file_system.cc", 22 | ], 23 | deps = [ 24 | "//mace/utils", 25 | "//include:public_headers", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /mace/port/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(port_base STATIC 2 | env.cc 3 | logger.cc 4 | file_system.cc 5 | ) 6 | 7 | target_link_libraries(port_base utils) 8 | 9 | if(ANDROID) 10 | add_subdirectory(posix) 11 | add_subdirectory(linux_base) 12 | add_subdirectory(android) 13 | add_library(port ALIAS port_android) 14 | elseif(APPLE) 15 | add_subdirectory(posix) 16 | add_subdirectory(darwin) 17 | add_library(port ALIAS port_darwin) 18 | elseif(WIN32) 19 | add_subdirectory(windows) 20 | add_library(port ALIAS port_windows) 21 | else(WIN32) 22 | add_subdirectory(posix) 23 | add_subdirectory(linux_base) 24 | add_subdirectory(linux) 25 | add_library(port ALIAS port_linux) 26 | endif(ANDROID) 27 | -------------------------------------------------------------------------------- /mace/port/README.md: -------------------------------------------------------------------------------- 1 | # port 2 | 3 | This module contains the interface and implementations for different platforms. 4 | All platform specific code should go here. It's not allowed to use non standard 5 | headers in other modules. 6 | 7 | This module splits into `port_api` and `port`. `port_api` is the interface, and 8 | it should not depends on any other modules including `utils`. 9 | 10 | If the code base goes large in the future, it should be split into core and 11 | test to keep the footprint for production libs as small as possible. 12 | 13 | Currently Linux, Darwin (MacOS, iOS etc.) are treated as POSIX. They will be 14 | handled differently if needed. 15 | -------------------------------------------------------------------------------- /mace/port/android/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load("//mace:mace.bzl", "if_android") 8 | 9 | cc_library( 10 | name = "port_android", 11 | srcs = if_android(glob([ 12 | "*.cc", 13 | ])), 14 | hdrs = if_android(glob([ 15 | "*.h", 16 | ])), 17 | deps = if_android([ 18 | "//mace/port/linux_base:port_linux_base", 19 | ]), 20 | alwayslink = 1, 21 | ) 22 | -------------------------------------------------------------------------------- /mace/port/android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(port_android STATIC 2 | logger.cc 3 | malloc_logger.cc 4 | env.cc 5 | ) 6 | 7 | target_link_libraries(port_android port_linux_base log) 8 | -------------------------------------------------------------------------------- /mace/port/android/logger.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The MACE 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 | #ifndef MACE_PORT_ANDROID_LOGGER_H_ 16 | #define MACE_PORT_ANDROID_LOGGER_H_ 17 | 18 | #include "mace/port/logger.h" 19 | 20 | namespace mace { 21 | namespace port { 22 | 23 | class AndroidLogWriter : public LogWriter { 24 | protected: 25 | void WriteLogMessage(const char *fname, 26 | const int line, 27 | const LogLevel severity, 28 | const char *message) override; 29 | }; 30 | 31 | } // namespace port 32 | } // namespace mace 33 | 34 | #endif // MACE_PORT_ANDROID_LOGGER_H_ 35 | -------------------------------------------------------------------------------- /mace/port/darwin/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load("//mace:mace.bzl", "if_darwin") 8 | 9 | cc_library( 10 | name = "port_darwin", 11 | srcs = if_darwin(glob([ 12 | "*.cc", 13 | ])), 14 | hdrs = if_darwin(glob([ 15 | "*.h", 16 | ])), 17 | deps = [ 18 | "//mace/port:port_base", 19 | "//mace/port/posix:port_posix", 20 | ], 21 | alwayslink = 1, 22 | ) 23 | 24 | sh_library( 25 | name = "darwin_ar_merge", 26 | srcs = ["ar_merge_on_darwin.sh"], 27 | ) 28 | -------------------------------------------------------------------------------- /mace/port/darwin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(port_darwin STATIC 2 | env.cc 3 | ) 4 | 5 | target_link_libraries(port_darwin port_posix) 6 | -------------------------------------------------------------------------------- /mace/port/linux/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load("//mace:mace.bzl", "if_linux") 8 | 9 | cc_library( 10 | name = "port_linux", 11 | srcs = if_linux(glob([ 12 | "*.cc", 13 | ])), 14 | hdrs = if_linux(glob([ 15 | "*.h", 16 | ])), 17 | deps = if_linux([ 18 | "//mace/port/linux_base:port_linux_base", 19 | ]), 20 | alwayslink = 1, 21 | ) 22 | -------------------------------------------------------------------------------- /mace/port/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(port_linux STATIC 2 | env.cc 3 | ) 4 | 5 | target_link_libraries(port_linux port_linux_base) 6 | -------------------------------------------------------------------------------- /mace/port/linux_base/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | cc_library( 8 | name = "port_linux_base", 9 | srcs = glob([ 10 | "*.cc", 11 | ]), 12 | hdrs = glob([ 13 | "*.h", 14 | ]), 15 | deps = [ 16 | "//mace/port:port_base", 17 | "//mace/port/posix:port_posix", 18 | ], 19 | alwayslink = 1, 20 | ) 21 | -------------------------------------------------------------------------------- /mace/port/linux_base/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(port_linux_base STATIC 2 | env.cc 3 | ) 4 | 5 | target_link_libraries(port_linux_base port_posix) 6 | -------------------------------------------------------------------------------- /mace/port/posix/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | cc_library( 8 | name = "port_posix", 9 | srcs = glob([ 10 | "*.cc", 11 | ]), 12 | hdrs = glob([ 13 | "*.h", 14 | ]), 15 | deps = [ 16 | "//mace/port:port_base", 17 | "//mace/utils", 18 | ], 19 | ) 20 | -------------------------------------------------------------------------------- /mace/port/posix/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(port_posix STATIC 2 | file_system.cc 3 | ) 4 | 5 | target_link_libraries(port_posix port_base) 6 | -------------------------------------------------------------------------------- /mace/port/posix/time.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The MACE 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 | #ifndef MACE_PORT_POSIX_TIME_H_ 16 | #define MACE_PORT_POSIX_TIME_H_ 17 | 18 | #include 19 | 20 | #include 21 | 22 | namespace mace { 23 | namespace port { 24 | namespace posix { 25 | 26 | inline int64_t NowMicros() { 27 | struct timeval tv; 28 | gettimeofday(&tv, nullptr); 29 | return static_cast(tv.tv_sec) * 1000000 + tv.tv_usec; 30 | } 31 | 32 | } // namespace posix 33 | } // namespace port 34 | } // namespace mace 35 | 36 | #endif // MACE_PORT_POSIX_TIME_H_ 37 | -------------------------------------------------------------------------------- /mace/port/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(port_windows STATIC 2 | env.cc 3 | file_system.cc 4 | ) 5 | 6 | target_link_libraries(port_windows port_base) 7 | -------------------------------------------------------------------------------- /mace/proto/micro_mem.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package micro; 4 | 5 | message OutputShape { 6 | repeated int64 dims = 1; 7 | } 8 | 9 | message OpContext { 10 | optional int32 op_idx = 1; 11 | // The input info of downstream operator is the output info of upstream 12 | // operator, so there is no output info defined here 13 | repeated uint32 input_infos = 2; 14 | repeated OutputShape output_resize_shapes = 3; 15 | } 16 | 17 | message Graph { 18 | repeated OpContext op_contexts = 1; 19 | repeated uint32 input_op_idxs = 2; 20 | // The output info of the last operator, which is not recorded in opcontext, 21 | // is the output of graph 22 | repeated uint32 output_infos = 3; 23 | } 24 | -------------------------------------------------------------------------------- /mace/proto/qnn_cache.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto2"; 2 | 3 | package qnn_cache; 4 | 5 | option optimize_for = LITE_RUNTIME; 6 | 7 | message CacheContext { 8 | repeated uint32 input_ids = 1; 9 | repeated uint32 output_ids = 2; 10 | optional string graph_name = 3; 11 | optional bytes graph_cache = 4; 12 | } 13 | -------------------------------------------------------------------------------- /mace/python/tools/BUILD.bazel: -------------------------------------------------------------------------------- 1 | py_binary( 2 | name = "archive_static_lib", 3 | srcs = ["archive_static_lib.py"], 4 | srcs_version = "PY2AND3", 5 | visibility = ["//visibility:public"], 6 | ) 7 | -------------------------------------------------------------------------------- /mace/python/tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/mace/python/tools/__init__.py -------------------------------------------------------------------------------- /mace/python/tools/file_binary.cc.jinja2: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The MACE 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 | // This is a generated file. DO NOT EDIT! 16 | 17 | #include 18 | 19 | namespace mace { 20 | 21 | const unsigned char *{{ load_func_name }}() { 22 | {% if data_size == 0 %} 23 | return nullptr; 24 | {% else %} 25 | static const unsigned char kData[{{ data_size }}] = { 26 | {% for d in data %}{{"0x%02X, " % d }}{%endfor%} 27 | }; 28 | 29 | return kData; 30 | {% endif %} 31 | } 32 | 33 | size_t {{ size_func_name }}() { 34 | return {{ data_size }}; 35 | } 36 | 37 | } // namespace mace 38 | 39 | -------------------------------------------------------------------------------- /mace/python/tools/str2vec_maps.h.jinja2: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | // This is a generated file. DO NOT EDIT! 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace mace { 22 | namespace {{tag}} { 23 | 24 | struct ClProgramInfo { 25 | const std::vector headers_; 26 | std::string hash_str_; 27 | const std::vector<{{data_type}}> encrypted_code_; 28 | }; 29 | 30 | extern const std::map {{variable_name}}; 31 | 32 | } // {{tag}} 33 | } // namespace mace 34 | -------------------------------------------------------------------------------- /mace/rpcmems/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load( 8 | "//mace:mace.bzl", 9 | "if_android_arm64", 10 | ) 11 | 12 | cc_library( 13 | name = "rpcmems", 14 | srcs = glob([ 15 | "*.cc", 16 | "qualcomm/*.cc", 17 | "dmabufheap/*.cc", 18 | ]) + if_android_arm64([ 19 | "mtk/mtk_rpcmem.cc", 20 | "mtk/mtk_ion_wrapper.cc", 21 | ]), 22 | hdrs = [ 23 | "qualcomm/qualcomm_rpcmem.h", 24 | "dmabufheap/dma_buf_heap_rpcmem.h", 25 | "dmabufheap/dma_buf_heap_wrapper.h", 26 | ] + if_android_arm64([ 27 | "mtk/mtk_rpcmem.h", 28 | "mtk/mtk_ion_wrapper.h", 29 | ]), 30 | copts = [ 31 | "-Werror", 32 | "-Wextra", 33 | "-Wno-missing-field-initializers", 34 | ], 35 | linkopts = ["-ldl"], 36 | deps = [ 37 | "//mace/core", 38 | "//third_party/rpcmem", 39 | "//third_party/dmabufheap", 40 | ] + if_android_arm64([ 41 | "//third_party/mtk_rpcmem", 42 | ]), 43 | ) 44 | -------------------------------------------------------------------------------- /mace/rpcmems/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(RPCMEMS_SRCS 2 | qualcomm/qualcomm_rpcmem.cc 3 | dmabufheap/dma_buf_heap_rpcmem.cc 4 | dmabufheap/dma_buf_heap_wrapper.cc 5 | rpcmem_factory.cc) 6 | 7 | if(ANDROID_ABI STREQUAL "arm64-v8a") 8 | set(RPCMEMS_SRCS ${RPCMEMS_SRCS} mtk/mtk_rpcmem.cc mtk/mtk_ion_wrapper.cc) 9 | endif(ANDROID_ABI STREQUAL "arm64-v8a") 10 | 11 | add_library(rpcmems STATIC ${RPCMEMS_SRCS}) 12 | target_link_libraries(rpcmems PRIVATE rpcmem) 13 | 14 | install(TARGETS rpcmems ARCHIVE DESTINATION lib) 15 | -------------------------------------------------------------------------------- /mace/runtimes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(RUNTIMES_SRCS STATIC runtime_registry.cc) 2 | 3 | add_subdirectory(cpu) 4 | 5 | if(MACE_ENABLE_OPENCL) 6 | add_subdirectory(opencl) 7 | endif(MACE_ENABLE_OPENCL) 8 | 9 | if(MACE_ENABLE_HEXAGON) 10 | add_subdirectory(hexagon) 11 | endif(MACE_ENABLE_HEXAGON) 12 | 13 | if(DMACE_ENABLE_MTK_APU) 14 | add_subdirectory(apu) 15 | endif(DMACE_ENABLE_MTK_APU) 16 | 17 | if(DMACE_ENABLE_QNN) 18 | add_subdirectory(qnn) 19 | endif(DMACE_ENABLE_QNN) 20 | 21 | add_library(runtimes STATIC ${RUNTIMES_SRCS}) 22 | target_link_libraries(runtimes PRIVATE core cpu_runtime) 23 | if(MACE_ENABLE_OPENCL) 24 | target_link_libraries(runtimes PRIVATE opencl_runtime) 25 | endif(MACE_ENABLE_OPENCL) 26 | install(TARGETS runtimes ARCHIVE DESTINATION lib) 27 | -------------------------------------------------------------------------------- /mace/runtimes/apu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(APU_SRCS apu_runtime.cc) 2 | 3 | if(MACE_MTK_APU_VERSION EQUAL 1) 4 | set(APU_SRCS ${APU_SRCS} runtime/apu/v1v2v3/v1/apu_wrapper.cc) 5 | set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} apu-frontend) 6 | elseif(MACE_MTK_APU_VERSION EQUAL 2) 7 | set(APU_SRCS ${APU_SRCS} runtime/apu/v1v2v3/v2v3/apu_wrapper.cc) 8 | set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} apu-frontend) 9 | elseif(MACE_MTK_APU_VERSION EQUAL 3) 10 | set(APU_SRCS ${APU_SRCS} runtime/apu/v1v2v3/v2v3/apu_wrapper.cc) 11 | set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} apu-frontend) 12 | elseif(MACE_MTK_APU_VERSION EQUAL 4) 13 | set(APU_SRCS ${APU_SRCS} 14 | runtime/apu/v4/apu_wrapper.cc 15 | runtime/apu/v4/neuron_delegate_kernel.cc 16 | runtime/apu/v4/neuron_implementation.cc 17 | ) 18 | else() 19 | message(FATAL_ERROR "Invalid MTK APU version.") 20 | endif() 21 | 22 | add_library(apu_runtime STATIC ${APU_SRCS}) 23 | 24 | set(EXTRA_LINK_LIBS apu-frontend) 25 | target_link_libraries(apu_runtime core ${EXTRA_LINK_LIBS}) 26 | 27 | install(TARGETS apu_runtime ARCHIVE DESTINATION lib) -------------------------------------------------------------------------------- /mace/runtimes/cpu/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load( 8 | "//mace:mace.bzl", 9 | "if_quantize_enabled", 10 | "if_rpcmem_enabled", 11 | ) 12 | 13 | cc_library( 14 | name = "cpu_runtimes", 15 | srcs = glob([ 16 | "*.cc", 17 | ]) + if_rpcmem_enabled(glob([ 18 | "ion/*.cc", 19 | ])), 20 | hdrs = glob([ 21 | "*.h", 22 | ]) + if_rpcmem_enabled(glob([ 23 | "ion/*.h", 24 | ])), 25 | copts = [ 26 | "-Werror", 27 | "-Wextra", 28 | "-Wno-missing-field-initializers", 29 | ] + if_quantize_enabled([ 30 | "-DMACE_ENABLE_QUANTIZE", 31 | ]) + if_rpcmem_enabled([ 32 | "-DMACE_ENABLE_RPCMEM", 33 | ]), 34 | linkopts = ["-ldl"], 35 | deps = [ 36 | "//mace/core", 37 | ] + if_quantize_enabled([ 38 | "@gemmlowp", 39 | ]), 40 | ) 41 | -------------------------------------------------------------------------------- /mace/runtimes/cpu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CPU_SRCS 2 | cpu_ref_allocator.cc 3 | cpu_ref_runtime.cc 4 | cpu_runtime.cc 5 | ) 6 | 7 | if(MACE_ENABLE_RPCMEM) 8 | set(CPU_SRCS 9 | ${CPU_SRCS} 10 | ion/cpu_ion_allocator.cc 11 | ion/cpu_ion_runtime.cc 12 | ) 13 | endif(MACE_ENABLE_RPCMEM) 14 | 15 | add_library(cpu_runtime STATIC ${CPU_SRCS}) 16 | target_link_libraries(cpu_runtime core) 17 | install(TARGETS cpu_runtime ARCHIVE DESTINATION lib) -------------------------------------------------------------------------------- /mace/runtimes/hexagon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(HEXAGON_SRCS 2 | hexagon_base_runtime.cc 3 | ) 4 | 5 | if(MACE_ENABLE_HEXAGON_DSP) 6 | set(HEXAGON_SRCS 7 | ${HEXAGON_SRCS} 8 | dsp/hexagon_dsp_runtime.cc 9 | dsp/hexagon_dsp_wrapper.cc 10 | ) 11 | endif(MACE_ENABLE_HEXAGON_DSP) 12 | 13 | if(MACE_ENABLE_HEXAGON_HTA) 14 | set(HEXAGON_SRCS 15 | ${HEXAGON_SRCS} 16 | hta/hexagon_hta_runtime.cc 17 | hta/hexagon_hta_transformer.cc 18 | hta/hexagon_hta_wrapper.cc 19 | ) 20 | if(MACE_ENABLE_OPENCL) 21 | set(HEXAGON_SRCS ${HEXAGON_SRCS} hta/opencl/hexagon_hta_opencl_runtime.cc) 22 | endif(MACE_ENABLE_OPENCL) 23 | endif(MACE_ENABLE_HEXAGON_HTA) 24 | 25 | 26 | add_library(hexagon_runtime STATIC ${HEXAGON_SRCS}) 27 | if(MACE_ENABLE_OPENCL) 28 | add_dependencies(hexagon_runtime opencl_clhpp) 29 | endif(MACE_ENABLE_OPENCL) 30 | target_link_libraries(hexagon_runtime core) 31 | install(TARGETS hexagon_runtime ARCHIVE DESTINATION lib) 32 | -------------------------------------------------------------------------------- /mace/runtimes/opencl/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load( 8 | "//mace:mace.bzl", 9 | "if_rpcmem_enabled", 10 | ) 11 | 12 | cc_library( 13 | name = "opencl_runtimes", 14 | srcs = glob([ 15 | "*.cc", 16 | "core/*.cc", 17 | "transform/*.cc", 18 | ]) + if_rpcmem_enabled(glob([ 19 | "qc_ion/*.cc", 20 | "mtk_ion/*.cc", 21 | ])), 22 | hdrs = glob([ 23 | "*.h", 24 | "core/*.h", 25 | "transform/*.h", 26 | ]) + if_rpcmem_enabled(glob([ 27 | "qc_ion/*.h", 28 | "mtk_ion/*.h", 29 | ])), 30 | copts = [ 31 | "-Werror", 32 | "-Wextra", 33 | "-Wno-missing-field-initializers", 34 | ] + if_rpcmem_enabled([ 35 | "-DMACE_ENABLE_RPCMEM", 36 | ]), 37 | linkopts = ["-ldl"], 38 | deps = [ 39 | "//mace/codegen:generated_opencl", 40 | "//mace/core", 41 | "//mace/runtimes:opencl_headers", 42 | "//mace/runtimes/cpu:cpu_runtimes", 43 | "@half", 44 | ], 45 | ) 46 | -------------------------------------------------------------------------------- /mace/runtimes/opencl/mtk_ion/opencl_mtk_ion_executor.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The MACE 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 | #include "mace/runtimes/opencl/mtk_ion/opencl_mtk_ion_executor.h" 16 | 17 | #include 18 | 19 | namespace mace { 20 | 21 | OpenclMtkIonExecutor::OpenclMtkIonExecutor() : OpenclExecutor() {} 22 | 23 | OpenclMtkIonExecutor *OpenclMtkIonExecutor::Get(OpenclExecutor *executor) { 24 | return static_cast(executor); 25 | } 26 | 27 | IONType OpenclMtkIonExecutor::ion_type() const { 28 | return IONType::MTK_ION; 29 | } 30 | 31 | } // namespace mace 32 | -------------------------------------------------------------------------------- /mace/runtimes/qnn/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB OPS_SRCS 2 | ops/*.cc 3 | ) 4 | 5 | set(QNN_SRCS 6 | qnn_performance.cc 7 | op_builder.cc 8 | qnn_runtime.cc 9 | qnn_wrapper.cc 10 | ) 11 | set(QNN_SRCS ${QNN_SRCS} ${OPS_SRCS}) 12 | 13 | add_library(qnn_runtime STATIC ${QNN_SRCS}) 14 | target_link_libraries(qnn_runtime core) 15 | install(TARGETS qnn_runtime ARCHIVE DESTINATION lib) 16 | -------------------------------------------------------------------------------- /mace/tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB MACE_RUN_SRCS 2 | mace_run.cc 3 | ) 4 | add_executable(mace_run ${MACE_RUN_SRCS}) 5 | target_link_libraries(mace_run 6 | mace_static 7 | model 8 | extra_link_libs_target 9 | gflags 10 | ) 11 | if(NOT ANDROID) 12 | target_link_libraries(mace_run pthread) 13 | endif() 14 | 15 | if(MACE_ENABLE_HEXAGON_DSP) 16 | target_link_libraries(mace_run hexagon_controller) 17 | endif() 18 | 19 | install(TARGETS mace_run RUNTIME DESTINATION bin) 20 | -------------------------------------------------------------------------------- /mace/utils/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Description: 2 | # Mace utils. 3 | # 4 | package( 5 | default_visibility = ["//visibility:public"], 6 | ) 7 | 8 | licenses(["notice"]) # Apache 2.0 9 | 10 | load( 11 | "//mace:mace.bzl", 12 | "if_android", 13 | "if_android_armv7", 14 | "if_neon_enabled", 15 | ) 16 | 17 | cc_library( 18 | name = "utils_hdrs", 19 | hdrs = glob([ 20 | "*.h", 21 | ]), 22 | copts = [ 23 | "-Werror", 24 | "-Wextra", 25 | "-Wno-missing-field-initializers", 26 | ], 27 | deps = [ 28 | "//include:public_headers", 29 | ], 30 | ) 31 | 32 | cc_library( 33 | name = "utils", 34 | srcs = glob( 35 | [ 36 | "*.cc", 37 | ], 38 | ), 39 | copts = [ 40 | "-Werror", 41 | "-Wextra", 42 | "-Wno-missing-field-initializers", 43 | ] + if_neon_enabled([ 44 | "-DMACE_ENABLE_NEON", 45 | ]) + if_android_armv7([ 46 | "-mfpu=neon", 47 | "-mfloat-abi=softfp", 48 | ]), 49 | linkopts = if_android([ 50 | "-llog", 51 | ]), 52 | deps = [ 53 | ":utils_hdrs", 54 | ], 55 | alwayslink = 1, 56 | ) 57 | -------------------------------------------------------------------------------- /mace/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(utils STATIC 2 | string_util.cc 3 | thread_pool.cc 4 | status.cc 5 | statistics.cc 6 | ) 7 | 8 | if(NOT ANDROID AND NOT WIN32) 9 | target_link_libraries(utils PUBLIC pthread) 10 | endif(NOT ANDROID AND NOT WIN32) 11 | -------------------------------------------------------------------------------- /micro/base/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(micro_base 2 | logger.cc 3 | serialize.cc 4 | utils.cc 5 | value_to_str.cc 6 | ) 7 | 8 | target_link_libraries(micro_base 9 | PUBLIC micro_port 10 | PUBLIC micro_include 11 | ) 12 | -------------------------------------------------------------------------------- /micro/cmake/config_gcc_arm.cmake: -------------------------------------------------------------------------------- 1 | if(NOT ARM_CPU) 2 | message(FATAL_ERROR "please set ARM_CPU, such as: -DARM_CPU=cortex-m4. We set -mcpu=${ARM_CPU}") 3 | endif() 4 | 5 | add_compile_options("-mcpu=${ARM_CPU};-mthumb") 6 | add_compile_options("-ffunction-sections;-fdata-sections") 7 | 8 | # floating-point ABI 9 | option(MACE_MICRO_ENABLE_HARDFP "Whether to use hard float-point ABI" ON) 10 | 11 | if(MACE_MICRO_ENABLE_HARDFP) 12 | add_compile_options("-mfloat-abi=hard") 13 | else() 14 | add_compile_options("-mfloat-abi=softfp") 15 | endif() 16 | 17 | # FPU 18 | if (ARM_CPU STREQUAL "cortex-m55" ) 19 | add_compile_options("-mfpu=fpv5-d16") 20 | add_link_options("-mfpu=fpv5-d16") 21 | endif() 22 | 23 | if (ARM_CPU STREQUAL "cortex-m33" ) 24 | add_compile_options("-mfpu=fpv5-sp-d16") 25 | add_link_options("-mfpu=fpv5-sp-d16") 26 | endif() 27 | 28 | if (ARM_CPU STREQUAL "cortex-m7" ) 29 | add_compile_options("-mfpu=fpv5-d16") 30 | add_link_options("-mfpu=fpv5-d16") 31 | endif() 32 | 33 | if (ARM_CPU STREQUAL "cortex-m4" ) 34 | add_compile_options("-mfpu=fpv4-sp-d16") 35 | add_link_options("-mfpu=fpv4-sp-d16") 36 | endif() 37 | -------------------------------------------------------------------------------- /micro/cmake/toolchain/gcc-arm-none-eabi.cmake: -------------------------------------------------------------------------------- 1 | 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR arm) 4 | 5 | find_program(CMAKE_C_COMPILER NAMES arm-none-eabi-gcc arm-none-eabi-gcc.exe) 6 | find_program(CMAKE_CXX_COMPILER NAMES arm-none-eabi-g++ arm-none-eabi-g++.exe) 7 | find_program(CMAKE_ASM_COMPILER NAMES arm-none-eabi-gcc arm-none-eabi-gcc.exe) 8 | find_program(CMAKE_AR NAMES arm-none-eabi-gcc-ar arm-none-eabi-gcc-ar.exe) 9 | find_program(CMAKE_CXX_COMPILER_AR NAMES arm-none-eabi-gcc-ar arm-none-eabi-gcc-ar.exe) 10 | find_program(CMAKE_C_COMPILER_AR NAMES arm-none-eabi-gcc-ar arm-none-eabi-gcc-ar.exe) 11 | find_program(CMAKE_LINKER NAMES arm-none-eabi-g++ arm-none-eabi-g++.exe) 12 | 13 | find_program(ELF2BIN NAMES arm-none-eabi-objcopy arm-none-eabi-objcopy.exe) 14 | 15 | # Force compiler settings 16 | set(CMAKE_C_COMPILER_WORKS TRUE) 17 | set(CMAKE_CXX_COMPILER_WORKS TRUE) 18 | 19 | set(CMAKE_FIND_ROOT_PATH "${GCC_ARM_ROOT}") 20 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 24 | 25 | set(MACE_MICRO_GCC_ARM ON) 26 | -------------------------------------------------------------------------------- /micro/cmake/toolchain/hexagon8.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_COMPILER "${HEXAGON_TOOLS}/bin/hexagon-clang") 2 | set(CMAKE_CXX_COMPILER "${HEXAGON_TOOLS}/bin/hexagon-clang") 3 | set(CMAKE_AR "${HEXAGON_TOOLS}/bin/hexagon-ar" CACHE FILEPATH "Archiver") 4 | set(CMAKE_LINKER ${HEXAGON_TOOLS}/bin/hexagon-link) 5 | 6 | set(CMAKE_FIND_ROOT_PATH "${HEXAGON_SDK_ROOT}") 7 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 9 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 11 | 12 | set(HEXAGON ON) 13 | set(HEXAGON8 ON) 14 | -------------------------------------------------------------------------------- /micro/codegen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | macro(SUBDIRLIST result curdir) 2 | file(GLOB children RELATIVE ${curdir} ${curdir}/*) 3 | set(DIR_LIST "") 4 | foreach(Entry ${children}) 5 | if(IS_DIRECTORY ${curdir}/${Entry}) 6 | list(APPEND DIR_LIST ${Entry}) 7 | endif() 8 | endforeach() 9 | set(${result} ${DIR_LIST}) 10 | endmacro() 11 | 12 | SUBDIRLIST(SUBDIRS ${CMAKE_CURRENT_SOURCE_DIR}) 13 | 14 | foreach (MODEL_DIR IN LISTS SUBDIRS) 15 | add_subdirectory(${MODEL_DIR}) 16 | endforeach() 17 | -------------------------------------------------------------------------------- /micro/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(classifier) 2 | add_subdirectory(runtime_load_model) 3 | -------------------------------------------------------------------------------- /micro/examples/classifier/.gitignore: -------------------------------------------------------------------------------- 1 | mbed-os 2 | BUILD 3 | install 4 | mbed_app.json 5 | __pycache__ 6 | mbed_settings.py -------------------------------------------------------------------------------- /micro/examples/classifier/.mbed: -------------------------------------------------------------------------------- 1 | TARGET=NUCLEO_F767ZI 2 | ROOT=. 3 | TOOLCHAIN=GCC_ARM 4 | -------------------------------------------------------------------------------- /micro/examples/classifier/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(NOT MICRO_MODEL_NAME OR NOT MICRO_DATA_NAME) 3 | message(FATAL_ERROR "MICRO_MODEL_NAME or MICRO_DATA_NAME is undefined") 4 | endif() 5 | 6 | add_executable(${MICRO_MODEL_NAME} main.cc) 7 | target_compile_options(${MICRO_MODEL_NAME} 8 | PRIVATE "-Wno-error" 9 | PRIVATE "-Wno-unused-variable" 10 | ) 11 | target_link_libraries(${MICRO_MODEL_NAME} model_${MICRO_MODEL_NAME} micro) 12 | target_include_directories(${MICRO_MODEL_NAME} PRIVATE ..) 13 | target_compile_definitions(${MICRO_MODEL_NAME} PRIVATE "-DMICRO_MODEL_NAME=${MICRO_MODEL_NAME}") 14 | target_compile_definitions(${MICRO_MODEL_NAME} PRIVATE "-DMICRO_DATA_NAME=${MICRO_DATA_NAME}") 15 | -------------------------------------------------------------------------------- /micro/examples/classifier/mbed-os.lib: -------------------------------------------------------------------------------- 1 | https://github.com/ARMmbed/mbed-os/#0db72d0cf26539016efbe38f80d6f2cb7a3d4414 2 | -------------------------------------------------------------------------------- /micro/examples/runtime_load_model/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(NOT MICRO_MODEL_NAME OR NOT MICRO_DATA_NAME) 3 | message(FATAL_ERROR "MICRO_MODEL_NAME or MICRO_DATA_NAME is undefined") 4 | endif() 5 | 6 | add_executable(runtime_load_${MICRO_MODEL_NAME} main.cc) 7 | target_link_libraries(runtime_load_${MICRO_MODEL_NAME} model_${MICRO_MODEL_NAME} micro) 8 | target_include_directories(runtime_load_${MICRO_MODEL_NAME} PRIVATE ../../codegen ..) 9 | target_compile_options(${MICRO_MODEL_NAME} 10 | PRIVATE "-Wno-error" 11 | PRIVATE "-Wno-unused-variable" 12 | ) 13 | target_compile_definitions(runtime_load_${MICRO_MODEL_NAME} PRIVATE "-DMICRO_MODEL_NAME=${MICRO_MODEL_NAME}") 14 | target_compile_definitions(runtime_load_${MICRO_MODEL_NAME} PRIVATE "-DMICRO_DATA_NAME=${MICRO_DATA_NAME}") 15 | 16 | -------------------------------------------------------------------------------- /micro/framework/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(micro_framework 2 | graph.cc 3 | micro_engine.cc 4 | op_context.cc 5 | operator.cc 6 | scratch_buffer.cc 7 | ) 8 | target_link_libraries(micro_framework 9 | PUBLIC micro_include 10 | PUBLIC micro_base 11 | PUBLIC micro_model 12 | ) 13 | 14 | add_library(micro_framework_for_optest 15 | graph.cc 16 | micro_engine.cc 17 | op_context.cc 18 | scratch_buffer.cc 19 | ) 20 | target_link_libraries(micro_framework_for_optest 21 | PUBLIC micro_include 22 | PUBLIC micro_base 23 | PUBLIC micro_model 24 | ) 25 | -------------------------------------------------------------------------------- /micro/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(micro_include INTERFACE) 2 | target_include_directories(micro_include 3 | INTERFACE $ 4 | INTERFACE $ 5 | ) 6 | -------------------------------------------------------------------------------- /micro/include/port/define.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_INCLUDE_PORT_DEFINE_H_ 16 | #define MICRO_INCLUDE_PORT_DEFINE_H_ 17 | 18 | #define MACE_API 19 | #define MACE_DEPRECATED 20 | 21 | #ifndef __FILE__ 22 | #define __FILE__ "" 23 | #endif 24 | 25 | #ifndef __LINE__ 26 | #define __LINE__ 0 27 | #endif 28 | 29 | #ifndef NULL 30 | #define NULL 0 31 | #endif 32 | 33 | #endif // MICRO_INCLUDE_PORT_DEFINE_H_ 34 | -------------------------------------------------------------------------------- /micro/include/utils/macros.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_INCLUDE_UTILS_MACROS_H_ 16 | #define MICRO_INCLUDE_UTILS_MACROS_H_ 17 | 18 | #include "micro/include/public/micro.h" 19 | 20 | namespace micro { 21 | 22 | #ifndef MACE_EMPTY_VIRTUAL_DESTRUCTOR 23 | #define MACE_EMPTY_VIRTUAL_DESTRUCTOR(CLASSNAME) \ 24 | public: \ 25 | virtual ~CLASSNAME() {} 26 | #endif // MACE_EMPTY_VIRTUAL_DESTRUCTOR 27 | 28 | #define MACE_UNUSED(var) (void)(var) 29 | 30 | } // namespace micro 31 | 32 | #endif // MICRO_INCLUDE_UTILS_MACROS_H_ 33 | -------------------------------------------------------------------------------- /micro/model/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(micro_model 2 | argument.cc 3 | const_tensor.cc 4 | input_output_info.cc 5 | net_def.cc 6 | operator_def.cc 7 | output_shape.cc 8 | ) 9 | 10 | target_link_libraries(micro_model 11 | PUBLIC micro_base 12 | PUBLIC micro_include 13 | ) 14 | -------------------------------------------------------------------------------- /micro/ops/cmsis_nn/utilities.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_CMSIS_NN_UTILITIES_H_ 16 | #define MICRO_OPS_CMSIS_NN_UTILITIES_H_ 17 | 18 | #include "micro/base/types.h" 19 | 20 | void QuantizeMultiplier(double double_multiplier, 21 | int32_t *quantized_multiplier, 22 | int32_t *shift); 23 | 24 | #endif // MICRO_OPS_CMSIS_NN_UTILITIES_H_ 25 | -------------------------------------------------------------------------------- /micro/ops/nhwc/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/micro/ops/nhwc/CMakeLists.txt -------------------------------------------------------------------------------- /micro/ops/nhwc/base/depthwise_conv_2d_base.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_BASE_DEPTHWISE_CONV_2D_BASE_H_ 16 | #define MICRO_OPS_NHWC_BASE_DEPTHWISE_CONV_2D_BASE_H_ 17 | 18 | #include "micro/ops/nhwc/base/conv_2d_base.h" 19 | #include "micro/ops/utils/activation.h" 20 | 21 | namespace micro { 22 | namespace ops { 23 | 24 | class DepthwiseConv2dBase : public Conv2dBase { 25 | public: 26 | MaceStatus Run(); 27 | }; 28 | } // namespace ops 29 | } // namespace micro 30 | 31 | 32 | #endif // MICRO_OPS_NHWC_BASE_DEPTHWISE_CONV_2D_BASE_H_ 33 | -------------------------------------------------------------------------------- /micro/ops/nhwc/conv_2d_c2_s4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_CONV_2D_C2_S4_H_ 16 | #define MICRO_OPS_NHWC_CONV_2D_C2_S4_H_ 17 | 18 | #include "micro/ops/nhwc/base/conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class Conv2dC2S4Op : public Conv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | } // namespace ops 28 | } // namespace micro 29 | 30 | 31 | #endif // MICRO_OPS_NHWC_CONV_2D_C2_S4_H_ 32 | -------------------------------------------------------------------------------- /micro/ops/nhwc/conv_2d_c3_s4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_CONV_2D_C3_S4_H_ 16 | #define MICRO_OPS_NHWC_CONV_2D_C3_S4_H_ 17 | 18 | #include "micro/ops/nhwc/base/conv_2d_base.h" 19 | #include "micro/ops/utils/activation.h" 20 | 21 | namespace micro { 22 | namespace ops { 23 | 24 | class Conv2dC3S4Op : public Conv2dBase { 25 | private: 26 | MaceStatus Compute(int32_t (&output_dims)[4]); 27 | }; 28 | } // namespace ops 29 | } // namespace micro 30 | 31 | 32 | #endif // MICRO_OPS_NHWC_CONV_2D_C3_S4_H_ 33 | -------------------------------------------------------------------------------- /micro/ops/nhwc/conv_2d_c4_s4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_CONV_2D_C4_S4_H_ 16 | #define MICRO_OPS_NHWC_CONV_2D_C4_S4_H_ 17 | 18 | #include "micro/ops/nhwc/base/conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class Conv2dC4S4Op : public Conv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | } // namespace ops 28 | } // namespace micro 29 | 30 | 31 | #endif // MICRO_OPS_NHWC_CONV_2D_C4_S4_H_ 32 | -------------------------------------------------------------------------------- /micro/ops/nhwc/conv_2d_ref.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_CONV_2D_REF_H_ 16 | #define MICRO_OPS_NHWC_CONV_2D_REF_H_ 17 | 18 | #include "micro/ops/nhwc/base/conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class Conv2dRefOp : public Conv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | 28 | } // namespace ops 29 | } // namespace micro 30 | 31 | 32 | #endif // MICRO_OPS_NHWC_CONV_2D_REF_H_ 33 | -------------------------------------------------------------------------------- /micro/ops/nhwc/depthwise_conv_2d_kb1_s4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB1_S4_H_ 16 | #define MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB1_S4_H_ 17 | 18 | #include "micro/ops/nhwc/base/depthwise_conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class DepthwiseConv2dKB1S4Op : public DepthwiseConv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | } // namespace ops 28 | } // namespace micro 29 | 30 | 31 | #endif // MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB1_S4_H_ 32 | -------------------------------------------------------------------------------- /micro/ops/nhwc/depthwise_conv_2d_kb2_s4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB2_S4_H_ 16 | #define MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB2_S4_H_ 17 | 18 | #include "micro/ops/nhwc/base/depthwise_conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class DepthwiseConv2dKB2S4Op : public DepthwiseConv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | } // namespace ops 28 | } // namespace micro 29 | 30 | 31 | #endif // MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB2_S4_H_ 32 | -------------------------------------------------------------------------------- /micro/ops/nhwc/depthwise_conv_2d_kb3_s4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB3_S4_H_ 16 | #define MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB3_S4_H_ 17 | 18 | #include "micro/ops/nhwc/base/depthwise_conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class DepthwiseConv2dKB3S4Op : public DepthwiseConv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | } // namespace ops 28 | } // namespace micro 29 | 30 | 31 | #endif // MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB3_S4_H_ 32 | -------------------------------------------------------------------------------- /micro/ops/nhwc/depthwise_conv_2d_kb4_s4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB4_S4_H_ 16 | #define MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB4_S4_H_ 17 | 18 | #include "micro/ops/nhwc/base/depthwise_conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class DepthwiseConv2dKB4S4Op : public DepthwiseConv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | } // namespace ops 28 | } // namespace micro 29 | 30 | 31 | #endif // MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_KB4_S4_H_ 32 | -------------------------------------------------------------------------------- /micro/ops/nhwc/depthwise_conv_2d_ref.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_REF_H_ 16 | #define MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_REF_H_ 17 | 18 | #include "micro/ops/nhwc/base/depthwise_conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class DepthwiseConv2dRefOp : public DepthwiseConv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | 28 | } // namespace ops 29 | } // namespace micro 30 | 31 | 32 | #endif // MICRO_OPS_NHWC_DEPTHWISE_CONV_2D_REF_H_ 33 | -------------------------------------------------------------------------------- /micro/ops/xtensa/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(micro_ops_xtensa 2 | conv_2d_xtensa.cc 3 | depthwise_conv_2d_xtensa.cc 4 | matmul_xtensa.cc 5 | ) 6 | 7 | target_link_libraries(micro_ops_xtensa 8 | PRIVATE micro_base 9 | ) 10 | 11 | target_include_directories(micro_ops_xtensa PRIVATE ${XA_NNLIB_INCLUDE_DIR}) 12 | 13 | target_link_libraries(micro_all_ops INTERFACE micro_ops_xtensa) 14 | 15 | set(combine_xtensa_stamp ${CMAKE_CURRENT_BINARY_DIR}/combine_xtensa.stamp) 16 | add_custom_command( 17 | OUTPUT ${combine_xtensa_stamp} 18 | COMMAND touch ${combine_xtensa_stamp} 19 | COMMAND ${MACE_MICRO_TOOLS_PATH}/combine_static_libs.sh ${lib_micro_path} "\"$\"" 20 | DEPENDS micro_ops_xtensa 21 | COMMENT "Combining xtensa libs ..." 22 | ) 23 | 24 | add_custom_target(micro_combine_xtensa 25 | ALL DEPENDS ${combine_xtensa_stamp} 26 | ) 27 | -------------------------------------------------------------------------------- /micro/ops/xtensa/conv_2d_xtensa.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_XTENSA_CONV_2D_XTENSA_H_ 16 | #define MICRO_OPS_XTENSA_CONV_2D_XTENSA_H_ 17 | 18 | #include "micro/ops/nhwc/base/conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class Conv2dXtensaOp : public Conv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | 28 | } // namespace ops 29 | } // namespace micro 30 | 31 | 32 | #endif // MICRO_OPS_XTENSA_CONV_2D_XTENSA_H_ 33 | -------------------------------------------------------------------------------- /micro/ops/xtensa/depthwise_conv_2d_xtensa.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_OPS_XTENSA_DEPTHWISE_CONV_2D_XTENSA_H_ 16 | #define MICRO_OPS_XTENSA_DEPTHWISE_CONV_2D_XTENSA_H_ 17 | 18 | #include "micro/ops/nhwc/base/depthwise_conv_2d_base.h" 19 | 20 | namespace micro { 21 | namespace ops { 22 | 23 | class DepthwiseConv2dXtensaOp : public DepthwiseConv2dBase { 24 | private: 25 | MaceStatus Compute(int32_t (&output_dims)[4]); 26 | }; 27 | 28 | } // namespace ops 29 | } // namespace micro 30 | 31 | 32 | #endif // MICRO_OPS_XTENSA_DEPTHWISE_CONV_2D_XTENSA_H_ 33 | -------------------------------------------------------------------------------- /micro/port/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(micro_port api.cc) 2 | target_include_directories(micro_port 3 | PUBLIC $ 4 | PUBLIC $ 5 | ) 6 | 7 | if(HEXAGON OR HEXAGON_STUB) 8 | target_link_libraries(micro_port hexagon_sdk_headers_dsp) 9 | endif() 10 | -------------------------------------------------------------------------------- /micro/port/api.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifndef MICRO_PORT_API_H_ 16 | #define MICRO_PORT_API_H_ 17 | 18 | #include 19 | 20 | namespace micro { 21 | namespace port { 22 | namespace api { 23 | 24 | void DebugLog(const char *str); 25 | int64_t NowMicros(); 26 | void Abort(); 27 | 28 | } // api 29 | } // namespace port 30 | } // namespace micro 31 | 32 | #endif // MICRO_PORT_API_H_ 33 | -------------------------------------------------------------------------------- /micro/pretrained_models/har-cnn/har-cnn-bf16.yml: -------------------------------------------------------------------------------- 1 | library_name: har-cnn 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | har_cnn: 7 | platform: tensorflow 8 | model_file_path: http://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/har-cnn/har-cnn.pb 9 | model_sha256_checksum: 93451bdf0590842ae80e9de72a22ce3b1faee3e0d9cf7b8e2d60421e885ed6e7 10 | subgraphs: 11 | - input_tensors: 12 | - conv1d/conv1d/ExpandDims 13 | input_shapes: 14 | - 1,1,128,9 15 | output_tensors: 16 | - dense/BiasAdd 17 | output_shapes: 18 | - 1,6 19 | runtime: cpu 20 | data_type: bf16_fp32 21 | -------------------------------------------------------------------------------- /micro/pretrained_models/har-cnn/har-cnn.yml: -------------------------------------------------------------------------------- 1 | library_name: har-cnn 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | har_cnn: 7 | platform: tensorflow 8 | model_file_path: http://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/har-cnn/har-cnn.pb 9 | model_sha256_checksum: 93451bdf0590842ae80e9de72a22ce3b1faee3e0d9cf7b8e2d60421e885ed6e7 10 | subgraphs: 11 | - input_tensors: 12 | - conv1d/conv1d/ExpandDims 13 | input_shapes: 14 | - 1,1,128,9 15 | output_tensors: 16 | - dense/BiasAdd 17 | output_shapes: 18 | - 1,6 19 | runtime: cpu 20 | data_type: fp32_fp32 21 | -------------------------------------------------------------------------------- /micro/pretrained_models/keras/README.md: -------------------------------------------------------------------------------- 1 | # Tensorflow Keras Models 2 | 3 | MACE Micro supports Keras models of Tensorflow 2.x 4 | 5 | ## HAR 6 | 7 | The model is from . 8 | 9 | ## MNIST 10 | 11 | The mnist_keras.py depends on tensorflow 2.x and tensorflow_model_optimization. You can run this script to generate "mnist.h5" and "mnist-int8.h5" models 12 | -------------------------------------------------------------------------------- /micro/pretrained_models/keras/har/har-int8.yml: -------------------------------------------------------------------------------- 1 | library_name: har 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | har_int8: 7 | platform: keras 8 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/keras/har/har.h5 9 | model_sha256_checksum: ec0477b8e489541bb34377c9cabc42ee6cefa8bdf0a9f726e06be1b967ea1dcd 10 | subgraphs: 11 | - input_tensors: 12 | - conv2d_1_input:0 13 | input_shapes: 14 | - 1,90,3,1 15 | input_ranges: 16 | - -5,15 17 | output_tensors: 18 | - dense_3/Softmax:0 19 | output_shapes: 20 | - 1,6 21 | runtime: cpu 22 | micro: 23 | backend: cmsis 24 | quantize: 1 25 | quantize_schema: int8 26 | quantize_range_file: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/keras/har/har.range 27 | -------------------------------------------------------------------------------- /micro/pretrained_models/keras/har/har.yml: -------------------------------------------------------------------------------- 1 | library_name: har 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | har: 7 | platform: keras 8 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/keras/har/har.h5 9 | model_sha256_checksum: ec0477b8e489541bb34377c9cabc42ee6cefa8bdf0a9f726e06be1b967ea1dcd 10 | subgraphs: 11 | - input_tensors: 12 | - conv2d_1_input:0 13 | input_shapes: 14 | - 1,90,3,1 15 | output_tensors: 16 | - dense_3/Softmax:0 17 | output_shapes: 18 | - 1,6 19 | runtime: cpu 20 | data_type: fp32_fp32 21 | -------------------------------------------------------------------------------- /micro/pretrained_models/keras/mnist/mnist-hifi4.yml: -------------------------------------------------------------------------------- 1 | library_name: mnist 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | mnist: 7 | platform: keras 8 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/keras/mnist/mnist.h5 9 | model_sha256_checksum: 134e9a632d6f541be4ea8b5eb6ed144b3bd96d1ef916778781b045854e05bdd6 10 | subgraphs: 11 | - input_tensors: 12 | - conv2d_input:0 13 | input_shapes: 14 | - 1,28,28,1 15 | output_tensors: 16 | - dense_1/Softmax:0 17 | output_shapes: 18 | - 1,10 19 | runtime: cpu 20 | micro: 21 | backend: "xtensa" # Micro will use Cadence HiFi4 22 | data_type: fp32_fp32 23 | quantize: 0 24 | -------------------------------------------------------------------------------- /micro/pretrained_models/keras/mnist/mnist-int8.yml: -------------------------------------------------------------------------------- 1 | library_name: mnist 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | mnist_int8: 7 | platform: keras 8 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/keras/mnist/mnist-int8.h5 9 | model_sha256_checksum: 0ff90446134c41fb5e0524484cd9d7452282d3825f13b839c364a58abd0490ee 10 | subgraphs: 11 | - input_tensors: 12 | - conv2d_input:0 13 | input_shapes: 14 | - 1,28,28,1 15 | input_ranges: 16 | - 0,1 17 | output_tensors: 18 | - quant_dense_1/Softmax:0 19 | output_shapes: 20 | - 1,10 21 | validation_inputs_data: 22 | - https://cnbj1.fds.api.xiaomi.com/mace/inputs/mnist4.npy 23 | runtime: cpu 24 | quantize: 1 25 | quantize_schema: int8 26 | micro: 27 | backend: cmsis # Micro will use CMSIS_5 NN modules 28 | -------------------------------------------------------------------------------- /micro/pretrained_models/keras/mnist/mnist.yml: -------------------------------------------------------------------------------- 1 | library_name: mnist 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | mnist: 7 | platform: keras 8 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/keras/mnist/mnist.h5 9 | model_sha256_checksum: 134e9a632d6f541be4ea8b5eb6ed144b3bd96d1ef916778781b045854e05bdd6 10 | subgraphs: 11 | - input_tensors: 12 | - conv2d_input:0 13 | input_shapes: 14 | - 1,28,28,1 15 | output_tensors: 16 | - dense_1/Softmax:0 17 | output_shapes: 18 | - 1,10 19 | runtime: cpu 20 | data_type: fp32_fp32 21 | quantize: 0 22 | -------------------------------------------------------------------------------- /micro/pretrained_models/tensorflow/README.md: -------------------------------------------------------------------------------- 1 | # Tensorflow frozen models 2 | 3 | ## KWS 4 | 5 | The model is from . 6 | -------------------------------------------------------------------------------- /micro/pretrained_models/tensorflow/kws/kws-tc_resnet8-bf16.yml: -------------------------------------------------------------------------------- 1 | library_name: kws-tc_resnet8 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | kws_tc_resnet8_bf16: 7 | platform: tensorflow 8 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/tensorflow/kws/kws-tc_resnet8.pb 9 | model_sha256_checksum: c552cf79cb64d3c755ae7d867c1c78b13f55f7589d46def1f70ce657c0db0d79 10 | subgraphs: 11 | - input_tensors: 12 | - input 13 | input_shapes: 14 | - 1,98,40,1 15 | output_tensors: 16 | - output/softmax 17 | output_shapes: 18 | - 1,12 19 | runtime: cpu 20 | data_type: bf16_fp32 21 | limit_opencl_kernel_time: 0 22 | nnlib_graph_mode: 0 23 | obfuscate: 0 24 | winograd: 0 25 | quantize: 0 26 | -------------------------------------------------------------------------------- /micro/pretrained_models/tensorflow/kws/kws-tc_resnet8-hifi4.yml: -------------------------------------------------------------------------------- 1 | library_name: kws-tc_resnet8 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | kws_tc_resnet8: 7 | platform: tensorflow 8 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/tensorflow/kws/kws-tc_resnet8.pb 9 | model_sha256_checksum: c552cf79cb64d3c755ae7d867c1c78b13f55f7589d46def1f70ce657c0db0d79 10 | subgraphs: 11 | - input_tensors: 12 | - input 13 | input_shapes: 14 | - 1,98,40,1 15 | output_tensors: 16 | - output/softmax 17 | output_shapes: 18 | - 1,12 19 | runtime: cpu 20 | backend: xtensa 21 | data_type: fp32_fp32 22 | quantize: 0 23 | -------------------------------------------------------------------------------- /micro/pretrained_models/tensorflow/kws/kws-tc_resnet8.yml: -------------------------------------------------------------------------------- 1 | library_name: kws-tc_resnet8 2 | target_abis: [host] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | kws_tc_resnet8: 7 | platform: tensorflow 8 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/micro/tensorflow/kws/kws-tc_resnet8.pb 9 | model_sha256_checksum: c552cf79cb64d3c755ae7d867c1c78b13f55f7589d46def1f70ce657c0db0d79 10 | subgraphs: 11 | - input_tensors: 12 | - input 13 | input_shapes: 14 | - 1,98,40,1 15 | output_tensors: 16 | - output/softmax 17 | output_shapes: 18 | - 1,12 19 | runtime: cpu 20 | data_type: fp32_fp32 21 | limit_opencl_kernel_time: 0 22 | nnlib_graph_mode: 0 23 | obfuscate: 0 24 | winograd: 0 25 | quantize: 0 26 | -------------------------------------------------------------------------------- /micro/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(ccutils) 2 | 3 | if(NOT HEXAGON) 4 | add_subdirectory(ccunit) 5 | endif() 6 | 7 | add_subdirectory(ccbenchmark) 8 | add_subdirectory(ccbaseline) 9 | -------------------------------------------------------------------------------- /micro/test/ccbaseline/macemc/rpc/macemc.idl: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #include "remote.idl" 17 | 18 | interface macemc : remote_handle64 { 19 | long run(); 20 | }; 21 | -------------------------------------------------------------------------------- /micro/test/ccbaseline/macemc/rpc/skel/macemc.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #include "rpc/skel/base_func.h" 16 | 17 | #include 18 | 19 | extern void MaceMcRun(); 20 | 21 | extern "C" { 22 | MACE_DEFINE_RANDOM_INPUT(macemc) 23 | int macemc_run(remote_handle64 h) { 24 | MaceMcRun(); 25 | FARF(ALWAYS, "run end, h=%d", h); 26 | return 0; 27 | } 28 | } // extern "C" 29 | -------------------------------------------------------------------------------- /micro/test/ccbaseline/macemc/rpc/stub/macemc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MICRO 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 MICRO_TEST_CCBASELINE_MACEMC_RPC_STUB_MACEMC_H_ 17 | #define MICRO_TEST_CCBASELINE_MACEMC_RPC_STUB_MACEMC_H_ 18 | 19 | #include "rpc/stub/base_handle.h" 20 | 21 | namespace micro { 22 | namespace testing { 23 | 24 | class MaceMc : public rpc::stub::BaseHandle { 25 | public: 26 | MaceMc(); 27 | 28 | void Run(); 29 | }; 30 | 31 | } // namespace testing 32 | } // namespace micro 33 | 34 | void MaceMcBaselineRun(); 35 | 36 | #endif // MICRO_TEST_CCBASELINE_MACEMC_RPC_STUB_MACEMC_H_ 37 | -------------------------------------------------------------------------------- /micro/test/ccbaseline/test_baseline_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | void MaceMcBaselineRun(); 16 | 17 | int main(int argc, char *argv[]) { 18 | (void) (argc); 19 | (void) (argv); 20 | MaceMcBaselineRun(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /micro/test/ccbenchmark/micro/rpc/benchmark.idl: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #include "remote.idl" 17 | 18 | interface benchmark: remote_handle64 { 19 | long run(); 20 | }; 21 | -------------------------------------------------------------------------------- /micro/test/ccbenchmark/micro/rpc/skel/benchmark.c: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #include 16 | 17 | #include "rpc/skel/base_func.h" 18 | 19 | extern void BenchmarkRun(); 20 | 21 | MACE_DEFINE_RANDOM_INPUT(benchmark) 22 | 23 | int benchmark_run(remote_handle64 h) { 24 | BenchmarkRun(); 25 | FARF(ALWAYS, "run end, h=%d", h); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /micro/test/ccbenchmark/micro/rpc/stub/benchmark.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MICRO 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 MICRO_TEST_CCBENCHMARK_MICRO_RPC_STUB_BENCHMARK_H_ 17 | #define MICRO_TEST_CCBENCHMARK_MICRO_RPC_STUB_BENCHMARK_H_ 18 | 19 | #include "rpc/stub/base_handle.h" 20 | 21 | namespace micro { 22 | namespace testing { 23 | 24 | class Benchmark : public rpc::stub::BaseHandle { 25 | public: 26 | Benchmark(); 27 | 28 | void Run(); 29 | }; 30 | 31 | } // namespace testing 32 | } // namespace micro 33 | 34 | extern "C" void BenchmarkRun(); 35 | 36 | #endif // MICRO_TEST_CCBENCHMARK_MICRO_RPC_STUB_BENCHMARK_H_ 37 | -------------------------------------------------------------------------------- /micro/test/ccbenchmark/micro/test_benchmark_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | #ifdef MACE_MICRO_ENABLE_HEXAGON_HAP 17 | #include "micro/rpc/stub/benchmark.h" 18 | #else 19 | #include "micro/benchmark_utils/test_benchmark.h" 20 | #endif 21 | 22 | int main(int argc, char *argv[]) { 23 | (void) (argc); 24 | (void) (argv); 25 | BenchmarkRun(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /micro/test/ccunit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(micro_ops_test 2 | micro/ops/stack_test.cc 3 | micro/ops/reshape_test.cc 4 | micro/ops/eltwise_test.cc 5 | micro/ops/nhwc/pooling_test.cc 6 | micro/ops/nhwc/conv_2d_test.cc 7 | micro/ops/nhwc/depthwise_conv_2d_opt_test.cc 8 | micro/ops/nhwc/batch_norm_test.cc 9 | micro/ops/nhwc/depthwise_conv_2d_test.cc 10 | micro/ops/nhwc/conv_2d_opt_test.cc 11 | micro/ops/squeeze_test.cc 12 | micro/ops/reduce_test.cc 13 | micro/ops/strided_slice_test.cc 14 | micro/ops/matmul_test.cc 15 | micro/ops/shape_test.cc 16 | micro/ops/activation_test.cc 17 | micro/ops/argmax_test.cc 18 | micro/ops/softmax_test.cc 19 | micro/ops/bias_add_test.cc 20 | micro/ops/expand_dims_test.cc 21 | micro/ops/concat_test.cc 22 | ) 23 | 24 | if(MACE_MICRO_ENABLE_CMSIS) 25 | target_link_libraries(micro_ops_test 26 | PRIVATE micro_ops_cmsis_nn 27 | ) 28 | target_compile_options(micro_ops_test 29 | PRIVATE "-DMACE_MICRO_ENABLE_CMSIS=ON" 30 | ) 31 | endif() 32 | 33 | target_link_libraries(micro_ops_test 34 | PRIVATE micro_base 35 | PRIVATE micro_ops 36 | PRIVATE micro_framework_for_optest 37 | PRIVATE micro_ccutils 38 | PRIVATE gtest 39 | PRIVATE gtest_main 40 | ) 41 | -------------------------------------------------------------------------------- /micro/test/ccutils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(micro_ccutils 2 | micro/ops/test_utils.cc 3 | micro/ops/operator.test.cc 4 | micro/ops/substitute_op.cc 5 | micro/common/global_buffer.cc 6 | ) 7 | 8 | target_include_directories(micro_ccutils PUBLIC .) 9 | target_link_libraries(micro_ccutils micro_base micro_framework_for_optest) 10 | target_compile_options(micro_ccutils PUBLIC "-std=c++11") 11 | 12 | if(HEXAGON_STUB) 13 | add_library(micro_rpc_stub 14 | rpc/stub/base_handle.cc 15 | ) 16 | target_include_directories(micro_rpc_stub PUBLIC .) 17 | target_link_libraries(micro_rpc_stub PUBLIC hexagon_sdk_headers_arm) 18 | endif() 19 | 20 | if(HEXAGON) 21 | add_library(micro_rpc_skel 22 | rpc/skel/base_func.cc 23 | ) 24 | target_include_directories(micro_rpc_skel PUBLIC .) 25 | target_link_libraries(micro_rpc_skel 26 | PUBLIC hexagon_sdk_headers_dsp 27 | ) 28 | endif() 29 | -------------------------------------------------------------------------------- /micro/test/ccutils/rpc/qaic.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | output_dir=${1} 4 | mkdir -p output_dir 5 | echo $HEXAGON_SDK_ROOT/tools/qaic/Ubuntu16/qaic \ 6 | -mdll -o ${output_dir} \ 7 | -I$HEXAGON_SDK_ROOT/libs/fastcv/dspCV/android_Debug/ship \ 8 | -I$HEXAGON_SDK_ROOT/libs/common/rpcmem/android_Debug/ship \ 9 | -I$HEXAGON_SDK_ROOT/libs/common/adspmsgd/ship/android_Debug \ 10 | -I$HEXAGON_SDK_ROOT/incs \ 11 | -I$HEXAGON_SDK_ROOT/libs/common/remote/ship/android_Debug \ 12 | -I$HEXAGON_SDK_ROOT/incs/stddef \ 13 | ${@:2} 14 | $HEXAGON_SDK_ROOT/tools/qaic/Ubuntu16/qaic \ 15 | -mdll -o ${output_dir} \ 16 | -I$HEXAGON_SDK_ROOT/libs/fastcv/dspCV/android_Debug/ship \ 17 | -I$HEXAGON_SDK_ROOT/libs/common/rpcmem/android_Debug/ship \ 18 | -I$HEXAGON_SDK_ROOT/libs/common/adspmsgd/ship/android_Debug \ 19 | -I$HEXAGON_SDK_ROOT/incs \ 20 | -I$HEXAGON_SDK_ROOT/libs/common/remote/ship/android_Debug \ 21 | -I$HEXAGON_SDK_ROOT/incs/stddef \ 22 | ${@:2} 23 | -------------------------------------------------------------------------------- /micro/tools/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT MICRO_MODEL_NAME) 2 | message(FATAL_ERROR "MICRO_MODEL_NAME is undefined") 3 | endif() 4 | 5 | add_executable(micro_run_static micro_run.cc) 6 | target_link_libraries(micro_run_static micro_port model_${MICRO_MODEL_NAME} micro gflags) 7 | target_compile_options(micro_run_static PRIVATE "-std=c++11") 8 | target_compile_definitions(micro_run_static PRIVATE "-DMICRO_MODEL_NAME=${MICRO_MODEL_NAME}") 9 | -------------------------------------------------------------------------------- /micro/tools/build_docker.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | cd docker/mace-micro-dev 4 | 5 | docker build . -f mace-micro-dev.dockerfile --tag mace-micro-dev 6 | 7 | cd ../.. -------------------------------------------------------------------------------- /micro/tools/ci/build_mbed_example.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | python tools/python/convert.py --config micro/pretrained_models/tensorflow/kws/kws-tc_resnet8.yml --enable_micro || exit -1 4 | 5 | ./micro/tools/cmake/cmake-build-gcc-arm-none-eabi.sh \ 6 | -DARM_CPU=cortex-m7 \ 7 | -DMACE_MICRO_ENABLE_CMSIS=ON \ 8 | -DMACE_MICRO_ENABLE_HARDFP=OFF || exit -1 9 | 10 | cp build/micro/gcc-arm-none-eabi/install micro/examples/classifier -r 11 | cp micro/examples/data micro/examples/classifier -r 12 | 13 | cd micro/examples/classifier 14 | 15 | mbed deploy || exit -1 16 | mbed compile -t GCC_ARM -m NUCLEO_F767ZI -D MICRO_MODEL_NAME=kws_tc_resnet8 -D MICRO_DATA_NAME=kws || exit -1 17 | 18 | cd ../../.. 19 | -------------------------------------------------------------------------------- /micro/tools/ci/cross_build.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | echo "Builds host float32" 4 | rm -rf build/micro 5 | ./micro/tools/cmake/cmake-build-host.sh \ 6 | -DMACE_MICRO_ENABLE_TESTS=ON \ 7 | -DMACE_MICRO_ENABLE_CMSIS=ON || exit -1 8 | 9 | echo "Builds host bfloat16" 10 | rm -rf build/micro 11 | ./micro/tools/cmake/cmake-build-host.sh \ 12 | -DMACE_MICRO_ENABLE_BFLOAT16=ON \ 13 | -DMACE_MICRO_ENABLE_TESTS=ON \ 14 | -DMACE_MICRO_ENABLE_CMSIS=ON || exit -1 15 | 16 | echo "Builds gcc arm cortex-m7" 17 | rm -rf build/micro 18 | ./micro/tools/cmake/cmake-build-gcc-arm-none-eabi.sh \ 19 | -DARM_CPU=cortex-m7 \ 20 | -DMACE_MICRO_ENABLE_TESTS=OFF \ 21 | -DMACE_MICRO_ENABLE_CMSIS=ON || exit -1 22 | 23 | cd .. -------------------------------------------------------------------------------- /micro/tools/ci/host_build_and_run_examples.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | python tools/python/convert.py --config micro/pretrained_models/tensorflow/kws/kws-tc_resnet8.yml --enable_micro || exit -1 4 | 5 | rm -rf build/micro 6 | ./micro/tools/cmake/cmake-build-host.sh \ 7 | -DMACE_MICRO_ENABLE_EXAMPLES=ON -DMICRO_MODEL_NAME=kws_tc_resnet8 -DMICRO_DATA_NAME=kws \ 8 | -DMACE_MICRO_ENABLE_TESTS=OFF \ 9 | -DMACE_MICRO_ENABLE_CMSIS=OFF || exit -1 10 | 11 | ./build/micro/host/examples/classifier/kws_tc_resnet8 12 | 13 | python3 tools/python/convert.py --config micro/pretrained_models/keras/mnist/mnist-int8.yml --enable_micro || exit -1 14 | 15 | rm -rf build/micro 16 | ./micro/tools/cmake/cmake-build-host.sh \ 17 | -DMACE_MICRO_ENABLE_CMSIS=ON \ 18 | -DMACE_MICRO_ENABLE_EXAMPLES=ON \ 19 | -DMICRO_MODEL_NAME=mnist_int8 -DMICRO_DATA_NAME=mnist \ 20 | -DMACE_MICRO_ENABLE_TESTS=OFF || exit -1 21 | 22 | ./build/micro/host/examples/classifier/mnist_int8 23 | 24 | cd .. -------------------------------------------------------------------------------- /micro/tools/ci/host_build_and_run_tests.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | rm -rf build/micro 4 | ./micro/tools/cmake/cmake-build-host.sh \ 5 | -DMACE_MICRO_ENABLE_TESTS=ON \ 6 | -DMACE_MICRO_ENABLE_CMSIS=ON || exit -1 7 | 8 | echo "MACE Micro ut" 9 | build/micro/host/test/ccunit/micro_ops_test || exit -1 10 | 11 | echo "MACE Micro benchmark" 12 | build/micro/host/test/ccbenchmark/micro_cc_benchmark || exit -1 13 | 14 | cd .. -------------------------------------------------------------------------------- /micro/tools/cmake/cmake-build-arm64-v8a-hexagon-stub.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z "$ANDROID_NDK_HOME" ]; then 4 | echo "ANDROID_NDK_HOME is undefined"; 5 | exit -1; 6 | fi 7 | 8 | if [ -z "$HEXAGON_SDK_ROOT" ]; then 9 | echo "HEXAGON_SDK_ROOT is undefined"; 10 | exit -1; 11 | fi 12 | 13 | BUILD_DIR=build/micro/arm64-v8a 14 | mkdir -p ${BUILD_DIR} 15 | cd ${BUILD_DIR} 16 | 17 | cmake ../../../micro \ 18 | -DANDROID_ABI="arm64-v8a" \ 19 | -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake \ 20 | -DHEXAGON_SDK_ROOT=${HEXAGON_SDK_ROOT} \ 21 | -DANDROID_NATIVE_API_LEVEL=21 \ 22 | -DCMAKE_BUILD_TYPE=Release \ 23 | -DANDROID_STL=c++_static \ 24 | -DMACE_ENABLE_RPCMEM=ON \ 25 | -DCMAKE_INSTALL_PREFIX=install \ 26 | -DMACE_MICRO_ENABLE_EXAMPLES=OFF \ 27 | -DHEXAGON_STUB=ON \ 28 | $@ || exit 1 29 | 30 | cmake --build . --target install --target install -- -j || exit 1 31 | 32 | cd ../../.. 33 | -------------------------------------------------------------------------------- /micro/tools/cmake/cmake-build-gcc-arm-none-eabi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_DIR=build/micro/gcc-arm-none-eabi 4 | 5 | mkdir -p ${BUILD_DIR} 6 | cd ${BUILD_DIR} 7 | 8 | cmake ../../../micro \ 9 | -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/gcc-arm-none-eabi.cmake \ 10 | -DMACE_MICRO_ENABLE_CMSIS=ON \ 11 | -DCMAKE_INSTALL_PREFIX=install \ 12 | -DMACE_MICRO_ENABLE_TESTS=OFF \ 13 | $@ || exit 1 14 | 15 | cmake --build . --target install -- -j || exit 1 16 | 17 | cd ../../.. 18 | -------------------------------------------------------------------------------- /micro/tools/cmake/cmake-build-hexagon6.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # HEXAGON_TOOLS is the path of "HEXAGON_Tools/6.*.*" toolchain 4 | if [ -z "$HEXAGON_TOOLS" ]; then 5 | echo "HEXAGON_TOOLS is undefined"; 6 | fi 7 | 8 | # # HEXAGON_SDK_ROOT is the path of "Hexagon_SDK/3.*.*" 9 | # if [ -z "$HEXAGON_SDK_ROOT" ]; then 10 | # echo "HEXAGON_SDK_ROOT is undefined"; 11 | # fi 12 | 13 | BUILD_DIR=build/micro/hexagon6 14 | mkdir -p ${BUILD_DIR} 15 | cd ${BUILD_DIR} 16 | 17 | cmake ../../../micro \ 18 | -DHEXAGON_SDK_ROOT=${HEXAGON_SDK_ROOT} \ 19 | -DHEXAGON_TOOLS=${HEXAGON_TOOLS} \ 20 | -DMACE_MICRO_ENABLE_EXAMPLES=OFF \ 21 | -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/hexagon6.toolchain.cmake \ 22 | -DCMAKE_INSTALL_PREFIX=install \ 23 | $@ || exit 1 24 | 25 | cmake --build . --target install -- -j || exit 1 26 | 27 | cd ../../.. 28 | -------------------------------------------------------------------------------- /micro/tools/cmake/cmake-build-hexagon8.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # HEXAGON_TOOLS is the path of "HEXAGON_Tools/8.*.*" toolchain 4 | if [ -z "$HEXAGON_TOOLS" ]; then 5 | echo "HEXAGON_TOOLS is undefined"; 6 | fi 7 | 8 | # HEXAGON_SDK_ROOT is the path of "Hexagon_SDK/3.*.*" 9 | if [ -z "$HEXAGON_SDK_ROOT" ]; then 10 | echo "HEXAGON_SDK_ROOT is undefined"; 11 | fi 12 | 13 | BUILD_DIR=build/micro/hexagon8 14 | mkdir -p ${BUILD_DIR} 15 | cd ${BUILD_DIR} 16 | 17 | cmake ../../../micro \ 18 | -DHEXAGON_SDK_ROOT=${HEXAGON_SDK_ROOT} \ 19 | -DHEXAGON_TOOLS=${HEXAGON_TOOLS} \ 20 | -DMACE_MICRO_ENABLE_EXAMPLES=OFF \ 21 | -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/hexagon8.toolchain.cmake \ 22 | -DCMAKE_INSTALL_PREFIX=install \ 23 | $@ || exit 1 24 | 25 | cmake --build . --target install -- -j || exit 1 26 | 27 | cd ../../.. 28 | -------------------------------------------------------------------------------- /micro/tools/cmake/cmake-build-host.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_DIR=build/micro/host 4 | mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} 5 | 6 | cmake ../../../micro \ 7 | -DCMAKE_INSTALL_PREFIX=install \ 8 | $@ || exit 1 9 | 10 | cmake --build . --target install -- -j || exit 1 11 | 12 | cd ../../.. 13 | -------------------------------------------------------------------------------- /micro/tools/cmake/cmake-build-xcc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BUILD_DIR=build/micro/xcc 4 | 5 | mkdir -p ${BUILD_DIR} 6 | cd ${BUILD_DIR} 7 | 8 | cmake ../../../micro \ 9 | -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchain/xcc.cmake \ 10 | -DMACE_MICRO_ENABLE_XTENSA=ON \ 11 | -DCMAKE_INSTALL_PREFIX=install \ 12 | -DMACE_MICRO_ENABLE_EXAMPLES=OFF \ 13 | -DMICRO_MODEL_NAME=kws_tc_resnet8 \ 14 | -DMICRO_DATA_NAME=kws \ 15 | $@ || exit 1 16 | 17 | cmake --build . --target install -- -j || exit 1 18 | 19 | cd ../../.. 20 | -------------------------------------------------------------------------------- /micro/tools/combine_static_libs.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | output_name=$1 4 | 5 | 6 | echo "$2" | tr -s ';' ' ' | xargs ar -crs $output_name 7 | -------------------------------------------------------------------------------- /repository/git/BUILD.bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/repository/git/BUILD.bazel -------------------------------------------------------------------------------- /repository/git/BUILD.bazel.tpl: -------------------------------------------------------------------------------- 1 | # Description: 2 | # Borrow from tensorflow 3 | # Exports generated files used to generate mace/codegen/version/version.cc 4 | 5 | package(default_visibility = ["//visibility:public"]) 6 | 7 | licenses(["notice"]) 8 | 9 | exports_files( 10 | glob(["gen/*"]), 11 | ) -------------------------------------------------------------------------------- /repository/git/git_configure.bzl: -------------------------------------------------------------------------------- 1 | """Repository rule for Git autoconfiguration, borrow from tensorflow 2 | """ 3 | def _git_version_conf_impl(repository_ctx): 4 | repository_ctx.template( 5 | "BUILD.bazel", 6 | Label("//repository/git:BUILD.bazel.tpl")) 7 | 8 | mace_root_path = str(repository_ctx.path(Label("@mace//:BUILD.bazel")))[:-len("BUILD.bazel")] 9 | 10 | generated_files_path = repository_ctx.path("gen") 11 | 12 | ret = repository_ctx.execute( 13 | ["test", "-f", "%s/.git/logs/HEAD" % mace_root_path]) 14 | if ret.return_code == 0: 15 | unused_var = repository_ctx.path(Label("//:.git/HEAD")) 16 | 17 | ret = repository_ctx.execute( 18 | ["test", "-f", "%s/.git/refs/heads/master" % mace_root_path]) 19 | if ret.return_code == 0: 20 | unused_var = repository_ctx.path(Label("//:.git/refs/heads/master")) 21 | 22 | repository_ctx.execute([ 23 | 'bash', '%s/mace/codegen/tools/gen_version_source.sh' % mace_root_path 24 | , '%s/version' % generated_files_path 25 | ], quiet=False) 26 | 27 | 28 | git_version_repository = repository_rule( 29 | implementation = _git_version_conf_impl, 30 | ) 31 | -------------------------------------------------------------------------------- /repository/opencl-kernel/BUILD.bazel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/repository/opencl-kernel/BUILD.bazel -------------------------------------------------------------------------------- /repository/opencl-kernel/BUILD.bazel.tpl: -------------------------------------------------------------------------------- 1 | # Description: 2 | # Exports generated files used to generate mace/codegen/opencl/opencl_encrypt_program.cc 3 | 4 | package(default_visibility = ["//visibility:public"]) 5 | 6 | licenses(["notice"]) 7 | 8 | exports_files( 9 | glob(["gen/*"]), 10 | ) -------------------------------------------------------------------------------- /setup/optionals.txt: -------------------------------------------------------------------------------- 1 | tensorflow>=1.8.0 2 | scipy>=1.0.0 3 | filelock>=3.0.0 4 | onnx>=1.5.0 -------------------------------------------------------------------------------- /setup/requirements.txt: -------------------------------------------------------------------------------- 1 | python>=2.7.0 2 | jinja2>=2.10 3 | pyyaml>=3.12 4 | sh>=1.12.14 5 | numpy>=1.14.0 6 | six>=1.11.0 -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/ccutils") 2 | 3 | add_subdirectory(ccutils) 4 | 5 | if(MACE_ENABLE_TESTS) 6 | add_subdirectory(ccunit) 7 | endif() 8 | 9 | if(MACE_ENABLE_BENCHMARKS) 10 | add_subdirectory(ccbenchmark) 11 | endif() 12 | -------------------------------------------------------------------------------- /test/ccbenchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}") 2 | 3 | if(NOT APPLE) 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") 5 | endif() 6 | 7 | file(GLOB MACE_BENCHMARK_TEST_SRCS 8 | mace/benchmark_utils/*.cc 9 | mace/ops/*.cc 10 | ) 11 | add_executable(mace_cc_benchmark ${MACE_BENCHMARK_TEST_SRCS}) 12 | target_link_libraries(mace_cc_benchmark PUBLIC 13 | mace_cc_test_utils 14 | mace_static 15 | gflags 16 | ) 17 | add_dependencies(mace_cc_benchmark eigen3) 18 | 19 | install(TARGETS mace_cc_benchmark RUNTIME DESTINATION bin) 20 | -------------------------------------------------------------------------------- /test/ccunit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}") 2 | 3 | file(GLOB MACE_CC_TEST_SRCS 4 | mace/utils/*.cc 5 | mace/port/*.cc 6 | mace/ops/*.cc 7 | ) 8 | 9 | if(MACE_ENABLE_HTA) 10 | set(MACE_CC_TEST_SRCS ${MACE_CC_TEST_SRCS}) 11 | endif(MACE_ENABLE_HTA) 12 | 13 | add_executable(mace_cc_test ${MACE_CC_TEST_SRCS}) 14 | target_link_libraries(mace_cc_test PUBLIC 15 | mace_cc_test_utils 16 | mace_static 17 | extra_link_libs_target 18 | gtest 19 | gtest_main 20 | ) 21 | 22 | install(TARGETS mace_cc_test RUNTIME DESTINATION bin) 23 | -------------------------------------------------------------------------------- /test/ccunit/mace/port/env_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The MACE 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 | #include "mace/port/env.h" 16 | 17 | #include 18 | 19 | namespace mace { 20 | namespace { 21 | 22 | class EnvTest : public ::testing::Test { 23 | }; 24 | 25 | TEST_F(EnvTest, NowMicros) { 26 | EXPECT_GT(NowMicros(), 0); 27 | } 28 | 29 | TEST_F(EnvTest, GetFileSystem) { 30 | GetFileSystem(); 31 | } 32 | 33 | TEST_F(EnvTest, CPUInfo) { 34 | std::vector freq; 35 | GetCPUMaxFreq(&freq); 36 | std::vector cpu_ids; 37 | SchedSetAffinity(cpu_ids); 38 | } 39 | 40 | } // namespace 41 | } // namespace mace 42 | -------------------------------------------------------------------------------- /test/ccutils/BUILD.bazel: -------------------------------------------------------------------------------- 1 | package( 2 | default_visibility = ["//visibility:public"], 3 | ) 4 | 5 | licenses(["notice"]) # Apache 2.0 6 | 7 | load( 8 | "//mace:mace.bzl", 9 | "if_android", 10 | "if_android_armv7", 11 | "if_hexagon_enabled", 12 | "if_neon_enabled", 13 | "if_opencl_enabled", 14 | "if_quantize_enabled", 15 | "if_rpcmem_enabled", 16 | ) 17 | 18 | cc_library( 19 | name = "ccutils", 20 | testonly = 1, 21 | srcs = glob([ 22 | "mace/ops/*.cc", 23 | ]), 24 | hdrs = glob([ 25 | "mace/ops/*.h", 26 | "mace/ops/testing/*.h", 27 | ]), 28 | copts = [ 29 | "-Werror", 30 | "-Wextra", 31 | ] + if_neon_enabled([ 32 | "-DMACE_ENABLE_NEON", 33 | ]) + if_android_armv7([ 34 | "-mfpu=neon-fp16", 35 | ]) + if_android_armv7([ 36 | "-mfloat-abi=softfp", 37 | ]) + if_opencl_enabled([ 38 | "-DMACE_ENABLE_OPENCL", 39 | ]) + if_hexagon_enabled([ 40 | "-DMACE_ENABLE_HEXAGON", 41 | ]) + if_rpcmem_enabled([ 42 | "-DMACE_ENABLE_RPCMEM", 43 | ]), 44 | strip_include_prefix = "", 45 | deps = [ 46 | "//mace/libmace", 47 | "@gtest", 48 | ], 49 | ) 50 | -------------------------------------------------------------------------------- /test/ccutils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}") 2 | 3 | file(GLOB MACE_CC_TEST_UTILS_SRCS 4 | mace/ops/*.cc 5 | ) 6 | 7 | add_library(mace_cc_test_utils ${MACE_CC_TEST_UTILS_SRCS}) 8 | target_link_libraries(mace_cc_test_utils PUBLIC 9 | ops 10 | ) 11 | -------------------------------------------------------------------------------- /test/ci-mace-models/onnx-models/pytorch2onnx/reduce_test/reduce_test_max_channel_103/reduce_test.gpu.fp16.speedupDownload.yml: -------------------------------------------------------------------------------- 1 | library_name: reduce_test_pt2onnx_gpu 2 | target_abis: 3 | - arm64-v8a 4 | model_graph_format: file 5 | model_data_format: file 6 | models: 7 | reduce_test_pt2onnx_gpu: 8 | platform: onnx 9 | model_file_path: https://cnbj1-fds.api.xiaomi.net/mace/ci-mace-models/onnx-models/pytorch2onnx/reduce_test/reduce_test_max_channel_103/reduce_test.onnx 10 | model_sha256_checksum: 872e74773461e4bf03c9df0442260b5875cf6204d5c8bb51a7daf118988a1119 11 | subgraphs: 12 | - input_tensors: 13 | - actual_input_0 14 | output_tensors: 15 | - actual_output_0 16 | input_shapes: 17 | - 1,103,255,235 18 | output_shapes: 19 | - 1,1,255,235 20 | backend: tensorflow 21 | input_data_formats: 22 | - NCHW 23 | output_data_formats: 24 | - NCHW 25 | runtime: gpu 26 | limit_opencl_kernel_time: 0 27 | nnlib_graph_mode: 0 28 | obfuscate: 0 29 | -------------------------------------------------------------------------------- /test/ci-mace-models/onnx-models/pytorch2onnx/reduce_test/reduce_test_min_channel_1003/reduce_test.gpu.fp16.speedupDownload.yml: -------------------------------------------------------------------------------- 1 | library_name: reduce_test_pt2onnx_gpu 2 | target_abis: 3 | - arm64-v8a 4 | model_graph_format: file 5 | model_data_format: file 6 | models: 7 | reduce_test_pt2onnx_gpu: 8 | platform: onnx 9 | model_file_path: https://cnbj1-fds.api.xiaomi.net/mace/ci-mace-models/onnx-models/pytorch2onnx/reduce_test/reduce_test_min_channel_1003/reduce_test.onnx 10 | model_sha256_checksum: daa56f4b2373dd03f182e563e6a2361eea19ce7bf1f96dbcbea571ce158f3409 11 | subgraphs: 12 | - input_tensors: 13 | - actual_input_0 14 | output_tensors: 15 | - actual_output_0 16 | input_shapes: 17 | - 1,1003,25,25 18 | output_shapes: 19 | - 1,1,25,25 20 | backend: tensorflow 21 | input_data_formats: 22 | - NCHW 23 | output_data_formats: 24 | - NCHW 25 | runtime: gpu 26 | limit_opencl_kernel_time: 0 27 | nnlib_graph_mode: 0 28 | obfuscate: 0 29 | -------------------------------------------------------------------------------- /test/ci-mace-models/onnx-models/pytorch2onnx/test_const_input/test_const_input.cpu.yml: -------------------------------------------------------------------------------- 1 | library_name: test_const_input_pt2onnx_cpu 2 | target_abis: 3 | - arm64-v8a 4 | model_graph_format: file 5 | model_data_format: file 6 | models: 7 | test_const_input_pt2onnx_cpu: 8 | platform: onnx 9 | model_file_path: https://cdn.cnbj1.fds.api.mi-img.com/mace/ci-mace-models/onnx-models/pytorch2onnx/test_const_input/test_const_input.onnx 10 | model_sha256_checksum: 920888b6562f86c480aaf41045e354dcd4a599a0c3fd514b3bdea123dcdd6fef 11 | subgraphs: 12 | - input_tensors: 13 | - actual_input_0 14 | output_tensors: 15 | - actual_output_0 16 | - actual_output_1 17 | input_data_formats: 18 | - NCHW 19 | output_data_formats: 20 | - NCHW 21 | - NCHW 22 | input_shapes: 23 | - 1,128,64,64 24 | output_shapes: 25 | - 1,256,32,32 26 | - 1,128,128 27 | backend: tensorflow 28 | input_ranges: 29 | - -300,300 30 | runtime: cpu 31 | limit_opencl_kernel_time: 0 32 | nnlib_graph_mode: 0 33 | obfuscate: 0 34 | -------------------------------------------------------------------------------- /test/ci-mace-models/onnx-models/pytorch2onnx/test_const_input/test_const_input.gpu.fp16.yml: -------------------------------------------------------------------------------- 1 | library_name: test_const_input_pt2onnx_gpu 2 | target_abis: 3 | - arm64-v8a 4 | model_graph_format: file 5 | model_data_format: file 6 | models: 7 | test_const_input_pt2onnx_gpu: 8 | platform: onnx 9 | model_file_path: https://cdn.cnbj1.fds.api.mi-img.com/mace/ci-mace-models/onnx-models/pytorch2onnx/test_const_input/test_const_input.onnx 10 | model_sha256_checksum: 920888b6562f86c480aaf41045e354dcd4a599a0c3fd514b3bdea123dcdd6fef 11 | subgraphs: 12 | - input_tensors: 13 | - actual_input_0 14 | output_tensors: 15 | - actual_output_0 16 | - actual_output_1 17 | input_data_formats: 18 | - NCHW 19 | output_data_formats: 20 | - NCHW 21 | - NCHW 22 | input_shapes: 23 | - 1,128,64,64 24 | output_shapes: 25 | - 1,256,32,32 26 | - 1,128,128 27 | backend: tensorflow 28 | input_ranges: 29 | - -10,10 30 | runtime: gpu 31 | limit_opencl_kernel_time: 0 32 | nnlib_graph_mode: 0 33 | obfuscate: 0 34 | -------------------------------------------------------------------------------- /test/ci-mace-models/onnx-models/pytorch2onnx/test_const_input/test_const_input.gpu.fp32.yml: -------------------------------------------------------------------------------- 1 | library_name: test_const_input_pt2onnx_gpu 2 | target_abis: 3 | - arm64-v8a 4 | model_graph_format: file 5 | model_data_format: file 6 | models: 7 | test_const_input_pt2onnx_gpu: 8 | platform: onnx 9 | model_file_path: https://cdn.cnbj1.fds.api.mi-img.com/mace/ci-mace-models/onnx-models/pytorch2onnx/test_const_input/test_const_input.onnx 10 | model_sha256_checksum: 920888b6562f86c480aaf41045e354dcd4a599a0c3fd514b3bdea123dcdd6fef 11 | subgraphs: 12 | - input_tensors: 13 | - actual_input_0 14 | output_tensors: 15 | - actual_output_0 16 | - actual_output_1 17 | input_data_formats: 18 | - NCHW 19 | output_data_formats: 20 | - NCHW 21 | - NCHW 22 | input_shapes: 23 | - 1,128,64,64 24 | output_shapes: 25 | - 1,256,32,32 26 | - 1,128,128 27 | backend: tensorflow 28 | input_ranges: 29 | - -200,200 30 | runtime: gpu 31 | data_type: fp32_fp32 32 | limit_opencl_kernel_time: 0 33 | nnlib_graph_mode: 0 34 | obfuscate: 0 35 | -------------------------------------------------------------------------------- /test/ci-mace-models/tf-models/test_const_input/test_const_input.cpu.yml: -------------------------------------------------------------------------------- 1 | library_name: test_const_input_tf_cpu 2 | target_abis: [arm64-v8a] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | test_const_input_tf_cpu: 7 | platform: tensorflow 8 | model_file_path: https://cdn.cnbj1.fds.api.mi-img.com/mace/ci-mace-models/tf-model/test_const_input_tf/test_const_input_tf.pb 9 | model_sha256_checksum: fa7bdb55cbea2c5c419cf4da01c220d1c5d8bf8ebf48b528a8dcdfae11febaac 10 | subgraphs: 11 | - input_tensors: 12 | - input 13 | input_shapes: 14 | - 1,224,224,3 15 | output_tensors: 16 | - output 17 | output_shapes: 18 | - 1,336,112,12 19 | input_ranges: 20 | - -200.0,200.0 21 | runtime: cpu 22 | limit_opencl_kernel_time: 0 23 | nnlib_graph_mode: 0 24 | obfuscate: 0 25 | winograd: 0 26 | -------------------------------------------------------------------------------- /test/ci-mace-models/tf-models/test_const_input/test_const_input.gpu.fp16.yml: -------------------------------------------------------------------------------- 1 | library_name: test_const_input_tf_gpu 2 | target_abis: [arm64-v8a] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | test_const_input_tf_gpu: 7 | platform: tensorflow 8 | model_file_path: https://cdn.cnbj1.fds.api.mi-img.com/mace/ci-mace-models/tf-model/test_const_input_tf/test_const_input_tf.pb 9 | model_sha256_checksum: fa7bdb55cbea2c5c419cf4da01c220d1c5d8bf8ebf48b528a8dcdfae11febaac 10 | subgraphs: 11 | - input_tensors: 12 | - input 13 | input_shapes: 14 | - 1,224,224,3 15 | output_tensors: 16 | - output 17 | output_shapes: 18 | - 1,336,112,12 19 | input_ranges: 20 | - -2.0,2.0 21 | runtime: gpu 22 | limit_opencl_kernel_time: 0 23 | nnlib_graph_mode: 0 24 | obfuscate: 0 25 | winograd: 0 26 | -------------------------------------------------------------------------------- /test/ci-mace-models/tf-models/test_const_input/test_const_input.gpu.fp32.yml: -------------------------------------------------------------------------------- 1 | library_name: test_const_input_tf_gpu 2 | target_abis: [arm64-v8a] 3 | model_graph_format: file 4 | model_data_format: file 5 | models: 6 | test_const_input_tf_gpu: 7 | platform: tensorflow 8 | model_file_path: https://cdn.cnbj1.fds.api.mi-img.com/mace/ci-mace-models/tf-model/test_const_input_tf/test_const_input_tf.pb 9 | model_sha256_checksum: fa7bdb55cbea2c5c419cf4da01c220d1c5d8bf8ebf48b528a8dcdfae11febaac 10 | subgraphs: 11 | - input_tensors: 12 | - input 13 | input_shapes: 14 | - 1,224,224,3 15 | output_tensors: 16 | - output 17 | output_shapes: 18 | - 1,336,112,12 19 | input_ranges: 20 | - -200.0,200.0 21 | runtime: gpu 22 | data_type: fp32_fp32 23 | limit_opencl_kernel_time: 0 24 | nnlib_graph_mode: 0 25 | obfuscate: 0 26 | winograd: 0 27 | -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt67xx/libapu-frontend.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt67xx/libapu-frontend.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt67xx/mt6779/libapu-platform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt67xx/mt6779/libapu-platform.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt67xx/mt6785/libapu-platform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt67xx/mt6785/libapu-platform.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt68xx/libapu-frontend.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt68xx/libapu-frontend.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt68xx/mt6853/libapu-frontend.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt68xx/mt6853/libapu-frontend.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt68xx/mt6853/libapu-platform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt68xx/mt6853/libapu-platform.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt68xx/mt6873/libapu-frontend.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt68xx/mt6873/libapu-frontend.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt68xx/mt6873/libapu-platform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt68xx/mt6873/libapu-platform.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt68xx/mt6885/libapu-frontend.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt68xx/mt6885/libapu-frontend.so -------------------------------------------------------------------------------- /third_party/apu/android_Q/mt68xx/mt6885/libapu-platform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_Q/mt68xx/mt6885/libapu-platform.so -------------------------------------------------------------------------------- /third_party/apu/android_R/libapu-apuwareapusys.mtk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_R/libapu-apuwareapusys.mtk.so -------------------------------------------------------------------------------- /third_party/apu/android_R/libapu-apuwareutils.mtk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_R/libapu-apuwareutils.mtk.so -------------------------------------------------------------------------------- /third_party/apu/android_R/libapu-apuwarexrp.mtk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_R/libapu-apuwarexrp.mtk.so -------------------------------------------------------------------------------- /third_party/apu/android_R/libapu-frontend.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_R/libapu-frontend.so -------------------------------------------------------------------------------- /third_party/apu/android_R/libapu-platform.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/apu/android_R/libapu-platform.so -------------------------------------------------------------------------------- /third_party/apu/apu.cmake: -------------------------------------------------------------------------------- 1 | set(APU_INSTALL_DIR "${PROJECT_SOURCE_DIR}/third_party/apu") 2 | set(APU_INCLUDE_DIR "${APU_INSTALL_DIR}") 3 | 4 | include_directories(SYSTEM "${APU_INCLUDE_DIR}") 5 | 6 | if(MACE_MTK_APU_VERSION EQUAL 1) 7 | set(APU-FRONTEND "${APU_INSTALL_DIR}/android_Q/mt67xx/libapu-frontend.so") 8 | elseif(MACE_MTK_APU_VERSION EQUAL 2) 9 | set(APU-FRONTEND "${APU_INSTALL_DIR}/android_Q/mt68xx/libapu-frontend.so") 10 | elseif(MACE_MTK_APU_VERSION EQUAL 3) 11 | set(APU-FRONTEND "${APU_INSTALL_DIR}/android_R/libapu-frontend.so") 12 | elseif(MACE_MTK_APU_VERSION EQUAL 4) 13 | else() 14 | message(FATAL_ERROR "Invalid MTK APU version: " ${MACE_MTK_APU_VERSION}) 15 | endif() 16 | 17 | if(APU-FRONTEND) 18 | add_library(apu-frontend SHARED IMPORTED GLOBAL) 19 | set_target_properties(apu-frontend PROPERTIES IMPORTED_LOCATION ${APU-FRONTEND}) 20 | install(FILES ${APU-FRONTEND} DESTINATION lib) 21 | endif(APU-FRONTEND) 22 | -------------------------------------------------------------------------------- /third_party/caffe/BUILD.bazel: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["LICENSE"]) 4 | 5 | package( 6 | default_visibility = ["//visibility:public"], 7 | ) 8 | 9 | licenses(["notice"]) # Apache 2.0 10 | 11 | load("@com_google_protobuf//:protobuf.bzl", "py_proto_library") 12 | 13 | py_proto_library( 14 | name = "caffe_py", 15 | srcs = ["caffe.proto"], 16 | default_runtime = "@com_google_protobuf//:protobuf_python", 17 | protoc = "@com_google_protobuf//:protoc", 18 | srcs_version = "PY2AND3", 19 | deps = ["@com_google_protobuf//:protobuf_python"], 20 | ) 21 | -------------------------------------------------------------------------------- /third_party/caffe/caffe.cmake: -------------------------------------------------------------------------------- 1 | set(CAFFE_PROTO_PROTOS ${PROJECT_SOURCE_DIR}/third_party/caffe/caffe.proto) 2 | set(MACE_PROTO_PYTHON_DIR ${PROJECT_SOURCE_DIR}/tools/python/py_proto) 3 | 4 | foreach(proto_file ${CAFFE_PROTO_PROTOS}) 5 | get_filename_component(proto_file_abs ${proto_file} ABSOLUTE) 6 | get_filename_component(basename ${proto_file} NAME_WE) 7 | set(PROTO_GENERATED_PY_FILES ${MACE_PROTO_PYTHON_DIR}/${basename}_pb2.py) 8 | 9 | add_custom_command( 10 | OUTPUT ${PROTO_GENERATED_PY_FILES} 11 | COMMAND ${PROTOC_BIN} --python_out ${MACE_PROTO_PYTHON_DIR} -I ${PROJECT_SOURCE_DIR}/third_party/caffe ${proto_file_abs} 12 | COMMENT "Generating ${PROTO_GENERATED_PY_FILES} from ${proto_file}" 13 | DEPENDS protoc_bin 14 | VERBATIM 15 | ) 16 | endforeach() 17 | 18 | add_custom_target(caffe_proto_src ALL DEPENDS ${PROTO_GENERATED_PY_FILES}) 19 | -------------------------------------------------------------------------------- /third_party/dmabufheap/BUILD.bazel: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["license.txt"]) 4 | 5 | cc_library( 6 | name = "dmabufheap", 7 | srcs = [], 8 | hdrs = [ 9 | "include/BufferAllocatorWrapper.h", 10 | "include/dmabufheap-defs.h", 11 | ], 12 | linkopts = ["-Wl,-unresolved-symbols=ignore-in-shared-libs"], 13 | visibility = ["//visibility:public"], 14 | ) 15 | -------------------------------------------------------------------------------- /third_party/dmabufheap/dmabufheap.cmake: -------------------------------------------------------------------------------- 1 | set(DMABUFHEAP_INSTALL_DIR "${PROJECT_SOURCE_DIR}/third_party/dmabufheap") 2 | set(DMABUFHEAP_INCLUDE_DIR "${DMABUFHEAP_INSTALL_DIR}") 3 | 4 | include_directories(SYSTEM "${DMABUFHEAP_INCLUDE_DIR}") 5 | -------------------------------------------------------------------------------- /third_party/eigen3/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # Description: 2 | # Eigen is a C++ template library for linear algebra: vectors, 3 | # matrices, and related algorithms. 4 | # This file is mostly stolen from tensorflow. 5 | 6 | licenses([ 7 | # Note: Eigen is an MPL2 library that includes GPL v3 and LGPL v2.1+ code. 8 | # We've taken special care to not reference any restricted code. 9 | "reciprocal", # MPL2 10 | "notice", # Portions BSD 11 | ]) 12 | 13 | exports_files(["LICENSE"]) 14 | 15 | cc_library( 16 | name = "eigen3", 17 | hdrs = glob(["unsupported/Eigen/CXX11/src/FixedPoint/*.h"]) + [ 18 | "Eigen/Core", 19 | "Eigen/LU", 20 | "Eigen/Cholesky", 21 | "Eigen/Eigenvalues", 22 | "Eigen/QR", 23 | "Eigen/SVD", 24 | "unsupported/Eigen/SpecialFunctions", 25 | "unsupported/Eigen/CXX11/ThreadPool", 26 | "unsupported/Eigen/CXX11/Tensor", 27 | "unsupported/Eigen/CXX11/FixedPoint", 28 | ], 29 | visibility = ["//visibility:public"], 30 | deps = [ 31 | "@eigen//:eigen", 32 | ], 33 | ) 34 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/Cholesky: -------------------------------------------------------------------------------- 1 | #include "Eigen/Cholesky" 2 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/Core: -------------------------------------------------------------------------------- 1 | #include "Eigen/Core" 2 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/Eigenvalues: -------------------------------------------------------------------------------- 1 | #include "Eigen/Eigenvalues" 2 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/LU: -------------------------------------------------------------------------------- 1 | #include "Eigen/LU" 2 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/QR: -------------------------------------------------------------------------------- 1 | #include "Eigen/QR" 2 | -------------------------------------------------------------------------------- /third_party/eigen3/Eigen/SVD: -------------------------------------------------------------------------------- 1 | #include "Eigen/SVD" 2 | -------------------------------------------------------------------------------- /third_party/eigen3/eigen3.cmake: -------------------------------------------------------------------------------- 1 | INCLUDE(ExternalProject) 2 | 3 | set(EIGEN3_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/eigen3") 4 | set(EIGEN3_INCLUDE_DIR "${EIGEN3_SRCS_DIR}/src/eigen3" CACHE PATH "eigen3 include directory." FORCE) 5 | 6 | include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR}) 7 | 8 | # Mirror of https://bitbucket.org/eigen/eigen/get/f3a22f35b044.tar.gz 9 | set(EIGEN3_URL "http://cnbj1.fds.api.xiaomi.com/mace/third-party/eigen/f3a22f35b044.tar.gz") 10 | set(EIGEN3_HASH "SHA256=ca7beac153d4059c02c8fc59816c82d54ea47fe58365e8aded4082ded0b820c4") 11 | 12 | ExternalProject_Add( 13 | eigen3 14 | URL_HASH "${EIGEN3_HASH}" 15 | URL "${EIGEN3_URL}" 16 | PREFIX "${EIGEN3_SRCS_DIR}" 17 | BINARY_DIR "" 18 | CONFIGURE_COMMAND "" 19 | BUILD_COMMAND "" 20 | INSTALL_COMMAND "" 21 | TEST_COMMAND "" 22 | ) 23 | -------------------------------------------------------------------------------- /third_party/eigen3/unsupported/Eigen/CXX11/Tensor: -------------------------------------------------------------------------------- 1 | #include "unsupported/Eigen/CXX11/Tensor" 2 | 3 | #ifdef _WIN32 4 | #ifndef SLEEP_FUNC_HEADER_GUARD 5 | #define SLEEP_FUNC_HEADER_GUARD 6 | inline void sleep(unsigned int seconds) { Sleep(1000*seconds); } 7 | #endif 8 | 9 | // On Windows, Eigen will include Windows.h, which defines various 10 | // macros that conflict with TensorFlow symbols. Undefine them here to 11 | // prevent clashes. 12 | #undef DeleteFile 13 | #undef ERROR 14 | #undef LoadLibrary 15 | #endif // _WIN32 16 | -------------------------------------------------------------------------------- /third_party/eigen3/unsupported/Eigen/CXX11/ThreadPool: -------------------------------------------------------------------------------- 1 | #include "unsupported/Eigen/CXX11/ThreadPool" 2 | -------------------------------------------------------------------------------- /third_party/eigen3/unsupported/Eigen/SpecialFunctions: -------------------------------------------------------------------------------- 1 | #include "unsupported/Eigen/SpecialFunctions" 2 | -------------------------------------------------------------------------------- /third_party/gemmlowp/gemmlowp.cmake: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | 3 | set(GEMMLOWP_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/gemmlowp") 4 | set(GEMMLOWP_INCLUDE_DIR "${GEMMLOWP_SRCS_DIR}/src/gemmlowp" CACHE PATH "gemmlowp include directory." FORCE) 5 | 6 | include_directories(SYSTEM ${GEMMLOWP_INCLUDE_DIR}) 7 | 8 | set(GEMMLOWP_URL "http://cnbj1.fds.api.xiaomi.com/mace/third-party/gemmlowp/gemmlowp-master-48c0547a046d49b466aa01e3a82a18028f288924.zip") 9 | set(GEMMLOWP_HASH "SHA256=f340384e7728cea605e83597593699dfe8d13ff333b834d24c256935e3dc1758") 10 | 11 | ExternalProject_Add( 12 | gemmlowp 13 | URL_HASH "${GEMMLOWP_HASH}" 14 | URL "${GEMMLOWP_URL}" 15 | PREFIX "${GEMMLOWP_SRCS_DIR}" 16 | BINARY_DIR "" 17 | CONFIGURE_COMMAND "" 18 | BUILD_COMMAND "" 19 | INSTALL_COMMAND "" 20 | TEST_COMMAND "" 21 | ) 22 | -------------------------------------------------------------------------------- /third_party/googletest/googletest.BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["LICENSE"]) 4 | 5 | cc_library( 6 | name = "gtest", 7 | srcs = [ 8 | "googletest/src/gtest-all.cc", 9 | "googlemock/src/gmock-all.cc", 10 | ], 11 | hdrs = glob([ 12 | "**/*.h", 13 | "googletest/src/*.cc", 14 | "googlemock/src/*.cc", 15 | ]), 16 | includes = [ 17 | "googlemock", 18 | "googletest", 19 | "googletest/include", 20 | "googlemock/include", 21 | ], 22 | linkopts = ["-pthread"], 23 | visibility = ["//visibility:public"], 24 | ) 25 | 26 | cc_library( 27 | name = "gtest_main", 28 | srcs = ["googlemock/src/gmock_main.cc"], 29 | linkopts = ["-pthread"], 30 | visibility = ["//visibility:public"], 31 | deps = [":gtest"], 32 | ) 33 | -------------------------------------------------------------------------------- /third_party/half/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2012-2017 Christian Rau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /third_party/half/half.BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["LICENSE.txt"]) 4 | 5 | cc_library( 6 | name = "half", 7 | hdrs = glob([ 8 | "include/half.hpp", 9 | ]), 10 | visibility = ["//visibility:public"], 11 | ) 12 | -------------------------------------------------------------------------------- /third_party/half/half.cmake: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | 3 | set(HALF_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/half") 4 | set(HALF_INCLUDE_DIR "${HALF_SRCS_DIR}/src/half" CACHE PATH "half include directory." FORCE) 5 | 6 | include_directories(SYSTEM ${HALF_INCLUDE_DIR}) 7 | 8 | set(HALF_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/half/half-code-356-trunk.zip") 9 | set(HALF_HASH "SHA256=0f514a1e877932b21dc5edc26a148ddc700b6af2facfed4c030ca72f74d0219e") 10 | 11 | ExternalProject_Add( 12 | half 13 | URL "${HALF_URL}" 14 | URL_HASH "${HALF_HASH}" 15 | PREFIX "${HALF_SRCS_DIR}" 16 | BINARY_DIR "" 17 | CONFIGURE_COMMAND "" 18 | BUILD_COMMAND "" 19 | INSTALL_COMMAND "" 20 | TEST_COMMAND "" 21 | ) 22 | -------------------------------------------------------------------------------- /third_party/mtk_rpcmem/BUILD.bazel: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["license.txt"]) 4 | 5 | load( 6 | "//mace:mace.bzl", 7 | "if_android_arm64", 8 | ) 9 | 10 | cc_library( 11 | name = "mtk_rpcmem", 12 | srcs = [], 13 | hdrs = if_android_arm64([ 14 | "includes/libion/ion.h", 15 | "includes/libion_mtk/ion.h", 16 | "includes/linux/ion_drv.h", 17 | ]), 18 | linkopts = ["-Wl,-unresolved-symbols=ignore-in-shared-libs"], 19 | visibility = ["//visibility:public"], 20 | ) 21 | -------------------------------------------------------------------------------- /third_party/mtk_rpcmem/libs/arm64-v8a/libion.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/mtk_rpcmem/libs/arm64-v8a/libion.so -------------------------------------------------------------------------------- /third_party/mtk_rpcmem/libs/arm64-v8a/libion_mtk.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/mtk_rpcmem/libs/arm64-v8a/libion_mtk.so -------------------------------------------------------------------------------- /third_party/mtk_rpcmem/mtk_rpcmem.cmake: -------------------------------------------------------------------------------- 1 | set(MTK_RPCMEM_INSTALL_DIR "${PROJECT_SOURCE_DIR}/third_party/mtk_rpcmem") 2 | set(MTK_RPCMEM_INCLUDE_DIR "${MTK_RPCMEM_INSTALL_DIR}") 3 | 4 | include_directories(SYSTEM "${MTK_RPCMEM_INCLUDE_DIR}") 5 | -------------------------------------------------------------------------------- /third_party/nnlib/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # These files are generated fron nnlib project 2 | 3 | licenses(["notice"]) 4 | 5 | exports_files(["license.txt"]) 6 | 7 | load( 8 | "//mace:mace.bzl", 9 | "if_android_arm64", 10 | "if_android_armv7", 11 | ) 12 | 13 | cc_library( 14 | name = "libhexagon", 15 | srcs = if_android_armv7([ 16 | "armeabi-v7a/libhexagon_controller.so", 17 | ]) + if_android_arm64([ 18 | "arm64-v8a/libcdsprpc.so", 19 | "arm64-v8a/libhexagon_controller.so", 20 | ]), 21 | hdrs = [ 22 | "hexagon_nn.h", 23 | "hexnn_dsp_controller.h", 24 | "ops.h", 25 | ], 26 | visibility = ["//visibility:public"], 27 | ) 28 | -------------------------------------------------------------------------------- /third_party/nnlib/arm64-v8a/libcdsprpc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/nnlib/arm64-v8a/libcdsprpc.so -------------------------------------------------------------------------------- /third_party/nnlib/arm64-v8a/libhexagon_controller.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/nnlib/arm64-v8a/libhexagon_controller.so -------------------------------------------------------------------------------- /third_party/nnlib/armeabi-v7a/libhexagon_controller.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/nnlib/armeabi-v7a/libhexagon_controller.so -------------------------------------------------------------------------------- /third_party/nnlib/nnlib.cmake: -------------------------------------------------------------------------------- 1 | set(NNLIB_INSTALL_DIR "${PROJECT_SOURCE_DIR}/third_party/nnlib") 2 | set(NNLIB_INCLUDE_DIR "${NNLIB_INSTALL_DIR}") 3 | 4 | include_directories(SYSTEM "${NNLIB_INCLUDE_DIR}") 5 | 6 | set(NNLIB_CONTROLLER "${NNLIB_INSTALL_DIR}/${ANDROID_ABI}/libhexagon_controller.so") 7 | add_library(hexagon_controller SHARED IMPORTED GLOBAL) 8 | set_target_properties(hexagon_controller PROPERTIES IMPORTED_LOCATION ${NNLIB_CONTROLLER}) 9 | 10 | install(FILES ${NNLIB_CONTROLLER} DESTINATION lib) 11 | -------------------------------------------------------------------------------- /third_party/nnlib/v60/libhexagon_nn_skel.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/nnlib/v60/libhexagon_nn_skel.so -------------------------------------------------------------------------------- /third_party/nnlib/v65/libhexagon_nn_skel.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/nnlib/v65/libhexagon_nn_skel.so -------------------------------------------------------------------------------- /third_party/nnlib/v66/libhexagon_nn_skel.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/nnlib/v66/libhexagon_nn_skel.so -------------------------------------------------------------------------------- /third_party/opencl-clhpp/opencl-clhpp.BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["LICENSE.txt"]) 4 | 5 | cc_library( 6 | name = "opencl_clhpp", 7 | hdrs = glob([ 8 | "include/CL/*.hpp", 9 | ]), 10 | includes = ["include"], 11 | visibility = ["//visibility:public"], 12 | ) 13 | -------------------------------------------------------------------------------- /third_party/opencl-headers/opencl-headers.BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | exports_files(["LICENSE"]) 4 | 5 | cc_library( 6 | name = "opencl_headers", 7 | hdrs = glob([ 8 | "CL/*.h", 9 | ]), 10 | includes = ["."], 11 | visibility = ["//visibility:public"], 12 | ) 13 | 14 | -------------------------------------------------------------------------------- /third_party/opencl-headers/opencl-headers.cmake: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | 3 | set(OPENCL_HEADERS_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/opencl-headers") 4 | set(OPENCL_HEADERS_INCLUDE_DIR "${OPENCL_HEADERS_SRCS_DIR}/src/opencl_headers/opencl20" CACHE PATH "opencl-headers include directory." FORCE) 5 | 6 | include_directories(SYSTEM ${OPENCL_HEADERS_INCLUDE_DIR}) 7 | 8 | # Mirror of https://github.com/KhronosGroup/OpenCL-Headers/archive/f039db6764d52388658ef15c30b2237bbda49803.zip 9 | set(OPENCL_HEADERS_URL "https://cnbj1.fds.api.xiaomi.com/mace/third-party/OpenCL-Headers/f039db6764d52388658ef15c30b2237bbda49803.zip") 10 | set(OPENCL_HEADERS_HASH "SHA256=b2b813dd88a7c39eb396afc153070f8f262504a7f956505b2049e223cfc2229b") 11 | 12 | ExternalProject_Add( 13 | opencl_headers 14 | URL_HASH "${OPENCL_HEADERS_HASH}" 15 | URL "${OPENCL_HEADERS_URL}" 16 | PREFIX "${OPENCL_HEADERS_SRCS_DIR}" 17 | BINARY_DIR "" 18 | CONFIGURE_COMMAND "" 19 | BUILD_COMMAND "" 20 | INSTALL_COMMAND "" 21 | TEST_COMMAND "" 22 | ) 23 | -------------------------------------------------------------------------------- /third_party/rpcmem/BUILD.bazel: -------------------------------------------------------------------------------- 1 | # These files are generated fron rpcmem project 2 | package( 3 | default_visibility = ["//visibility:public"], 4 | ) 5 | 6 | licenses(["notice"]) 7 | 8 | exports_files(["license.txt"]) 9 | 10 | load( 11 | "//mace:mace.bzl", 12 | "if_android_arm64", 13 | "if_android_armv7", 14 | ) 15 | 16 | filegroup( 17 | name = "rpcmem.a", 18 | srcs = if_android_armv7([ 19 | "armeabi-v7a/rpcmem.a", 20 | ]) + if_android_arm64([ 21 | "arm64-v8a/rpcmem.a", 22 | ]), 23 | ) 24 | 25 | cc_library( 26 | name = "rpcmem", 27 | srcs = [ 28 | ":rpcmem.a", 29 | ], 30 | hdrs = [ 31 | "rpcmem.h", 32 | ], 33 | visibility = ["//visibility:public"], 34 | ) 35 | -------------------------------------------------------------------------------- /third_party/rpcmem/arm64-v8a/rpcmem.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/rpcmem/arm64-v8a/rpcmem.a -------------------------------------------------------------------------------- /third_party/rpcmem/armeabi-v7a/rpcmem.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/third_party/rpcmem/armeabi-v7a/rpcmem.a -------------------------------------------------------------------------------- /third_party/rpcmem/license.txt: -------------------------------------------------------------------------------- 1 | /*============================================================================== 2 | Copyright (c) 2012-2013 Qualcomm Technologies, Inc. 3 | All rights reserved. Qualcomm Proprietary and Confidential. 4 | rpcmem.h and rpcmem.a are generated from Hexagon SDK and modified by Xiaomi, Inc. 5 | ==============================================================================*/ 6 | -------------------------------------------------------------------------------- /third_party/rpcmem/rpcmem.cmake: -------------------------------------------------------------------------------- 1 | set(RPCMEM_INSTALL_DIR "${PROJECT_SOURCE_DIR}/third_party/rpcmem") 2 | set(RPCMEM_INCLUDE_DIR "${RPCMEM_INSTALL_DIR}") 3 | 4 | include_directories(SYSTEM "${RPCMEM_INCLUDE_DIR}") 5 | 6 | set(RPCMEM_LIB "${RPCMEM_INSTALL_DIR}/${ANDROID_ABI}/rpcmem.a") 7 | add_library(rpcmem STATIC IMPORTED GLOBAL) 8 | set_target_properties(rpcmem PROPERTIES IMPORTED_LOCATION ${RPCMEM_LIB}) 9 | -------------------------------------------------------------------------------- /third_party/six/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2015 Benjamin Peterson 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /third_party/six/six.BUILD: -------------------------------------------------------------------------------- 1 | # Description: 2 | # Six provides simple utilities for wrapping over differences between Python 2 3 | # and Python 3. 4 | 5 | licenses(["notice"]) 6 | 7 | exports_files(["LICENSE"]) 8 | 9 | py_library( 10 | name = "six", 11 | srcs = ["six.py"], 12 | srcs_version = "PY2AND3", 13 | visibility = ["//visibility:public"], 14 | ) 15 | -------------------------------------------------------------------------------- /third_party/tflite/tflite.cmake: -------------------------------------------------------------------------------- 1 | include(ExternalProject) 2 | 3 | set(TFLITE_SRCS_DIR "${MACE_THIRD_PARTY_DIR}/tflite") 4 | set(TFLITE_INCLUDE_DIR "${TFLITE_SRCS_DIR}/src/tflite" CACHE PATH "tflite include directory." FORCE) 5 | 6 | include_directories(SYSTEM ${TFLITE_INCLUDE_DIR}) 7 | 8 | set(TFLITE_URL "http://cnbj1.fds.api.xiaomi.com/mace/third-party/tflite/tensorflow-mace-d73e88fc830320d3818ac24e57cd441820a85cc9.zip") 9 | set(TFLITE_HASH "SHA256=6f2671a02fe635a82c289c8c40a6e5bc24670ff1d4c3c2ab4a7aa9b825256a18") 10 | 11 | ExternalProject_Add( 12 | tflite 13 | URL_HASH "${TFLITE_HASH}" 14 | URL "${TFLITE_URL}" 15 | PREFIX "${TFLITE_SRCS_DIR}" 16 | BINARY_DIR "" 17 | CONFIGURE_COMMAND "" 18 | BUILD_COMMAND "" 19 | INSTALL_COMMAND "" 20 | TEST_COMMAND "" 21 | ) 22 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-ar: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a aarch64-linux-gnu-ar \ 4 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-ar \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-as: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a aarch64-linux-gnu-as \ 4 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-as \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-gcc: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | PATH="external/gcc_linaro_7_3_1_aarch64_linux_gnu/libexec/gcc/aarch64-linux-gnu/7.3.1:$PATH" \ 4 | exec \ 5 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-gcc \ 6 | "$@" 7 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-gcov: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a aarch64-linux-gnu-gcov \ 4 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-gcov \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-ld: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a aarch64-linux-gnu-ld \ 4 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-ld \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-nm: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a aarch64-linux-gnu-nm \ 4 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-nm \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-objcopy: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a aarch64-linux-gnu-objcopy \ 4 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-objcopy \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-objdump: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a aarch64-linux-gnu-objdump \ 4 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-objdump \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/aarch64_compiler/linaro_linux_gcc/aarch64-linux-gnu-strip: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a aarch64-linux-gnu-strip \ 4 | external/gcc_linaro_7_3_1_aarch64_linux_gnu/bin/aarch64-linux-gnu-strip \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ar: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-ar \ 4 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-ar \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-as: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-as \ 4 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-as \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcc: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | PATH="external/gcc_linaro_7_3_1_arm_linux_gnueabihf/libexec/gcc/arm-linux-gnueabihf/7.3.1:$PATH" \ 4 | exec \ 5 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-gcc \ 6 | "$@" 7 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-gcov: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-gcov \ 4 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-gcov \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-ld: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-ld \ 4 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-ld \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-nm: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-nm \ 4 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-nm \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objcopy: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-objcopy \ 4 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-objcopy \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-objdump: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-objdump \ 4 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-objdump \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/arm_compiler/linaro_linux_gcc/arm-linux-gnueabihf-strip: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a arm-linux-gnueabihf-strip \ 4 | external/gcc_linaro_7_3_1_arm_linux_gnueabihf/bin/arm-linux-gnueabihf-strip \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/clear_workspace.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | rm -rf mace/codegen/models 4 | rm -rf mace/codegen/engine 5 | rm -rf mace/codegen/opencl 6 | 7 | for d in build/*; do 8 | if [[ "$1" == "--expunge" || "$d" != "build/cmake-build" ]]; then 9 | echo "remove $d" 10 | rm -rf "$d" 11 | fi 12 | done 13 | -------------------------------------------------------------------------------- /tools/cmake/cmake-build-host.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | set -e 4 | 5 | # build for host 6 | if [[ -z "$BUILD_DIR" ]]; then 7 | BUILD_DIR=build/cmake-build/host 8 | fi 9 | 10 | MACE_ENABLE_CPU=ON 11 | 12 | MACE_ENABLE_CODE_MODE=OFF 13 | if [[ "$RUNMODE" == "code" ]]; then 14 | MACE_ENABLE_CODE_MODE=ON 15 | fi 16 | 17 | DMACE_ENABLE_BFLOAT16=OFF 18 | if [[ "$BFLOAT16" == "ON" ]]; then 19 | DMACE_ENABLE_BFLOAT16=ON 20 | fi 21 | 22 | mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} 23 | cmake -DMACE_ENABLE_NEON=OFF \ 24 | -DMACE_ENABLE_QUANTIZE=OFF \ 25 | -DMACE_ENABLE_OPENCL=OFF \ 26 | -DMACE_ENABLE_BFLOAT16=${DMACE_ENABLE_BFLOAT16} \ 27 | -DMACE_ENABLE_TESTS=ON \ 28 | -DMACE_ENABLE_BENCHMARKS=ON \ 29 | -DMACE_ENABLE_CODE_MODE=${MACE_ENABLE_CODE_MODE} \ 30 | -DCMAKE_INSTALL_PREFIX=install \ 31 | ../../.. 32 | make -j$(nproc) && make install 33 | cd ../../.. 34 | -------------------------------------------------------------------------------- /tools/cmake/cmake-generate-proto-py-host.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ -z "$BUILD_DIR" ]]; then 4 | BUILD_DIR=build/cmake-build/host 5 | fi 6 | 7 | mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR} 8 | cmake ../../.. 9 | make mace_proto_py micro_mem_proto_py -j 10 | cd ../../.. 11 | -------------------------------------------------------------------------------- /tools/dana/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/tools/dana/__init__.py -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-ar: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a hexagon-qualcomm-ar \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-ar \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-as: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a hexagon-qualcomm-as \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-llvm-mc \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-gcc: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-clang \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-gcov: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a hexagon-qualcomm-gcov \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-coverage \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-ld: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a hexagon-qualcomm-ld \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-link \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-nm: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a hexagon-qualcomm-nm \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-nm \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-objcopy: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a hexagon-qualcomm-objcopy \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-elfcopy \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-objdump: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a hexagon-qualcomm-objdump \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-llvm-objdump \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/hexagon_compiler/hexagon_gcc/hexagon-qualcomm-strip: -------------------------------------------------------------------------------- 1 | #!/bin/bash --norc 2 | 3 | exec -a hexagon-qualcomm-strip \ 4 | ${HL_HEXAGON_TOOLS}/bin/hexagon-strip \ 5 | "$@" 6 | -------------------------------------------------------------------------------- /tools/python/CMakeLists.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/tools/python/CMakeLists.txt -------------------------------------------------------------------------------- /tools/python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/tools/python/__init__.py -------------------------------------------------------------------------------- /tools/python/config/model/model-template.yaml: -------------------------------------------------------------------------------- 1 | models: 2 | mobilenet_v2: 3 | platform: tensorflow 4 | model_file_path: https://cnbj1.fds.api.xiaomi.com/mace/miai-models/mobilenet-v2/mobilenet-v2-1.0.pb 5 | model_sha256_checksum: 369f9a5f38f3c15b4311c1c84c032ce868da9f371b5f78c13d3ea3c537389bb4 6 | subgraphs: 7 | - input_tensors: 8 | - input 9 | input_shapes: 10 | - 1,224,224,3 11 | output_tensors: 12 | - MobilenetV2/Predictions/Reshape_1 13 | output_shapes: 14 | - 1,1001 15 | validation_inputs_data: 16 | - https://cnbj1.fds.api.xiaomi.com/mace/inputs/dog.npy 17 | 18 | -------------------------------------------------------------------------------- /tools/python/micro/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/tools/python/micro/__init__.py -------------------------------------------------------------------------------- /tools/python/micro/jinja2_files/CMakeLists.txt.jinja2: -------------------------------------------------------------------------------- 1 | add_library(model_{{model_tag}} 2 | micro_engine_c_interface.cc 3 | micro_engine_config.cc 4 | micro_engine_factory.cc 5 | ) 6 | 7 | target_link_libraries(model_{{model_tag}} 8 | micro_ops 9 | ) 10 | 11 | install(TARGETS model_{{model_tag}} 12 | ARCHIVE DESTINATION lib 13 | ) 14 | 15 | install(DIRECTORY . DESTINATION include 16 | FILES_MATCHING PATTERN "*interface.h" 17 | ) 18 | 19 | -------------------------------------------------------------------------------- /tools/python/micro/jinja2_files/micro_engine_factory.h.jinja2: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | // This is a generated file. DO NOT EDIT! 16 | 17 | #include "micro/include/public/micro.h" 18 | 19 | 20 | namespace micro { 21 | namespace {{model_tag}} { 22 | 23 | MaceStatus GetMicroEngineSingleton(MaceMicroEngine **engine); 24 | 25 | MaceStatus CreateMaceMicroEngineFromBinary(uint8_t *model_data, 26 | int32_t size, 27 | MaceMicroEngine **engine); 28 | 29 | } // namespace {{model_tag}} 30 | } // namespace micro 31 | -------------------------------------------------------------------------------- /tools/python/micro/jinja2_files/micro_graph_data.h.jinja2: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | // This is a generated file. DO NOT EDIT! 16 | 17 | #include 18 | 19 | namespace micro { 20 | namespace {{model_tag}} { 21 | 22 | uint8_t kGraphData[{{ data_size }}] = { 23 | {{ hex_bytes_string }} 24 | }; 25 | 26 | } // namespace {{model_tag}} 27 | } // namespace micro 28 | -------------------------------------------------------------------------------- /tools/python/micro/jinja2_files/micro_model_data.h.jinja2: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | // This is a generated file. DO NOT EDIT! 16 | 17 | #include 18 | 19 | namespace micro { 20 | namespace {{model_tag}} { 21 | 22 | const uint8_t kModelData[{{ data_size }}] = { 23 | {{ hex_bytes_string }} 24 | }; 25 | 26 | } // namespace {{model_tag}} 27 | } // namespace micro 28 | -------------------------------------------------------------------------------- /tools/python/micro/jinja2_files/micro_net_def.h.jinja2: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The MACE 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 | // This is a generated file. DO NOT EDIT! 16 | 17 | #include 18 | 19 | namespace micro { 20 | namespace {{model_tag}} { 21 | 22 | uint8_t kNetDef[{{ data_size }}] = { 23 | {{ hex_bytes_string }} 24 | }; 25 | 26 | } // namespace {{model_tag}} 27 | } // namespace micro 28 | -------------------------------------------------------------------------------- /tools/python/quantize/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/tools/python/quantize/__init__.py -------------------------------------------------------------------------------- /tools/python/quantize/quantize_util_test.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 The MACE 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 | import unittest 16 | import numpy as np 17 | import quantize.quantize_util 18 | 19 | 20 | class TestQuantize(unittest.TestCase): 21 | 22 | def test_quantize_dequantize(self): 23 | test_input = np.random.rand(20, 30) * 5 24 | quantized_data = quantize_util.quantize(test_input) 25 | dequantized_output = quantize_util.dequantize(quantized_data) 26 | np.testing.assert_array_almost_equal(test_input, dequantized_output, 2) 27 | 28 | 29 | if __name__ == '__main__': 30 | unittest.main() 31 | -------------------------------------------------------------------------------- /tools/python/template/file_binary.cc.jinja2: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The MACE 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 | // This is a generated file. DO NOT EDIT! 16 | 17 | #include 18 | 19 | namespace mace { 20 | 21 | const unsigned char *{{ load_func_name }}() { 22 | {% if data_size == 0 %} 23 | return NULL; 24 | {% else %} 25 | static const unsigned char kData[{{ data_size }}] = { 26 | {% for d in data %}{{"0x%02X, " % d }}{%endfor%} 27 | }; 28 | 29 | return kData; 30 | {% endif %} 31 | } 32 | 33 | size_t {{ size_func_name }}() { 34 | return {{ data_size }}; 35 | } 36 | 37 | } // namespace mace 38 | 39 | -------------------------------------------------------------------------------- /tools/python/template/tensor_data.jinja2: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The MACE 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 | // This is a generated file. DO NOT EDIT! 16 | 17 | #include "mace/public/mace.h" 18 | 19 | namespace mace { 20 | namespace {{model_tag}} { 21 | 22 | alignas(4) const unsigned char model_data[{{ model_data_size }}] = { 23 | {% for d in model_data %}{{"0x%02X, " % d }}{%endfor%} 24 | }; 25 | 26 | MACE_API const unsigned char *LoadModelData() { 27 | return model_data; 28 | } 29 | 30 | MACE_API int64_t GetModelSize() { 31 | return {{ model_data_size }}; 32 | } 33 | 34 | } // namespace {{model_tag}} 35 | } // namespace mace 36 | 37 | -------------------------------------------------------------------------------- /tools/python/transform/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/tools/python/transform/__init__.py -------------------------------------------------------------------------------- /tools/python/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/tools/python/utils/__init__.py -------------------------------------------------------------------------------- /tools/python/visualize/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XiaoMi/mace/0fc55a548ef41b37fd15fd8944de5155eb09b3c1/tools/python/visualize/__init__.py --------------------------------------------------------------------------------