已合并
build: 升级C++编译标准至c++20 #3478
chz34创建于 25 天前
build: 升级C++编译标准至c++20 #3478
已合并
共 8 个文件变更+12-12
| @@ -1,7 +1,7 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.14) | 1 | cmake_minimum_required(VERSION 3.14) |
| 2 | project(AscendAdapter2) | 2 | project(AscendAdapter2) |
| 3 | 3 | ||
| 4 | -set(CMAKE_CXX_STANDARD 17) | 4 | +set(CMAKE_CXX_STANDARD 20) |
| 5 | set(CMAKE_CXX_FLAGS "-D_FORTIFY_SOURCE=2 -Wno-class-memaccess -Wno-float-equal -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-comment -Wno-deprecated-declarations -Wall -fPIC -fPIE -pie -s -fstack-protector-all -Wl,--no-as-needed -Wl,-z,relro,-z,now,-z,noexecstack -fno-common -pipe -fno-strict-aliasing -Wdate-time -Wformat=2 -Wno-shadow -Wno-undef -Wunused -Wdelete-non-virtual-dtor -Wnon-virtual-dtor -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}") | 5 | set(CMAKE_CXX_FLAGS "-D_FORTIFY_SOURCE=2 -Wno-class-memaccess -Wno-float-equal -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-comment -Wno-deprecated-declarations -Wall -fPIC -fPIE -pie -s -fstack-protector-all -Wl,--no-as-needed -Wl,-z,relro,-z,now,-z,noexecstack -fno-common -pipe -fno-strict-aliasing -Wdate-time -Wformat=2 -Wno-shadow -Wno-undef -Wunused -Wdelete-non-virtual-dtor -Wnon-virtual-dtor -Wno-overloaded-virtual ${CMAKE_CXX_FLAGS}") |
| 6 | set(CMAKE_SKIP_RPATH TRUE) | 6 | set(CMAKE_SKIP_RPATH TRUE) |
| 7 | 7 | ||
| @@ -62,7 +62,7 @@ class AscendBuildExtension(build_ext): | |||
| 62 | "--npu-arch=dav-2201", | 62 | "--npu-arch=dav-2201", |
| 63 | "-shared", | 63 | "-shared", |
| 64 | "-fPIC", | 64 | "-fPIC", |
| 65 | - "-std=c++17", | 65 | + "-std=c++20", |
| 66 | f"-D_GLIBCXX_USE_CXX11_ABI={abi_value}", | 66 | f"-D_GLIBCXX_USE_CXX11_ABI={abi_value}", |
| 67 | "-ltorch_npu", | 67 | "-ltorch_npu", |
| 68 | "-ltorch", | 68 | "-ltorch", |
| @@ -62,7 +62,7 @@ class AscendBuildExtension(build_ext): | |||
| 62 | "--npu-arch=dav-2201", | 62 | "--npu-arch=dav-2201", |
| 63 | "-shared", | 63 | "-shared", |
| 64 | "-fPIC", | 64 | "-fPIC", |
| 65 | - "-std=c++17", | 65 | + "-std=c++20", |
| 66 | f"-D_GLIBCXX_USE_CXX11_ABI={abi_value}", | 66 | f"-D_GLIBCXX_USE_CXX11_ABI={abi_value}", |
| 67 | "-ltorch_npu", | 67 | "-ltorch_npu", |
| 68 | "-ltorch", | 68 | "-ltorch", |
| @@ -214,7 +214,7 @@ class AscCompilerStub: | |||
| 214 | with tempfile.NamedTemporaryFile(suffix='.cpp', mode='w+', delete=True) as temp_file: | 214 | with tempfile.NamedTemporaryFile(suffix='.cpp', mode='w+', delete=True) as temp_file: |
| 215 | temp_file.write('\n'.join([tiling_def, host_tiling, op_kernel])) | 215 | temp_file.write('\n'.join([tiling_def, host_tiling, op_kernel])) |
| 216 | temp_file.flush() | 216 | temp_file.flush() |
| 217 | - args = ["g++", "-shared", "-std=c++17", "-fPIC", "-Wall", "-O2", "-o", output_file, temp_file.name] | 217 | + args = ["g++", "-shared", "-std=c++20", "-fPIC", "-Wall", "-O2", "-o", output_file, temp_file.name] |
| 218 | logger.debug(' '.join(args)) | 218 | logger.debug(' '.join(args)) |
| 219 | subprocess.run(args, check=True) | 219 | subprocess.run(args, check=True) |
| 220 | 220 | ||
| @@ -230,7 +230,7 @@ class AscCompilerStub: | |||
| 230 | args = [ | 230 | args = [ |
| 231 | "g++", | 231 | "g++", |
| 232 | "-shared", | 232 | "-shared", |
| 233 | - "-std=c++17", | 233 | + "-std=c++20", |
| 234 | "-fPIC", | 234 | "-fPIC", |
| 235 | "-Wall", | 235 | "-Wall", |
| 236 | "-O2", | 236 | "-O2", |
| @@ -251,6 +251,6 @@ class AscCompilerStub: | |||
| 251 | with tempfile.NamedTemporaryFile(suffix='.cpp', mode='w+', delete=True) as temp_file: | 251 | with tempfile.NamedTemporaryFile(suffix='.cpp', mode='w+', delete=True) as temp_file: |
| 252 | temp_file.write('\n'.join([tiling_def, device_impl])) | 252 | temp_file.write('\n'.join([tiling_def, device_impl])) |
| 253 | temp_file.flush() | 253 | temp_file.flush() |
| 254 | - args = ["g++", "-shared", "-std=c++17", "-fPIC", "-Wall", "-O2", "-o", output_file, temp_file.name] | 254 | + args = ["g++", "-shared", "-std=c++20", "-fPIC", "-Wall", "-O2", "-o", output_file, temp_file.name] |
| 255 | logger.debug(' '.join(args)) | 255 | logger.debug(' '.join(args)) |
| 256 | subprocess.run(args, check=True) | 256 | subprocess.run(args, check=True) |
| @@ -174,7 +174,7 @@ def build_ascend_lib(kernel_py): | |||
| 174 | 174 | ||
| 175 | 175 | ||
| 176 | def _build_cpp(wrapper_cpp: str, *, compile_flags, output_file): | 176 | def _build_cpp(wrapper_cpp: str, *, compile_flags, output_file): |
| 177 | - args = ["g++", "-shared", "-std=c++17", "-fPIC", "-w", "-O2", "-o", output_file, wrapper_cpp] + compile_flags | 177 | + args = ["g++", "-shared", "-std=c++20", "-fPIC", "-w", "-O2", "-o", output_file, wrapper_cpp] + compile_flags |
| 178 | try: | 178 | try: |
| 179 | subprocess.run(args, check=True) | 179 | subprocess.run(args, check=True) |
| 180 | except subprocess.CalledProcessError: | 180 | except subprocess.CalledProcessError: |
| @@ -245,7 +245,7 @@ def get_kernel_hash(tiling_info: TilingInfo): | |||
| 245 | def compile_wrapper(lib_dir, kernel_spec, asserts_base, compile_flags): | 245 | def compile_wrapper(lib_dir, kernel_spec, asserts_base, compile_flags): |
| 246 | lib_wrapper = os.path.join(lib_dir, "wrapper.so") | 246 | lib_wrapper = os.path.join(lib_dir, "wrapper.so") |
| 247 | compile_comments = ' '.join( | 247 | compile_comments = ' '.join( |
| 248 | - ["//", "g++", "-shared", "-std=c++17", "-fPIC", "-Wall", "-O2", "-o", lib_wrapper, "inductor_wrapper.cpp"] | 248 | + ["//", "g++", "-shared", "-std=c++20", "-fPIC", "-Wall", "-O2", "-o", lib_wrapper, "inductor_wrapper.cpp"] |
| 249 | + compile_flags | 249 | + compile_flags |
| 250 | + ['\n'] | 250 | + ['\n'] |
| 251 | ) | 251 | ) |
| @@ -264,7 +264,7 @@ def compile_tiling_wrapper(lib_dir, kernel_spec, asserts_base, compile_flags): | |||
| 264 | "//", | 264 | "//", |
| 265 | "g++", | 265 | "g++", |
| 266 | "-shared", | 266 | "-shared", |
| 267 | - "-std=c++17", | 267 | + "-std=c++20", |
| 268 | "-fPIC", | 268 | "-fPIC", |
| 269 | "-Wall", | 269 | "-Wall", |
| 270 | "-O2", | 270 | "-O2", |
| @@ -99,7 +99,7 @@ def build_gcc_command( | |||
| 99 | "g++", | 99 | "g++", |
| 100 | "-shared", | 100 | "-shared", |
| 101 | "-fPIC", | 101 | "-fPIC", |
| 102 | - "-std=c++17", | 102 | + "-std=c++20", |
| 103 | "-O2", | 103 | "-O2", |
| 104 | ] | 104 | ] |
| 105 | parts.extend(includes) | 105 | parts.extend(includes) |
| @@ -3,7 +3,7 @@ project(TorchairTest) | |||
| 3 | 3 | ||
| 4 | set(TORCHAIR_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../) | 4 | set(TORCHAIR_SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../) |
| 5 | 5 | ||
| 6 | -set(CMAKE_CXX_STANDARD 17) | 6 | +set(CMAKE_CXX_STANDARD 20) |
| 7 | 7 | ||
| 8 | file(STRINGS "${TORCHAIR_SRC_DIR}/tools/TORCH_INSTALLED_PATH" TORCH_INSTALLED_PATH) | 8 | file(STRINGS "${TORCHAIR_SRC_DIR}/tools/TORCH_INSTALLED_PATH" TORCH_INSTALLED_PATH) |
| 9 | set(ASCEND_SDK_HEADERS_PATH ${TORCHAIR_SRC_DIR}/third_party/ascend) | 9 | set(ASCEND_SDK_HEADERS_PATH ${TORCHAIR_SRC_DIR}/third_party/ascend) |
| @@ -59,7 +59,7 @@ class TestBuildGccCommand(unittest.TestCase): | |||
| 59 | self.assertIn("g++", cmd) | 59 | self.assertIn("g++", cmd) |
| 60 | self.assertIn("-shared", cmd) | 60 | self.assertIn("-shared", cmd) |
| 61 | self.assertIn("-fPIC", cmd) | 61 | self.assertIn("-fPIC", cmd) |
| 62 | - self.assertIn("-std=c++17", cmd) | 62 | + self.assertIn("-std=c++20", cmd) |
| 63 | self.assertIn("-O2", cmd) | 63 | self.assertIn("-O2", cmd) |
| 64 | self.assertIn("-I/torch/include", cmd) | 64 | self.assertIn("-I/torch/include", cmd) |
| 65 | self.assertIn("-I/torch/include/torch/csrc/api/include", cmd) | 65 | self.assertIn("-I/torch/include/torch/csrc/api/include", cmd) |