def bazel_build(target, abi, executor, device_types): print("* Build %s for %s with ABI %s" % (target, base_pb2.ExecutorType.Name(executor), abi)) if abi == "host": bazel_args = ( "build", target, ) else: bazel_args = ( "build", target, "--config", ABI_TOOLCHAIN_CONFIG[abi], "--cpu=%s" % abi, "--action_env=ANDROID_NDK_HOME=%s" % os.environ["ANDROID_NDK_HOME"], ) bazel_args += ("--define", "%s=true" % base_pb2.ExecutorType.Name(executor).lower()) if executor == base_pb2.MACE: bazel_args += ("--define", "neon=true") bazel_args += ("--define", "openmp=true") bazel_args += ("--define", "opencl=true") bazel_args += ("--define", "quantize=true") if base_pb2.DSP in device_types: bazel_args += ("--define", "hexagon=true") sh.bazel(_fg=True, *bazel_args) print("Build done!\n")
def bazel_build(target, abi="armeabi-v7a", hexagon_mode=False, enable_openmp=True, enable_neon=True, enable_opencl=True, address_sanitizer=False, symbol_hidden=True, extra_args=""): print("* Build %s with ABI %s" % (target, abi)) if abi == "host": bazel_args = ( "build", "--define", "openmp=%s" % str(enable_openmp).lower(), target, ) else: bazel_args = ("build", target, "--config", "android", "--cpu=%s" % abi, "--define", "neon=%s" % str(enable_neon).lower(), "--define", "openmp=%s" % str(enable_openmp).lower(), "--define", "opencl=%s" % str(enable_opencl).lower(), "--define", "hexagon=%s" % str(hexagon_mode).lower()) if address_sanitizer: bazel_args += ("--config", "asan") else: bazel_args += ("--config", "optimization") if symbol_hidden: bazel_args += ("--config", "symbol_hidden") if extra_args: bazel_args += (extra_args, ) print bazel_args sh.bazel(_fg=True, *bazel_args) print("Build done!\n")
def bazel_build(serialno, target, abi, frameworks, runtimes): print("* Build %s with ABI %s" % (target, abi)) if abi == "host": bazel_args = ( "build", target, ) else: bazel_args = ( "build", target, "--config", "android", "--cpu=%s" % abi, "--action_env=ANDROID_NDK_HOME=%s" % os.environ["ANDROID_NDK_HOME"], ) for framework in frameworks: bazel_args += ("--define", "%s=true" % framework.lower()) if "DSP" in runtimes and abi == "armeabi-v7a": with device_lock(serialno): output = sh.adb("-s", serialno, "shell", "ls /system/lib/libcdsprpc.so") if "No such file or directory" in output: print("/system/lib/libcdsprpc.so does not exists! Skip DSP.") else: bazel_args += ("--define", "dsp=true") sh.bazel(_fg=True, *bazel_args) print("Build done!\n")
def bazel_build(target, abi="armeabi-v7a", hexagon_mode=False, enable_openmp=True, enable_neon=True, address_sanitizer=False): print("* Build %s with ABI %s" % (target, abi)) if abi == "host": bazel_args = ( "build", "--define", "openmp=%s" % str(enable_openmp).lower(), target, ) else: bazel_args = ( "build", target, "--config", "android", "--cpu=%s" % abi, "--define", "neon=%s" % str(enable_neon).lower(), "--define", "openmp=%s" % str(enable_openmp).lower(), "--define", "hexagon=%s" % str(hexagon_mode).lower()) if address_sanitizer: bazel_args += ("--config", "asan") else: bazel_args += ("--config", "optimization") sh.bazel( _fg=True, *bazel_args) print("Build done!\n")
def bazel_build(target, abi="armeabi-v7a", toolchain='android', enable_hexagon=False, enable_hta=False, enable_apu=False, apu_ancient=False, enable_neon=True, enable_opencl=True, enable_quantize=True, enable_bfloat16=False, enable_fp16=False, enable_rpcmem=True, address_sanitizer=False, symbol_hidden=True, debug_mode=False, extra_args=""): six.print_("* Build %s with ABI %s" % (target, abi)) if abi == "host": toolchain = platform.system().lower() bazel_args = ( "build", "--config", toolchain, "--define", "quantize=%s" % str(enable_quantize).lower(), "--define", "bfloat16=%s" % str(enable_bfloat16).lower(), target, ) else: bazel_args = ("build", target, "--config", toolchain, "--cpu=%s" % abi_to_internal(abi), "--define", "neon=%s" % str(enable_neon).lower(), "--define", "opencl=%s" % str(enable_opencl).lower(), "--define", "quantize=%s" % str(enable_quantize).lower(), "--define", "bfloat16=%s" % str(enable_bfloat16).lower(), "--define", "fp16=%s" % str(enable_fp16).lower(), "--define", "rpcmem=%s" % str(enable_rpcmem).lower(), "--define", "hexagon=%s" % str(enable_hexagon).lower(), "--define", "hta=%s" % str(enable_hta).lower(), "--define", "apu=%s" % str(enable_apu).lower(), "--define", "apu_ancient=%s" % str(apu_ancient).lower()) if address_sanitizer: bazel_args += ("--config", "asan") if debug_mode: bazel_args += ("--config", "debug") if not address_sanitizer and not debug_mode: if toolchain == "darwin" or toolchain == "ios": bazel_args += ("--config", "optimization_darwin") else: bazel_args += ("--config", "optimization") if symbol_hidden: bazel_args += ("--config", "symbol_hidden") if extra_args: bazel_args += (extra_args, ) six.print_(bazel_args) sh.bazel(_fg=True, *bazel_args) six.print_(bazel_args) six.print_("Build done!\n")
def bazel_build_common(target, build_args=""): stdout_buff = [] process_output = make_output_processor(stdout_buff) sh.bazel("build", target + build_args, _tty_in=True, _out=process_output, _err_to_out=True) return "".join(stdout_buff)
def bazel_build_common(target, build_args=""): stdout_buff = [] process_output = make_output_processor(stdout_buff) sh.bazel( "build", target + build_args, _tty_in=True, _out=process_output, _err_to_out=True) return "".join(stdout_buff)
def bazel_build(target, abi="armeabi-v7a", toolchain='android', hexagon_mode=False, enable_openmp=True, enable_neon=True, enable_opencl=True, enable_quantize=True, address_sanitizer=False, symbol_hidden=True, extra_args=""): six.print_("* Build %s with ABI %s" % (target, abi)) if abi == "host": bazel_args = ( "build", "--config", platform.system().lower(), "--define", "openmp=%s" % str(enable_openmp).lower(), "--define", "quantize=%s" % str(enable_quantize).lower(), target, ) else: bazel_args = ( "build", target, "--config", toolchain, "--cpu=%s" % abi_to_internal(abi), "--define", "neon=%s" % str(enable_neon).lower(), "--define", "openmp=%s" % str(enable_openmp).lower(), "--define", "opencl=%s" % str(enable_opencl).lower(), "--define", "quantize=%s" % str(enable_quantize).lower(), "--define", "hexagon=%s" % str(hexagon_mode).lower()) if address_sanitizer: bazel_args += ("--config", "asan") else: bazel_args += ("--config", "optimization") if symbol_hidden: bazel_args += ("--config", "symbol_hidden") if extra_args: bazel_args += (extra_args,) six.print_(bazel_args) sh.bazel( _fg=True, *bazel_args) six.print_("Build done!\n")
def bazel_build(serialno, target, abi, executor, device_types): print("* Build %s for %s with ABI %s" % (target, base_pb2.ExecutorType.Name(executor), abi)) if abi == "host": bazel_args = ( "build", target, ) else: bazel_args = ( "build", target, "--config", "android", "--cpu=%s" % abi, "--action_env=ANDROID_NDK_HOME=%s" % os.environ["ANDROID_NDK_HOME"], ) bazel_args += ("--define", "%s=true" % base_pb2.ExecutorType.Name(executor).lower()) if executor == base_pb2.MACE: bazel_args += ("--define", "neon=true") bazel_args += ("--define", "openmp=true") bazel_args += ("--define", "opencl=true") bazel_args += ("--define", "quantize=true") avail_device_types = copy.copy(device_types) if base_pb2.DSP in avail_device_types: avail_device_types.remove(base_pb2.DSP) if abi == "armeabi-v7a": with device_lock(serialno): try: output = sh.adb( "-s", serialno, "shell", "ls /system/vendor/lib/rfsa/adsp/libhexagon_nn_skel.so" ) # noqa except sh.ErrorReturnCode_1: print( "/system/vendor/lib/rfsa/adsp/libhexagon_nn_skel.so does not exists! Skip DSP." ) # noqa else: if "No such file or directory" in output: print( "/system/vendor/lib/rfsa/adsp/libhexagon_nn_skel.so does not exists! Skip DSP." ) # noqa else: avail_device_types.append(base_pb2.DSP) bazel_args += ("--define", "hexagon=true") sh.bazel(_fg=True, *bazel_args) print("Build done!\n") return avail_device_types
def bazel_build(serialno, target, abi, executors, device_types): print("* Build %s with ABI %s" % (target, abi)) if abi == "host": bazel_args = ( "build", target, ) else: bazel_args = ( "build", target, "--config", "android", "--cpu=%s" % abi, "--action_env=ANDROID_NDK_HOME=%s" % os.environ["ANDROID_NDK_HOME"], ) for executor in executors: bazel_args += ("--define", "%s=true" % base_pb2.ExecutorType.Name(executor).lower()) bazel_args += ("--define", "neon=true") bazel_args += ("--define", "openmp=true") bazel_args += ("--define", "opencl=true") bazel_args += ("--define", "quantize=true") if base_pb2.DSP in device_types and abi == "armeabi-v7a": with device_lock(serialno): try: output = sh.adb("-s", serialno, "shell", "ls /system/lib/libcdsprpc.so") except sh.ErrorReturnCode_1: print("/system/lib/libcdsprpc.so does not exists! Skip DSP.") else: if "No such file or directory" in output: print("/system/lib/libcdsprpc.so does not exists! Skip DSP.") # noqa else: bazel_args += ("--define", "dsp=true") bazel_args += ("--define", "hexagon=true") sh.bazel( _fg=True, *bazel_args) print("Build done!\n")
def bazel_build(target, abi="armeabi-v7a", frameworks=None): print("* Build %s with ABI %s" % (target, abi)) if abi == "host": bazel_args = ( "build", target, ) else: bazel_args = ( "build", target, "--config", "android", "--cpu=%s" % abi, "--action_env=ANDROID_NDK_HOME=%s" % os.environ["ANDROID_NDK_HOME"], ) for framework in frameworks: bazel_args += ("--define", "%s=true" % framework.lower()) sh.bazel(_fg=True, *bazel_args) print("Build done!\n")
def build_run_throughput_test(abi, serialno, vlog_level, run_seconds, merged_lib_file, model_input_dir, embed_model_data, input_nodes, output_nodes, input_shapes, output_shapes, cpu_model_tag, gpu_model_tag, dsp_model_tag, phone_data_dir, strip="always", input_file_name="model_input"): print("* Build and run throughput_test") model_tag_build_flag = "" if cpu_model_tag: model_tag_build_flag += "--copt=-DMACE_CPU_MODEL_TAG=%s " % \ cpu_model_tag if gpu_model_tag: model_tag_build_flag += "--copt=-DMACE_GPU_MODEL_TAG=%s " % \ gpu_model_tag if dsp_model_tag: model_tag_build_flag += "--copt=-DMACE_DSP_MODEL_TAG=%s " % \ dsp_model_tag sh.cp("-f", merged_lib_file, "mace/benchmark/libmace_merged.a") sh.bazel( "build", "-c", "opt", "--strip", strip, "--verbose_failures", "//mace/benchmark:model_throughput_test", "--crosstool_top=//external:android/crosstool", "--host_crosstool_top=@bazel_tools//tools/cpp:toolchain", "--cpu=%s" % abi, "--copt=-std=c++11", "--copt=-D_GLIBCXX_USE_C99_MATH_TR1", "--copt=-Werror=return-type", "--copt=-O3", "--define", "neon=true", "--define", "openmp=true", model_tag_build_flag, _fg=True) sh.rm("mace/benchmark/libmace_merged.a") sh.adb("-s", serialno, "shell", "mkdir", "-p", phone_data_dir) adb_push("%s/%s_%s" % (model_input_dir, input_file_name, ",".join(input_nodes)), phone_data_dir, serialno) adb_push("bazel-bin/mace/benchmark/model_throughput_test", phone_data_dir, serialno) if not embed_model_data: adb_push("codegen/models/%s/%s.data" % cpu_model_tag, phone_data_dir, serialno) adb_push("codegen/models/%s/%s.data" % gpu_model_tag, phone_data_dir, serialno) adb_push("codegen/models/%s/%s.data" % dsp_model_tag, phone_data_dir, serialno) adb_push("third_party/nnlib/libhexagon_controller.so", phone_data_dir, serialno) sh.adb( "-s", serialno, "shell", "LD_LIBRARY_PATH=%s" % phone_data_dir, "MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level, "MACE_RUN_PARAMETER_PATH=%s/mace_run.config" % phone_data_dir, "%s/model_throughput_test" % phone_data_dir, "--input_node=%s" % ",".join(input_nodes), "--output_node=%s" % ",".join(output_nodes), "--input_shape=%s" % ":".join(input_shapes), "--output_shape=%s" % ":".join(output_shapes), "--input_file=%s/%s" % (phone_data_dir, input_file_name), "--cpu_model_data_file=%s/%s.data" % (phone_data_dir, cpu_model_tag), "--gpu_model_data_file=%s/%s.data" % (phone_data_dir, gpu_model_tag), "--dsp_model_data_file=%s/%s.data" % (phone_data_dir, dsp_model_tag), "--run_seconds=%s" % run_seconds, _fg=True) print("throughput_test done!\n")
def build_run_throughput_test(abi, serialno, vlog_level, run_seconds, merged_lib_file, model_input_dir, embed_model_data, input_nodes, output_nodes, input_shapes, output_shapes, cpu_model_tag, gpu_model_tag, dsp_model_tag, phone_data_dir, strip="always", input_file_name="model_input"): print("* Build and run throughput_test") model_tag_build_flag = "" if cpu_model_tag: model_tag_build_flag += "--copt=-DMACE_CPU_MODEL_TAG=%s " % \ cpu_model_tag if gpu_model_tag: model_tag_build_flag += "--copt=-DMACE_GPU_MODEL_TAG=%s " % \ gpu_model_tag if dsp_model_tag: model_tag_build_flag += "--copt=-DMACE_DSP_MODEL_TAG=%s " % \ dsp_model_tag sh.cp("-f", merged_lib_file, "mace/benchmark/libmace_merged.a") sh.bazel( "build", "-c", "opt", "--strip", strip, "--verbose_failures", "//mace/benchmark:model_throughput_test", "--crosstool_top=//external:android/crosstool", "--host_crosstool_top=@bazel_tools//tools/cpp:toolchain", "--cpu=%s" % abi, "--copt=-std=c++11", "--copt=-D_GLIBCXX_USE_C99_MATH_TR1", "--copt=-Werror=return-type", "--copt=-O3", "--define", "neon=true", "--define", "openmp=true", model_tag_build_flag, _fg=True) sh.rm("mace/benchmark/libmace_merged.a") sh.adb("-s", serialno, "shell", "mkdir", "-p", phone_data_dir) adb_push("%s/%s_%s" % (model_input_dir, input_file_name, ",".join(input_nodes)), phone_data_dir, serialno) adb_push("bazel-bin/mace/benchmark/model_throughput_test", phone_data_dir, serialno) if not embed_model_data: adb_push("codegen/models/%s/%s.data" % cpu_model_tag, phone_data_dir, serialno) adb_push("codegen/models/%s/%s.data" % gpu_model_tag, phone_data_dir, serialno) adb_push("codegen/models/%s/%s.data" % dsp_model_tag, phone_data_dir, serialno) adb_push("third_party/nnlib/libhexagon_controller.so", phone_data_dir, serialno) sh.adb( "-s", serialno, "shell", "LD_LIBRARY_PATH=%s" % phone_data_dir, "MACE_CPP_MIN_VLOG_LEVEL=%s" % vlog_level, "MACE_RUN_PARAMETER_PATH=%s/mace_run.config" % phone_data_dir, "%s/model_throughput_test" % phone_data_dir, "--input_node=%s" % ",".join(input_nodes), "--output_node=%s" % ",".join(output_nodes), "--input_shape=%s" % ":".join(input_shapes), "--output_shape=%s" % ":".join(output_shapes), "--input_file=%s/%s" % (phone_data_dir, input_file_name), "--cpu_model_data_file=%s/%s.data" % (phone_data_dir, cpu_model_tag), "--gpu_model_data_file=%s/%s.data" % (phone_data_dir, gpu_model_tag), "--dsp_model_data_file=%s/%s.data" % (phone_data_dir, dsp_model_tag), "--run_seconds=%s" % run_seconds, _fg=True) print("throughput_test done!\n")