From 9086a4115cdb9acd196654f7661434467554fbc8 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 21:42:13 -0800 Subject: [PATCH 01/20] Update build.py --- .gitignore | 1 + requirements.txt | 17 + tools/ci_build/build.py | 577 ++++++--------------- tools/python/util/BaseError.py | 7 + tools/python/util/BuildError.py | 10 + tools/python/util/UsageError.py | 10 + tools/python/util/__init__.py | 22 + tools/python/util/add_openvino_win_libs.py | 35 -- tools/python/util/build_helpers.py | 181 +++++++ tools/python/util/cuda_helpers.py | 26 + tools/python/util/open_vino_utils.py | 89 ++++ 11 files changed, 512 insertions(+), 463 deletions(-) create mode 100644 requirements.txt create mode 100644 tools/python/util/BaseError.py create mode 100644 tools/python/util/BuildError.py create mode 100644 tools/python/util/UsageError.py delete mode 100644 tools/python/util/add_openvino_win_libs.py create mode 100644 tools/python/util/build_helpers.py create mode 100644 tools/python/util/cuda_helpers.py create mode 100644 tools/python/util/open_vino_utils.py diff --git a/.gitignore b/.gitignore index 4d0a1205b7c1..abd4d7a631db 100644 --- a/.gitignore +++ b/.gitignore @@ -196,3 +196,4 @@ Package.resolved .build/ .swiftpm/ repros/ +!/tools/ci_build/build_uitl/ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 000000000000..41b3cccf4c11 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,17 @@ +onnx~=1.15.0 +numpy~=1.26.2 +packaging~=23.2 +onnxruntime~=1.12.0 +setuptools~=68.2.0 +flatbuffers~=23.5.26 +pip~=23.3.2 +wheel~=0.41.2 +keyring~=24.3.0 +typing_extensions~=4.9.0 +certifi~=2023.11.17 +urllib3~=2.1.0 +idna~=3.4 +requests~=2.31.0 +coloredlogs~=15.0.1 +psutil~=5.9.7 +sympy~=1.12 \ No newline at end of file diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 0da4adb51767..7ec4c1d10dbe 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -14,118 +14,41 @@ import sys from pathlib import Path - -def version_to_tuple(version: str) -> tuple: - v = [] - for s in version.split("."): - with contextlib.suppress(ValueError): - v.append(int(s)) - return tuple(v) - - SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..")) sys.path.insert(0, os.path.join(REPO_DIR, "tools", "python")) - +# The Following uil packages is from onnxruntime/tools/python/util import util.android as android # noqa: E402 -from util import get_logger, is_linux, is_macOS, is_windows, run # noqa: E402 +from util import ( + get_logger, + is_linux, + is_macOS, + is_windows, + run, + version_to_tuple, + check_python_version, + str_to_bool, + openvino_verify_device_type, + is_reduced_ops_build, + resolve_executable_path, + get_config_build_dir, + use_dev_mode, + add_default_definition, + normalize_arg_list, + number_of_parallel_jobs, + number_of_nvcc_threads, + BuildError, + BaseError, + setup_cuda_vars, + setup_tensorrt_vars, + setup_migraphx_vars, + setup_cann_vars, +) # noqa: E402 log = get_logger("build") - - -class BaseError(Exception): - """Base class for errors originating from build.py.""" - - pass - - -class BuildError(BaseError): - """Error from running build steps.""" - - def __init__(self, *messages): - super().__init__("\n".join(messages)) - - -class UsageError(BaseError): - """Usage related error.""" - - def __init__(self, message): - super().__init__(message) - - -def _check_python_version(): - required_minor_version = 7 - if (sys.version_info.major, sys.version_info.minor) < (3, required_minor_version): - raise UsageError( - f"Invalid Python version. At least Python 3.{required_minor_version} is required. " - f"Actual Python version: {sys.version}" - ) - - -def _str_to_bool(s): - """Convert string to bool (in argparse context).""" - if s.lower() not in ["true", "false"]: - raise ValueError("Need bool; got %r" % s) - return {"true": True, "false": False}[s.lower()] - - -_check_python_version() - - -def _openvino_verify_device_type(device_read): - choices = ["CPU_FP32", "CPU_FP16", "GPU_FP32", "GPU_FP16"] - - choices1 = [ - "CPU_FP32_NO_PARTITION", - "CPU_FP16_NO_PARTITION", - "GPU_FP32_NO_PARTITION", - "GPU_FP16_NO_PARTITION", - ] - status_hetero = True - res = False - if device_read in choices: - res = True - elif device_read in choices1: - res = True - elif device_read.startswith("HETERO:") or device_read.startswith("MULTI:") or device_read.startswith("AUTO:"): - res = True - comma_separated_devices = device_read.split(":") - comma_separated_devices = comma_separated_devices[1].split(",") - if len(comma_separated_devices) < 2: - print("At least two devices required in Hetero/Multi/Auto Mode") - status_hetero = False - dev_options = ["CPU", "GPU"] - for dev in comma_separated_devices: - if dev not in dev_options: - status_hetero = False - break - - def invalid_hetero_build(): - print("\nIf trying to build Hetero/Multi/Auto, specify the supported devices along with it.\n") - print("specify the keyword HETERO or MULTI or AUTO followed by the devices ") - print("in the order of priority you want to build\n") - print("The different hardware devices that can be added in HETERO or MULTI or AUTO") - print("are ['CPU','GPU'] \n") - print("An example of how to specify the hetero build type. Ex: HETERO:GPU,CPU \n") - print("An example of how to specify the MULTI build type. Ex: MULTI:GPU,CPU \n") - print("An example of how to specify the AUTO build type. Ex: AUTO:GPU,CPU \n") - sys.exit("Wrong Build Type selected") - - if res is False: - print("\nYou have selected wrong configuration for the build.") - print("pick the build type for specific Hardware Device from following options: ", choices) - print("(or) from the following options with graph partitioning disabled: ", choices1) - print("\n") - if not (device_read.startswith("HETERO") or device_read.startswith("MULTI") or device_read.startswith("AUTO")): - invalid_hetero_build() - sys.exit("Wrong Build Type selected") - - if status_hetero is False: - invalid_hetero_build() - - return device_read +check_python_version() def parse_arguments(): @@ -171,7 +94,7 @@ def convert_arg_line_to_args(self, arg_line): default="1", type=int, help="Use parallel build. The optional value specifies the maximum number of parallel jobs. " - "If the optional value is 0 or unspecified, it is interpreted as the number of CPUs.", + "If the optional value is 0 or unspecified, it is interpreted as the number of CPUs.", ) parser.add_argument( "--nvcc_threads", @@ -179,7 +102,7 @@ def convert_arg_line_to_args(self, arg_line): default=-1, type=int, help="Maximum number of NVCC threads in each parallel job." - "If the value is unspecified, it will be computed based on available memory and number of parallel jobs.", + "If the value is unspecified, it will be computed based on available memory and number of parallel jobs.", ) parser.add_argument("--test", action="store_true", help="Run unit tests.") @@ -204,7 +127,7 @@ def convert_arg_line_to_args(self, arg_line): parser.add_argument("--mpi_home", help="Path to MPI installation dir") parser.add_argument("--nccl_home", help="Path to NCCL installation dir") parser.add_argument( - "--use_mpi", nargs="?", default=False, const=True, type=_str_to_bool, help="Disabled by default." + "--use_mpi", nargs="?", default=False, const=True, type=str_to_bool, help="Disabled by default." ) # enable ONNX tests @@ -230,8 +153,8 @@ def convert_arg_line_to_args(self, arg_line): const="yes", type=str, help="Generate documentation listing standard ONNX operators and types implemented by " - "various execution providers and contrib operator schemas. Must be used for inference builds, only!" - "Use `--gen_doc validate` to validate these match the current contents in /docs.", + "various execution providers and contrib operator schemas. Must be used for inference builds, only!" + "Use `--gen_doc validate` to validate these match the current contents in /docs.", ) parser.add_argument("--gen-api-doc", action="store_true", help="Generate API documentation for PyTorch frontend") @@ -244,14 +167,14 @@ def convert_arg_line_to_args(self, arg_line): parser.add_argument( "--cuda_home", help="Path to CUDA home." - "Read from CUDA_HOME environment variable if --use_cuda is true and " - "--cuda_home is not specified.", + "Read from CUDA_HOME environment variable if --use_cuda is true and " + "--cuda_home is not specified.", ) parser.add_argument( "--cudnn_home", help="Path to CUDNN home. " - "Read from CUDNN_HOME environment variable if --use_cuda is true and " - "--cudnn_home is not specified.", + "Read from CUDNN_HOME environment variable if --use_cuda is true and " + "--cudnn_home is not specified.", ) parser.add_argument("--enable_cuda_line_info", action="store_true", help="Enable CUDA line info.") parser.add_argument("--enable_cuda_nhwc_ops", action="store_true", help="Enable CUDA NHWC ops in build.") @@ -273,14 +196,14 @@ def convert_arg_line_to_args(self, arg_line): "--build_csharp", action="store_true", help="Build C#.Net DLL and NuGet package. This should be only used in CI pipelines. " - "For building C# bindings and packaging them into nuget package use --build_nuget arg.", + "For building C# bindings and packaging them into nuget package use --build_nuget arg.", ) parser.add_argument( "--build_nuget", action="store_true", help="Build C#.Net DLL and NuGet package on the local machine. " - "Currently only Windows and Linux platforms are supported.", + "Currently only Windows and Linux platforms are supported.", ) parser.add_argument( @@ -288,7 +211,7 @@ def convert_arg_line_to_args(self, arg_line): nargs="+", action="append", help="Extra properties to pass to msbuild during build. " - "These are just msbuild /p: options without the leading /p:.", + "These are just msbuild /p: options without the leading /p:.", ) # Java bindings @@ -314,7 +237,7 @@ def convert_arg_line_to_args(self, arg_line): nargs="+", action="append", help="Extra definitions to pass to CMake during build system " - "generation. These are just CMake -D options without the leading -D.", + "generation. These are just CMake -D options without the leading -D.", ) parser.add_argument("--target", help="Build a specific target, e.g. winml_dll") # This flag is needed when : @@ -326,25 +249,25 @@ def convert_arg_line_to_args(self, arg_line): "--x86", action="store_true", help="[cross-compiling] Create Windows x86 makefiles. Requires --update and no existing cache " - "CMake setup. Delete CMakeCache.txt if needed", + "CMake setup. Delete CMakeCache.txt if needed", ) parser.add_argument( "--arm", action="store_true", help="[cross-compiling] Create ARM makefiles. Requires --update and no existing cache " - "CMake setup. Delete CMakeCache.txt if needed", + "CMake setup. Delete CMakeCache.txt if needed", ) parser.add_argument( "--arm64", action="store_true", help="[cross-compiling] Create ARM64 makefiles. Requires --update and no existing cache " - "CMake setup. Delete CMakeCache.txt if needed", + "CMake setup. Delete CMakeCache.txt if needed", ) parser.add_argument( "--arm64ec", action="store_true", help="[cross-compiling] Create ARM64EC makefiles. Requires --update and no existing cache " - "CMake setup. Delete CMakeCache.txt if needed", + "CMake setup. Delete CMakeCache.txt if needed", ) parser.add_argument( "--buildasx", @@ -415,8 +338,8 @@ def convert_arg_line_to_args(self, arg_line): "--apple_deploy_target", type=str, help="Specify the minimum version of the target platform " - "(e.g. macOS or iOS)" - "This is only supported on MacOS", + "(e.g. macOS or iOS)" + "This is only supported on MacOS", ) # A 32-bit progress doesn't have enough memory to run all the tests in onnxruntime_test_all. # Mimalloc is incompatible with address sanitizer. @@ -450,7 +373,7 @@ def convert_arg_line_to_args(self, arg_line): "--enable_wasm_exception_throwing_override", action="store_true", help="Enable exception throwing in WebAssembly, this will override default disabling exception throwing " - "behavior when disable exceptions.", + "behavior when disable exceptions.", ) parser.add_argument("--wasm_run_tests_in_browser", action="store_true", help="Run WebAssembly tests in browser") @@ -475,7 +398,7 @@ def convert_arg_line_to_args(self, arg_line): "--use_extensions", action="store_true", help="Enable custom operators in onnxruntime-extensions, use git submodule onnxruntime-extensions " - "in path cmake/external/onnxruntime-extensions by default.", + "in path cmake/external/onnxruntime-extensions by default.", ) parser.add_argument( "--extensions_overridden_path", @@ -489,7 +412,7 @@ def convert_arg_line_to_args(self, arg_line): "--ctest_path", default="ctest", help="Path to the CTest program. It can be an empty string. If it is empty, " - "we will use this script driving the test programs directly.", + "we will use this script driving the test programs directly.", ) parser.add_argument( "--skip_submodule_sync", @@ -506,13 +429,13 @@ def convert_arg_line_to_args(self, arg_line): action="store", default="", help="Path to OpenCL SDK. " - 'e.g. --dnnl_opencl_root "C:/Program Files (x86)/IntelSWTools/sw_dev_tools/OpenCL/sdk"', + 'e.g. --dnnl_opencl_root "C:/Program Files (x86)/IntelSWTools/sw_dev_tools/OpenCL/sdk"', ) parser.add_argument( "--use_openvino", nargs="?", const="CPU_FP32", - type=_openvino_verify_device_type, + type=openvino_verify_device_type, help="Build with OpenVINO for specific hardware.", ) parser.add_argument( @@ -644,13 +567,13 @@ def convert_arg_line_to_args(self, arg_line): nargs="*", type=str.lower, help="Create a build that only supports ORT format models. " - "See https://onnxruntime.ai/docs/tutorials/mobile/ for more information. " - "RTTI is automatically disabled in a minimal build. " - "To enable execution providers that compile kernels at runtime (e.g. NNAPI) pass 'extended' " - "as a parameter. e.g. '--minimal_build extended'. " - "To enable support for custom operators pass 'custom_ops' as a parameter. " - "e.g. '--minimal_build custom_ops'. This can be combined with an 'extended' build by passing " - "'--minimal_build extended custom_ops'", + "See https://onnxruntime.ai/docs/tutorials/mobile/ for more information. " + "RTTI is automatically disabled in a minimal build. " + "To enable execution providers that compile kernels at runtime (e.g. NNAPI) pass 'extended' " + "as a parameter. e.g. '--minimal_build extended'. " + "To enable support for custom operators pass 'custom_ops' as a parameter. " + "e.g. '--minimal_build custom_ops'. This can be combined with an 'extended' build by passing " + "'--minimal_build extended custom_ops'", ) parser.add_argument( @@ -662,9 +585,9 @@ def convert_arg_line_to_args(self, arg_line): "--enable_reduced_operator_type_support", action="store_true", help="If --include_ops_by_config is specified, and the configuration file has type reduction " - "information, limit the types individual operators support where possible to further " - "reduce the build size. " - "See /docs/Reduced_Operator_Kernel_build.md for more information.", + "information, limit the types individual operators support where possible to further " + "reduce the build size. " + "See /docs/Reduced_Operator_Kernel_build.md for more information.", ) parser.add_argument("--disable_contrib_ops", action="store_true", help="Disable contrib ops (reduces binary size)") @@ -762,49 +685,15 @@ def convert_arg_line_to_args(self, arg_line): return args -def is_reduced_ops_build(args): - return args.include_ops_by_config is not None - - -def resolve_executable_path(command_or_path): - """Returns the absolute path of an executable.""" - if command_or_path and command_or_path.strip(): - executable_path = shutil.which(command_or_path) - if executable_path is None: - raise BuildError(f"Failed to resolve executable path for '{command_or_path}'.") - return os.path.abspath(executable_path) - else: - return None - - -def get_linux_distro(): - try: - with open("/etc/os-release") as f: - dist_info = dict(line.strip().split("=", 1) for line in f.readlines()) - return dist_info.get("NAME", "").strip('"'), dist_info.get("VERSION", "").strip('"') - except (OSError, ValueError): - return "", "" - - -def is_ubuntu_1604(): - dist, ver = get_linux_distro() - return dist == "Ubuntu" and ver.startswith("16.04") - - -def get_config_build_dir(build_dir, config): - # build directory per configuration - return os.path.join(build_dir, config) - - def run_subprocess( - args, - cwd=None, - capture_stdout=False, - dll_path=None, - shell=False, - env=None, - python_path=None, - cuda_home=None, + args, + cwd=None, + capture_stdout=False, + dll_path=None, + shell=False, + env=None, + python_path=None, + cuda_home=None, ): if env is None: env = {} @@ -844,15 +733,6 @@ def update_submodules(source_dir): run_subprocess(["git", "submodule", "update", "--init", "--recursive"], cwd=source_dir) -def is_docker(): - path = "/proc/self/cgroup" - return ( - os.path.exists("/.dockerenv") - or os.path.isfile(path) - and any("docker" in line for line in open(path)) # noqa: SIM115 - ) - - def install_python_deps(numpy_version=""): dep_packages = ["setuptools", "wheel", "pytest"] dep_packages.append(f"numpy=={numpy_version}" if numpy_version else "numpy>=1.16.6") @@ -888,92 +768,29 @@ def setup_test_data(source_onnx_model_dir, dest_model_dir_name, build_dir, confi os.symlink(source_onnx_model_dir, src_model_dir, target_is_directory=True) -def use_dev_mode(args): - if args.compile_no_warning_as_error: - return False - if args.use_acl: - return False - if args.use_armnn: - return False - if args.ios and is_macOS(): - return False - SYSTEM_COLLECTIONURI = os.getenv("SYSTEM_COLLECTIONURI") # noqa: N806 - if SYSTEM_COLLECTIONURI and SYSTEM_COLLECTIONURI != "https://dev.azure.com/onnxruntime/": - return False - return True - - -def add_default_definition(definition_list, key, default_value): - for x in definition_list: - if x.startswith(key + "="): - return definition_list - definition_list.append(key + "=" + default_value) - - -def normalize_arg_list(nested_list): - return [i for j in nested_list for i in j] if nested_list else [] - - -def number_of_parallel_jobs(args): - return os.cpu_count() if args.parallel == 0 else args.parallel - - -def number_of_nvcc_threads(args): - if args.nvcc_threads >= 0: - return args.nvcc_threads - - nvcc_threads = 1 - try: - import psutil - - available_memory = psutil.virtual_memory().available - if isinstance(available_memory, int) and available_memory > 0: - if available_memory > 60 * 1024 * 1024 * 1024: - # When available memory is large enough, chance of OOM is small. - nvcc_threads = 4 - else: - # NVCC need a lot of memory to compile 8 flash attention cu files in Linux or 4 cutlass fmha cu files in Windows. - # Here we select number of threads to ensure each thread has enough memory (>= 4 GB). For example, - # Standard_NC4as_T4_v3 has 4 CPUs and 28 GB memory. When parallel=4 and nvcc_threads=2, - # total nvcc threads is 4 * 2, which is barely able to build in 28 GB memory so we will use nvcc_threads=1. - memory_per_thread = 4 * 1024 * 1024 * 1024 - fmha_cu_files = 4 if is_windows() else 16 - fmha_parallel_jobs = min(fmha_cu_files, number_of_parallel_jobs(args)) - nvcc_threads = max(1, int(available_memory / (memory_per_thread * fmha_parallel_jobs))) - print( - f"nvcc_threads={nvcc_threads} to ensure memory per thread >= 4GB for available_memory={available_memory} and fmha_parallel_jobs={fmha_parallel_jobs}" - ) - except ImportError: - print( - "Failed to import psutil. Please `pip install psutil` for better estimation of nvcc threads. Use nvcc_threads=1" - ) - - return nvcc_threads - - def generate_build_tree( - cmake_path, - source_dir, - build_dir, - cuda_home, - cudnn_home, - rocm_home, - mpi_home, - nccl_home, - tensorrt_home, - migraphx_home, - acl_home, - acl_libs, - armnn_home, - armnn_libs, - qnn_home, - snpe_root, - cann_home, - path_to_protoc_exe, - configs, - cmake_extra_defines, - args, - cmake_extra_args, + cmake_path, + source_dir, + build_dir, + cuda_home, + cudnn_home, + rocm_home, + mpi_home, + nccl_home, + tensorrt_home, + migraphx_home, + acl_home, + acl_libs, + armnn_home, + armnn_libs, + qnn_home, + snpe_root, + cann_home, + path_to_protoc_exe, + configs, + cmake_extra_defines, + args, + cmake_extra_args, ): log.info("Generating CMake build tree") cmake_dir = os.path.join(source_dir, "cmake") @@ -1397,10 +1214,10 @@ def generate_build_tree( if args.fuzz_testing: if not ( - args.build_shared_lib - and is_windows() - and args.cmake_generator == "Visual Studio 17 2022" - and args.use_full_protobuf + args.build_shared_lib + and is_windows() + and args.cmake_generator == "Visual Studio 17 2022" + and args.use_full_protobuf ): raise BuildError("Fuzz test has only be tested with build shared libs option using MSVC on windows") cmake_args += [ @@ -1479,14 +1296,14 @@ def generate_build_tree( # Setup default values for cflags/cxxflags/ldflags. # The values set here are purely for security and compliance purposes. ONNX Runtime should work fine without these flags. if ( - "CFLAGS" not in os.environ - and "CXXFLAGS" not in os.environ - and (not args.use_cuda or "CUDAFLAGS" not in os.environ) - and not args.ios - and not args.android - and not args.build_wasm - and not args.use_rocm - and not (is_linux() and platform.machine() != "aarch64" and platform.machine() != "x86_64") + "CFLAGS" not in os.environ + and "CXXFLAGS" not in os.environ + and (not args.use_cuda or "CUDAFLAGS" not in os.environ) + and not args.ios + and not args.android + and not args.build_wasm + and not args.use_rocm + and not (is_linux() and platform.machine() != "aarch64" and platform.machine() != "x86_64") ): if is_windows(): cflags = ["/guard:cf", "/DWIN32", "/D_WINDOWS"] @@ -1579,13 +1396,13 @@ def generate_build_tree( os.makedirs(config_build_dir, exist_ok=True) if args.use_tvm: os.environ["PATH"] = ( - os.path.join(config_build_dir, "_deps", "tvm-build") - + os.pathsep - + os.path.join(config_build_dir, "_deps", "tvm-src") - + os.pathsep - + os.path.dirname(sys.executable) - + os.pathsep - + os.environ["PATH"] + os.path.join(config_build_dir, "_deps", "tvm-build") + + os.pathsep + + os.path.join(config_build_dir, "_deps", "tvm-src") + + os.pathsep + + os.path.dirname(sys.executable) + + os.pathsep + + os.environ["PATH"] ) preinstalled_dir = Path(build_dir) / config temp_cmake_args = cmake_args.copy() @@ -1659,96 +1476,6 @@ def build_targets(args, cmake_path, build_dir, configs, num_parallel_jobs, targe run_subprocess(cmd_args, env=env) -def add_dir_if_exists(directory, dir_list): - if os.path.isdir(directory): - dir_list.append(directory) - - -def setup_cuda_vars(args): - cuda_home = "" - cudnn_home = "" - - if args.use_cuda: - cuda_home = args.cuda_home if args.cuda_home else os.getenv("CUDA_HOME") - cudnn_home = args.cudnn_home if args.cudnn_home else os.getenv("CUDNN_HOME") - - cuda_home_valid = cuda_home is not None and os.path.exists(cuda_home) - cudnn_home_valid = cudnn_home is not None and os.path.exists(cudnn_home) - - if not cuda_home_valid or (not is_windows() and not cudnn_home_valid): - raise BuildError( - "cuda_home and cudnn_home paths must be specified and valid.", - "cuda_home='{}' valid={}. cudnn_home='{}' valid={}".format( - cuda_home, cuda_home_valid, cudnn_home, cudnn_home_valid - ), - ) - - return cuda_home, cudnn_home - - -def setup_cann_vars(args): - cann_home = "" - - if args.use_cann: - cann_home = args.cann_home if args.cann_home else os.getenv("ASCEND_HOME_PATH") - - cann_home_valid = cann_home is not None and os.path.exists(cann_home) - - if not cann_home_valid: - raise BuildError( - "cann_home paths must be specified and valid.", - f"cann_home='{cann_home}' valid={cann_home_valid}.", - ) - - return cann_home - - -def setup_tensorrt_vars(args): - tensorrt_home = "" - if args.use_tensorrt: - tensorrt_home = args.tensorrt_home if args.tensorrt_home else os.getenv("TENSORRT_HOME") - tensorrt_home_valid = tensorrt_home is not None and os.path.exists(tensorrt_home) - if not tensorrt_home_valid: - raise BuildError( - "tensorrt_home paths must be specified and valid.", - f"tensorrt_home='{tensorrt_home}' valid={tensorrt_home_valid}.", - ) - - # Set maximum workspace size in byte for - # TensorRT (1GB = 1073741824 bytes). - os.environ["ORT_TENSORRT_MAX_WORKSPACE_SIZE"] = "1073741824" - - # Set maximum number of iterations to detect unsupported nodes - # and partition the models for TensorRT. - os.environ["ORT_TENSORRT_MAX_PARTITION_ITERATIONS"] = "1000" - - # Set minimum subgraph node size in graph partitioning - # for TensorRT. - os.environ["ORT_TENSORRT_MIN_SUBGRAPH_SIZE"] = "1" - - # Set FP16 flag - os.environ["ORT_TENSORRT_FP16_ENABLE"] = "0" - - return tensorrt_home - - -def setup_migraphx_vars(args): - migraphx_home = None - - if args.use_migraphx: - print(f"migraphx_home = {args.migraphx_home}") - migraphx_home = args.migraphx_home or os.getenv("MIGRAPHX_HOME") or None - - migraphx_home_not_valid = migraphx_home and not os.path.exists(migraphx_home) - - if migraphx_home_not_valid: - raise BuildError( - "migraphx_home paths must be specified and valid.", - f"migraphx_home='{migraphx_home}' valid={migraphx_home_not_valid}.", - ) - return migraphx_home or "" - - def setup_dml_build(args, cmake_path, build_dir, configs): if not args.use_dml: return @@ -2123,31 +1850,31 @@ def run_nodejs_tests(nodejs_binding_dir): def build_python_wheel( - source_dir, - build_dir, - configs, - use_cuda, - cuda_version, - use_rocm, - rocm_version, - use_dnnl, - use_tensorrt, - use_openvino, - use_tvm, - use_vitisai, - use_acl, - use_armnn, - use_dml, - use_cann, - use_azure, - use_qnn, - wheel_name_suffix, - enable_training, - nightly_build=False, - default_training_package_device=False, - use_ninja=False, - enable_training_apis=False, - enable_rocm_profiling=False, + source_dir, + build_dir, + configs, + use_cuda, + cuda_version, + use_rocm, + rocm_version, + use_dnnl, + use_tensorrt, + use_openvino, + use_tvm, + use_vitisai, + use_acl, + use_armnn, + use_dml, + use_cann, + use_azure, + use_qnn, + wheel_name_suffix, + enable_training, + nightly_build=False, + default_training_package_device=False, + use_ninja=False, + enable_training_apis=False, + enable_rocm_profiling=False, ): for config in configs: cwd = get_config_build_dir(build_dir, config) @@ -2205,20 +1932,20 @@ def build_python_wheel( def build_nuget_package( - cmake_path, - source_dir, - build_dir, - configs, - use_cuda, - use_rocm, - use_openvino, - use_tensorrt, - use_dnnl, - use_tvm, - use_winml, - use_qnn, - enable_training_apis, - msbuild_extra_options, + cmake_path, + source_dir, + build_dir, + configs, + use_cuda, + use_rocm, + use_openvino, + use_tensorrt, + use_dnnl, + use_tvm, + use_winml, + use_qnn, + enable_training_apis, + msbuild_extra_options, ): if not (is_windows() or is_linux()): raise BuildError( @@ -2725,12 +2452,6 @@ def main(): log.info("Activating emsdk...") run_subprocess([emsdk_file, "activate", emsdk_version], cwd=emsdk_dir) - if is_ubuntu_1604(): - if args.arm or args.arm64: - raise BuildError("Only Windows ARM(64) cross-compiled builds supported currently through this script") - if not is_docker() and not args.use_acl and not args.use_armnn: - install_python_deps() - if args.enable_pybind and is_windows(): install_python_deps(args.numpy_version) diff --git a/tools/python/util/BaseError.py b/tools/python/util/BaseError.py new file mode 100644 index 000000000000..42b180b876e9 --- /dev/null +++ b/tools/python/util/BaseError.py @@ -0,0 +1,7 @@ +# // Copyright (c) Microsoft Corporation. All rights reserved. +# // Licensed under the MIT License. +class BaseError(Exception): + """Base class for errors originating from build.py.""" + + pass + diff --git a/tools/python/util/BuildError.py b/tools/python/util/BuildError.py new file mode 100644 index 000000000000..e9898330e85f --- /dev/null +++ b/tools/python/util/BuildError.py @@ -0,0 +1,10 @@ +# // Copyright (c) Microsoft Corporation. All rights reserved. +# // Licensed under the MIT License. +import BaseError + + +class BuildError(BaseError): + """Error from running build steps.""" + + def __init__(self, *messages): + super().__init__("\n".join(messages)) diff --git a/tools/python/util/UsageError.py b/tools/python/util/UsageError.py new file mode 100644 index 000000000000..761214ba2189 --- /dev/null +++ b/tools/python/util/UsageError.py @@ -0,0 +1,10 @@ +# // Copyright (c) Microsoft Corporation. All rights reserved. +# // Licensed under the MIT License. +import BaseError + + +class UsageError(BaseError): + """Usage related error.""" + + def __init__(self, message): + super().__init__(message) \ No newline at end of file diff --git a/tools/python/util/__init__.py b/tools/python/util/__init__.py index 0a791165dd15..62b112c984fc 100644 --- a/tools/python/util/__init__.py +++ b/tools/python/util/__init__.py @@ -5,6 +5,28 @@ from .logger import get_logger from .platform_helpers import is_linux, is_macOS, is_windows # noqa: F401 from .run import run # noqa: F401 +from .build_helpers import ( + version_to_tuple, + check_python_version, + str_to_bool, + is_reduced_ops_build, + resolve_executable_path, + get_config_build_dir, + use_dev_mode, + add_default_definition, + normalize_arg_list, + number_of_parallel_jobs, + number_of_nvcc_threads, + setup_cann_vars, + setup_tensorrt_vars, + setup_migraphx_vars, + +) + +from .UsageError import UsageError +from .BuildError import BuildError +from .open_vino_utils import openvino_verify_device_type +from .cuda_helpers import setup_cuda_vars try: import flatbuffers # noqa: F401 diff --git a/tools/python/util/add_openvino_win_libs.py b/tools/python/util/add_openvino_win_libs.py deleted file mode 100644 index 0cd4c41c1742..000000000000 --- a/tools/python/util/add_openvino_win_libs.py +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (C) 2022-2023 Intel Corporation -# Licensed under the MIT License - -import os -import site -import sys - - -def add_openvino_libs_to_path() -> None: - """Adds OpenVINO libraries to the PATH environment variable on Windows.""" - if sys.platform == "win32": - # Installer, pip installs openvino dlls to the different directories - # and those paths need to be visible to the openvino-ep modules - # - # If you're using a custom installation of openvino, - # add the location of openvino dlls to your system PATH. - openvino_libs = [] - # looking for the libs in the pip installation path. - if os.path.isdir(os.path.join(site.getsitepackages()[1], "openvino", "libs")): - openvino_libs.append(os.path.join(site.getsitepackages()[1], "openvino", "libs")) - else: - # setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable. - openvino_libs_installer = os.getenv("OPENVINO_LIB_PATHS") - if openvino_libs_installer: - openvino_libs.extend(openvino_libs_installer.split(";")) - else: - sys.exit( - "Error: Please set the OPENVINO_LIB_PATHS environment variable. " - "If you use an install package, please, run setupvars.bat" - ) - for lib in openvino_libs: - lib_path = os.path.join(os.path.dirname(__file__), lib) - if os.path.isdir(lib_path): - os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] - os.add_dll_directory(os.path.abspath(lib_path)) diff --git a/tools/python/util/build_helpers.py b/tools/python/util/build_helpers.py new file mode 100644 index 000000000000..499ec0a56c34 --- /dev/null +++ b/tools/python/util/build_helpers.py @@ -0,0 +1,181 @@ +# // Copyright (c) Microsoft Corporation. All rights reserved. +# // Licensed under the MIT License. +import contextlib +import sys +import shutil +import os +from UsageError import UsageError +from BuildError import BuildError +from .platform_helpers import is_windows, is_macOS + + +def version_to_tuple(version: str) -> tuple: + v = [] + for s in version.split("."): + with contextlib.suppress(ValueError): + v.append(int(s)) + return tuple(v) + + +def check_python_version(): + required_minor_version = 7 + if (sys.version_info.major, sys.version_info.minor) < (3, required_minor_version): + raise UsageError( + f"Invalid Python version. At least Python 3.{required_minor_version} is required. " + f"Actual Python version: {sys.version}" + ) + + +def str_to_bool(s): + """Convert string to bool (in argparse context).""" + if s.lower() not in ["true", "false"]: + raise ValueError("Need bool; got %r" % s) + return {"true": True, "false": False}[s.lower()] + + +def is_reduced_ops_build(args): + return args.include_ops_by_config is not None + + +def resolve_executable_path(command_or_path): + """Returns the absolute path of an executable.""" + if command_or_path and command_or_path.strip(): + executable_path = shutil.which(command_or_path) + if executable_path is None: + raise BuildError(f"Failed to resolve executable path for '{command_or_path}'.") + return os.path.abspath(executable_path) + else: + return None + + +def get_config_build_dir(build_dir, config): + # build directory per configuration + return os.path.join(build_dir, config) + + +def use_dev_mode(args): + if args.compile_no_warning_as_error: + return False + if args.use_acl: + return False + if args.use_armnn: + return False + if args.ios and is_macOS(): + return False + SYSTEM_COLLECTIONURI = os.getenv("SYSTEM_COLLECTIONURI") # noqa: N806 + if SYSTEM_COLLECTIONURI and SYSTEM_COLLECTIONURI != "https://dev.azure.com/onnxruntime/": + return False + return True + + +def add_default_definition(definition_list, key, default_value): + for x in definition_list: + if x.startswith(key + "="): + return definition_list + definition_list.append(key + "=" + default_value) + + +def normalize_arg_list(nested_list): + return [i for j in nested_list for i in j] if nested_list else [] + + +def number_of_parallel_jobs(args): + return os.cpu_count() if args.parallel == 0 else args.parallel + + +def number_of_nvcc_threads(args): + if args.nvcc_threads >= 0: + return args.nvcc_threads + + nvcc_threads = 1 + import psutil + try: + available_memory = psutil.virtual_memory().available + if isinstance(available_memory, int) and available_memory > 0: + if available_memory > 60 * 1024 * 1024 * 1024: + # When available memory is large enough, chance of OOM is small. + nvcc_threads = 4 + else: + # NVCC need a lot of memory to compile 8 flash attention cu files in Linux or 4 cutlass fmha cu files + # in Windows. Here we select number of threads to ensure each thread has enough memory (>= 4 GB). For + # example, Standard_NC4as_T4_v3 has 4 CPUs and 28 GB memory. When parallel=4 and nvcc_threads=2, + # total nvcc threads is 4 * 2, which is barely able to build in 28 GB memory so we will use + # nvcc_threads=1. + memory_per_thread = 4 * 1024 * 1024 * 1024 + fmha_cu_files = 4 if is_windows() else 16 + fmha_parallel_jobs = min(fmha_cu_files, number_of_parallel_jobs(args)) + nvcc_threads = max(1, int(available_memory / (memory_per_thread * fmha_parallel_jobs))) + print( + f"nvcc_threads={nvcc_threads} to ensure memory per thread >= 4GB for available_memory=" + f"{available_memory} and fmha_parallel_jobs={fmha_parallel_jobs}" + ) + except ImportError: + print( + "Failed to import psutil. Please `pip install psutil` for better estimation of nvcc threads. Use " + "nvcc_threads=1" + ) + + return nvcc_threads + + +def setup_cann_vars(args): + cann_home = "" + + if args.use_cann: + cann_home = args.cann_home if args.cann_home else os.getenv("ASCEND_HOME_PATH") + + cann_home_valid = cann_home is not None and os.path.exists(cann_home) + + if not cann_home_valid: + raise BuildError( + "cann_home paths must be specified and valid.", + f"cann_home='{cann_home}' valid={cann_home_valid}.", + ) + + return cann_home + + +def setup_tensorrt_vars(args): + tensorrt_home = "" + if args.use_tensorrt: + tensorrt_home = args.tensorrt_home if args.tensorrt_home else os.getenv("TENSORRT_HOME") + tensorrt_home_valid = tensorrt_home is not None and os.path.exists(tensorrt_home) + if not tensorrt_home_valid: + raise BuildError( + "tensorrt_home paths must be specified and valid.", + f"tensorrt_home='{tensorrt_home}' valid={tensorrt_home_valid}.", + ) + + # Set maximum workspace size in byte for + # TensorRT (1GB = 1073741824 bytes). + os.environ["ORT_TENSORRT_MAX_WORKSPACE_SIZE"] = "1073741824" + + # Set maximum number of iterations to detect unsupported nodes + # and partition the models for TensorRT. + os.environ["ORT_TENSORRT_MAX_PARTITION_ITERATIONS"] = "1000" + + # Set minimum subgraph node size in graph partitioning + # for TensorRT. + os.environ["ORT_TENSORRT_MIN_SUBGRAPH_SIZE"] = "1" + + # Set FP16 flag + os.environ["ORT_TENSORRT_FP16_ENABLE"] = "0" + + return tensorrt_home + + +def setup_migraphx_vars(args): + migraphx_home = None + + if args.use_migraphx: + print(f"migraphx_home = {args.migraphx_home}") + migraphx_home = args.migraphx_home or os.getenv("MIGRAPHX_HOME") or None + + migraphx_home_not_valid = migraphx_home and not os.path.exists(migraphx_home) + + if migraphx_home_not_valid: + raise BuildError( + "migraphx_home paths must be specified and valid.", + f"migraphx_home='{migraphx_home}' valid={migraphx_home_not_valid}.", + ) + return migraphx_home or "" diff --git a/tools/python/util/cuda_helpers.py b/tools/python/util/cuda_helpers.py new file mode 100644 index 000000000000..d72173cfc70a --- /dev/null +++ b/tools/python/util/cuda_helpers.py @@ -0,0 +1,26 @@ +# // Copyright (c) Microsoft Corporation. All rights reserved. +# // Licensed under the MIT License. +import os +from .BuildError import BuildError +from .platform_helpers import is_windows + +def setup_cuda_vars(args): + cuda_home = "" + cudnn_home = "" + + if args.use_cuda: + cuda_home = args.cuda_home if args.cuda_home else os.getenv("CUDA_HOME") + cudnn_home = args.cudnn_home if args.cudnn_home else os.getenv("CUDNN_HOME") + + cuda_home_valid = cuda_home is not None and os.path.exists(cuda_home) + cudnn_home_valid = cudnn_home is not None and os.path.exists(cudnn_home) + + if not cuda_home_valid or (not is_windows() and not cudnn_home_valid): + raise BuildError( + "cuda_home and cudnn_home paths must be specified and valid.", + "cuda_home='{}' valid={}. cudnn_home='{}' valid={}".format( + cuda_home, cuda_home_valid, cudnn_home, cudnn_home_valid + ), + ) + + return cuda_home, cudnn_home diff --git a/tools/python/util/open_vino_utils.py b/tools/python/util/open_vino_utils.py new file mode 100644 index 000000000000..b709b6014a2b --- /dev/null +++ b/tools/python/util/open_vino_utils.py @@ -0,0 +1,89 @@ +# Copyright (C) 2022-2023 Intel Corporation +# Licensed under the MIT License + +import os +import site +import sys + + +def add_openvino_libs_to_path() -> None: + """Adds OpenVINO libraries to the PATH environment variable on Windows.""" + if sys.platform == "win32": + # Installer, pip installs openvino dlls to the different directories + # and those paths need to be visible to the openvino-ep modules + # + # If you're using a custom installation of openvino, + # add the location of openvino dlls to your system PATH. + openvino_libs = [] + # looking for the libs in the pip installation path. + if os.path.isdir(os.path.join(site.getsitepackages()[1], "openvino", "libs")): + openvino_libs.append(os.path.join(site.getsitepackages()[1], "openvino", "libs")) + else: + # setupvars.bat script set all libs paths to OPENVINO_LIB_PATHS environment variable. + openvino_libs_installer = os.getenv("OPENVINO_LIB_PATHS") + if openvino_libs_installer: + openvino_libs.extend(openvino_libs_installer.split(";")) + else: + sys.exit( + "Error: Please set the OPENVINO_LIB_PATHS environment variable. " + "If you use an install package, please, run setupvars.bat" + ) + for lib in openvino_libs: + lib_path = os.path.join(os.path.dirname(__file__), lib) + if os.path.isdir(lib_path): + os.environ["PATH"] = os.path.abspath(lib_path) + ";" + os.environ["PATH"] + os.add_dll_directory(os.path.abspath(lib_path)) + + +def openvino_verify_device_type(device_read): + choices = ["CPU_FP32", "CPU_FP16", "GPU_FP32", "GPU_FP16"] + + choices1 = [ + "CPU_FP32_NO_PARTITION", + "CPU_FP16_NO_PARTITION", + "GPU_FP32_NO_PARTITION", + "GPU_FP16_NO_PARTITION", + ] + status_hetero = True + res = False + if device_read in choices: + res = True + elif device_read in choices1: + res = True + elif device_read.startswith("HETERO:") or device_read.startswith("MULTI:") or device_read.startswith("AUTO:"): + res = True + comma_separated_devices = device_read.split(":") + comma_separated_devices = comma_separated_devices[1].split(",") + if len(comma_separated_devices) < 2: + print("At least two devices required in Hetero/Multi/Auto Mode") + status_hetero = False + dev_options = ["CPU", "GPU"] + for dev in comma_separated_devices: + if dev not in dev_options: + status_hetero = False + break + + def invalid_hetero_build(): + print("\nIf trying to build Hetero/Multi/Auto, specify the supported devices along with it.\n") + print("specify the keyword HETERO or MULTI or AUTO followed by the devices ") + print("in the order of priority you want to build\n") + print("The different hardware devices that can be added in HETERO or MULTI or AUTO") + print("are ['CPU','GPU'] \n") + print("An example of how to specify the hetero build type. Ex: HETERO:GPU,CPU \n") + print("An example of how to specify the MULTI build type. Ex: MULTI:GPU,CPU \n") + print("An example of how to specify the AUTO build type. Ex: AUTO:GPU,CPU \n") + sys.exit("Wrong Build Type selected") + + if res is False: + print("\nYou have selected wrong configuration for the build.") + print("pick the build type for specific Hardware Device from following options: ", choices) + print("(or) from the following options with graph partitioning disabled: ", choices1) + print("\n") + if not (device_read.startswith("HETERO") or device_read.startswith("MULTI") or device_read.startswith("AUTO")): + invalid_hetero_build() + sys.exit("Wrong Build Type selected") + + if status_hetero is False: + invalid_hetero_build() + + return device_read From a925a42151567519e3f8c12ae10d3341cb156502 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 21:43:30 -0800 Subject: [PATCH 02/20] Remove requirements.txt --- requirements.txt | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 41b3cccf4c11..000000000000 --- a/requirements.txt +++ /dev/null @@ -1,17 +0,0 @@ -onnx~=1.15.0 -numpy~=1.26.2 -packaging~=23.2 -onnxruntime~=1.12.0 -setuptools~=68.2.0 -flatbuffers~=23.5.26 -pip~=23.3.2 -wheel~=0.41.2 -keyring~=24.3.0 -typing_extensions~=4.9.0 -certifi~=2023.11.17 -urllib3~=2.1.0 -idna~=3.4 -requests~=2.31.0 -coloredlogs~=15.0.1 -psutil~=5.9.7 -sympy~=1.12 \ No newline at end of file From 47ea31e69f3e3701d073a0ffb8ddc77c22220ce6 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 21:47:57 -0800 Subject: [PATCH 03/20] Reformating files --- tools/python/util/BaseError.py | 1 - tools/python/util/UsageError.py | 2 +- tools/python/util/__init__.py | 2 +- tools/python/util/build_helpers.py | 22 ++++++++++++++++++++++ tools/python/util/cuda_helpers.py | 20 -------------------- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/tools/python/util/BaseError.py b/tools/python/util/BaseError.py index 42b180b876e9..668fe6b285ce 100644 --- a/tools/python/util/BaseError.py +++ b/tools/python/util/BaseError.py @@ -4,4 +4,3 @@ class BaseError(Exception): """Base class for errors originating from build.py.""" pass - diff --git a/tools/python/util/UsageError.py b/tools/python/util/UsageError.py index 761214ba2189..bb54fe6cef8e 100644 --- a/tools/python/util/UsageError.py +++ b/tools/python/util/UsageError.py @@ -7,4 +7,4 @@ class UsageError(BaseError): """Usage related error.""" def __init__(self, message): - super().__init__(message) \ No newline at end of file + super().__init__(message) diff --git a/tools/python/util/__init__.py b/tools/python/util/__init__.py index 62b112c984fc..3acf989a778c 100644 --- a/tools/python/util/__init__.py +++ b/tools/python/util/__init__.py @@ -20,13 +20,13 @@ setup_cann_vars, setup_tensorrt_vars, setup_migraphx_vars, + setup_cuda_vars, ) from .UsageError import UsageError from .BuildError import BuildError from .open_vino_utils import openvino_verify_device_type -from .cuda_helpers import setup_cuda_vars try: import flatbuffers # noqa: F401 diff --git a/tools/python/util/build_helpers.py b/tools/python/util/build_helpers.py index 499ec0a56c34..c96975511354 100644 --- a/tools/python/util/build_helpers.py +++ b/tools/python/util/build_helpers.py @@ -179,3 +179,25 @@ def setup_migraphx_vars(args): f"migraphx_home='{migraphx_home}' valid={migraphx_home_not_valid}.", ) return migraphx_home or "" + + +def setup_cuda_vars(args): + cuda_home = "" + cudnn_home = "" + + if args.use_cuda: + cuda_home = args.cuda_home if args.cuda_home else os.getenv("CUDA_HOME") + cudnn_home = args.cudnn_home if args.cudnn_home else os.getenv("CUDNN_HOME") + + cuda_home_valid = cuda_home is not None and os.path.exists(cuda_home) + cudnn_home_valid = cudnn_home is not None and os.path.exists(cudnn_home) + + if not cuda_home_valid or (not is_windows() and not cudnn_home_valid): + raise BuildError( + "cuda_home and cudnn_home paths must be specified and valid.", + "cuda_home='{}' valid={}. cudnn_home='{}' valid={}".format( + cuda_home, cuda_home_valid, cudnn_home, cudnn_home_valid + ), + ) + + return cuda_home, cudnn_home diff --git a/tools/python/util/cuda_helpers.py b/tools/python/util/cuda_helpers.py index d72173cfc70a..81d4f3b01b4d 100644 --- a/tools/python/util/cuda_helpers.py +++ b/tools/python/util/cuda_helpers.py @@ -4,23 +4,3 @@ from .BuildError import BuildError from .platform_helpers import is_windows -def setup_cuda_vars(args): - cuda_home = "" - cudnn_home = "" - - if args.use_cuda: - cuda_home = args.cuda_home if args.cuda_home else os.getenv("CUDA_HOME") - cudnn_home = args.cudnn_home if args.cudnn_home else os.getenv("CUDNN_HOME") - - cuda_home_valid = cuda_home is not None and os.path.exists(cuda_home) - cudnn_home_valid = cudnn_home is not None and os.path.exists(cudnn_home) - - if not cuda_home_valid or (not is_windows() and not cudnn_home_valid): - raise BuildError( - "cuda_home and cudnn_home paths must be specified and valid.", - "cuda_home='{}' valid={}. cudnn_home='{}' valid={}".format( - cuda_home, cuda_home_valid, cudnn_home, cudnn_home_valid - ), - ) - - return cuda_home, cudnn_home From cc214df5d653766f5750a5de468b38631e599184 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 21:48:39 -0800 Subject: [PATCH 04/20] Remove cuda_helpers.py --- tools/python/util/cuda_helpers.py | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 tools/python/util/cuda_helpers.py diff --git a/tools/python/util/cuda_helpers.py b/tools/python/util/cuda_helpers.py deleted file mode 100644 index 81d4f3b01b4d..000000000000 --- a/tools/python/util/cuda_helpers.py +++ /dev/null @@ -1,6 +0,0 @@ -# // Copyright (c) Microsoft Corporation. All rights reserved. -# // Licensed under the MIT License. -import os -from .BuildError import BuildError -from .platform_helpers import is_windows - From 413e66e5b8570daa715be736b3cbe497d5ea742e Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 21:53:24 -0800 Subject: [PATCH 05/20] Reformat file again --- tools/ci_build/build.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 7ec4c1d10dbe..94e3592f8fff 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1293,8 +1293,8 @@ def generate_build_tree( ldflags = None cudaflags = [] for config in configs: - # Setup default values for cflags/cxxflags/ldflags. - # The values set here are purely for security and compliance purposes. ONNX Runtime should work fine without these flags. + # Setup default values for cflags/cxxflags/ldflags. The values set here are purely for security and + # compliance purposes. ONNX Runtime should work fine without these flags. if ( "CFLAGS" not in os.environ and "CXXFLAGS" not in os.environ @@ -1317,8 +1317,9 @@ def generate_build_tree( "/D_WIN32_WINNT=0x0A00", "/DNTDDI_VERSION=0x0A000000", ] - # The "/profile" flag implies "/DEBUG:FULL /DEBUGTYPE:cv,fixup /OPT:REF /OPT:NOICF /INCREMENTAL:NO /FIXED:NO". We set it for satisfying a Microsoft internal compliance requirement. External users - # do not need to have it. + # The "/profile" flag implies "/DEBUG:FULL /DEBUGTYPE:cv,fixup /OPT:REF /OPT:NOICF /INCREMENTAL:NO + # /FIXED:NO". We set it for satisfying a Microsoft internal compliance requirement. External users do + # not need to have it. ldflags = ["/profile", "/DYNAMICBASE"] if args.enable_qspectre: cflags += ["/Qspectre"] From ad65375a1a26b9fdafd08ab33e192928620394d3 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 22:02:32 -0800 Subject: [PATCH 06/20] Adding dot to import files --- tools/python/util/build_helpers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/python/util/build_helpers.py b/tools/python/util/build_helpers.py index c96975511354..9b91b886219d 100644 --- a/tools/python/util/build_helpers.py +++ b/tools/python/util/build_helpers.py @@ -4,8 +4,8 @@ import sys import shutil import os -from UsageError import UsageError -from BuildError import BuildError +from .UsageError import UsageError +from .BuildError import BuildError from .platform_helpers import is_windows, is_macOS From 6d07a50d10e1ef5cc50314e36521dfbe7373b44c Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 22:07:30 -0800 Subject: [PATCH 07/20] Adding dot to import files --- tools/python/util/BuildError.py | 2 +- tools/python/util/UsageError.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/python/util/BuildError.py b/tools/python/util/BuildError.py index e9898330e85f..1c3670b4e47d 100644 --- a/tools/python/util/BuildError.py +++ b/tools/python/util/BuildError.py @@ -1,6 +1,6 @@ # // Copyright (c) Microsoft Corporation. All rights reserved. # // Licensed under the MIT License. -import BaseError +from .BaseError import BaseError class BuildError(BaseError): diff --git a/tools/python/util/UsageError.py b/tools/python/util/UsageError.py index bb54fe6cef8e..94ac35898432 100644 --- a/tools/python/util/UsageError.py +++ b/tools/python/util/UsageError.py @@ -1,6 +1,6 @@ # // Copyright (c) Microsoft Corporation. All rights reserved. # // Licensed under the MIT License. -import BaseError +from .BaseError import BaseError class UsageError(BaseError): From add33e1fe089c7220fa3e89aff3eeb92157c227a Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 22:12:40 -0800 Subject: [PATCH 08/20] Adding missing class BaseError(Exception): """Base class for errors originating from build.py.""" pass --- tools/python/util/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/python/util/__init__.py b/tools/python/util/__init__.py index 3acf989a778c..0bd2159b7b8c 100644 --- a/tools/python/util/__init__.py +++ b/tools/python/util/__init__.py @@ -23,7 +23,7 @@ setup_cuda_vars, ) - +from .BaseError import BaseError from .UsageError import UsageError from .BuildError import BuildError from .open_vino_utils import openvino_verify_device_type From ca47978b81ff51fba3d1a7d555945d30332e3214 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Mon, 15 Jan 2024 22:23:25 -0800 Subject: [PATCH 09/20] Removed unused file --- tools/ci_build/build.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 94e3592f8fff..debf4c9de936 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -734,11 +734,8 @@ def update_submodules(source_dir): def install_python_deps(numpy_version=""): - dep_packages = ["setuptools", "wheel", "pytest"] - dep_packages.append(f"numpy=={numpy_version}" if numpy_version else "numpy>=1.16.6") - dep_packages.append("sympy>=1.10") - dep_packages.append("packaging") - dep_packages.append("cerberus") + dep_packages = ["setuptools", "wheel", "pytest", f"numpy=={numpy_version}" if numpy_version else "numpy>=1.16.6", + "sympy>=1.10", "packaging", "cerberus"] run_subprocess([sys.executable, "-m", "pip", "install", *dep_packages]) @@ -2129,16 +2126,6 @@ def run_csharp_tests(source_dir, build_dir, use_cuda, use_openvino, use_tensorrt run_subprocess(cmd_args, cwd=csharp_source_dir) -def is_cross_compiling_on_apple(args): - if not is_macOS(): - return False - if args.ios: - return True - if args.osx_arch != platform.machine(): - return True - return False - - def generate_documentation(source_dir, build_dir, configs, validate): # Randomly choose one build config config = next(iter(configs)) From 1f89cb9b1ba46261a29416ef60549561a6eb2dc6 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 16 Jan 2024 11:39:50 -0800 Subject: [PATCH 10/20] Update tools/ci_build/build.py Co-authored-by: Justin Chu --- tools/ci_build/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index debf4c9de936..a7de4d4d342e 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -19,7 +19,7 @@ sys.path.insert(0, os.path.join(REPO_DIR, "tools", "python")) -# The Following uil packages is from onnxruntime/tools/python/util +# The Following utility packages are from onnxruntime/tools/python/util import util.android as android # noqa: E402 from util import ( get_logger, From 7c4579467a2874646e84dc93b97819eb1a25e8a2 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 16 Jan 2024 11:53:49 -0800 Subject: [PATCH 11/20] Change file name case --- .gitignore | 3 +-- tools/python/util/__init__.py | 6 +++--- tools/python/util/{BaseError.py => base_error.py} | 0 tools/python/util/{BuildError.py => build_error.py} | 2 +- tools/python/util/{UsageError.py => usage_error.py} | 2 +- 5 files changed, 6 insertions(+), 7 deletions(-) rename tools/python/util/{BaseError.py => base_error.py} (100%) rename tools/python/util/{BuildError.py => build_error.py} (88%) rename tools/python/util/{UsageError.py => usage_error.py} (87%) diff --git a/.gitignore b/.gitignore index abd4d7a631db..53af0019a7b5 100644 --- a/.gitignore +++ b/.gitignore @@ -195,5 +195,4 @@ Package.pins Package.resolved .build/ .swiftpm/ -repros/ -!/tools/ci_build/build_uitl/ +repros/ \ No newline at end of file diff --git a/tools/python/util/__init__.py b/tools/python/util/__init__.py index 0bd2159b7b8c..3cd62a417118 100644 --- a/tools/python/util/__init__.py +++ b/tools/python/util/__init__.py @@ -23,9 +23,9 @@ setup_cuda_vars, ) -from .BaseError import BaseError -from .UsageError import UsageError -from .BuildError import BuildError +from .base_error import BaseError +from .usage_error import UsageError +from .build_error import BuildError from .open_vino_utils import openvino_verify_device_type try: diff --git a/tools/python/util/BaseError.py b/tools/python/util/base_error.py similarity index 100% rename from tools/python/util/BaseError.py rename to tools/python/util/base_error.py diff --git a/tools/python/util/BuildError.py b/tools/python/util/build_error.py similarity index 88% rename from tools/python/util/BuildError.py rename to tools/python/util/build_error.py index 1c3670b4e47d..37ad94823d8c 100644 --- a/tools/python/util/BuildError.py +++ b/tools/python/util/build_error.py @@ -1,6 +1,6 @@ # // Copyright (c) Microsoft Corporation. All rights reserved. # // Licensed under the MIT License. -from .BaseError import BaseError +from .base_error import BaseError class BuildError(BaseError): diff --git a/tools/python/util/UsageError.py b/tools/python/util/usage_error.py similarity index 87% rename from tools/python/util/UsageError.py rename to tools/python/util/usage_error.py index 94ac35898432..d63538344ad4 100644 --- a/tools/python/util/UsageError.py +++ b/tools/python/util/usage_error.py @@ -1,6 +1,6 @@ # // Copyright (c) Microsoft Corporation. All rights reserved. # // Licensed under the MIT License. -from .BaseError import BaseError +from .base_error import BaseError class UsageError(BaseError): From 62d14751bbd1cbfcfe5453f750a3df7962c10b86 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 16 Jan 2024 12:03:30 -0800 Subject: [PATCH 12/20] Remove sys.path --- tools/ci_build/build.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index a7de4d4d342e..82584c33fa3d 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -13,15 +13,10 @@ import subprocess import sys from pathlib import Path - -SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) -REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..")) - -sys.path.insert(0, os.path.join(REPO_DIR, "tools", "python")) +from ..python.util import android # The Following utility packages are from onnxruntime/tools/python/util -import util.android as android # noqa: E402 -from util import ( +from ..python.util import ( get_logger, is_linux, is_macOS, @@ -47,6 +42,7 @@ setup_cann_vars, ) # noqa: E402 +SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) log = get_logger("build") check_python_version() From 56e3f4dfa8ef6a722678a2c1a424b7aad7065ef5 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 16 Jan 2024 12:20:54 -0800 Subject: [PATCH 13/20] Update tools/python/util/build_helpers.py Co-authored-by: Justin Chu --- tools/python/util/build_helpers.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/python/util/build_helpers.py b/tools/python/util/build_helpers.py index 9b91b886219d..0904ff002940 100644 --- a/tools/python/util/build_helpers.py +++ b/tools/python/util/build_helpers.py @@ -88,9 +88,16 @@ def number_of_nvcc_threads(args): return args.nvcc_threads nvcc_threads = 1 - import psutil + try: - available_memory = psutil.virtual_memory().available + import psutil + except ImportError: + print( + "Failed to import psutil. Please `pip install psutil` for better estimation of nvcc threads. Use " + "nvcc_threads=1" + ) + + available_memory = psutil.virtual_memory().available if isinstance(available_memory, int) and available_memory > 0: if available_memory > 60 * 1024 * 1024 * 1024: # When available memory is large enough, chance of OOM is small. From b218d5964da043944b4d9df33d5ea5ea2430852c Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 16 Jan 2024 12:21:17 -0800 Subject: [PATCH 14/20] Update tools/python/util/usage_error.py Co-authored-by: Justin Chu --- tools/python/util/usage_error.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/python/util/usage_error.py b/tools/python/util/usage_error.py index d63538344ad4..815680822cc8 100644 --- a/tools/python/util/usage_error.py +++ b/tools/python/util/usage_error.py @@ -6,5 +6,3 @@ class UsageError(BaseError): """Usage related error.""" - def __init__(self, message): - super().__init__(message) From 6d3800948bfdf2008e75c8025c8dc1889ffc97b6 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 16 Jan 2024 12:39:27 -0800 Subject: [PATCH 15/20] Update format --- tools/python/util/build_helpers.py | 17 ++++------------- tools/python/util/open_vino_utils.py | 12 ++++++------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tools/python/util/build_helpers.py b/tools/python/util/build_helpers.py index 0904ff002940..d21cd1bff17e 100644 --- a/tools/python/util/build_helpers.py +++ b/tools/python/util/build_helpers.py @@ -4,8 +4,8 @@ import sys import shutil import os -from .UsageError import UsageError -from .BuildError import BuildError +from .usage_error import UsageError +from .build_error import BuildError from .platform_helpers import is_windows, is_macOS @@ -71,7 +71,7 @@ def use_dev_mode(args): def add_default_definition(definition_list, key, default_value): for x in definition_list: if x.startswith(key + "="): - return definition_list + return definition_list.append(key + "=" + default_value) @@ -86,18 +86,10 @@ def number_of_parallel_jobs(args): def number_of_nvcc_threads(args): if args.nvcc_threads >= 0: return args.nvcc_threads - nvcc_threads = 1 - try: import psutil - except ImportError: - print( - "Failed to import psutil. Please `pip install psutil` for better estimation of nvcc threads. Use " - "nvcc_threads=1" - ) - - available_memory = psutil.virtual_memory().available + available_memory = psutil.virtual_memory().available if isinstance(available_memory, int) and available_memory > 0: if available_memory > 60 * 1024 * 1024 * 1024: # When available memory is large enough, chance of OOM is small. @@ -127,7 +119,6 @@ def number_of_nvcc_threads(args): def setup_cann_vars(args): cann_home = "" - if args.use_cann: cann_home = args.cann_home if args.cann_home else os.getenv("ASCEND_HOME_PATH") diff --git a/tools/python/util/open_vino_utils.py b/tools/python/util/open_vino_utils.py index b709b6014a2b..a82913d18778 100644 --- a/tools/python/util/open_vino_utils.py +++ b/tools/python/util/open_vino_utils.py @@ -36,9 +36,9 @@ def add_openvino_libs_to_path() -> None: def openvino_verify_device_type(device_read): - choices = ["CPU_FP32", "CPU_FP16", "GPU_FP32", "GPU_FP16"] + supported_fp = ["CPU_FP32", "CPU_FP16", "GPU_FP32", "GPU_FP16"] - choices1 = [ + supported_fp_no_partition = [ "CPU_FP32_NO_PARTITION", "CPU_FP16_NO_PARTITION", "GPU_FP32_NO_PARTITION", @@ -46,9 +46,9 @@ def openvino_verify_device_type(device_read): ] status_hetero = True res = False - if device_read in choices: + if device_read in supported_fp: res = True - elif device_read in choices1: + elif device_read in supported_fp_no_partition: res = True elif device_read.startswith("HETERO:") or device_read.startswith("MULTI:") or device_read.startswith("AUTO:"): res = True @@ -76,8 +76,8 @@ def invalid_hetero_build(): if res is False: print("\nYou have selected wrong configuration for the build.") - print("pick the build type for specific Hardware Device from following options: ", choices) - print("(or) from the following options with graph partitioning disabled: ", choices1) + print("pick the build type for specific Hardware Device from following options: ", supported_fp) + print("(or) from the following options with graph partitioning disabled: ", supported_fp_no_partition) print("\n") if not (device_read.startswith("HETERO") or device_read.startswith("MULTI") or device_read.startswith("AUTO")): invalid_hetero_build() From 196d5b94534892dedb1be7cd24bb9b2c1e1f1c87 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 16 Jan 2024 12:44:25 -0800 Subject: [PATCH 16/20] Merging Errors into 1 module --- tools/python/util/__init__.py | 4 +--- tools/python/util/base_error.py | 6 ------ tools/python/util/{build_error.py => build_errors.py} | 9 ++++++++- tools/python/util/build_helpers.py | 3 +-- tools/python/util/usage_error.py | 8 -------- 5 files changed, 10 insertions(+), 20 deletions(-) delete mode 100644 tools/python/util/base_error.py rename tools/python/util/{build_error.py => build_errors.py} (61%) delete mode 100644 tools/python/util/usage_error.py diff --git a/tools/python/util/__init__.py b/tools/python/util/__init__.py index 3cd62a417118..b3b28d9aa6a7 100644 --- a/tools/python/util/__init__.py +++ b/tools/python/util/__init__.py @@ -23,9 +23,7 @@ setup_cuda_vars, ) -from .base_error import BaseError -from .usage_error import UsageError -from .build_error import BuildError +from .build_errors import BaseError, BuildError, UsageError from .open_vino_utils import openvino_verify_device_type try: diff --git a/tools/python/util/base_error.py b/tools/python/util/base_error.py deleted file mode 100644 index 668fe6b285ce..000000000000 --- a/tools/python/util/base_error.py +++ /dev/null @@ -1,6 +0,0 @@ -# // Copyright (c) Microsoft Corporation. All rights reserved. -# // Licensed under the MIT License. -class BaseError(Exception): - """Base class for errors originating from build.py.""" - - pass diff --git a/tools/python/util/build_error.py b/tools/python/util/build_errors.py similarity index 61% rename from tools/python/util/build_error.py rename to tools/python/util/build_errors.py index 37ad94823d8c..ffd13416622e 100644 --- a/tools/python/util/build_error.py +++ b/tools/python/util/build_errors.py @@ -1,6 +1,9 @@ # // Copyright (c) Microsoft Corporation. All rights reserved. # // Licensed under the MIT License. -from .base_error import BaseError +class BaseError(Exception): + """Base class for errors originating from build.py.""" + + pass class BuildError(BaseError): @@ -8,3 +11,7 @@ class BuildError(BaseError): def __init__(self, *messages): super().__init__("\n".join(messages)) + + +class UsageError(BaseError): + """Usage related error.""" diff --git a/tools/python/util/build_helpers.py b/tools/python/util/build_helpers.py index d21cd1bff17e..0c7f1e72175b 100644 --- a/tools/python/util/build_helpers.py +++ b/tools/python/util/build_helpers.py @@ -4,8 +4,7 @@ import sys import shutil import os -from .usage_error import UsageError -from .build_error import BuildError +from .build_errors import BuildError, UsageError from .platform_helpers import is_windows, is_macOS diff --git a/tools/python/util/usage_error.py b/tools/python/util/usage_error.py deleted file mode 100644 index 815680822cc8..000000000000 --- a/tools/python/util/usage_error.py +++ /dev/null @@ -1,8 +0,0 @@ -# // Copyright (c) Microsoft Corporation. All rights reserved. -# // Licensed under the MIT License. -from .base_error import BaseError - - -class UsageError(BaseError): - """Usage related error.""" - From fafe56d181f85bfc774ec590da9ac02ea732240f Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 16 Jan 2024 14:30:01 -0800 Subject: [PATCH 17/20] Update parent module path --- tools/ci_build/build.py | 2 +- tools/python/util/build_helpers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 82584c33fa3d..811d84337d5e 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -13,7 +13,7 @@ import subprocess import sys from pathlib import Path -from ..python.util import android +from ..python.util.android import android # The Following utility packages are from onnxruntime/tools/python/util from ..python.util import ( diff --git a/tools/python/util/build_helpers.py b/tools/python/util/build_helpers.py index 0c7f1e72175b..766a7e9191d9 100644 --- a/tools/python/util/build_helpers.py +++ b/tools/python/util/build_helpers.py @@ -17,7 +17,7 @@ def version_to_tuple(version: str) -> tuple: def check_python_version(): - required_minor_version = 7 + required_minor_version = 8 if (sys.version_info.major, sys.version_info.minor) < (3, required_minor_version): raise UsageError( f"Invalid Python version. At least Python 3.{required_minor_version} is required. " From 8da3a84956433884e922cdd35731e7e7398f3aaf Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Thu, 18 Jan 2024 13:45:04 -0800 Subject: [PATCH 18/20] Import android --- tools/ci_build/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 8283481e56c0..d5e00652eb00 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -13,7 +13,7 @@ import subprocess import sys from pathlib import Path -from ..python.util.android import android +from ..python.util import android as android # The Following utility packages are from onnxruntime/tools/python/util from ..python.util import ( From 10e2aeabb3aa4ab3524ef6e201ef7430d75c04f7 Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Thu, 18 Jan 2024 14:34:15 -0800 Subject: [PATCH 19/20] Adding back sys.path --- tools/ci_build/build.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index d5e00652eb00..f7b58d8a56b5 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -13,10 +13,14 @@ import subprocess import sys from pathlib import Path -from ..python.util import android as android +SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) +REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..")) + +sys.path.insert(0, os.path.join(REPO_DIR, "tools", "python")) # The Following utility packages are from onnxruntime/tools/python/util -from ..python.util import ( +import util.android as android # noqa: E402 +from util import ( get_logger, is_linux, is_macOS, @@ -42,7 +46,6 @@ setup_cann_vars, ) # noqa: E402 -SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) log = get_logger("build") check_python_version() From 64e8252028b24ee3c0e2ed21f5505861d451aa9d Mon Sep 17 00:00:00 2001 From: Jian Chen Date: Tue, 21 May 2024 10:33:25 -0700 Subject: [PATCH 20/20] dotnet tool install --global protoc --- tools/python/util/build_helpers.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/python/util/build_helpers.py b/tools/python/util/build_helpers.py index 766a7e9191d9..6ea6d74abf71 100644 --- a/tools/python/util/build_helpers.py +++ b/tools/python/util/build_helpers.py @@ -59,7 +59,7 @@ def use_dev_mode(args): return False if args.use_armnn: return False - if args.ios and is_macOS(): + if args.ios and is_macOS() or args.visionos: return False SYSTEM_COLLECTIONURI = os.getenv("SYSTEM_COLLECTIONURI") # noqa: N806 if SYSTEM_COLLECTIONURI and SYSTEM_COLLECTIONURI != "https://dev.azure.com/onnxruntime/": @@ -102,7 +102,8 @@ def number_of_nvcc_threads(args): memory_per_thread = 4 * 1024 * 1024 * 1024 fmha_cu_files = 4 if is_windows() else 16 fmha_parallel_jobs = min(fmha_cu_files, number_of_parallel_jobs(args)) - nvcc_threads = max(1, int(available_memory / (memory_per_thread * fmha_parallel_jobs))) + nvcc_threads = max(1, + int(available_memory / (memory_per_thread * fmha_parallel_jobs))) print( f"nvcc_threads={nvcc_threads} to ensure memory per thread >= 4GB for available_memory=" f"{available_memory} and fmha_parallel_jobs={fmha_parallel_jobs}" @@ -192,9 +193,8 @@ def setup_cuda_vars(args): if not cuda_home_valid or (not is_windows() and not cudnn_home_valid): raise BuildError( "cuda_home and cudnn_home paths must be specified and valid.", - "cuda_home='{}' valid={}. cudnn_home='{}' valid={}".format( - cuda_home, cuda_home_valid, cudnn_home, cudnn_home_valid - ), + f"cuda_home='{cuda_home}' valid={cuda_home_valid}. cudnn_home='{cudnn_home}'" + f" valid={cudnn_home_valid}",, ) - return cuda_home, cudnn_home + return cuda_home, cudnn_home