From f9369e16e22be813a4d8bb03c407386f499c2464 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Fri, 12 Jan 2024 11:13:59 -0800 Subject: [PATCH 1/5] update --- tools/ci_build/build.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 315b9a237b1c4..33ab7f06418b4 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1474,12 +1474,14 @@ def generate_build_tree( cflags = None cxxflags = None ldflags = None + cudaflags = None 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. 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 @@ -1515,6 +1517,9 @@ def generate_build_tree( cxxflags = cflags.copy() if not args.disable_exceptions: cxxflags += ["/EHsc"] + if args.use_cuda: + # On Windows, nvcc passes /EHsc to the host compiler by default. + cudaflags = cflags.copy() elif is_linux() or is_macOS(): if is_linux(): ldflags = ["-Wl,-Bsymbolic-functions", "-Wl,-z,relro", "-Wl,-z,now"] @@ -1560,7 +1565,8 @@ def generate_build_tree( # The following flags needs GCC 8 and newer cflags += ["-fstack-clash-protection", "-fcf-protection"] cxxflags = cflags.copy() - + if args.use_cuda: + cudaflags = cflags.copy() config_build_dir = get_config_build_dir(build_dir, config) os.makedirs(config_build_dir, exist_ok=True) if args.use_tvm: @@ -1580,6 +1586,8 @@ def generate_build_tree( "-DCMAKE_C_FLAGS=%s" % (" ".join(cflags)), "-DCMAKE_CXX_FLAGS=%s" % (" ".join(cxxflags)), ] + if cudaflags is not None: + temp_cmake_args += ["-DCMAKE_CUDA_FLAGS_INIT=%s" % (" ".join(cudaflags))] if ldflags is not None and len(ldflags) != 0: temp_cmake_args += [ "-DCMAKE_EXE_LINKER_FLAGS_INIT=%s" % (" ".join(ldflags)), From 0894b9d45a7ba761628b9a0ad1f3bff4fdcc6ee9 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Fri, 12 Jan 2024 13:58:42 -0800 Subject: [PATCH 2/5] update --- tools/ci_build/build.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 33ab7f06418b4..8ae0fd2bb53aa 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1474,7 +1474,7 @@ def generate_build_tree( cflags = None cxxflags = None ldflags = None - cudaflags = 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. @@ -1519,7 +1519,14 @@ def generate_build_tree( cxxflags += ["/EHsc"] if args.use_cuda: # On Windows, nvcc passes /EHsc to the host compiler by default. - cudaflags = cflags.copy() + cuda_compile_flags_str = "" + for compile_flag in cflags: + if compile_flag.startswith("/D"): + cudaflags.append(compile_flag) + else: + cuda_compile_flags_str =cuda_compile_flags_str + " " + compile_flag + if len(cuda_compile_flags_str) !=0: + cudaflags.append("-Xcompiler=\"%s\"" % cuda_compile_flags_str) elif is_linux() or is_macOS(): if is_linux(): ldflags = ["-Wl,-Bsymbolic-functions", "-Wl,-z,relro", "-Wl,-z,now"] @@ -1586,7 +1593,7 @@ def generate_build_tree( "-DCMAKE_C_FLAGS=%s" % (" ".join(cflags)), "-DCMAKE_CXX_FLAGS=%s" % (" ".join(cxxflags)), ] - if cudaflags is not None: + if cudaflags is not None and len(cudaflags) != 0: temp_cmake_args += ["-DCMAKE_CUDA_FLAGS_INIT=%s" % (" ".join(cudaflags))] if ldflags is not None and len(ldflags) != 0: temp_cmake_args += [ From be8787e13ef8e13b65ae07d7c4c3ca02840a48be Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Fri, 12 Jan 2024 19:38:30 -0800 Subject: [PATCH 3/5] update --- tools/ci_build/build.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 8ae0fd2bb53aa..34b97e4809565 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1524,11 +1524,11 @@ def generate_build_tree( if compile_flag.startswith("/D"): cudaflags.append(compile_flag) else: - cuda_compile_flags_str =cuda_compile_flags_str + " " + compile_flag - if len(cuda_compile_flags_str) !=0: - cudaflags.append("-Xcompiler=\"%s\"" % cuda_compile_flags_str) + cuda_compile_flags_str = cuda_compile_flags_str + " " + compile_flag + if len(cuda_compile_flags_str) != 0: + cudaflags.append('-Xcompiler="%s"' % cuda_compile_flags_str) elif is_linux() or is_macOS(): - if is_linux(): + if is_linux() and not args.use_rocm: ldflags = ["-Wl,-Bsymbolic-functions", "-Wl,-z,relro", "-Wl,-z,now"] else: ldflags = [] From ac9426584d1da82305dad28981ecd990397dc6d1 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Fri, 12 Jan 2024 20:14:37 -0800 Subject: [PATCH 4/5] update --- tools/ci_build/build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 34b97e4809565..41ab23d655eea 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1485,6 +1485,7 @@ def generate_build_tree( 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(): @@ -1528,7 +1529,7 @@ def generate_build_tree( if len(cuda_compile_flags_str) != 0: cudaflags.append('-Xcompiler="%s"' % cuda_compile_flags_str) elif is_linux() or is_macOS(): - if is_linux() and not args.use_rocm: + if is_linux(): ldflags = ["-Wl,-Bsymbolic-functions", "-Wl,-z,relro", "-Wl,-z,now"] else: ldflags = [] From 09caf6bf49c311da9e1395a46a8f48e54173ff75 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Fri, 12 Jan 2024 20:48:08 -0800 Subject: [PATCH 5/5] update --- 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 41ab23d655eea..0da4adb51767d 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -1530,7 +1530,7 @@ def generate_build_tree( cudaflags.append('-Xcompiler="%s"' % cuda_compile_flags_str) elif is_linux() or is_macOS(): if is_linux(): - ldflags = ["-Wl,-Bsymbolic-functions", "-Wl,-z,relro", "-Wl,-z,now"] + ldflags = ["-Wl,-Bsymbolic-functions", "-Wl,-z,relro", "-Wl,-z,now", "-Wl,-z,noexecstack"] else: ldflags = [] if config == "Release":