type: commit

message: update build

reason: unsigned

login: liuziyue

type: User

user_view_type: public

status: modified

patch:
@@ -27,11 +27,11 @@ def build_onnxruntime(onnxruntime_dir, config, build_args, build_name, args):

         copy(os.path.join(onnxruntime_dir, "build/Windows", config, config, "onnxruntime_perf_test.exe"), target_dir)
         copy(os.path.join(onnxruntime_dir, "build/Windows", config, config, "onnxruntime.dll"), target_dir)
-        if "mkldnn" in build_name:
+        if "--use_mkldnn" in build_args:
             copy(os.path.join(onnxruntime_dir, "build/Windows", config, config, "mkldnn.dll"), target_dir)
-        if "cuda" in build_name or "tensorrt" == build_name:
+        if args.use_cuda or args.use_tensorrt:
             copy(os.path.join(args.cudnn_home, "bin/cudnn*.dll"), target_dir)
-        if "tensorrt" in build_name:
+        if args.use_tensorrt:
             copy(os.path.join(args.tensorrt_home, "lib/nvinfer.dll"), target_dir)
     else:
         build_env = os.environ.copy()
@@ -47,19 +47,19 @@ def build_onnxruntime(onnxruntime_dir, config, build_args, build_name, args):
         copy(os.path.join(onnxruntime_dir, "build/Linux", config, "onnxruntime_perf_test"), target_dir)
         copy(os.path.join(onnxruntime_dir, "build/Linux", config, "libonnxruntime.so*"), target_dir)
         copy(os.path.join(onnxruntime_dir, "build/Linux", config, "mklml/src/project_mklml/lib/*.so*"), target_dir)
-        if "mkldnn" in build_name:
+        if "--use_mkldnn" in build_args:
             copy(os.path.join(onnxruntime_dir, "build/Linux", config, "mkl-dnn/install/lib/libmkldnn.so*"), target_dir)
-        if "cuda" in build_name or "tensorrt" == build_name:
+        if args.use_cuda or args.use_tensorrt:
             if is_windows():
                 copy(os.path.join(args.cudnn_home, "bin/cudnn*.dll"), target_dir)
             else:
                 copy(os.path.join(args.cudnn_home, "lib64/libcudnn.so*"), target_dir)
-        if "tensorrt" in build_name:
+        if args.use_tensorrt:
             if is_windows():
                 copy(os.path.join(args.tensorrt_home, "lib/nvinfer.dll"), target_dir)
             else:
                 copy(os.path.join(args.tensorrt_home, "lib/libnvinfer.so*"), target_dir)
-        if "ngraph" in build_name:
+        if args.use_ngraph:
             if is_windows():
                 pass
             else:
@@ -94,29 +94,32 @@ def parse_arguments():
 if __name__ == "__main__":
     args = parse_arguments()

-    build_onnxruntime(args.onnxruntime_home, args.config, ["--parallel"], "cpu", args)
+    build_args = ["--parallel", "--use_mkldnn", "--use_openmp"]
+    # build_onnxruntime(args.onnxruntime_home, args.config, ["--parallel"], "cpu", args)

-    build_onnxruntime(args.onnxruntime_home, args.config, ["--use_openmp", "--parallel"], "cpu_openmp", args)
+    # build_onnxruntime(args.onnxruntime_home, args.config, ["--use_openmp", "--parallel"], "cpu_openmp", args)

-    build_onnxruntime(args.onnxruntime_home, args.config, ["--use_mkldnn", "--parallel"], "mkldnn", args)
+    # build_onnxruntime(args.onnxruntime_home, args.config, ["--use_mkldnn", "--parallel"], "mkldnn", args)

-    build_onnxruntime(args.onnxruntime_home, args.config, ["--use_mkldnn", "--use_openmp", "--parallel"], "mkldnn_openmp", args)
+    # build_onnxruntime(args.onnxruntime_home, args.config, ["--use_mkldnn", "--use_openmp", "--parallel"], "mkldnn_openmp", args)

     if args.use_mklml:
-        build_onnxruntime(args.onnxruntime_home, args.config, ["--use_mkldnn", "--use_mklml", "--parallel"], "mkldnn_mklml", args)
+        build_onnxruntime(args.onnxruntime_home, args.config, ["--use_mklml", "--parallel"], "mklml", args)
+        # build_args += ["--use_mklml"]

     if args.use_cuda:
-        build_args = ["--use_cuda", "--parallel"]
+        # build_args = ["--use_cuda", "--parallel"]
+        build_args += ["--use_cuda"]
         if args.cuda_version:
             build_args = build_args + ["--cuda_version", args.cuda_version]
         if args.cuda_home:
             build_args = build_args + ["--cuda_home", args.cuda_home]
         if args.cudnn_home:
             build_args = build_args + ["--cudnn_home", args.cudnn_home]
-        build_onnxruntime(args.onnxruntime_home, args.config, build_args, "cuda", args)
+        # build_onnxruntime(args.onnxruntime_home, args.config, build_args, "cuda", args)

     if args.use_tensorrt:
-        build_args = ["--use_tensorrt", "--use_full_protobuf"]
+        build_args += ["--use_tensorrt", "--use_full_protobuf"]
         if args.tensorrt_home:
             build_args = build_args + ["--tensorrt_home", args.tensorrt_home]
         if args.cuda_version:
@@ -125,8 +128,10 @@ def parse_arguments():
             build_args = build_args + ["--cuda_home", args.cuda_home]
         if args.cudnn_home:
             build_args = build_args + ["--cudnn_home", args.cudnn_home]
-        build_onnxruntime(args.onnxruntime_home, args.config, build_args, "tensorrt", args)
+        # build_onnxruntime(args.onnxruntime_home, args.config, build_args, "tensorrt", args)

     if args.use_ngraph:
-        build_args = ["--use_ngraph"]
-        build_onnxruntime(args.onnxruntime_home, args.config, build_args, "ngraph", args)
+        build_args += ["--use_ngraph"]
+        # build_onnxruntime(args.onnxruntime_home, args.config, build_args, "ngraph", args)
+
+    build_onnxruntime(args.onnxruntime_home, args.config, build_args, "all_eps", args)

patch:
@@ -363,7 +363,7 @@ def parse_arguments():
     bin_dir = os.path.join(os.path.dirname(__file__), "bin", args.config)
     build_dirs = os.listdir(bin_dir)

-    providers = [p for p in args.execution_provider.split(",") if p != ""] if len(args.execution_provider) > 0 else build_dirs
+    providers = [p for p in args.execution_provider.split(",") if p != ""] if len(args.execution_provider) > 0 else ["mklml", "cpu_openmp", "mkldnn", "mkldnn_openmp", "cpu", "tensorrt", "ngraph", "cuda"]

     if len(GPUtil.getGPUs()) == 0:
         print("No GPU found on current device. Cuda and TensorRT performance tuning might not be available. ")
@@ -377,86 +377,89 @@ def parse_arguments():
     successful = []
     failed = []
     # Loop for every pre-built execution provider
-    for build_name in build_dirs:
-        build_path = os.path.join(bin_dir, build_name)
+    for build_name in providers:
+        if "mklml" in build_name:
+            build_path = os.path.join(bin_dir, build_name)
+        else:
+            build_path = os.path.join(bin_dir, "all_eps")
         if os.path.isdir(build_path):
-            # If current build is requested by user, run perf tuning
-            if build_name in providers:
-                test_args = []
-
-                if "mkldnn" in build_name:
-                    test_args = test_args + ["-e", "mkldnn"]
-                if "cuda" in build_name:
-                    test_args = test_args + ["-e", "cuda"]
-                if "tensorrt" in build_name:
-                    test_args = test_args + ["-e", "tensorrt"]
-                if "ngraph" in build_name:
-                    test_args = test_args + ["-e", "ngraph"]
-
-                env_vars = ep_envvar_map.get(build_name)
-                env_var_combos = get_env_var_combos(env_vars)
-                env_names = list(env_vars.keys()) if env_vars is not None else []
-                # Tune all possible combinations of environment variables, including defaults
-                for combo in env_var_combos:
-                    # generate env var dict {env_var_name: env_var_option}.
-                    env = gen_env_var_dict(env_names, combo)
-                    env_option = ""
-                    for e in env:
-                        env_option += "_" + e + "_" + env.get(e)
-
-                    best_run = -1
-                    is_omp = "openmp" in build_name
-                    num_threads = int(args.num_threads) if is_omp else int(args.threadpool_size)
-                    if args.parallel and "cuda" not in build_name and "tensorrt" not in build_name:
-                        # Tune environment variables and thread pool size using parallel executor
-                        best_run = run_perf_test_binary(
-                            PerfTestParams(
-                                build_name + "_parallel_",
-                                build_name + " ",
-                                build_path,
-                                test_args + ["-P"],
-                                env,
-                                args,
-                                build_name,
-                            ), num_threads, "_threads" + env_option, " threads, " + env_option, failed, successful, is_omp)
-                    if best_run != None and best_run > 1:
-                        # Run the best thread pool candidate with environment variable on sequential executor
-                        param = PerfTestParams(
-                            build_name + "_" + str(best_run) + "_threads" + env_option,
-                            build_name + " " + str(best_run) + " threads, " + env_option,
+            # # If current build is requested by user, run perf tuning
+            # if build_name in providers:
+            test_args = []
+
+            if "mkldnn" in build_name:
+                test_args = test_args + ["-e", "mkldnn"]
+            if "cuda" in build_name:
+                test_args = test_args + ["-e", "cuda"]
+            if "tensorrt" in build_name:
+                test_args = test_args + ["-e", "tensorrt"]
+            if "ngraph" in build_name:
+                test_args = test_args + ["-e", "ngraph"]
+
+            env_vars = ep_envvar_map.get(build_name)
+            env_var_combos = get_env_var_combos(env_vars)
+            env_names = list(env_vars.keys()) if env_vars is not None else []
+            # Tune all possible combinations of environment variables, including defaults
+            for combo in env_var_combos:
+                # generate env var dict {env_var_name: env_var_option}.
+                env = gen_env_var_dict(env_names, combo)
+                env_option = ""
+                for e in env:
+                    env_option += "_" + e + "_" + env.get(e)
+
+                best_run = -1
+                is_omp = "openmp" in build_name
+                num_threads = int(args.num_threads) if is_omp else int(args.threadpool_size)
+                if args.parallel and "cuda" not in build_name and "tensorrt" not in build_name:
+                    # Tune environment variables and thread pool size using parallel executor
+                    best_run = run_perf_test_binary(
+                        PerfTestParams(
+                            build_name + "_parallel_",
+                            build_name + " ",
                             build_path,
-                            test_args,
+                            test_args + ["-P"],
                             env,
-                            args,
-                            build_name
-                        )
-                        if is_omp:
-                            param.env.update({"OMP_NUM_THREADS": str(best_run)})
-                        else:
-                            param.test_args += ["-x", str(best_run)]
-                        tests.append(param)
-                    else:
-                        # Tune environment variables and thread pool size using sequential executor
-                        run_perf_test_binary(
-                            PerfTestParams(
-                                build_name + "_",
-                                build_name + " ",
-                                build_path,
-                                test_args,
-                                env,
-                                args,
-                                build_name
-                            ), num_threads, "_threads" + env_option, " threads, " + env_option, failed, successful, is_omp)
-                    # Tune environment variables using sequential executor
-                    params = PerfTestParams(
-                        build_name + env_option,
-                        build_name + " " + env_option,
+                            args,
+                            build_name,
+                        ), num_threads, "_threads" + env_option, " threads, " + env_option, failed, successful, is_omp)
+                if best_run != None and best_run > 1:
+                    # Run the best thread pool candidate with environment variable on sequential executor
+                    param = PerfTestParams(
+                        build_name + "_" + str(best_run) + "_threads" + env_option,
+                        build_name + " " + str(best_run) + " threads, " + env_option,
                         build_path,
                         test_args,
                         env,
-                        args,
-                        build_name)
-                    tests.append(params)
+                        args,
+                        build_name
+                    )
+                    if is_omp:
+                        param.env.update({"OMP_NUM_THREADS": str(best_run)})
+                    else:
+                        param.test_args += ["-x", str(best_run)]
+                    tests.append(param)
+                else:
+                    # Tune environment variables and thread pool size using sequential executor
+                    run_perf_test_binary(
+                        PerfTestParams(
+                            build_name + "_",
+                            build_name + " ",
+                            build_path,
+                            test_args,
+                            env,
+                            args,
+                            build_name
+                        ), num_threads, "_threads" + env_option, " threads, " + env_option, failed, successful, is_omp)
+                # Tune environment variables using sequential executor
+                params = PerfTestParams(
+                    build_name + env_option,
+                    build_name + " " + env_option,
+                    build_path,
+                    test_args,
+                    env,
+                    args,
+                    build_name)
+                tests.append(params)

     # Run the tests.
     for test in tests:


message: update build

event: committed


type: pr

state: closed

title: Update Perf Tuning Build

body: Update ONNX Runtime build to use a single command line to build all execution providers.

ref: ziyl/build

login: microsoft

type: Organization

Olive

full_name: microsoft/Olive

description: Olive: Simplify ML Model Finetuning, Conversion, Quantization, and Optimization for CPUs, GPUs and NPUs.

MIT License

key: mit

spdx_id: MIT

pull_request_creation_policy: all

visibility: public

default_branch: main

ref: master

author_association: CONTRIBUTOR

mergeable_state: dirty