提交 5d9b931e 编写于 作者: L lichao18

add cmake for apu

add converter run for apu
上级 ffb4acd0
......@@ -9,6 +9,7 @@ option(MACE_ENABLE_OPENCL "whether to enable OpenCL support" OFF)
option(MACE_ENABLE_CUDA "whether to enable CUDA support" OFF)
option(MACE_ENABLE_HEXAGON_DSP "whether to enable Hexagon DSP support" OFF)
option(MACE_ENABLE_HEXAGON_HTA "whether to enable Hexagon HTA support" OFF)
option(MACE_ENABLE_MTK_APU "whether to enable MTK APU support" OFF)
option(MACE_ENABLE_TESTS "whether to build c++ unit tests" OFF)
option(MACE_ENABLE_BENCHMARKS "whether to build c++ micro benchmarks" OFF)
option(MACE_ENABLE_EXAMPLES "whether to build examples" OFF)
......@@ -89,6 +90,13 @@ if(MACE_ENABLE_HEXAGON_HTA)
add_definitions(-DMACE_ENABLE_HEXAGON_HTA)
endif(MACE_ENABLE_HEXAGON_HTA)
if(MACE_ENABLE_MTK_APU)
if(NOT ANDROID)
message(FATAL_ERROR "MTK APU is only supported on Android")
endif(NOT ANDROID)
add_definitions(-DMACE_ENABLE_MTK_APU)
endif(MACE_ENABLE_MTK_APU)
if(MACE_ENABLE_OBFUSCATE)
add_definitions(-DMACE_OBFUSCATE_LITERALS)
endif(MACE_ENABLE_OBFUSCATE)
......
......@@ -40,6 +40,11 @@ if(MACE_ENABLE_HEXAGON_HTA)
set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} hta_controller hta_hexagon_runtime npu)
endif(MACE_ENABLE_HEXAGON_HTA)
if(MACE_ENABLE_MTK_APU)
set(CORE_SRCS ${CORE_SRCS} runtime/apu/apu_wrapper.cc)
set(EXTRA_LINK_LIBS ${EXTRA_LINK_LIBS} apu-frontend)
endif(MACE_ENABLE_MTK_APU)
add_library(core STATIC ${CORE_SRCS})
target_link_libraries(core PRIVATE
proto
......
......@@ -397,12 +397,13 @@ class ApuConverter(base_converter.ConverterInterface):
_op.input.extend([tensor.name])
def use_uint8_in_out(self):
replace_dict = {}
for input_info in self._model.input_info:
if input_info.data_type == mace_pb2.DT_FLOAT:
for op in self._model.op:
if op.input[0] == input_info.name \
and op.type == MaceOp.Quantize.name:
input_info.name = op.output[0]
replace_dict[op.output[0]] = input_info.name
input_info.scale = op.quantize_info[0].scale
input_info.zero_point = op.quantize_info[0].zero_point
break
......@@ -412,6 +413,13 @@ class ApuConverter(base_converter.ConverterInterface):
for op in self._model.op:
if op.output[0] == output_info.name \
and op.type == MaceOp.Dequantize.name:
output_info.name = op.input[0]
replace_dict[op.input[0]] = output_info.name
break
self._model.op.remove(op)
for op in self._model.op:
for i, op_input in enumerate(op.input):
if op_input in replace_dict.keys():
op.input[i] = replace_dict[op_input]
for i, op_output in enumerate(op.output):
if op_output in replace_dict.keys():
op.output[i] = replace_dict[op_output]
set(APU_INSTALL_DIR "${PROJECT_SOURCE_DIR}/third_party/apu")
set(APU_INCLUDE_DIR "${APU_INSTALL_DIR}")
include_directories(SYSTEM "${APU_INCLUDE_DIR}")
set(APU-FRONTEND
"${APU_INSTALL_DIR}/libapu-frontend.so"
)
add_library(apu-frontend SHARED IMPORTED GLOBAL)
set_target_properties(apu-frontend PROPERTIES IMPORTED_LOCATION ${APU-FRONTEND})
install(FILES ${APU-FRONTEND} DESTINATION lib)
......@@ -58,3 +58,7 @@ endif(MACE_ENABLE_HEXAGON_DSP)
if(MACE_ENABLE_HEXAGON_HTA)
include(${PROJECT_SOURCE_DIR}/third_party/hta/hta.cmake)
endif(MACE_ENABLE_HEXAGON_HTA)
if(MACE_ENABLE_MTK_APU)
include(${PROJECT_SOURCE_DIR}/third_party/apu/apu.cmake)
endif(MACE_ENABLE_MTK_APU)
......@@ -19,6 +19,7 @@ mkdir -p $LIB_DIR/armeabi-v7a/cpu_gpu
rm -rf $LIB_DIR/arm64-v8a
mkdir -p $LIB_DIR/arm64-v8a/cpu_gpu_dsp
mkdir -p $LIB_DIR/arm64-v8a/cpu_gpu
mkdir -p $LIB_DIR/arm64-v8a/cpu_gpu_apu
rm -rf $LIB_DIR/linux-x86-64
mkdir -p $LIB_DIR/linux-x86-64
......@@ -42,6 +43,11 @@ bazel build --config android --config optimization mace/libmace:libmace_dynamic
cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/arm64-v8a/cpu_gpu_dsp/
cp third_party/nnlib/arm64-v8a/*so $LIB_DIR/arm64-v8a/cpu_gpu_dsp/
echo "build shared lib for arm64-v8a + cpu_gpu_apu"
bazel build --config android --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=true --define apu=true --define quantize=true --cpu=arm64-v8a
cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/arm64-v8a/cpu_gpu_apu/
cp third_party/apu/*so $LIB_DIR/arm64-v8a/cpu_gpu_apu/
echo "build shared lib for armeabi-v7a + cpu_gpu"
bazel build --config android --config optimization mace/libmace:libmace_dynamic --define neon=true --define openmp=false --define opencl=true --define quantize=true --cpu=armeabi-v7a
cp bazel-bin/mace/libmace/libmace.so $LIB_DIR/armeabi-v7a/cpu_gpu/
......@@ -75,6 +81,11 @@ bazel build --config android --config optimization mace/libmace:libmace_static -
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/arm64-v8a/cpu_gpu_dsp/
cp third_party/nnlib/arm64-v8a/*so $LIB_DIR/arm64-v8a/cpu_gpu_dsp/
echo "build static lib for arm64-v8a + cpu_gpu_apu"
bazel build --config android --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=false --define opencl=true --define apu=true --define quantize=true --cpu=arm64-v8a
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/arm64-v8a/cpu_gpu_apu/
cp third_party/apu/*so $LIB_DIR/arm64-v8a/cpu_gpu_apu/
echo "build static lib for armeabi-v7a + cpu_gpu"
bazel build --config android --config optimization mace/libmace:libmace_static --config symbol_hidden --define neon=true --define openmp=false --define opencl=true --define quantize=true --cpu=armeabi-v7a
cp bazel-genfiles/mace/libmace/libmace.a $LIB_DIR/armeabi-v7a/cpu_gpu/
......
......@@ -15,6 +15,7 @@ cmake -DANDROID_ABI="arm64-v8a" \
-DMACE_ENABLE_OPENCL=OFF \
-DMACE_ENABLE_HEXAGON_DSP=OFF \
-DMACE_ENABLE_HEXAGON_HTA=OFF \
-DMACE_ENABLE_MTK_APU=OFF \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
......
......@@ -15,6 +15,7 @@ cmake -DANDROID_ABI="arm64-v8a" \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_HEXAGON_DSP=ON \
-DMACE_ENABLE_HEXAGON_HTA=ON \
-DMACE_ENABLE_MTK_APU=ON \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
......
......@@ -16,6 +16,7 @@ cmake -DANDROID_ABI="armeabi-v7a" \
-DMACE_ENABLE_OPENCL=OFF \
-DMACE_ENABLE_HEXAGON_DSP=OFF \
-DMACE_ENABLE_HEXAGON_HTA=OFF \
-DMACE_ENABLE_MTK_APU=OFF \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
......
......@@ -16,6 +16,7 @@ cmake -DANDROID_ABI="armeabi-v7a" \
-DMACE_ENABLE_OPENCL=ON \
-DMACE_ENABLE_HEXAGON_DSP=ON \
-DMACE_ENABLE_HEXAGON_HTA=ON \
-DMACE_ENABLE_MTK_APU=OFF \
-DMACE_ENABLE_OPT_SIZE=ON \
-DMACE_ENABLE_OBFUSCATE=ON \
-DCMAKE_INSTALL_PREFIX=install \
......
......@@ -189,6 +189,19 @@ def get_hta_mode(configs):
return False
def get_apu_mode(configs):
runtime_list = []
for model_name in configs[YAMLKeyword.models]:
model_runtime = \
configs[YAMLKeyword.models][model_name].get(
YAMLKeyword.runtime, "")
runtime_list.append(model_runtime.lower())
if RuntimeType.apu in runtime_list:
return True
return False
def get_opencl_mode(configs):
runtime_list = []
for model_name in configs[YAMLKeyword.models]:
......@@ -575,6 +588,7 @@ def format_model_config(flags):
DeviceType.GPU: ValidationThreshold.gpu_threshold,
DeviceType.HEXAGON: ValidationThreshold.quantize_threshold,
DeviceType.HTA: ValidationThreshold.quantize_threshold,
DeviceType.APU: ValidationThreshold.quantize_threshold,
DeviceType.QUANTIZE: ValidationThreshold.quantize_threshold,
}
for k, v in six.iteritems(validation_threshold):
......@@ -816,6 +830,7 @@ def build_model_lib(configs, address_sanitizer, debug_mode):
toolchain=toolchain,
enable_hexagon=get_hexagon_mode(configs),
enable_hta=get_hta_mode(configs),
enable_apu=get_apu_mode(configs),
enable_opencl=get_opencl_mode(configs),
enable_quantize=get_quantize_mode(configs),
address_sanitizer=address_sanitizer,
......@@ -884,6 +899,7 @@ def build_mace_run(configs, target_abi, toolchain, enable_openmp,
toolchain=toolchain,
enable_hexagon=get_hexagon_mode(configs),
enable_hta=get_hta_mode(configs),
enable_apu=get_apu_mode(configs),
enable_openmp=enable_openmp,
enable_opencl=get_opencl_mode(configs),
enable_quantize=get_quantize_mode(configs),
......@@ -931,6 +947,7 @@ def build_example(configs, target_abi, toolchain, enable_openmp, mace_lib_type,
enable_quantize=get_quantize_mode(configs),
enable_hexagon=get_hexagon_mode(configs),
enable_hta=get_hta_mode(configs),
enable_apu=get_apu_mode(configs),
address_sanitizer=flags.address_sanitizer,
symbol_hidden=get_symbol_hidden_mode(debug_mode, mace_lib_type), # noqa
debug_mode=debug_mode)
......@@ -964,6 +981,7 @@ def build_example(configs, target_abi, toolchain, enable_openmp, mace_lib_type,
enable_quantize=get_quantize_mode(configs),
enable_hexagon=get_hexagon_mode(configs),
enable_hta=get_hta_mode(configs),
enable_apu=get_apu_mode(configs),
address_sanitizer=flags.address_sanitizer,
debug_mode=debug_mode,
extra_args=build_arg)
......@@ -1072,6 +1090,7 @@ def build_benchmark_model(configs,
enable_quantize=get_quantize_mode(configs),
enable_hexagon=get_hexagon_mode(configs),
enable_hta=get_hta_mode(configs),
enable_apu=get_apu_mode(configs),
symbol_hidden=get_symbol_hidden_mode(debug_mode, mace_lib_type), # noqa
debug_mode=debug_mode,
extra_args=build_arg)
......
......@@ -280,6 +280,10 @@ class DeviceWrapper:
"third_party/nnlib/%s/libhexagon_controller.so" % abi,
self.data_dir)
if device_type == common.DeviceType.APU:
self.push("third_party/apu/libapu-frontend.so",
self.data_dir)
mace_model_phone_path = ""
if model_graph_format == ModelFormat.file:
mace_model_phone_path = "%s/%s.pb" % (self.data_dir,
......
......@@ -264,6 +264,7 @@ def bazel_build(target,
toolchain='android',
enable_hexagon=False,
enable_hta=False,
enable_apu=False,
enable_openmp=False,
enable_neon=True,
enable_opencl=True,
......@@ -303,8 +304,9 @@ def bazel_build(target,
"--define",
"hexagon=%s" % str(enable_hexagon).lower(),
"--define",
"hta=%s" % str(enable_hta).lower())
"hta=%s" % str(enable_hta).lower(),
"--define",
"apu=%s" % str(enable_apu).lower())
if address_sanitizer:
bazel_args += ("--config", "asan")
if debug_mode:
......@@ -322,6 +324,7 @@ def bazel_build(target,
sh.bazel(
_fg=True,
*bazel_args)
six.print_(bazel_args)
six.print_("Build done!\n")
......@@ -881,6 +884,7 @@ def build_run_throughput_test(abi,
cpu_model_tag,
gpu_model_tag,
dsp_model_tag,
apu_model_tag,
phone_data_dir,
strip="always",
input_file_name="model_input"):
......@@ -896,7 +900,9 @@ def build_run_throughput_test(abi,
if dsp_model_tag:
model_tag_build_flag += "--copt=-DMACE_DSP_MODEL_TAG=%s " % \
dsp_model_tag
if apu_model_tag:
model_tag_build_flag += "--copt=-DMACE_APU_MODEL_TAG=%s " % \
apu_model_tag
sh.cp("-f", merged_lib_file, "mace/benchmark/libmace_merged.a")
sh.bazel(
"build",
......@@ -948,7 +954,10 @@ def build_run_throughput_test(abi,
adb_push("third_party/nnlib/%s/libhexagon_controller.so" % abi,
phone_data_dir,
serialno)
if apu_model_tag:
adb_push("third_party/apu/libapu-frontend.so",
phone_data_dir,
serialno)
sh.adb(
"-s",
serialno,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册