MCPcopy Create free account
hub / github.com/MegEngine/MegCC / build_megcc_lib

Function build_megcc_lib

benchmark/python/common.py:20–83  ·  view source on GitHub ↗
(arch_desc="x86",
                    model_config_json="",
                    kernel_build_dir="",
                    dtype="fp32")

Source from the content-addressed store, hash-verified

18
19
20def build_megcc_lib(arch_desc="x86",
21 model_config_json="",
22 kernel_build_dir="",
23 dtype="fp32"):
24 MEGCC_MGB_TO_TINYNN_PATH = os.environ.get("MEGCC_MGB_TO_TINYNN_PATH")
25 # build prepare
26 change_dir = ""
27 dtype_ = ""
28 if (dtype == "fp16"):
29 dtype_ = "_fp16"
30 if model_config_json == "":
31 arch_ = arch_desc
32 if arch_desc == "arm64" or arch_desc == "armv7":
33 arch_ = "arm"
34 model_config_json = "{}/benchmark/model/model_{}{}.json".format(
35 megcc_path, arch_, dtype_)
36 change_dir = "cd {}/benchmark/model".format(megcc_path)
37 else:
38 change_dir = "cd {}".format(
39 Path(model_config_json).parent().absolute())
40 if kernel_build_dir == "":
41 # WARNING: the dir path should be the same with path set in model_config_json file
42 kernel_build_dir = "{}/benchmark/model/benchmark_kernel_{}{}".format(
43 megcc_path, arch_desc, dtype_)
44 if not os.path.exists(kernel_build_dir) or os.path.isfile(
45 kernel_build_dir):
46 os.makedirs(kernel_build_dir)
47 # set runtime build options
48 if arch_desc == "x86":
49 arch = "--baremetal"
50 runtime_flag = ""
51 elif arch_desc == "arm64":
52 arch = "--arm64"
53 runtime_flag = "--cross_build --cross_build_target_arch aarch64 --cross_build_target_os ANDROID"
54 elif arch_desc == "armv7":
55 arch = "--armv7"
56 runtime_flag = "--cross_build --cross_build_target_arch armv7-a --cross_build_target_os ANDROID "
57 elif arch_desc == "riscv":
58 arch = "--baremetal"
59 runtime_flag = "--cross_build --cross_build_target_arch rv64gcv0p7 --cross_build_target_os LINUX"
60 if dtype == "fp16":
61 runtime_flag = runtime_flag + " --enable_fp16"
62 # convert model
63 if len(change_dir) != 0:
64 cmd = "{} && {}/mgb-to-tinynn -json={} {} --dump {}".format(
65 change_dir,
66 MEGCC_MGB_TO_TINYNN_PATH,
67 model_config_json,
68 arch,
69 kernel_build_dir,
70 )
71 else:
72 cmd = "{} && {}/mgb-to-tinynn -json={} {} --dump {}".format(
73 change_dir,
74 MEGCC_MGB_TO_TINYNN_PATH,
75 model_config_json,
76 arch,
77 kernel_build_dir,

Callers 1

Calls 1

getMethod · 0.45

Tested by

no test coverage detected