已合并
fix: lintrunner --all-files --take NEWLINE -a #35875
Jingwei Huang创建于 5月17日
fix: lintrunner --all-files --take NEWLINE -a #35875
已合并
Jingwei Huang创建于 5月17日
88 个文件变更+16689-16703
@@ -1,387 +1,386 @@
1-cmake_minimum_required(VERSION 3.18 FATAL_ERROR)1+cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
2- 2+ 
3-find_program(CCACHE ccache)3+find_program(CCACHE ccache)
4-if(${CCACHE} STREQUAL "CCACHE-NOTFOUND")4+if(${CCACHE} STREQUAL "CCACHE-NOTFOUND")
5- message(STATUS "Compile without ccache")5+ message(STATUS "Compile without ccache")
6-else()6+else()
7- set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE} CACHE PATH "cache Compiler")7+ set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE} CACHE PATH "cache Compiler")
8- set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE} CACHE PATH "cache Compiler")8+ set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE} CACHE PATH "cache Compiler")
9- message(STATUS "CMAKE_C_COMPILER_LAUNCHER:${CMAKE_C_COMPILER_LAUNCHER}")9+ message(STATUS "CMAKE_C_COMPILER_LAUNCHER:${CMAKE_C_COMPILER_LAUNCHER}")
10- message(STATUS "CMAKE_CXX_COMPILER_LAUNCHER:${CMAKE_CXX_COMPILER_LAUNCHER}")10+ message(STATUS "CMAKE_CXX_COMPILER_LAUNCHER:${CMAKE_CXX_COMPILER_LAUNCHER}")
11-endif()11+endif()
12- 12+ 
13-project(TORCHNPU CXX C)13+project(TORCHNPU CXX C)
14-add_compile_options(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=)14+add_compile_options(-fmacro-prefix-map=${CMAKE_SOURCE_DIR}/=)
15- 15+ 
16-find_program(MOLD_LINKER mold)16+find_program(MOLD_LINKER mold)
17-if(MOLD_LINKER)17+if(MOLD_LINKER)
18- add_link_options(-fuse-ld=mold)18+ add_link_options(-fuse-ld=mold)
19- message(STATUS "Using mold linker: ${MOLD_LINKER}")19+ message(STATUS "Using mold linker: ${MOLD_LINKER}")
20-else()20+else()
21- message(STATUS "mold linker not found, using default linker")21+ message(STATUS "mold linker not found, using default linker")
22-endif()22+endif()
23- 23+ 
24-set(LINUX TRUE)24+set(LINUX TRUE)
25-set(CMAKE_INSTALL_MESSAGE NEVER)25+set(CMAKE_INSTALL_MESSAGE NEVER)
26-# set(CMAKE_VERBOSE_MAKEFILE ON)26+# set(CMAKE_VERBOSE_MAKEFILE ON)
27-set(CMAKE_EXPORT_COMPILE_COMMANDS ON)27+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
28- 28+ 
29-if(DEFINED TORCH_VERSION)29+if(DEFINED TORCH_VERSION)
30- add_definitions(-DPYTORCH_NPU_VERSION="${TORCH_VERSION}")30+ add_definitions(-DPYTORCH_NPU_VERSION="${TORCH_VERSION}")
31-endif()31+endif()
32- 32+ 
33-set(PLUGIN_NAME torch_npu)33+set(PLUGIN_NAME torch_npu)
34- 34+ 
35-set(RPATH_VALUE $ORIGIN)35+set(RPATH_VALUE $ORIGIN)
36-set(CMAKE_SKIP_BUILD_RPATH FALSE)36+set(CMAKE_SKIP_BUILD_RPATH FALSE)
37-set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)37+set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
38-set(CMAKE_INSTALL_RPATH "${RPATH_VALUE}/lib/:${RPATH_VALUE}/")38+set(CMAKE_INSTALL_RPATH "${RPATH_VALUE}/lib/:${RPATH_VALUE}/")
39-set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)39+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
40-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${TORCHNPU_INSTALL_LIBDIR})40+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${TORCHNPU_INSTALL_LIBDIR})
41-SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")41+SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
42-SET(CMAKE_CXX_FLAGS_RELEASE "-O2")42+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
43-SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")43+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
44- 44+ 
45-# LTO&PGO optimization in compile option45+# LTO&PGO optimization in compile option
46-SET(IF_APPEND FALSE)46+SET(IF_APPEND FALSE)
47-if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")47+if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
48- SET(APPEND_FLAGS "-fGNU-compatibility -Wno-non-pod-varargs")48+ SET(APPEND_FLAGS "-fGNU-compatibility -Wno-non-pod-varargs")
49- if(NOT MOLD_LINKER)49+ if(NOT MOLD_LINKER)
50- add_link_options(-fuse-ld=lld)50+ add_link_options(-fuse-ld=lld)
51- endif()51+ endif()
52- if (DEFINED ENABLE_LTO)52+ if (DEFINED ENABLE_LTO)
53- SET(IF_APPEND TRUE)53+ SET(IF_APPEND TRUE)
54- SET(APPEND_FLAGS "${APPEND_FLAGS} -flto=thin")54+ SET(APPEND_FLAGS "${APPEND_FLAGS} -flto=thin")
55- endif()55+ endif()
56- if (DEFINED PGO_MODE)56+ if (DEFINED PGO_MODE)
57- SET(IF_APPEND TRUE)57+ SET(IF_APPEND TRUE)
58- if (PGO_MODE EQUAL 1)58+ if (PGO_MODE EQUAL 1)
59- SET(APPEND_FLAGS "${APPEND_FLAGS} -fprofile-generate")59+ SET(APPEND_FLAGS "${APPEND_FLAGS} -fprofile-generate")
60- elseif (PGO_MODE EQUAL 2)60+ elseif (PGO_MODE EQUAL 2)
61- SET(APPEND_FLAGS "${APPEND_FLAGS} -fprofile-use=${CMAKE_CURRENT_SOURCE_DIR}/default.profdata")61+ SET(APPEND_FLAGS "${APPEND_FLAGS} -fprofile-use=${CMAKE_CURRENT_SOURCE_DIR}/default.profdata")
62- endif()62+ endif()
63- endif()63+ endif()
64-else()64+else()
65- if (DEFINED ENABLE_LTO)65+ if (DEFINED ENABLE_LTO)
66- message(FATAL_ERROR "Currently, LTO auto build is not supported in ${CMAKE_CXX_COMPILER_ID}")66+ message(FATAL_ERROR "Currently, LTO auto build is not supported in ${CMAKE_CXX_COMPILER_ID}")
67- endif()67+ endif()
68- if (DEFINED PGO_MODE)68+ if (DEFINED PGO_MODE)
69- message(FATAL_ERROR "Currently, PGO auto build is not supported in ${CMAKE_CXX_COMPILER_ID}")69+ message(FATAL_ERROR "Currently, PGO auto build is not supported in ${CMAKE_CXX_COMPILER_ID}")
70- endif()70+ endif()
71-endif()71+endif()
72-if (IF_APPEND)72+if (IF_APPEND)
73- SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${APPEND_FLAGS}")73+ SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${APPEND_FLAGS}")
74-endif()74+endif()
75- 75+ 
76-# check and set CMAKE_CXX_STANDARD76+# check and set CMAKE_CXX_STANDARD
77-string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++" env_cxx_standard)77+string(FIND "${CMAKE_CXX_FLAGS}" "-std=c++" env_cxx_standard)
78-if(env_cxx_standard GREATER -1)78+if(env_cxx_standard GREATER -1)
79- message(79+ message(
80- WARNING "C++ standard version definition detected in environment variable."80+ WARNING "C++ standard version definition detected in environment variable."
81- "PyTorch requires -std=c++17. Please remove -std=c++ settings in your environment.")81+ "PyTorch requires -std=c++17. Please remove -std=c++ settings in your environment.")
82-endif()82+endif()
83-set(CMAKE_CXX_STANDARD 17)83+set(CMAKE_CXX_STANDARD 17)
84-set(CMAKE_C_STANDARD 11)84+set(CMAKE_C_STANDARD 11)
85-set(CMAKE_CXX_EXTENSIONS OFF)85+set(CMAKE_CXX_EXTENSIONS OFF)
86- 86+ 
87-set(TORCHNPU_ROOT "${PROJECT_SOURCE_DIR}/torch_npu/csrc")87+set(TORCHNPU_ROOT "${PROJECT_SOURCE_DIR}/torch_npu/csrc")
88-set(TORCHNPU_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")88+set(TORCHNPU_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party")
89- 89+ 
90-set(Torch_DIR ${PYTORCH_INSTALL_DIR}/share/cmake/Torch)90+set(Torch_DIR ${PYTORCH_INSTALL_DIR}/share/cmake/Torch)
91-FIND_PACKAGE(Torch REQUIRED)91+FIND_PACKAGE(Torch REQUIRED)
92- 92+ 
93-set(LINUX TRUE)93+set(LINUX TRUE)
94-set(CMAKE_INSTALL_MESSAGE NEVER)94+set(CMAKE_INSTALL_MESSAGE NEVER)
95-#set(CMAKE_VERBOSE_MAKEFILE ON)95+#set(CMAKE_VERBOSE_MAKEFILE ON)
96-set(CMAKE_EXPORT_COMPILE_COMMANDS ON)96+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
97- 97+ 
98-# Define build type98+# Define build type
99-IF(CMAKE_BUILD_TYPE MATCHES Debug)99+IF(CMAKE_BUILD_TYPE MATCHES Debug)
100- message("Debug build.")100+ message("Debug build.")
101- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DEBUG")101+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_DEBUG")
102-ELSEIF(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)102+ELSEIF(CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
103- message("RelWithDebInfo build")103+ message("RelWithDebInfo build")
104- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")104+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
105-ELSE()105+ELSE()
106- message("Release build.")106+ message("Release build.")
107- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")107+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNDEBUG")
108-ENDIF()108+ENDIF()
109- 109+ 
110-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")110+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
111-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")111+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
112-# Eigen fails to build with some versions, so convert this to a warning112+# Eigen fails to build with some versions, so convert this to a warning
113-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")113+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
114-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")114+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
115-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")115+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-field-initializers")
116-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-type-limits")116+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-type-limits")
117-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-array-bounds")117+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-array-bounds")
118-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")118+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-pragmas")
119-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")119+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-sign-compare")
120-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")120+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
121-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")121+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
122-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")122+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-function")
123-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result")123+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result")
124-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-overflow")124+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-overflow")
125-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")125+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")
126-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")126+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=deprecated-declarations")
127-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ignored-qualifiers")127+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-ignored-qualifiers")
128-if (CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0))128+if (CMAKE_COMPILER_IS_GNUCXX AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0))
129- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-overflow")129+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-stringop-overflow")
130-endif()130+endif()
131-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=pedantic")131+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=pedantic")
132-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=redundant-decls")132+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=redundant-decls")
133-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=old-style-cast")133+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=old-style-cast")
134- 134+ 
135-# These flags are not available in GCC-4.8.5. Set only when using clang.135+# These flags are not available in GCC-4.8.5. Set only when using clang.
136-if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")136+if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
137- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization")137+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization")
138- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-typedef-redefinition")138+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-typedef-redefinition")
139- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")139+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option")
140- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field")140+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field")
141- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")141+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-inconsistent-missing-override")
142- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-aligned-allocation-unavailable")142+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-aligned-allocation-unavailable")
143- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions")143+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions")
144- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-constexpr-not-const")144+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-constexpr-not-const")
145- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")145+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces")
146- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")146+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments")
147- if (${COLORIZE_OUTPUT})147+ if (${COLORIZE_OUTPUT})
148- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")148+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
149- endif()149+ endif()
150-endif()150+endif()
151-if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)151+if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
152- if (${COLORIZE_OUTPUT})152+ if (${COLORIZE_OUTPUT})
153- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")153+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
154- endif()154+ endif()
155-endif()155+endif()
156-if ((APPLE AND (NOT ("${CLANG_VERSION_STRING}" VERSION_LESS "9.0")))156+if ((APPLE AND (NOT ("${CLANG_VERSION_STRING}" VERSION_LESS "9.0")))
157- OR (CMAKE_COMPILER_IS_GNUCXX157+ OR (CMAKE_COMPILER_IS_GNUCXX
158- AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 AND NOT APPLE)))158+ AND (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0 AND NOT APPLE)))
159- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faligned-new")159+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -faligned-new")
160-endif()160+endif()
161-if (WERROR)161+if (WERROR)
162- check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)162+ check_cxx_compiler_flag("-Werror" COMPILER_SUPPORT_WERROR)
163- if (NOT COMPILER_SUPPORT_WERROR)163+ if (NOT COMPILER_SUPPORT_WERROR)
164- set(WERROR FALSE)164+ set(WERROR FALSE)
165- else()165+ else()
166- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")166+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
167- endif()167+ endif()
168-endif(WERROR)168+endif(WERROR)
169-if (NOT APPLE)169+if (NOT APPLE)
170- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")170+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-but-set-variable")
171- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized")171+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-uninitialized")
172-endif()172+endif()
173-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -O0")173+set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -O0")
174-set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -O0")174+set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -O0")
175-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-math-errno")175+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-math-errno")
176-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math")176+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-trapping-math")
177-set(CMAKE_CXX_COVERAGE $ENV{CALCULATE_CXX_COVERAGE})177+set(CMAKE_CXX_COVERAGE $ENV{CALCULATE_CXX_COVERAGE})
178- 178+ 
179-if (CMAKE_BUILD_TYPE MATCHES Debug)179+if (CMAKE_BUILD_TYPE MATCHES Debug)
180- set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_C_FLAGS}")180+ set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_C_FLAGS}")
181- set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}")181+ set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}")
182- set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CXXFLAGS}")182+ set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CXXFLAGS}")
183-elseif (CMAKE_CXX_COVERAGE STREQUAL "1")183+elseif (CMAKE_CXX_COVERAGE STREQUAL "1")
184- set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fprofile-arcs -ftest-coverage -fPIE -pie ${CMAKE_C_FLAGS}")184+ set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fprofile-arcs -ftest-coverage -fPIE -pie ${CMAKE_C_FLAGS}")
185- set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fprofile-arcs -ftest-coverage -fPIE -pie ${CMAKE_CXX_FLAGS}")185+ set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fprofile-arcs -ftest-coverage -fPIE -pie ${CMAKE_CXX_FLAGS}")
186- set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fprofile-arcs -ftest-coverage -fPIE -pie ${CXXFLAGS}")186+ set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fprofile-arcs -ftest-coverage -fPIE -pie ${CXXFLAGS}")
187-else()187+else()
188- set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_C_FLAGS}")188+ set(CMAKE_C_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_C_FLAGS}")
189- set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}")189+ set(CMAKE_CXX_FLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CMAKE_CXX_FLAGS}")
190- set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CXXFLAGS}")190+ set(CXXFLAGS "-fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -fPIE -pie ${CXXFLAGS}")
191-endif()191+endif()
192- 192+ 
193-if (NOT DEFINED GLIBCXX_USE_CXX11_ABI)193+if (NOT DEFINED GLIBCXX_USE_CXX11_ABI)
194- set(GLIBCXX_USE_CXX11_ABI 0)194+ set(GLIBCXX_USE_CXX11_ABI 0)
195-endif()195+endif()
196-message(STATUS "Determined _GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")196+message(STATUS "Determined _GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
197-set(_GLIBCXX_USE_CXX11_ABI ${GLIBCXX_USE_CXX11_ABI})197+set(_GLIBCXX_USE_CXX11_ABI ${GLIBCXX_USE_CXX11_ABI})
198-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")198+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${GLIBCXX_USE_CXX11_ABI}")
199-if (${GLIBCXX_USE_CXX11_ABI} EQUAL 0)199+if (${GLIBCXX_USE_CXX11_ABI} EQUAL 0)
200- set(CMAKE_CXX_FLAGS "-fabi-version=11 ${CMAKE_CXX_FLAGS}")200+ set(CMAKE_CXX_FLAGS "-fabi-version=11 ${CMAKE_CXX_FLAGS}")
201-else()201+else()
202- set(CXX_STANDARD_REQUIRED ON)202+ set(CXX_STANDARD_REQUIRED ON)
203- if (DEFINED ABI_VERSION)203+ if (DEFINED ABI_VERSION)
204- set(CMAKE_CXX_FLAGS "-fabi-version=${ABI_VERSION} ${CMAKE_CXX_FLAGS}")204+ set(CMAKE_CXX_FLAGS "-fabi-version=${ABI_VERSION} ${CMAKE_CXX_FLAGS}")
205- endif()205+ endif()
206-endif()206+endif()
207- 207+ 
208- 208+ 
209-if (DEFINED BUILD_LIBTORCH)209+if (DEFINED BUILD_LIBTORCH)
210- add_compile_definitions(BUILD_LIBTORCH)210+ add_compile_definitions(BUILD_LIBTORCH)
211-endif()211+endif()
212- 212+ 
213- 213+ 
214-include_directories(${PROJECT_SOURCE_DIR})214+include_directories(${PROJECT_SOURCE_DIR})
215-include_directories(${PROJECT_SOURCE_DIR}/torch_npu/csrc/aten)215+include_directories(${PROJECT_SOURCE_DIR}/torch_npu/csrc/aten)
216-include_directories(${PROJECT_SOURCE_DIR}/torch_npu/csrc/inductor)216+include_directories(${PROJECT_SOURCE_DIR}/torch_npu/csrc/inductor)
217-include_directories(${PROJECT_SOURCE_DIR}/third_party/hccl/inc)217+include_directories(${PROJECT_SOURCE_DIR}/third_party/hccl/inc)
218-include_directories(${PROJECT_SOURCE_DIR}/third_party/acl/inc)218+include_directories(${PROJECT_SOURCE_DIR}/third_party/acl/inc)
219-include_directories(${PROJECT_SOURCE_DIR}/third_party/Tensorpipe)219+include_directories(${PROJECT_SOURCE_DIR}/third_party/Tensorpipe)
220-include_directories(${PROJECT_SOURCE_DIR}/third_party/nlohmann/include)220+include_directories(${PROJECT_SOURCE_DIR}/third_party/nlohmann/include)
221- 221+ 
222-# Set installed PyTorch dir222+# Set installed PyTorch dir
223-if(DEFINED PYTORCH_INSTALL_DIR)223+if(DEFINED PYTORCH_INSTALL_DIR)
224- include_directories(${PYTORCH_INSTALL_DIR}/include)224+ include_directories(${PYTORCH_INSTALL_DIR}/include)
225- include_directories(${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include)225+ include_directories(${PYTORCH_INSTALL_DIR}/include/torch/csrc/api/include)
226- include_directories(${PYTORCH_INSTALL_DIR}/include/torch/csrc/distributed)226+ include_directories(${PYTORCH_INSTALL_DIR}/include/torch/csrc/distributed)
227-else()227+else()
228- message(FATAL_ERROR "Cannot find installed PyTorch directory")228+ message(FATAL_ERROR "Cannot find installed PyTorch directory")
229-endif()229+endif()
230- 230+ 
231-# Set Python include dir231+# Set Python include dir
232-if(DEFINED PYTHON_INCLUDE_DIR)232+if(DEFINED PYTHON_INCLUDE_DIR)
233- include_directories(${PYTHON_INCLUDE_DIR})233+ include_directories(${PYTHON_INCLUDE_DIR})
234-else()234+else()
235- message(FATAL_ERROR "Cannot find installed Python head file directory")235+ message(FATAL_ERROR "Cannot find installed Python head file directory")
236-endif()236+endif()
237- 237+ 
238-# sources238+# sources
239-set(ATEN_SRCS)239+set(ATEN_SRCS)
240-set(CORE_SRCS)240+set(CORE_SRCS)
241-set(FRAMEWORK_SRCS)241+set(FRAMEWORK_SRCS)
242-set(LOGGING_SRCS)242+set(LOGGING_SRCS)
243-set(INDUCTOR_SRCS)243+set(INDUCTOR_SRCS)
244-set(DIST_SRCS)244+set(DIST_SRCS)
245- 245+ 
246-if (NOT DEFINED BUILD_LIBTORCH)246+if (NOT DEFINED BUILD_LIBTORCH)
247- set(FLOP_SRCS)247+ set(FLOP_SRCS)
248- set(NPU_SRCS)248+ set(NPU_SRCS)
249- set(PROF_SRCS)249+ set(PROF_SRCS)
250- set(IPC_SRCS)250+ set(IPC_SRCS)
251- set(UTILS_SRCS)251+ set(UTILS_SRCS)
252- set(SAN_SRCS)252+ set(SAN_SRCS)
253- set(AFD_SRCS)253+ set(AFD_SRCS)
254-endif()254+endif()
255- 255+ 
256-if (DEFINED BUILD_LIBTORCH)256+if (DEFINED BUILD_LIBTORCH)
257- set(NPU_CPP_LIBS_SRCS)257+ set(NPU_CPP_LIBS_SRCS)
258-endif()258+endif()
259- 259+ 
260-add_subdirectory(${TORCHNPU_ROOT}/aten)260+add_subdirectory(${TORCHNPU_ROOT}/aten)
261-add_subdirectory(${TORCHNPU_ROOT}/core)261+add_subdirectory(${TORCHNPU_ROOT}/core)
262-add_subdirectory(${TORCHNPU_ROOT}/framework)262+add_subdirectory(${TORCHNPU_ROOT}/framework)
263-add_subdirectory(${TORCHNPU_ROOT}/flopcount)263+add_subdirectory(${TORCHNPU_ROOT}/flopcount)
264-add_subdirectory(${TORCHNPU_ROOT}/logging)264+add_subdirectory(${TORCHNPU_ROOT}/logging)
265-add_subdirectory(${TORCHNPU_ROOT}/custom_dtype)265+add_subdirectory(${TORCHNPU_ROOT}/custom_dtype)
266-add_subdirectory(${TORCHNPU_ROOT}/inductor)266+add_subdirectory(${TORCHNPU_ROOT}/inductor)
267-add_subdirectory(${TORCHNPU_ROOT}/distributed)267+add_subdirectory(${TORCHNPU_ROOT}/distributed)
268- 268+ 
269-if (NOT DEFINED BUILD_LIBTORCH)269+if (NOT DEFINED BUILD_LIBTORCH)
270- add_subdirectory(${TORCHNPU_ROOT}/npu)270+ add_subdirectory(${TORCHNPU_ROOT}/npu)
271- add_subdirectory(${TORCHNPU_ROOT}/profiler)271+ add_subdirectory(${TORCHNPU_ROOT}/profiler)
272- add_subdirectory(${TORCHNPU_ROOT}/ipc)272+ add_subdirectory(${TORCHNPU_ROOT}/ipc)
273- add_subdirectory(${TORCHNPU_ROOT}/utils)273+ add_subdirectory(${TORCHNPU_ROOT}/utils)
274- add_subdirectory(${TORCHNPU_ROOT}/sanitizer)274+ add_subdirectory(${TORCHNPU_ROOT}/sanitizer)
275- add_subdirectory(${TORCHNPU_ROOT}/afd)275+ add_subdirectory(${TORCHNPU_ROOT}/afd)
276-endif()276+endif()
277- 277+ 
278-if (DEFINED BUILD_LIBTORCH)278+if (DEFINED BUILD_LIBTORCH)
279- add_subdirectory(${TORCHNPU_ROOT}/libs)279+ add_subdirectory(${TORCHNPU_ROOT}/libs)
280-endif()280+endif()
281- 281+ 
282-set(OPS_PLUGIN_SRCS)282+set(OPS_PLUGIN_SRCS)
283-# Add subdirectory of op-plugin283+# Add subdirectory of op-plugin
284-include_directories(${PROJECT_SOURCE_DIR}/third_party/op-plugin)284+include_directories(${PROJECT_SOURCE_DIR}/third_party/op-plugin)
285-add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/op-plugin/op_plugin)285+add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/op-plugin/op_plugin)
286- 286+ 
287-if (DEFINED BUILD_TENSORPIPE)287+if (DEFINED BUILD_TENSORPIPE)
288- add_definitions(-DUSE_RPC_FRAMEWORK)288+ add_definitions(-DUSE_RPC_FRAMEWORK)
289- set(BUILD_SHARED_LIBS ON)289+ set(BUILD_SHARED_LIBS ON)
290- if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")290+ if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")
291- message(WARNING "tensorpipe forces CMake compatibility")291+ message(WARNING "tensorpipe forces CMake compatibility")
292- set(CMAKE_POLICY_VERSION_MINIMUM 3.5)292+ set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
293- endif()293+ endif()
294- add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/Tensorpipe)294+ add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/Tensorpipe)
295- if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")295+ if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.0.0")
296- unset(CMAKE_POLICY_VERSION_MINIMUM)296+ unset(CMAKE_POLICY_VERSION_MINIMUM)
297- endif()297+ endif()
298- set(BUILD_SHARED_LIBS OFF)298+ set(BUILD_SHARED_LIBS OFF)
299-endif()299+endif()
300- 300+ 
301-if (DEFINED BUILD_LIBTORCH)301+if (DEFINED BUILD_LIBTORCH)
302- set(CPP_SRCS ${ATEN_SRCS} ${INDUCTOR_SRCS} ${CORE_SRCS} ${OPS_PLUGIN_SRCS} ${DIST_SRCS} ${FLOP_SRCS} ${CUS_DTYPE_SRCS} ${FRAMEWORK_SRCS} ${LOGGING_SRCS} ${NPU_CPP_LIBS_SRCS} )302+ set(CPP_SRCS ${ATEN_SRCS} ${INDUCTOR_SRCS} ${CORE_SRCS} ${OPS_PLUGIN_SRCS} ${DIST_SRCS} ${FLOP_SRCS} ${CUS_DTYPE_SRCS} ${FRAMEWORK_SRCS} ${LOGGING_SRCS} ${NPU_CPP_LIBS_SRCS} )
303-else()303+else()
304-# Compile code with pybind11304+# Compile code with pybind11
305- set(CPP_SRCS ${ATEN_SRCS} ${INDUCTOR_SRCS} ${CORE_SRCS} ${OPS_PLUGIN_SRCS} ${DIST_SRCS} ${FLOP_SRCS} ${CUS_DTYPE_SRCS} ${LOGGING_SRCS} ${FRAMEWORK_SRCS} ${NPU_SRCS} ${PROF_SRCS} ${IPC_SRCS} ${UTILS_SRCS} ${SAN_SRCS} ${AFD_SRCS})305+ set(CPP_SRCS ${ATEN_SRCS} ${INDUCTOR_SRCS} ${CORE_SRCS} ${OPS_PLUGIN_SRCS} ${DIST_SRCS} ${FLOP_SRCS} ${CUS_DTYPE_SRCS} ${LOGGING_SRCS} ${FRAMEWORK_SRCS} ${NPU_SRCS} ${PROF_SRCS} ${IPC_SRCS} ${UTILS_SRCS} ${SAN_SRCS} ${AFD_SRCS})
306-endif()306+endif()
307- 307+ 
308-add_library(${PLUGIN_NAME} SHARED ${CPP_SRCS})308+add_library(${PLUGIN_NAME} SHARED ${CPP_SRCS})
309-include(CheckCXXCompilerFlag)309+include(CheckCXXCompilerFlag)
310-check_cxx_compiler_flag("-fvisibility=hidden" COMPILER_SUPPORTS_HIDDEN_VISIBILITY)310+check_cxx_compiler_flag("-fvisibility=hidden" COMPILER_SUPPORTS_HIDDEN_VISIBILITY)
311-if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})311+if(${COMPILER_SUPPORTS_HIDDEN_VISIBILITY})
312- target_compile_options(${PLUGIN_NAME} PRIVATE "-fvisibility=hidden")312+ target_compile_options(${PLUGIN_NAME} PRIVATE "-fvisibility=hidden")
313-endif()313+endif()
314- 314+ 
315-target_link_options(${PLUGIN_NAME} PRIVATE "-Wl,-Bsymbolic-functions,--no-as-needed")315+target_link_options(${PLUGIN_NAME} PRIVATE "-Wl,-Bsymbolic-functions,--no-as-needed")
316- 316+ 
317-if (DEFINED BUILD_TORCHAIR)317+if (DEFINED BUILD_TORCHAIR)
318- add_subdirectory(${TORCHNPU_THIRD_PARTY_ROOT}/torchair)318+ add_subdirectory(${TORCHNPU_THIRD_PARTY_ROOT}/torchair)
319- add_dependencies(${PLUGIN_NAME} copy_torchair_pyfiles)319+ add_dependencies(${PLUGIN_NAME} copy_torchair_pyfiles)
320-endif()320+endif()
321- 321+ 
322-add_subdirectory(${TORCHNPU_THIRD_PARTY_ROOT}/fmt EXCLUDE_FROM_ALL)322+add_subdirectory(${TORCHNPU_THIRD_PARTY_ROOT}/fmt EXCLUDE_FROM_ALL)
323- 323+ 
324-link_directories(${PYTORCH_INSTALL_DIR}/lib)324+link_directories(${PYTORCH_INSTALL_DIR}/lib)
325-link_directories(${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs)325+link_directories(${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs)
326- 326+ 
327-target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libhccl.so)327+target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libhccl.so)
328- 328+ 
329-if (NOT DEFINED BUILD_LIBTORCH)329+if (NOT DEFINED BUILD_LIBTORCH)
330- target_link_libraries(${PLUGIN_NAME} PUBLIC ${PYTORCH_INSTALL_DIR}/lib/libtorch_python.so)330+ target_link_libraries(${PLUGIN_NAME} PUBLIC ${PYTORCH_INSTALL_DIR}/lib/libtorch_python.so)
331-endif()331+endif()
332- 332+ 
333-target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libascendcl.so)333+target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libascendcl.so)
334-target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libacl_op_compiler.so)334+target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libacl_op_compiler.so)
335-target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libge_runner.so)335+target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libge_runner.so)
336-target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libgraph.so)336+target_link_libraries(${PLUGIN_NAME} PUBLIC ${TORCHNPU_THIRD_PARTY_ROOT}/acl/libs/libgraph.so)
337- 337+ 
338-if (DEFINED BUILD_TENSORPIPE)338+if (DEFINED BUILD_TENSORPIPE)
339- target_link_libraries(${PLUGIN_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/build/packages/torch_npu/lib/libtensorpipe.so)339+ target_link_libraries(${PLUGIN_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/build/packages/torch_npu/lib/libtensorpipe.so)
340-endif()340+endif()
341- 341+ 
342-target_link_libraries(${PLUGIN_NAME} PUBLIC torch torch_cpu c10 fmt::fmt-header-only)342+target_link_libraries(${PLUGIN_NAME} PUBLIC torch torch_cpu c10 fmt::fmt-header-only)
343- 343+ 
344-if (NOT DEFINED BUILD_LIBTORCH)344+if (NOT DEFINED BUILD_LIBTORCH)
345- set(ATEN_THREADING "OMP" CACHE STRING "ATen parallel backend")345+ set(ATEN_THREADING "OMP" CACHE STRING "ATen parallel backend")
346- message(STATUS "Using ATen parallel backend: ${ATEN_THREADING}")346+ message(STATUS "Using ATen parallel backend: ${ATEN_THREADING}")
347- if ("${ATEN_THREADING}" STREQUAL "OMP")347+ if ("${ATEN_THREADING}" STREQUAL "OMP")
348- target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_OPENMP=1")348+ target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_OPENMP=1")
349- elseif ("${ATEN_THREADING}" STREQUAL "NATIVE")349+ elseif ("${ATEN_THREADING}" STREQUAL "NATIVE")
350- target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_NATIVE=1")350+ target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_NATIVE=1")
351- elseif ("${ATEN_THREADING}" STREQUAL "TBB")351+ elseif ("${ATEN_THREADING}" STREQUAL "TBB")
352- target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_NATIVE_TBB=1")352+ target_compile_definitions(${PLUGIN_NAME} PUBLIC "-DAT_PARALLEL_NATIVE_TBB=1")
353- else()353+ else()
354- message(FATAL_ERROR "Unknown ATen parallel backend: ${ATEN_THREADING}")354+ message(FATAL_ERROR "Unknown ATen parallel backend: ${ATEN_THREADING}")
355- endif()355+ endif()
356- 356+ 
357- include(GNUInstallDirs)357+ include(GNUInstallDirs)
358- target_compile_options(${PLUGIN_NAME} PRIVATE "-DC10_BUILD_MAIN_LIB")358+ target_compile_options(${PLUGIN_NAME} PRIVATE "-DC10_BUILD_MAIN_LIB")
359- install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})359+ install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
360-endif()360+endif()
361- 361+ 
362-if (NOT DEFINED BUILD_LIBTORCH)362+if (NOT DEFINED BUILD_LIBTORCH)
363- add_subdirectory(${TORCHNPU_ROOT}/toolkit)363+ add_subdirectory(${TORCHNPU_ROOT}/toolkit)
364- target_link_libraries(${PLUGIN_NAME} PUBLIC npu_profiler)364+ target_link_libraries(${PLUGIN_NAME} PUBLIC npu_profiler)
365-endif()365+endif()
366- 366+ 
367-if (DEFINED BUILD_GTEST)367+if (DEFINED BUILD_GTEST)
368- enable_testing()368+ enable_testing()
369- SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build/gtest)369+ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build/gtest)
370- add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/googletest)370+ add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/googletest)
371- include_directories(${PROJECT_SOURCE_DIR}/third_party/googletest/googletest/include)371+ include_directories(${PROJECT_SOURCE_DIR}/third_party/googletest/googletest/include)
372- 372+ 
373- set(TORCH_API_TEST_SOURCES)373+ set(TORCH_API_TEST_SOURCES)
374- add_subdirectory(${PROJECT_SOURCE_DIR}/test/cpp/api)374+ add_subdirectory(${PROJECT_SOURCE_DIR}/test/cpp/api)
375- add_executable(test_api ${TORCH_API_TEST_SOURCES})375+ add_executable(test_api ${TORCH_API_TEST_SOURCES})
376- 376+ 
377- target_link_libraries(test_api PUBLIC torch_npu)377+ target_link_libraries(test_api PUBLIC torch_npu)
378- target_link_libraries(test_api PUBLIC gtest_main gtest)378+ target_link_libraries(test_api PUBLIC gtest_main gtest)
379-endif()379+endif()
380- 380+ 
381-if (DEFINED BUILD_LIBTORCH)381+if (DEFINED BUILD_LIBTORCH)
382- configure_file(382+ configure_file(
383- ${PROJECT_SOURCE_DIR}/cmake/Torch_npuConfig.cmake.in383+ ${PROJECT_SOURCE_DIR}/cmake/Torch_npuConfig.cmake.in
384- ${PROJECT_SOURCE_DIR}/build/Torch_npuConfig.cmake384+ ${PROJECT_SOURCE_DIR}/build/Torch_npuConfig.cmake
385- @ONLY)385+ @ONLY)
386-endif()386+endif()
387- 
@@ -1,190 +1,190 @@
1-OPEN SOURCE SOFTWARE NOTICE1+OPEN SOURCE SOFTWARE NOTICE
2-Please note we provide an open source software notice along with this product and/or this product firmware (in the following just "this product"). The open source software licenses are granted by the respective right holders. And the open source licenses prevail all other license information with regard to the respective open source software contained in the product, including but not limited to End User Software Licensing Agreement. This notice is provided on behalf of Huawei Technologies Co. Ltd. and any of its local subsidiaries which may have provided this product to you in your local country.2+Please note we provide an open source software notice along with this product and/or this product firmware (in the following just "this product"). The open source software licenses are granted by the respective right holders. And the open source licenses prevail all other license information with regard to the respective open source software contained in the product, including but not limited to End User Software Licensing Agreement. This notice is provided on behalf of Huawei Technologies Co. Ltd. and any of its local subsidiaries which may have provided this product to you in your local country.
3- 3+ 
4-Warranty Disclaimer4+Warranty Disclaimer
5-THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.5+THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
6- 6+ 
7-Copyright Notice and License Texts7+Copyright Notice and License Texts
8-Software: pytorch v2.6.08+Software: pytorch v2.6.0
9-Copyright notice:9+Copyright notice:
10-Copyright (c) Advanced Micro Devices, Inc.10+Copyright (c) Advanced Micro Devices, Inc.
11- 11+ 
12-Copyright (c) Microsoft Corporation12+Copyright (c) Microsoft Corporation
13- 13+ 
14-Copyright (c) Bjorn Fahller14+Copyright (c) Bjorn Fahller
15- 15+ 
16-Copyright (c) 2001-2014 Python Software Foundation All Rights Reserved16+Copyright (c) 2001-2014 Python Software Foundation All Rights Reserved
17- 17+ 
18-Copyright (c) 2011-2013 NYU18+Copyright (c) 2011-2013 NYU
19- 19+ 
20-Copyright (c) 1995-2011 by Fredrik Lundh20+Copyright (c) 1995-2011 by Fredrik Lundh
21- 21+ 
22-Copyright (c) Edward Z. Yang ezyang@mit.edu22+Copyright (c) Edward Z. Yang ezyang@mit.edu
23- 23+ 
24-Copyright (c) 2014- Facebook, Inc24+Copyright (c) 2014- Facebook, Inc
25- 25+ 
26-Copyright (c) 2017 The Android Open Source Project26+Copyright (c) 2017 The Android Open Source Project
27- 27+ 
28-Copyright Python Software Foundation28+Copyright Python Software Foundation
29- 29+ 
30-Copyright (c) 2012 Massachusetts Institute of Technology30+Copyright (c) 2012 Massachusetts Institute of Technology
31- 31+ 
32-Copyright (c) 2018 Alex Rogozhnikov32+Copyright (c) 2018 Alex Rogozhnikov
33- 33+ 
34-Copyright (c) 2007-2009 Scientific Computing and Imaging Institute, University of Utah34+Copyright (c) 2007-2009 Scientific Computing and Imaging Institute, University of Utah
35- 35+ 
36-Copyright (c) 2006 Idiap Research Institute36+Copyright (c) 2006 Idiap Research Institute
37- 37+ 
38-Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved38+Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved
39- 39+ 
40-Copyright (c) 2015 Yangqing Jia All rights reserved40+Copyright (c) 2015 Yangqing Jia All rights reserved
41- 41+ 
42-Copyright (c) Meta Platforms, Inc.42+Copyright (c) Meta Platforms, Inc.
43- 43+ 
44-Copyright 2023-present Facebook. All Rights Reserved44+Copyright 2023-present Facebook. All Rights Reserved
45- 45+ 
46-Copyright (c) 2022 Apple Inc.46+Copyright (c) 2022 Apple Inc.
47- 47+ 
48-Copyright (c) 2005-2017, NumPy Developers. All rights reserved48+Copyright (c) 2005-2017, NumPy Developers. All rights reserved
49- 49+ 
50-Copyright (c) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved50+Copyright (c) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved
51- 51+ 
52-Copyright (c) 2014, The Regents52+Copyright (c) 2014, The Regents
53- 53+ 
54-Copyright (c) 2005-2010 ActiveState Software Inc.54+Copyright (c) 2005-2010 ActiveState Software Inc.
55- 55+ 
56-Copyright Malte Skarupke 201756+Copyright Malte Skarupke 2017
57- 57+ 
58-Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)58+Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
59- 59+ 
60-Copyright 2005, Google Inc. All rights reserved60+Copyright 2005, Google Inc. All rights reserved
61- 61+ 
62-Copyright (c) Meta Platforms, Inc. and affiliates62+Copyright (c) Meta Platforms, Inc. and affiliates
63- 63+ 
64-Copyright (c) 2023, Advanced Micro Devices, Inc.64+Copyright (c) 2023, Advanced Micro Devices, Inc.
65- 65+ 
66-Copyright (c) 2022, Tri Dao66+Copyright (c) 2022, Tri Dao
67- 67+ 
68-Copyright (c) 2005-2023 NVIDIA Corporation Built68+Copyright (c) 2005-2023 NVIDIA Corporation Built
69- 69+ 
70-Copyright (c) 2001-2002 Enthought, Inc. 2003-2019, SciPy Developers. All rights reserved70+Copyright (c) 2001-2002 Enthought, Inc. 2003-2019, SciPy Developers. All rights reserved
71- 71+ 
72-Copyright 2008 Google Inc. All rights reserved72+Copyright 2008 Google Inc. All rights reserved
73- 73+ 
74-Copyright (c) 2021, 2023-2024 Arm Limited74+Copyright (c) 2021, 2023-2024 Arm Limited
75- 75+ 
76-Copyright (c) 2003-2017 Josef Weidendorfer. All rights reserved76+Copyright (c) 2003-2017 Josef Weidendorfer. All rights reserved
77- 77+ 
78-Copyright (c) 1997-2011 by Secret Labs AB78+Copyright (c) 1997-2011 by Secret Labs AB
79- 79+ 
80-Copyright (c) 2016- Facebook, Inc80+Copyright (c) 2016- Facebook, Inc
81- 81+ 
82-Copyright (c) 2014 Matthew Rocklin82+Copyright (c) 2014 Matthew Rocklin
83- 83+ 
84-Copyright (c) 2005-2022 NVIDIA Corporation Built84+Copyright (c) 2005-2022 NVIDIA Corporation Built
85- 85+ 
86-Copyright (c) Facebook, Inc.86+Copyright (c) Facebook, Inc.
87- 87+ 
88-Copyright 2019-2020 Kakao Brain88+Copyright 2019-2020 Kakao Brain
89- 89+ 
90-Copyright (c) 2000-2017 Julian Seward. All rights reserved90+Copyright (c) 2000-2017 Julian Seward. All rights reserved
91- 91+ 
92-Copyright (c) 2005-2020 Rich Felker92+Copyright (c) 2005-2020 Rich Felker
93- 93+ 
94-Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved94+Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved
95- 95+ 
96-Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC96+Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
97- 97+ 
98-Copyright (c) 2016 Facebook Inc.98+Copyright (c) 2016 Facebook Inc.
99- 99+ 
100-Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)100+Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)
101- 101+ 
102-Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC All Rights Reserved102+Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC All Rights Reserved
103- 103+ 
104-Copyright (c) 2012-2014 Deepmind Technologies104+Copyright (c) 2012-2014 Deepmind Technologies
105- 105+ 
106-Copyright (c) 2012 Giovanni Garberoglio Interdisciplinary Laboratory106+Copyright (c) 2012 Giovanni Garberoglio Interdisciplinary Laboratory
107- 107+ 
108-Copyright (c) 2024, Tri Dao108+Copyright (c) 2024, Tri Dao
109- 109+ 
110-Copyright (c) Donald Stufft and individual contributors. All rights reserved110+Copyright (c) Donald Stufft and individual contributors. All rights reserved
111- 111+ 
112-Copyright (c) 2018, Steven Moshier All rights reserved112+Copyright (c) 2018, Steven Moshier All rights reserved
113- 113+ 
114-Copyright (c) 2015 Google Inc. All rights reserved114+Copyright (c) 2015 Google Inc. All rights reserved
115- 115+ 
116-Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved116+Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved
117- 117+ 
118-Copyright (c) 2010-2022 by Alex Clark and contributors118+Copyright (c) 2010-2022 by Alex Clark and contributors
119- 119+ 
120-Copyright 2015 Google Inc. All Rights Reserved120+Copyright 2015 Google Inc. All Rights Reserved
121- 121+ 
122-Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved122+Copyright (c) 2017 - 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved
123- 123+ 
124-Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved124+Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved
125- 125+ 
126-Copyright (c) 2016 manylinux126+Copyright (c) 2016 manylinux
127- 127+ 
128-Copyright (c) 2017 - 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved128+Copyright (c) 2017 - 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved
129- 129+ 
130-Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)130+Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
131- 131+ 
132-Copyright 2013-2014 RAD Game132+Copyright 2013-2014 RAD Game
133- 133+ 
134-Copyright (c) 2011-2019 Stephan Brumme. All rights reserved134+Copyright (c) 2011-2019 Stephan Brumme. All rights reserved
135- 135+ 
136-Copyright (c) 2018 MathInf GmbH, Thomas Viehmann136+Copyright (c) 2018 MathInf GmbH, Thomas Viehmann
137- 137+ 
138-Copyright (c) 2013 Eddy Petrisor138+Copyright (c) 2013 Eddy Petrisor
139- 139+ 
140-Copyright (c) 2023-2024 The ggml140+Copyright (c) 2023-2024 The ggml
141- 141+ 
142-Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Python Software Foundation All Rights Reserved142+Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Python Software Foundation All Rights Reserved
143- 143+ 
144-Copyright 2004-present Facebook. All Rights Reserved144+Copyright 2004-present Facebook. All Rights Reserved
145- 145+ 
146-Copyright (c) 2010 ActiveState Software Inc.146+Copyright (c) 2010 ActiveState Software Inc.
147- 147+ 
148-Copyright (c) 2006 The Android Open Source Project148+Copyright (c) 2006 The Android Open Source Project
149- 149+ 
150-(c) Meta Platforms, Inc. and affiliates. All rights reserved150+(c) Meta Platforms, Inc. and affiliates. All rights reserved
151- 151+ 
152-Copyright (c) 2023 Apple Inc.152+Copyright (c) 2023 Apple Inc.
153- 153+ 
154-Copyright (c) Microsoft Corporation. All rights reserved154+Copyright (c) Microsoft Corporation. All rights reserved
155- 155+ 
156-Copyright 2015 The TensorFlow Authors. All Rights Reserved156+Copyright 2015 The TensorFlow Authors. All Rights Reserved
157- 157+ 
158-Copyright (c) 2023, Tri Dao158+Copyright (c) 2023, Tri Dao
159- 159+ 
160-Copyright 2022 Cruise LLC160+Copyright 2022 Cruise LLC
161- 161+ 
162-Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved162+Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved
163- 163+ 
164-Copyright (c) 2022 Cruise LLC. All rights reserved164+Copyright (c) 2022 Cruise LLC. All rights reserved
165- 165+ 
166-Copyright (c) 2016-present, Facebook, Inc.166+Copyright (c) 2016-present, Facebook, Inc.
167- 167+ 
168-(c) Copyright John Maddock 2006168+(c) Copyright John Maddock 2006
169- 169+ 
170-Copyright (c) 2011-2014 Idiap Research Institute170+Copyright (c) 2011-2014 Idiap Research Institute
171- 171+ 
172-Copyright (c) 2014 Indiana University All rights reserved172+Copyright (c) 2014 Indiana University All rights reserved
173- 173+ 
174-copyright 2019 The TensorFlow Authors174+copyright 2019 The TensorFlow Authors
175- 175+ 
176-Copyright (c) 2016-present, Facebook Inc. All rights reserved176+Copyright (c) 2016-present, Facebook Inc. All rights reserved
177- 177+ 
178-License: BSD 3-Clause License178+License: BSD 3-Clause License
179-Copyright (c) ,179+Copyright (c) ,
180-All rights reserved.180+All rights reserved.
181- 181+ 
182-1. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:182+1. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
183- 183+ 
184-2. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.184+2. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
185- 185+ 
186-3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.186+3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
187- 187+ 
188-Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.188+Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
189- 189+ 
190-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.190+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Msetup.py+790-790
@@ -1,790 +1,790 @@
1-import glob1+import glob
2-import multiprocessing2+import multiprocessing
3-import multiprocessing.pool3+import multiprocessing.pool
4-import os4+import os
5-import re5+import re
6-import shutil6+import shutil
7-import stat7+import stat
8-import subprocess8+import subprocess
9-import sys9+import sys
10-import traceback10+import traceback
11-import platform11+import platform
12-import time12+import time
13-from pathlib import Path13+from pathlib import Path
14-from typing import Union14+from typing import Union
15- 15+ 
16-import distutils.ccompiler16+import distutils.ccompiler
17-import distutils.command.clean17+import distutils.command.clean
18-from sysconfig import get_paths18+from sysconfig import get_paths
19-from distutils.version import LooseVersion19+from distutils.version import LooseVersion
20-from distutils.command.build_py import build_py20+from distutils.command.build_py import build_py
21-from setuptools.command.build_ext import build_ext21+from setuptools.command.build_ext import build_ext
22-from setuptools.command.install import install22+from setuptools.command.install import install
23-from setuptools import setup, distutils, Extension23+from setuptools import setup, distutils, Extension
24-from setuptools.command.build_clib import build_clib24+from setuptools.command.build_clib import build_clib
25-from setuptools.command.egg_info import egg_info25+from setuptools.command.egg_info import egg_info
26-from wheel.bdist_wheel import bdist_wheel26+from wheel.bdist_wheel import bdist_wheel
27- 27+ 
28-# Disable autoloading before running 'import torch' to avoid circular dependencies28+# Disable autoloading before running 'import torch' to avoid circular dependencies
29-os.environ["TORCH_DEVICE_BACKEND_AUTOLOAD"] = "0"29+os.environ["TORCH_DEVICE_BACKEND_AUTOLOAD"] = "0"
30- 30+ 
31-from torchnpugen.utils import PathManager31+from torchnpugen.utils import PathManager
32- 32+ 
33-BASE_DIR = os.path.dirname(os.path.realpath(__file__))33+BASE_DIR = os.path.dirname(os.path.realpath(__file__))
34-THIRD_PARTY_PATH = os.path.join(BASE_DIR, "third_party")34+THIRD_PARTY_PATH = os.path.join(BASE_DIR, "third_party")
35-PathManager.check_directory_path_readable(os.path.join(BASE_DIR, "version.txt"))35+PathManager.check_directory_path_readable(os.path.join(BASE_DIR, "version.txt"))
36-with open(os.path.join(BASE_DIR, "version.txt")) as version_f:36+with open(os.path.join(BASE_DIR, "version.txt")) as version_f:
37- VERSION = version_f.read().strip()37+ VERSION = version_f.read().strip()
38-UNKNOWN = "Unknown"38+UNKNOWN = "Unknown"
39-BUILD_PERMISSION = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP39+BUILD_PERMISSION = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IXGRP
40- 40+ 
41-DISABLE_TORCHAIR = "FALSE"41+DISABLE_TORCHAIR = "FALSE"
42-if os.environ.get("DISABLE_INSTALL_TORCHAIR") is not None:42+if os.environ.get("DISABLE_INSTALL_TORCHAIR") is not None:
43- DISABLE_TORCHAIR = os.environ.get("DISABLE_INSTALL_TORCHAIR")43+ DISABLE_TORCHAIR = os.environ.get("DISABLE_INSTALL_TORCHAIR")
44-DISABLE_RPC = "FALSE"44+DISABLE_RPC = "FALSE"
45-if os.environ.get("DISABLE_RPC_FRAMEWORK") is not None:45+if os.environ.get("DISABLE_RPC_FRAMEWORK") is not None:
46- DISABLE_RPC = os.environ.get("DISABLE_RPC_FRAMEWORK")46+ DISABLE_RPC = os.environ.get("DISABLE_RPC_FRAMEWORK")
47-ENABLE_LTO = "FALSE"47+ENABLE_LTO = "FALSE"
48-if os.environ.get("ENABLE_LTO") is not None:48+if os.environ.get("ENABLE_LTO") is not None:
49- ENABLE_LTO = os.environ.get("ENABLE_LTO")49+ ENABLE_LTO = os.environ.get("ENABLE_LTO")
50-PGO_MODE = 050+PGO_MODE = 0
51-if os.environ.get("PGO_MODE") is not None:51+if os.environ.get("PGO_MODE") is not None:
52- PGO_MODE = int(os.environ.get("PGO_MODE"))52+ PGO_MODE = int(os.environ.get("PGO_MODE"))
53- 53+ 
54-# change to use cxx11.abi in default since 2.754+# change to use cxx11.abi in default since 2.7
55-USE_CXX11_ABI = True55+USE_CXX11_ABI = True
56-if os.environ.get("_GLIBCXX_USE_CXX11_ABI") is not None and os.environ.get("_GLIBCXX_USE_CXX11_ABI") == "0":56+if os.environ.get("_GLIBCXX_USE_CXX11_ABI") is not None and os.environ.get("_GLIBCXX_USE_CXX11_ABI") == "0":
57- USE_CXX11_ABI = False57+ USE_CXX11_ABI = False
58- 58+ 
59- 59+ 
60-def get_submodule_folders():60+def get_submodule_folders():
61- git_modules_path = os.path.join(BASE_DIR, ".gitmodules")61+ git_modules_path = os.path.join(BASE_DIR, ".gitmodules")
62- default_modules_path = [62+ default_modules_path = [
63- os.path.join(THIRD_PARTY_PATH, name)63+ os.path.join(THIRD_PARTY_PATH, name)
64- for name in [64+ for name in [
65- "op-plugin",65+ "op-plugin",
66- ]66+ ]
67- ]67+ ]
68- if not os.path.exists(git_modules_path):68+ if not os.path.exists(git_modules_path):
69- return default_modules_path69+ return default_modules_path
70- with open(git_modules_path) as f:70+ with open(git_modules_path) as f:
71- return [71+ return [
72- os.path.join(BASE_DIR, line.split("=", 1)[1].strip())72+ os.path.join(BASE_DIR, line.split("=", 1)[1].strip())
73- for line in f.readlines()73+ for line in f.readlines()
74- if line.strip().startswith("path")74+ if line.strip().startswith("path")
75- ]75+ ]
76- 76+ 
77- 77+ 
78-def check_submodules():78+def check_submodules():
79- def not_exists_or_empty(folder):79+ def not_exists_or_empty(folder):
80- return not os.path.exists(folder) or (80+ return not os.path.exists(folder) or (
81- os.path.isdir(folder) and len(os.listdir(folder)) == 081+ os.path.isdir(folder) and len(os.listdir(folder)) == 0
82- )82+ )
83- 83+ 
84- folders = get_submodule_folders()84+ folders = get_submodule_folders()
85- # If none of the submodule folders exists, try to initialize them85+ # If none of the submodule folders exists, try to initialize them
86- if all(not_exists_or_empty(folder) for folder in folders):86+ if all(not_exists_or_empty(folder) for folder in folders):
87- try:87+ try:
88- print(" --- Trying to initialize submodules")88+ print(" --- Trying to initialize submodules")
89- start = time.time()89+ start = time.time()
90- subprocess.check_call(["git", "submodule", "update", "--init", "--recursive"], cwd=BASE_DIR) # Compliant90+ subprocess.check_call(["git", "submodule", "update", "--init", "--recursive"], cwd=BASE_DIR) # Compliant
91- end = time.time()91+ end = time.time()
92- print(f" --- Submodule initialization took {end - start:.2f} sec")92+ print(f" --- Submodule initialization took {end - start:.2f} sec")
93- except Exception:93+ except Exception:
94- print(" --- Submodule initalization failed")94+ print(" --- Submodule initalization failed")
95- print("Please run:\n\tgit submodule init && git submodule update")95+ print("Please run:\n\tgit submodule init && git submodule update")
96- sys.exit(1)96+ sys.exit(1)
97- 97+ 
98- 98+ 
99-check_submodules()99+check_submodules()
100- 100+ 
101- 101+ 
102-def get_sha(pytorch_root: Union[str, Path]) -> str:102+def get_sha(pytorch_root: Union[str, Path]) -> str:
103- try:103+ try:
104- return (104+ return (
105- subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=pytorch_root) # Compliant105+ subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=pytorch_root) # Compliant
106- .decode("ascii")106+ .decode("ascii")
107- .strip()107+ .strip()
108- )108+ )
109- except Exception:109+ except Exception:
110- return UNKNOWN110+ return UNKNOWN
111- 111+ 
112- 112+ 
113-def generate_torch_npu_version():113+def generate_torch_npu_version():
114- torch_npu_root = Path(__file__).parent114+ torch_npu_root = Path(__file__).parent
115- version_path = torch_npu_root / "torch_npu" / "version.py"115+ version_path = torch_npu_root / "torch_npu" / "version.py"
116- if version_path.exists():116+ if version_path.exists():
117- version_path.unlink()117+ version_path.unlink()
118- flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL118+ flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
119- modes = stat.S_IWUSR | stat.S_IRUSR119+ modes = stat.S_IWUSR | stat.S_IRUSR
120- sha = get_sha(torch_npu_root)120+ sha = get_sha(torch_npu_root)
121- if os.getenv("BUILD_WITHOUT_SHA") is None:121+ if os.getenv("BUILD_WITHOUT_SHA") is None:
122- global VERSION122+ global VERSION
123- VERSION += "+git" + sha[:7]123+ VERSION += "+git" + sha[:7]
124- with os.fdopen(os.open(version_path, flags, modes), 'w') as f:124+ with os.fdopen(os.open(version_path, flags, modes), 'w') as f:
125- f.write("__version__ = '{version}'\n".format(version=VERSION))125+ f.write("__version__ = '{version}'\n".format(version=VERSION))
126- f.write("git_version = {}\n".format(repr(sha)))126+ f.write("git_version = {}\n".format(repr(sha)))
127- os.chmod(version_path, mode=stat.S_IRUSR | stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)127+ os.chmod(version_path, mode=stat.S_IRUSR | stat.S_IEXEC | stat.S_IRGRP | stat.S_IXGRP)
128- 128+ 
129- 129+ 
130-generate_torch_npu_version()130+generate_torch_npu_version()
131- 131+ 
132- 132+ 
133-def _get_torch_requires():133+def _get_torch_requires():
134- torch_version = os.environ.get("TORCH_VERSION", "")134+ torch_version = os.environ.get("TORCH_VERSION", "")
135- if not torch_version:135+ if not torch_version:
136- try:136+ try:
137- import torch137+ import torch
138- torch_version = torch.__version__.split("+")[0]138+ torch_version = torch.__version__.split("+")[0]
139- except ImportError:139+ except ImportError:
140- pass140+ pass
141- return ["torch==" + torch_version] if torch_version else []141+ return ["torch==" + torch_version] if torch_version else []
142- 142+ 
143- 143+ 
144-def which(thefile):144+def which(thefile):
145- path = os.environ.get("PATH", os.defpath).split(os.pathsep)145+ path = os.environ.get("PATH", os.defpath).split(os.pathsep)
146- for d in path:146+ for d in path:
147- fname = os.path.join(d, thefile)147+ fname = os.path.join(d, thefile)
148- fnames = [fname]148+ fnames = [fname]
149- if sys.platform == 'win32':149+ if sys.platform == 'win32':
150- exts = os.environ.get('PATHEXT', '').split(os.pathsep)150+ exts = os.environ.get('PATHEXT', '').split(os.pathsep)
151- fnames += [fname + ext for ext in exts]151+ fnames += [fname + ext for ext in exts]
152- for name in fnames:152+ for name in fnames:
153- if os.access(name, os.F_OK | os.X_OK) and not os.path.isdir(name):153+ if os.access(name, os.F_OK | os.X_OK) and not os.path.isdir(name):
154- return name154+ return name
155- return None155+ return None
156- 156+ 
157- 157+ 
158-def get_cmake_command():158+def get_cmake_command():
159- def _get_version(cmd):159+ def _get_version(cmd):
160- for line in subprocess.check_output([cmd, '--version']).decode('utf-8').split('\n'):160+ for line in subprocess.check_output([cmd, '--version']).decode('utf-8').split('\n'):
161- if 'version' in line:161+ if 'version' in line:
162- return LooseVersion(line.strip().split(' ')[2])162+ return LooseVersion(line.strip().split(' ')[2])
163- raise RuntimeError('no version found')163+ raise RuntimeError('no version found')
164- "Returns cmake command."164+ "Returns cmake command."
165- cmake_command = 'cmake'165+ cmake_command = 'cmake'
166- if platform.system() == 'Windows':166+ if platform.system() == 'Windows':
167- return cmake_command167+ return cmake_command
168- cmake3 = which('cmake3')168+ cmake3 = which('cmake3')
169- cmake = which('cmake')169+ cmake = which('cmake')
170- if cmake3 is not None and _get_version(cmake3) >= LooseVersion("3.18.0"):170+ if cmake3 is not None and _get_version(cmake3) >= LooseVersion("3.18.0"):
171- cmake_command = 'cmake3'171+ cmake_command = 'cmake3'
172- return cmake_command172+ return cmake_command
173- elif cmake is not None and _get_version(cmake) >= LooseVersion("3.18.0"):173+ elif cmake is not None and _get_version(cmake) >= LooseVersion("3.18.0"):
174- return cmake_command174+ return cmake_command
175- else:175+ else:
176- raise RuntimeError('no cmake or cmake3 with version >= 3.18.0 found')176+ raise RuntimeError('no cmake or cmake3 with version >= 3.18.0 found')
177- 177+ 
178- 178+ 
179-def get_build_type():179+def get_build_type():
180- build_type = 'Release'180+ build_type = 'Release'
181- if os.getenv('DEBUG', default='0').upper() in ['ON', '1', 'YES', 'TRUE', 'Y']:181+ if os.getenv('DEBUG', default='0').upper() in ['ON', '1', 'YES', 'TRUE', 'Y']:
182- build_type = 'Debug'182+ build_type = 'Debug'
183- 183+ 
184- if os.getenv('REL_WITH_DEB_INFO', default='0').upper() in ['ON', '1', 'YES', 'TRUE', 'Y']:184+ if os.getenv('REL_WITH_DEB_INFO', default='0').upper() in ['ON', '1', 'YES', 'TRUE', 'Y']:
185- build_type = 'RelWithDebInfo'185+ build_type = 'RelWithDebInfo'
186- 186+ 
187- return build_type187+ return build_type
188- 188+ 
189- 189+ 
190-def _get_build_mode():190+def _get_build_mode():
191- for i in range(1, len(sys.argv)):191+ for i in range(1, len(sys.argv)):
192- if not sys.argv[i].startswith('-'):192+ if not sys.argv[i].startswith('-'):
193- return sys.argv[i]193+ return sys.argv[i]
194- 194+ 
195- raise RuntimeError("Run setup.py without build mode.")195+ raise RuntimeError("Run setup.py without build mode.")
196- 196+ 
197- 197+ 
198-def get_pytorch_dir():198+def get_pytorch_dir():
199- try:199+ try:
200- import torch200+ import torch
201- return os.path.dirname(os.path.realpath(torch.__file__))201+ return os.path.dirname(os.path.realpath(torch.__file__))
202- except Exception:202+ except Exception:
203- _, _, exc_traceback = sys.exc_info()203+ _, _, exc_traceback = sys.exc_info()
204- frame_summary = traceback.extract_tb(exc_traceback)[-1]204+ frame_summary = traceback.extract_tb(exc_traceback)[-1]
205- return os.path.dirname(frame_summary.filename)205+ return os.path.dirname(frame_summary.filename)
206- 206+ 
207- 207+ 
208-def generate_bindings_code(base_dir):208+def generate_bindings_code(base_dir):
209- python_execute = sys.executable209+ python_execute = sys.executable
210- generate_code_cmd = ["bash", os.path.join(base_dir, 'generate_code.sh'), python_execute, VERSION]210+ generate_code_cmd = ["bash", os.path.join(base_dir, 'generate_code.sh'), python_execute, VERSION]
211- if subprocess.call(generate_code_cmd) != 0: # Compliant211+ if subprocess.call(generate_code_cmd) != 0: # Compliant
212- print(212+ print(
213- 'Failed to generate ATEN bindings: {}'.format(generate_code_cmd),213+ 'Failed to generate ATEN bindings: {}'.format(generate_code_cmd),
214- file=sys.stderr)214+ file=sys.stderr)
215- sys.exit(1)215+ sys.exit(1)
216- 216+ 
217- 217+ 
218-def build_stub(base_dir):218+def build_stub(base_dir):
219- build_stub_cmd = ["sh", os.path.join(base_dir, 'third_party/acl/libs/build_stub.sh')]219+ build_stub_cmd = ["sh", os.path.join(base_dir, 'third_party/acl/libs/build_stub.sh')]
220- if subprocess.call(build_stub_cmd) != 0:220+ if subprocess.call(build_stub_cmd) != 0:
221- print(221+ print(
222- 'Failed to build stub: {}'.format(build_stub_cmd),222+ 'Failed to build stub: {}'.format(build_stub_cmd),
223- file=sys.stderr)223+ file=sys.stderr)
224- sys.exit(1)224+ sys.exit(1)
225- 225+ 
226- 226+ 
227-def check_torchair_valid(base_dir):227+def check_torchair_valid(base_dir):
228- # build with submodule of torchair, if path of torchair is valid228+ # build with submodule of torchair, if path of torchair is valid
229- torchair_path = os.path.join(base_dir, 'third_party/torchair/torchair')229+ torchair_path = os.path.join(base_dir, 'third_party/torchair/torchair')
230- return os.path.exists(torchair_path) and (230+ return os.path.exists(torchair_path) and (
231- os.path.isdir(torchair_path) and len(os.listdir(torchair_path)) != 0231+ os.path.isdir(torchair_path) and len(os.listdir(torchair_path)) != 0
232- )232+ )
233- 233+ 
234- 234+ 
235-def check_tensorpipe_valid(base_dir):235+def check_tensorpipe_valid(base_dir):
236- tensorpipe_path = os.path.join(base_dir, 'third_party/Tensorpipe/tensorpipe')236+ tensorpipe_path = os.path.join(base_dir, 'third_party/Tensorpipe/tensorpipe')
237- return os.path.exists(tensorpipe_path)237+ return os.path.exists(tensorpipe_path)
238- 238+ 
239- 239+ 
240-def generate_dbg_files_and_strip():240+def generate_dbg_files_and_strip():
241- library_dir = Path(BASE_DIR).joinpath("build/packages/torch_npu")241+ library_dir = Path(BASE_DIR).joinpath("build/packages/torch_npu")
242- dbg_dir = Path(BASE_DIR).joinpath("build/dbg")242+ dbg_dir = Path(BASE_DIR).joinpath("build/dbg")
243- os.makedirs(dbg_dir, exist_ok=True)243+ os.makedirs(dbg_dir, exist_ok=True)
244- library_files = [Path(i) for i in library_dir.rglob('*.so')]244+ library_files = [Path(i) for i in library_dir.rglob('*.so')]
245- for library_file in library_files:245+ for library_file in library_files:
246- subprocess.check_call(["eu-strip", library_file, "-f",246+ subprocess.check_call(["eu-strip", library_file, "-f",
247- str(dbg_dir.joinpath(library_file.name)) + ".debug"], cwd=BASE_DIR) # Compliant247+ str(dbg_dir.joinpath(library_file.name)) + ".debug"], cwd=BASE_DIR) # Compliant
248- 248+ 
249- 249+ 
250-def patchelf_dynamic_library():250+def patchelf_dynamic_library():
251- # Process all .so files in lib directory251+ # Process all .so files in lib directory
252- lib_dir = Path(BASE_DIR).joinpath("build/packages/torch_npu/lib")252+ lib_dir = Path(BASE_DIR).joinpath("build/packages/torch_npu/lib")
253- lib_files = [str(i) for i in lib_dir.rglob('*.so')]253+ lib_files = [str(i) for i in lib_dir.rglob('*.so')]
254- 254+ 
255- for library_file in lib_files:255+ for library_file in lib_files:
256- subprocess.check_call(["patchelf", "--remove-needed", "libgomp.so.1", library_file], cwd=BASE_DIR) # Compliant256+ subprocess.check_call(["patchelf", "--remove-needed", "libgomp.so.1", library_file], cwd=BASE_DIR) # Compliant
257- 257+ 
258- 258+ 
259- 259+ 
260-def CppExtension(name, sources, *args, **kwargs):260+def CppExtension(name, sources, *args, **kwargs):
261- r'''261+ r'''
262- Creates a :class:`setuptools.Extension` for C++.262+ Creates a :class:`setuptools.Extension` for C++.
263- '''263+ '''
264- pytorch_dir = get_pytorch_dir()264+ pytorch_dir = get_pytorch_dir()
265- temp_include_dirs = kwargs.get('include_dirs', [])265+ temp_include_dirs = kwargs.get('include_dirs', [])
266- temp_include_dirs.append(os.path.join(pytorch_dir, 'include'))266+ temp_include_dirs.append(os.path.join(pytorch_dir, 'include'))
267- temp_include_dirs.append(os.path.join(pytorch_dir, 'include/torch/csrc/api/include'))267+ temp_include_dirs.append(os.path.join(pytorch_dir, 'include/torch/csrc/api/include'))
268- kwargs['include_dirs'] = temp_include_dirs268+ kwargs['include_dirs'] = temp_include_dirs
269- 269+ 
270- temp_library_dirs = kwargs.get('library_dirs', [])270+ temp_library_dirs = kwargs.get('library_dirs', [])
271- temp_library_dirs.append(os.path.join(pytorch_dir, 'lib'))271+ temp_library_dirs.append(os.path.join(pytorch_dir, 'lib'))
272- temp_library_dirs.append(os.path.join(BASE_DIR, "third_party/acl/libs"))272+ temp_library_dirs.append(os.path.join(BASE_DIR, "third_party/acl/libs"))
273- kwargs['library_dirs'] = temp_library_dirs273+ kwargs['library_dirs'] = temp_library_dirs
274- 274+ 
275- libraries = kwargs.get('libraries', [])275+ libraries = kwargs.get('libraries', [])
276- libraries.append('c10')276+ libraries.append('c10')
277- libraries.append('torch')277+ libraries.append('torch')
278- libraries.append('torch_cpu')278+ libraries.append('torch_cpu')
279- libraries.append('torch_python')279+ libraries.append('torch_python')
280- libraries.append('hccl')280+ libraries.append('hccl')
281- kwargs['libraries'] = libraries281+ kwargs['libraries'] = libraries
282- kwargs['language'] = 'c++'282+ kwargs['language'] = 'c++'
283- return Extension(name, sources, *args, **kwargs)283+ return Extension(name, sources, *args, **kwargs)
284- 284+ 
285- 285+ 
286-class Clean(distutils.command.clean.clean):286+class Clean(distutils.command.clean.clean):
287- 287+ 
288- def run(self):288+ def run(self):
289- f_ignore = open('.gitignore', 'r')289+ f_ignore = open('.gitignore', 'r')
290- ignores = f_ignore.read()290+ ignores = f_ignore.read()
291- pat = re.compile(r'^#( BEGIN NOT-CLEAN-FILES )?')291+ pat = re.compile(r'^#( BEGIN NOT-CLEAN-FILES )?')
292- for wildcard in filter(None, ignores.split('\n')):292+ for wildcard in filter(None, ignores.split('\n')):
293- match = pat.match(wildcard)293+ match = pat.match(wildcard)
294- if match:294+ if match:
295- if match.group(1):295+ if match.group(1):
296- # Marker is found and stop reading .gitignore.296+ # Marker is found and stop reading .gitignore.
297- break297+ break
298- # Ignore lines which begin with '#'.298+ # Ignore lines which begin with '#'.
299- else:299+ else:
300- for filename in glob.glob(wildcard):300+ for filename in glob.glob(wildcard):
301- if os.path.islink(filename):301+ if os.path.islink(filename):
302- raise RuntimeError(f"Failed to remove path: {filename}")302+ raise RuntimeError(f"Failed to remove path: {filename}")
303- if os.path.exists(filename):303+ if os.path.exists(filename):
304- try:304+ try:
305- shutil.rmtree(filename, ignore_errors=True)305+ shutil.rmtree(filename, ignore_errors=True)
306- except Exception as err:306+ except Exception as err:
307- raise RuntimeError(f"Failed to remove path: {filename}") from err307+ raise RuntimeError(f"Failed to remove path: {filename}") from err
308- f_ignore.close()308+ f_ignore.close()
309- 309+ 
310- # It's an old-style class in Python 2.7...310+ # It's an old-style class in Python 2.7...
311- distutils.command.clean.clean.run(self)311+ distutils.command.clean.clean.run(self)
312- 312+ 
313- remove_files = [313+ remove_files = [
314- 'torch_npu/csrc/aten/RegisterCPU.cpp',314+ 'torch_npu/csrc/aten/RegisterCPU.cpp',
315- 'torch_npu/csrc/aten/RegisterNPU.cpp',315+ 'torch_npu/csrc/aten/RegisterNPU.cpp',
316- 'torch_npu/csrc/aten/RegisterAutogradNPU.cpp',316+ 'torch_npu/csrc/aten/RegisterAutogradNPU.cpp',
317- 'torch_npu/csrc/aten/NPUNativeFunctions.h',317+ 'torch_npu/csrc/aten/NPUNativeFunctions.h',
318- 'torch_npu/csrc/aten/CustomRegisterSchema.cpp',318+ 'torch_npu/csrc/aten/CustomRegisterSchema.cpp',
319- 'torch_npu/csrc/aten/ForeachRegister.cpp',319+ 'torch_npu/csrc/aten/ForeachRegister.cpp',
320- 'torch_npu/utils/custom_ops.py',320+ 'torch_npu/utils/custom_ops.py',
321- 'torch_npu/version.py',321+ 'torch_npu/version.py',
322- ]322+ ]
323- for remove_file in remove_files:323+ for remove_file in remove_files:
324- file_path = os.path.join(BASE_DIR, remove_file)324+ file_path = os.path.join(BASE_DIR, remove_file)
325- if os.path.exists(file_path):325+ if os.path.exists(file_path):
326- os.remove(file_path)326+ os.remove(file_path)
327- 327+ 
328-USE_NINJA = os.environ["CMAKE_GENERATOR"].lower() == "ninja" if "CMAKE_GENERATOR" in os.environ else shutil.which("ninja")328+USE_NINJA = os.environ["CMAKE_GENERATOR"].lower() == "ninja" if "CMAKE_GENERATOR" in os.environ else shutil.which("ninja")
329- 329+ 
330-class CPPLibBuild(build_clib, object):330+class CPPLibBuild(build_clib, object):
331- def run(self):331+ def run(self):
332- cmake = get_cmake_command()332+ cmake = get_cmake_command()
333- 333+ 
334- if cmake is None:334+ if cmake is None:
335- raise RuntimeError(335+ raise RuntimeError(
336- "CMake must be installed to build the following extensions: " +336+ "CMake must be installed to build the following extensions: " +
337- ", ".join(e.name for e in self.extensions))337+ ", ".join(e.name for e in self.extensions))
338- self.cmake = cmake338+ self.cmake = cmake
339- 339+ 
340- build_dir = os.path.join(BASE_DIR, "build")340+ build_dir = os.path.join(BASE_DIR, "build")
341- build_type_dir = os.path.join(build_dir)341+ build_type_dir = os.path.join(build_dir)
342- output_lib_path = os.path.join(build_type_dir, "packages/torch_npu/lib")342+ output_lib_path = os.path.join(build_type_dir, "packages/torch_npu/lib")
343- os.makedirs(build_type_dir, exist_ok=True)343+ os.makedirs(build_type_dir, exist_ok=True)
344- os.chmod(build_type_dir, mode=BUILD_PERMISSION)344+ os.chmod(build_type_dir, mode=BUILD_PERMISSION)
345- os.makedirs(output_lib_path, exist_ok=True)345+ os.makedirs(output_lib_path, exist_ok=True)
346- self.build_lib = os.path.relpath(os.path.join(build_dir, "packages/torch_npu"))346+ self.build_lib = os.path.relpath(os.path.join(build_dir, "packages/torch_npu"))
347- self.build_temp = os.path.relpath(build_type_dir)347+ self.build_temp = os.path.relpath(build_type_dir)
348- 348+ 
349- cmake_args = [349+ cmake_args = [
350- '-DCMAKE_BUILD_TYPE=' + get_build_type(),350+ '-DCMAKE_BUILD_TYPE=' + get_build_type(),
351- '-DCMAKE_INSTALL_PREFIX=' + os.path.realpath(output_lib_path),351+ '-DCMAKE_INSTALL_PREFIX=' + os.path.realpath(output_lib_path),
352- '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + os.path.realpath(output_lib_path),352+ '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + os.path.realpath(output_lib_path),
353- '-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=' + os.path.realpath(output_lib_path),353+ '-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=' + os.path.realpath(output_lib_path),
354- '-DTORCHNPU_INSTALL_LIBDIR=' + os.path.realpath(output_lib_path),354+ '-DTORCHNPU_INSTALL_LIBDIR=' + os.path.realpath(output_lib_path),
355- '-DPYTHON_INCLUDE_DIR=' + get_paths().get('include'),355+ '-DPYTHON_INCLUDE_DIR=' + get_paths().get('include'),
356- '-DTORCH_VERSION=' + VERSION,356+ '-DTORCH_VERSION=' + VERSION,
357- '-DPYTORCH_INSTALL_DIR=' + get_pytorch_dir()]357+ '-DPYTORCH_INSTALL_DIR=' + get_pytorch_dir()]
358- 358+ 
359- if DISABLE_TORCHAIR == 'FALSE':359+ if DISABLE_TORCHAIR == 'FALSE':
360- if check_torchair_valid(BASE_DIR):360+ if check_torchair_valid(BASE_DIR):
361- cmake_args.append('-DBUILD_TORCHAIR=on')361+ cmake_args.append('-DBUILD_TORCHAIR=on')
362- torchair_install_prefix = os.path.join(build_type_dir, "packages/torch_npu/dynamo/torchair")362+ torchair_install_prefix = os.path.join(build_type_dir, "packages/torch_npu/dynamo/torchair")
363- cmake_args.append(f'-DTORCHAIR_INSTALL_PREFIX={torchair_install_prefix}')363+ cmake_args.append(f'-DTORCHAIR_INSTALL_PREFIX={torchair_install_prefix}')
364- cmake_args.append(f'-DTORCHAIR_TARGET_PYTHON={sys.executable}')364+ cmake_args.append(f'-DTORCHAIR_TARGET_PYTHON={sys.executable}')
365- 365+ 
366- if DISABLE_RPC == 'FALSE':366+ if DISABLE_RPC == 'FALSE':
367- if check_tensorpipe_valid(BASE_DIR):367+ if check_tensorpipe_valid(BASE_DIR):
368- cmake_args.append('-DBUILD_TENSORPIPE=on')368+ cmake_args.append('-DBUILD_TENSORPIPE=on')
369- 369+
370- if ENABLE_LTO == "TRUE":370+ if ENABLE_LTO == "TRUE":
371- cmake_args.append('-DENABLE_LTO=on')371+ cmake_args.append('-DENABLE_LTO=on')
372- if PGO_MODE != 0:372+ if PGO_MODE != 0:
373- cmake_args.append('-DPGO_MODE=' + str(PGO_MODE))373+ cmake_args.append('-DPGO_MODE=' + str(PGO_MODE))
374- 374+
375- if USE_CXX11_ABI:375+ if USE_CXX11_ABI:
376- cmake_args.append('-DGLIBCXX_USE_CXX11_ABI=1')376+ cmake_args.append('-DGLIBCXX_USE_CXX11_ABI=1')
377- 377+ 
378- if os.getenv('_ABI_VERSION') is not None:378+ if os.getenv('_ABI_VERSION') is not None:
379- cmake_args.append('-DABI_VERSION=' + os.getenv('_ABI_VERSION'))379+ cmake_args.append('-DABI_VERSION=' + os.getenv('_ABI_VERSION'))
380- 380+ 
381- if USE_NINJA:381+ if USE_NINJA:
382- cmake_args.append("-GNinja")382+ cmake_args.append("-GNinja")
383- 383+ 
384- max_jobs = os.getenv("MAX_JOBS")384+ max_jobs = os.getenv("MAX_JOBS")
385- if max_jobs is not None or not USE_NINJA:385+ if max_jobs is not None or not USE_NINJA:
386- max_jobs = max_jobs or str(multiprocessing.cpu_count())386+ max_jobs = max_jobs or str(multiprocessing.cpu_count())
387- build_args = ['-j', max_jobs]387+ build_args = ['-j', max_jobs]
388- else:388+ else:
389- build_args = []389+ build_args = []
390- 390+ 
391- subprocess.check_call([self.cmake, BASE_DIR] + cmake_args, cwd=build_type_dir, env=os.environ)391+ subprocess.check_call([self.cmake, BASE_DIR] + cmake_args, cwd=build_type_dir, env=os.environ)
392- for base_dir, dirs, files in os.walk(build_type_dir):392+ for base_dir, dirs, files in os.walk(build_type_dir):
393- for dir_name in dirs:393+ for dir_name in dirs:
394- dir_path = os.path.join(base_dir, dir_name)394+ dir_path = os.path.join(base_dir, dir_name)
395- os.chmod(dir_path, mode=BUILD_PERMISSION)395+ os.chmod(dir_path, mode=BUILD_PERMISSION)
396- for file_name in files:396+ for file_name in files:
397- file_path = os.path.join(base_dir, file_name)397+ file_path = os.path.join(base_dir, file_name)
398- os.chmod(file_path, mode=BUILD_PERMISSION)398+ os.chmod(file_path, mode=BUILD_PERMISSION)
399- 399+ 
400- if USE_NINJA:400+ if USE_NINJA:
401- subprocess.check_call(['ninja'] + build_args, cwd=build_type_dir, env=os.environ)401+ subprocess.check_call(['ninja'] + build_args, cwd=build_type_dir, env=os.environ)
402- else:402+ else:
403- subprocess.check_call(['make'] + build_args, cwd=build_type_dir, env=os.environ)403+ subprocess.check_call(['make'] + build_args, cwd=build_type_dir, env=os.environ)
404- 404+ 
405- 405+ 
406-class Build(build_ext, object):406+class Build(build_ext, object):
407- 407+ 
408- def run(self):408+ def run(self):
409- self.run_command('build_clib')409+ self.run_command('build_clib')
410- self.build_lib = os.path.relpath(os.path.join(BASE_DIR, "build/packages"))410+ self.build_lib = os.path.relpath(os.path.join(BASE_DIR, "build/packages"))
411- self.build_temp = os.path.relpath(os.path.join(BASE_DIR, "build"))411+ self.build_temp = os.path.relpath(os.path.join(BASE_DIR, "build"))
412- self.library_dirs.append(412+ self.library_dirs.append(
413- os.path.relpath(os.path.join(BASE_DIR, "build/packages/torch_npu/lib")))413+ os.path.relpath(os.path.join(BASE_DIR, "build/packages/torch_npu/lib")))
414- super(Build, self).run()414+ super(Build, self).run()
415- 415+ 
416- 416+ 
417-class InstallCmd(install):417+class InstallCmd(install):
418- 418+ 
419- def finalize_options(self) -> None:419+ def finalize_options(self) -> None:
420- self.build_lib = os.path.relpath(os.path.join(BASE_DIR, "build/packages"))420+ self.build_lib = os.path.relpath(os.path.join(BASE_DIR, "build/packages"))
421- return super(InstallCmd, self).finalize_options()421+ return super(InstallCmd, self).finalize_options()
422- 422+ 
423- 423+ 
424-def add_ops_files(base_dir, file_list):424+def add_ops_files(base_dir, file_list):
425- # add ops header files425+ # add ops header files
426- plugin_path = os.path.join(base_dir, 'third_party/op-plugin/op_plugin/include')426+ plugin_path = os.path.join(base_dir, 'third_party/op-plugin/op_plugin/include')
427- if os.path.exists(plugin_path):427+ if os.path.exists(plugin_path):
428- file_list.append('third_party/op-plugin/op_plugin/include/*.h')428+ file_list.append('third_party/op-plugin/op_plugin/include/*.h')
429- plugin_utils_path = os.path.join(base_dir, 'third_party/op-plugin/op_plugin/utils')429+ plugin_utils_path = os.path.join(base_dir, 'third_party/op-plugin/op_plugin/utils')
430- if os.path.exists(plugin_utils_path):430+ if os.path.exists(plugin_utils_path):
431- file_list.append('third_party/op-plugin/op_plugin/utils/*.h')431+ file_list.append('third_party/op-plugin/op_plugin/utils/*.h')
432- return432+ return
433- 433+ 
434- 434+ 
435-def add_ops_python_files(ret_list):435+def add_ops_python_files(ret_list):
436- # add ops python files436+ # add ops python files
437- opplugin_path = os.path.join(BASE_DIR, 'third_party/op-plugin/op_plugin/python')437+ opplugin_path = os.path.join(BASE_DIR, 'third_party/op-plugin/op_plugin/python')
438- 438+ 
439- if os.path.exists(opplugin_path):439+ if os.path.exists(opplugin_path):
440- ops_python_files = glob.glob(os.path.join(opplugin_path, '**/*.py'), recursive=True) 440+ ops_python_files = glob.glob(os.path.join(opplugin_path, '**/*.py'), recursive=True)
441- for src in ops_python_files:441+ for src in ops_python_files:
442- dst = os.path.join(442+ dst = os.path.join(
443- os.path.join(BASE_DIR, "build/packages/torch_npu/op_plugin"),443+ os.path.join(BASE_DIR, "build/packages/torch_npu/op_plugin"),
444- os.path.relpath(src, opplugin_path))444+ os.path.relpath(src, opplugin_path))
445- os.makedirs(os.path.dirname(dst), exist_ok=True) 445+ os.makedirs(os.path.dirname(dst), exist_ok=True)
446- ret_list.append((src, dst))446+ ret_list.append((src, dst))
447- return447+ return
448- 448+ 
449- 449+ 
450-def get_src_py_and_dst():450+def get_src_py_and_dst():
451- ret = []451+ ret = []
452- generated_python_files = glob.glob(452+ generated_python_files = glob.glob(
453- os.path.join(BASE_DIR, "torch_npu", '**/*.py'),453+ os.path.join(BASE_DIR, "torch_npu", '**/*.py'),
454- recursive=True) + glob.glob(454+ recursive=True) + glob.glob(
455- os.path.join(BASE_DIR, "torch_npu", '**/*.yaml'),455+ os.path.join(BASE_DIR, "torch_npu", '**/*.yaml'),
456- recursive=True) + glob.glob(456+ recursive=True) + glob.glob(
457- os.path.join(BASE_DIR, "torch_npu", 'acl*.json'),457+ os.path.join(BASE_DIR, "torch_npu", 'acl*.json'),
458- recursive=True) + glob.glob(458+ recursive=True) + glob.glob(
459- os.path.join(BASE_DIR, "torch_npu", 'contrib/apis_config.json'),459+ os.path.join(BASE_DIR, "torch_npu", 'contrib/apis_config.json'),
460- recursive=True)460+ recursive=True)
461- for src in generated_python_files:461+ for src in generated_python_files:
462- dst = os.path.join(462+ dst = os.path.join(
463- os.path.join(BASE_DIR, "build/packages/torch_npu"),463+ os.path.join(BASE_DIR, "build/packages/torch_npu"),
464- os.path.relpath(src, os.path.join(BASE_DIR, "torch_npu")))464+ os.path.relpath(src, os.path.join(BASE_DIR, "torch_npu")))
465- os.makedirs(os.path.dirname(dst), exist_ok=True)465+ os.makedirs(os.path.dirname(dst), exist_ok=True)
466- ret.append((src, dst))466+ ret.append((src, dst))
467- 467+ 
468- add_ops_python_files(ret)468+ add_ops_python_files(ret)
469- 469+ 
470- header_files = [470+ header_files = [
471- "torch_npu/csrc/*.h",471+ "torch_npu/csrc/*.h",
472- "torch_npu/csrc/*/*.h",472+ "torch_npu/csrc/*/*.h",
473- "torch_npu/csrc/*/*.hpp",473+ "torch_npu/csrc/*/*.hpp",
474- "torch_npu/csrc/*/*/*.h",474+ "torch_npu/csrc/*/*/*.h",
475- "torch_npu/csrc/*/*/*/*.h",475+ "torch_npu/csrc/*/*/*/*.h",
476- "torch_npu/csrc/*/*/*/*/*.h",476+ "torch_npu/csrc/*/*/*/*/*.h",
477- "third_party/acl/inc/*/*.h",477+ "third_party/acl/inc/*/*.h",
478- "third_party/hccl/inc/*/*.h",478+ "third_party/hccl/inc/*/*.h",
479- "third_party/acl/inc/*/*/*.h",479+ "third_party/acl/inc/*/*/*.h",
480- "torch_npu/csrc/distributed/HCCLUtils.hpp",480+ "torch_npu/csrc/distributed/HCCLUtils.hpp",
481- "torch_npu/csrc/distributed/ProcessGroupHCCL.hpp"481+ "torch_npu/csrc/distributed/ProcessGroupHCCL.hpp"
482- ]482+ ]
483- add_ops_files(BASE_DIR, header_files)483+ add_ops_files(BASE_DIR, header_files)
484- glob_header_files = []484+ glob_header_files = []
485- for regex_pattern in header_files:485+ for regex_pattern in header_files:
486- glob_header_files += glob.glob(os.path.join(BASE_DIR, regex_pattern), recursive=True)486+ glob_header_files += glob.glob(os.path.join(BASE_DIR, regex_pattern), recursive=True)
487- 487+ 
488- for src in glob_header_files:488+ for src in glob_header_files:
489- dst = os.path.join(489+ dst = os.path.join(
490- os.path.join(BASE_DIR, "build/packages/torch_npu/include/torch_npu"),490+ os.path.join(BASE_DIR, "build/packages/torch_npu/include/torch_npu"),
491- os.path.relpath(src, os.path.join(BASE_DIR, "torch_npu")))491+ os.path.relpath(src, os.path.join(BASE_DIR, "torch_npu")))
492- os.makedirs(os.path.dirname(dst), exist_ok=True)492+ os.makedirs(os.path.dirname(dst), exist_ok=True)
493- ret.append((src, dst))493+ ret.append((src, dst))
494- 494+ 
495- torch_header_files = [495+ torch_header_files = [
496- "*/*.h",496+ "*/*.h",
497- "*/*/*.h",497+ "*/*/*.h",
498- "*/*/*/*.h",498+ "*/*/*/*.h",
499- "*/*/*/*/*.h",499+ "*/*/*/*/*.h",
500- "*/*/*/*/*/*.h"500+ "*/*/*/*/*/*.h"
501- ]501+ ]
502- torch_glob_header_files = []502+ torch_glob_header_files = []
503- for regex_pattern in torch_header_files:503+ for regex_pattern in torch_header_files:
504- torch_glob_header_files += glob.glob(os.path.join(BASE_DIR, "patch/include", regex_pattern), recursive=True)504+ torch_glob_header_files += glob.glob(os.path.join(BASE_DIR, "patch/include", regex_pattern), recursive=True)
505- 505+ 
506- for src in torch_glob_header_files:506+ for src in torch_glob_header_files:
507- dst = os.path.join(507+ dst = os.path.join(
508- os.path.join(BASE_DIR, "build/packages/torch_npu/include"),508+ os.path.join(BASE_DIR, "build/packages/torch_npu/include"),
509- os.path.relpath(src, os.path.join(BASE_DIR, "patch/include")))509+ os.path.relpath(src, os.path.join(BASE_DIR, "patch/include")))
510- os.makedirs(os.path.dirname(dst), exist_ok=True)510+ os.makedirs(os.path.dirname(dst), exist_ok=True)
511- ret.append((src, dst))511+ ret.append((src, dst))
512- 512+ 
513- aot_inductor_files = [513+ aot_inductor_files = [
514- # Follow torch v2.6.0.514+ # Follow torch v2.6.0.
515- # These aoti_runtime/*.cpp don't compile to libtorch_npu,515+ # These aoti_runtime/*.cpp don't compile to libtorch_npu,
516- # but act like header files when generate cppwrapper in aot-inductor.516+ # but act like header files when generate cppwrapper in aot-inductor.
517- "torch_npu/_inductor/codegen/aoti_runtime/*.cpp"517+ "torch_npu/_inductor/codegen/aoti_runtime/*.cpp"
518- ]518+ ]
519- glob_aoti_files = []519+ glob_aoti_files = []
520- for regex_pattern in aot_inductor_files:520+ for regex_pattern in aot_inductor_files:
521- glob_aoti_files += glob.glob(521+ glob_aoti_files += glob.glob(
522- os.path.join(BASE_DIR, regex_pattern), recursive=True522+ os.path.join(BASE_DIR, regex_pattern), recursive=True
523- )523+ )
524- 524+ 
525- for src in glob_aoti_files:525+ for src in glob_aoti_files:
526- # Dst: torch_npu/_inductor/codegen/aoti_runtime/*.cpp526+ # Dst: torch_npu/_inductor/codegen/aoti_runtime/*.cpp
527- dst = os.path.join(527+ dst = os.path.join(
528- os.path.join(BASE_DIR, "build/packages/torch_npu/"),528+ os.path.join(BASE_DIR, "build/packages/torch_npu/"),
529- os.path.relpath(src, os.path.join(BASE_DIR, "torch_npu")),529+ os.path.relpath(src, os.path.join(BASE_DIR, "torch_npu")),
530- )530+ )
531- os.makedirs(os.path.dirname(dst), exist_ok=True)531+ os.makedirs(os.path.dirname(dst), exist_ok=True)
532- ret.append((src, dst))532+ ret.append((src, dst))
533- 533+ 
534- 534+ 
535- def add_torch_npu_codegen(codegen_src_dir, codegen_dst_dir, exclude_root_init=None):535+ def add_torch_npu_codegen(codegen_src_dir, codegen_dst_dir, exclude_root_init=None):
536- """536+ """
537- 复制codegen目录下的文件到目标路径537+ 复制codegen目录下的文件到目标路径
538- :param codegen_src_dir: 源codegen目录538+ :param codegen_src_dir: 源codegen目录
539- :param codegen_dst_dir: 目标目录539+ :param codegen_dst_dir: 目标目录
540- :param exclude_root_init: 需要排除根目录__init__.py的源目录(仅过滤该目录下的__init__.py)540+ :param exclude_root_init: 需要排除根目录__init__.py的源目录(仅过滤该目录下的__init__.py)
541- """541+ """
542- # 匹配需要复制的文件类型542+ # 匹配需要复制的文件类型
543- codegen_files = glob.glob(543+ codegen_files = glob.glob(
544- os.path.join(codegen_src_dir, '**/*.py'), recursive=True544+ os.path.join(codegen_src_dir, '**/*.py'), recursive=True
545- ) + glob.glob(545+ ) + glob.glob(
546- os.path.join(codegen_src_dir, '**/*.yaml'), recursive=True546+ os.path.join(codegen_src_dir, '**/*.yaml'), recursive=True
547- ) + glob.glob(547+ ) + glob.glob(
548- os.path.join(codegen_src_dir, '**/*.json'), recursive=True548+ os.path.join(codegen_src_dir, '**/*.json'), recursive=True
549- ) + glob.glob(549+ ) + glob.glob(
550- os.path.join(codegen_src_dir, '**/*.cpp'), recursive=True550+ os.path.join(codegen_src_dir, '**/*.cpp'), recursive=True
551- ) + glob.glob(551+ ) + glob.glob(
552- os.path.join(codegen_src_dir, '**/*.h'), recursive=True552+ os.path.join(codegen_src_dir, '**/*.h'), recursive=True
553- )553+ )
554- 554+ 
555- # 按原目录结构复制到目标路径555+ # 按原目录结构复制到目标路径
556- for src in codegen_files:556+ for src in codegen_files:
557- # 仅过滤指定目录下的根级__init__.py557+ # 仅过滤指定目录下的根级__init__.py
558- if (exclude_root_init is not None and 558+ if (exclude_root_init is not None and
559- os.path.basename(src) == '__init__.py' and 559+ os.path.basename(src) == '__init__.py' and
560- os.path.dirname(src) == exclude_root_init):560+ os.path.dirname(src) == exclude_root_init):
561- continue # 跳过op-plugin/codegen根目录的__init__.py561+ continue # 跳过op-plugin/codegen根目录的__init__.py
562- 562+
563- # 计算目标路径(保留原目录层级)563+ # 计算目标路径(保留原目录层级)
564- dst = os.path.join(564+ dst = os.path.join(
565- codegen_dst_dir,565+ codegen_dst_dir,
566- os.path.relpath(src, codegen_src_dir) # 保留torchnpugen内部的目录层级566+ os.path.relpath(src, codegen_src_dir) # 保留torchnpugen内部的目录层级
567- )567+ )
568- print(os.path.relpath(src, codegen_src_dir))568+ print(os.path.relpath(src, codegen_src_dir))
569- # 确保目标目录存在569+ # 确保目标目录存在
570- os.makedirs(os.path.dirname(dst), exist_ok=True)570+ os.makedirs(os.path.dirname(dst), exist_ok=True)
571- # 加入文件复制列表571+ # 加入文件复制列表
572- ret.append((src, dst))572+ ret.append((src, dst))
573- 573+ 
574- # 新增:提前创建 torchnpugen 根目录574+ # 新增:提前创建 torchnpugen 根目录
575- torchnpugen_root = os.path.join(BASE_DIR, "build/packages/torchnpugen")575+ torchnpugen_root = os.path.join(BASE_DIR, "build/packages/torchnpugen")
576- os.makedirs(torchnpugen_root, exist_ok=True)576+ os.makedirs(torchnpugen_root, exist_ok=True)
577- # 将codegen复制到package路径577+ # 将codegen复制到package路径
578- codegen_src_dir = os.path.join(BASE_DIR, "torchnpugen")578+ codegen_src_dir = os.path.join(BASE_DIR, "torchnpugen")
579- codegen_dst_dir = os.path.join(BASE_DIR, "build/packages/torchnpugen")579+ codegen_dst_dir = os.path.join(BASE_DIR, "build/packages/torchnpugen")
580- # 复制torch_npu的torchnpugen580+ # 复制torch_npu的torchnpugen
581- add_torch_npu_codegen(codegen_src_dir, codegen_dst_dir)581+ add_torch_npu_codegen(codegen_src_dir, codegen_dst_dir)
582- # 复制op-plugin的torchnpugen(仅过滤其根目录的__init__.py)582+ # 复制op-plugin的torchnpugen(仅过滤其根目录的__init__.py)
583- op_plugin_codegen_src = os.path.join(BASE_DIR, "third_party/op-plugin/torchnpugen")583+ op_plugin_codegen_src = os.path.join(BASE_DIR, "third_party/op-plugin/torchnpugen")
584- add_torch_npu_codegen(584+ add_torch_npu_codegen(
585- op_plugin_codegen_src,585+ op_plugin_codegen_src,
586- codegen_dst_dir,586+ codegen_dst_dir,
587- exclude_root_init=op_plugin_codegen_src # 指定要过滤根目录__init__.py的源目录587+ exclude_root_init=op_plugin_codegen_src # 指定要过滤根目录__init__.py的源目录
588- )588+ )
589- 589+ 
590- return ret590+ return ret
591- 591+ 
592- 592+ 
593-class EggInfoBuild(egg_info, object):593+class EggInfoBuild(egg_info, object):
594- def finalize_options(self):594+ def finalize_options(self):
595- self.egg_base = os.path.relpath(os.path.join(BASE_DIR, "build/packages"))595+ self.egg_base = os.path.relpath(os.path.join(BASE_DIR, "build/packages"))
596- ret = get_src_py_and_dst()596+ ret = get_src_py_and_dst()
597- for src, dst in ret:597+ for src, dst in ret:
598- self.copy_file(src, dst)598+ self.copy_file(src, dst)
599- super(EggInfoBuild, self).finalize_options()599+ super(EggInfoBuild, self).finalize_options()
600- 600+ 
601- 601+ 
602-class PythonPackageBuild(build_py, object):602+class PythonPackageBuild(build_py, object):
603- def run(self) -> None:603+ def run(self) -> None:
604- ret = get_src_py_and_dst()604+ ret = get_src_py_and_dst()
605- for src, dst in ret:605+ for src, dst in ret:
606- self.copy_file(src, dst)606+ self.copy_file(src, dst)
607- super(PythonPackageBuild, self).finalize_options()607+ super(PythonPackageBuild, self).finalize_options()
608- 608+ 
609- 609+ 
610-class BdistWheelBuild(bdist_wheel):610+class BdistWheelBuild(bdist_wheel):
611- def run(self):611+ def run(self):
612- if which('patchelf') is not None:612+ if which('patchelf') is not None:
613- patchelf_dynamic_library()613+ patchelf_dynamic_library()
614- 614+ 
615- if not DEBUG and which('eu-strip') is not None:615+ if not DEBUG and which('eu-strip') is not None:
616- generate_dbg_files_and_strip()616+ generate_dbg_files_and_strip()
617- 617+ 
618- torch_dependencies = ["libc10.so", "libtorch.so", "libtorch_cpu.so", "libtorch_python.so"]618+ torch_dependencies = ["libc10.so", "libtorch.so", "libtorch_cpu.so", "libtorch_python.so"]
619- cann_dependencies = ["libhccl.so", "libascendcl.so", "libacl_op_compiler.so", "libge_runner.so",619+ cann_dependencies = ["libhccl.so", "libascendcl.so", "libacl_op_compiler.so", "libge_runner.so",
620- "libgraph.so", "libacl_tdt_channel.so", "libfmk_parser.so", "libascend_protobuf.so",620+ "libgraph.so", "libacl_tdt_channel.so", "libfmk_parser.so", "libascend_protobuf.so",
621- "libascend_ml.so"]621+ "libascend_ml.so"]
622- other_dependencies = ["libtorch_npu.so", "libnpu_profiler.so", "libgomp.so.1", "libatb.so"]622+ other_dependencies = ["libtorch_npu.so", "libnpu_profiler.so", "libgomp.so.1", "libatb.so"]
623- 623+ 
624- dependencies = torch_dependencies + cann_dependencies + other_dependencies624+ dependencies = torch_dependencies + cann_dependencies + other_dependencies
625- 625+ 
626- bdist_wheel.run(self)626+ bdist_wheel.run(self)
627- 627+ 
628- if is_manylinux:628+ if is_manylinux:
629- file = glob.glob(os.path.join(self.dist_dir, "*linux*.whl"))[0]629+ file = glob.glob(os.path.join(self.dist_dir, "*linux*.whl"))[0]
630- 630+ 
631- auditwheel_cmd = ["auditwheel", "-v", "repair", "-w", self.dist_dir, file]631+ auditwheel_cmd = ["auditwheel", "-v", "repair", "-w", self.dist_dir, file]
632- for i in dependencies:632+ for i in dependencies:
633- auditwheel_cmd += ["--exclude", i]633+ auditwheel_cmd += ["--exclude", i]
634- 634+ 
635- try:635+ try:
636- subprocess.run(auditwheel_cmd, check=True, stdout=subprocess.PIPE)636+ subprocess.run(auditwheel_cmd, check=True, stdout=subprocess.PIPE)
637- finally:637+ finally:
638- os.remove(file)638+ os.remove(file)
639- 639+ 
640- 640+ 
641-build_mode = _get_build_mode()641+build_mode = _get_build_mode()
642-if build_mode not in ['clean']:642+if build_mode not in ['clean']:
643- # Generate bindings code, including RegisterNPU.cpp & NPUNativeFunctions.h.643+ # Generate bindings code, including RegisterNPU.cpp & NPUNativeFunctions.h.
644- generate_bindings_code(BASE_DIR)644+ generate_bindings_code(BASE_DIR)
645- if Path(BASE_DIR).joinpath("third_party/Tensorpipe/third_party/acl/libs").exists():645+ if Path(BASE_DIR).joinpath("third_party/Tensorpipe/third_party/acl/libs").exists():
646- build_stub(Path(BASE_DIR).joinpath("third_party/Tensorpipe"))646+ build_stub(Path(BASE_DIR).joinpath("third_party/Tensorpipe"))
647- build_stub(BASE_DIR)647+ build_stub(BASE_DIR)
648- 648+ 
649-# Setup include directories folders.649+# Setup include directories folders.
650-include_directories = [650+include_directories = [
651- BASE_DIR,651+ BASE_DIR,
652- os.path.join(BASE_DIR, 'patch/include'),652+ os.path.join(BASE_DIR, 'patch/include'),
653- os.path.join(BASE_DIR, 'third_party/hccl/inc'),653+ os.path.join(BASE_DIR, 'third_party/hccl/inc'),
654- os.path.join(BASE_DIR, 'third_party/acl/inc'),654+ os.path.join(BASE_DIR, 'third_party/acl/inc'),
655- os.path.join(BASE_DIR, 'third_party/nlohmann/include')655+ os.path.join(BASE_DIR, 'third_party/nlohmann/include')
656-]656+]
657- 657+ 
658-extra_link_args = []658+extra_link_args = []
659- 659+ 
660-DEBUG = (os.getenv('DEBUG', default='').upper() in ['ON', '1', 'YES', 'TRUE', 'Y'])660+DEBUG = (os.getenv('DEBUG', default='').upper() in ['ON', '1', 'YES', 'TRUE', 'Y'])
661- 661+ 
662-extra_compile_args = [662+extra_compile_args = [
663- '-std=c++17',663+ '-std=c++17',
664- '-Wno-sign-compare',664+ '-Wno-sign-compare',
665- '-Wno-deprecated-declarations',665+ '-Wno-deprecated-declarations',
666- '-Wno-return-type'666+ '-Wno-return-type'
667-]667+]
668- 668+ 
669-if re.match(r'clang', os.getenv('CC', '')):669+if re.match(r'clang', os.getenv('CC', '')):
670- extra_compile_args += [670+ extra_compile_args += [
671- '-Wno-macro-redefined',671+ '-Wno-macro-redefined',
672- '-Wno-return-std-move',672+ '-Wno-return-std-move',
673- ]673+ ]
674- 674+ 
675-if DEBUG:675+if DEBUG:
676- extra_compile_args += ['-O0', '-g']676+ extra_compile_args += ['-O0', '-g']
677- extra_link_args += ['-O0', '-g', '-Wl,-z,now']677+ extra_link_args += ['-O0', '-g', '-Wl,-z,now']
678-else:678+else:
679- extra_compile_args += ['-DNDEBUG']679+ extra_compile_args += ['-DNDEBUG']
680- extra_link_args += ['-Wl,-z,now']680+ extra_link_args += ['-Wl,-z,now']
681- 681+ 
682-# valid manylinux tags682+# valid manylinux tags
683-manylinux_tags = [683+manylinux_tags = [
684- "manylinux1_x86_64",684+ "manylinux1_x86_64",
685- "manylinux2010_x86_64",685+ "manylinux2010_x86_64",
686- "manylinux2014_x86_64",686+ "manylinux2014_x86_64",
687- "manylinux2014_aarch64",687+ "manylinux2014_aarch64",
688- "manylinux_2_5_x86_64",688+ "manylinux_2_5_x86_64",
689- "manylinux_2_12_x86_64",689+ "manylinux_2_12_x86_64",
690- "manylinux_2_17_x86_64",690+ "manylinux_2_17_x86_64",
691- "manylinux_2_17_aarch64",691+ "manylinux_2_17_aarch64",
692- "manylinux_2_24_x86_64",692+ "manylinux_2_24_x86_64",
693- "manylinux_2_24_aarch64",693+ "manylinux_2_24_aarch64",
694- "manylinux_2_27_x86_64",694+ "manylinux_2_27_x86_64",
695- "manylinux_2_27_aarch64",695+ "manylinux_2_27_aarch64",
696- "manylinux_2_28_x86_64",696+ "manylinux_2_28_x86_64",
697- "manylinux_2_28_aarch64",697+ "manylinux_2_28_aarch64",
698- "manylinux_2_31_x86_64",698+ "manylinux_2_31_x86_64",
699- "manylinux_2_31_aarch64",699+ "manylinux_2_31_aarch64",
700- "manylinux_2_34_x86_64",700+ "manylinux_2_34_x86_64",
701- "manylinux_2_34_aarch64",701+ "manylinux_2_34_aarch64",
702- "manylinux_2_35_x86_64"702+ "manylinux_2_35_x86_64"
703- "manylinux_2_35_aarch64",703+ "manylinux_2_35_aarch64",
704-]704+]
705-is_manylinux = os.environ.get("AUDITWHEEL_PLAT", None) in manylinux_tags705+is_manylinux = os.environ.get("AUDITWHEEL_PLAT", None) in manylinux_tags
706- 706+ 
707-readme = os.path.join(BASE_DIR, "README.md")707+readme = os.path.join(BASE_DIR, "README.md")
708-if not os.path.exists(readme):708+if not os.path.exists(readme):
709- raise FileNotFoundError("Unable to find 'README.md'")709+ raise FileNotFoundError("Unable to find 'README.md'")
710-with open(readme, encoding="utf-8") as fdesc:710+with open(readme, encoding="utf-8") as fdesc:
711- long_description = fdesc.read()711+ long_description = fdesc.read()
712- 712+ 
713-classifiers = [713+classifiers = [
714- "Development Status :: 5 - Production/Stable",714+ "Development Status :: 5 - Production/Stable",
715- "Intended Audience :: Developers",715+ "Intended Audience :: Developers",
716- "License :: OSI Approved :: BSD License",716+ "License :: OSI Approved :: BSD License",
717- "Operating System :: POSIX :: Linux",717+ "Operating System :: POSIX :: Linux",
718- "Topic :: Scientific/Engineering",718+ "Topic :: Scientific/Engineering",
719- "Topic :: Scientific/Engineering :: Mathematics",719+ "Topic :: Scientific/Engineering :: Mathematics",
720- "Topic :: Scientific/Engineering :: Artificial Intelligence",720+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
721- "Topic :: Software Development",721+ "Topic :: Software Development",
722- "Topic :: Software Development :: Libraries",722+ "Topic :: Software Development :: Libraries",
723- "Topic :: Software Development :: Libraries :: Python Modules",723+ "Topic :: Software Development :: Libraries :: Python Modules",
724- "Programming Language :: Python",724+ "Programming Language :: Python",
725- "Programming Language :: Python :: 3 :: Only",725+ "Programming Language :: Python :: 3 :: Only",
726- "Programming Language :: Python :: 3.8",726+ "Programming Language :: Python :: 3.8",
727- "Programming Language :: Python :: 3.9",727+ "Programming Language :: Python :: 3.9",
728- "Programming Language :: Python :: 3.10",728+ "Programming Language :: Python :: 3.10",
729- "Programming Language :: Python :: 3.11",729+ "Programming Language :: Python :: 3.11",
730- "Programming Language :: Python :: 3.12",730+ "Programming Language :: Python :: 3.12",
731-]731+]
732- 732+ 
733- 733+ 
734-setup(734+setup(
735- name=os.environ.get('TORCH_NPU_PACKAGE_NAME', 'torch_npu'),735+ name=os.environ.get('TORCH_NPU_PACKAGE_NAME', 'torch_npu'),
736- version=VERSION,736+ version=VERSION,
737- description='NPU bridge for PyTorch',737+ description='NPU bridge for PyTorch',
738- long_description=long_description,738+ long_description=long_description,
739- long_description_content_type="text/markdown",739+ long_description_content_type="text/markdown",
740- license="BSD License",740+ license="BSD License",
741- classifiers=classifiers,741+ classifiers=classifiers,
742- packages=["torch_npu", "torchnpugen"],742+ packages=["torch_npu", "torchnpugen"],
743- libraries=[('torch_npu', {'sources': list()})],743+ libraries=[('torch_npu', {'sources': list()})],
744- package_dir={'': os.path.relpath(os.path.join(BASE_DIR, "build/packages"))},744+ package_dir={'': os.path.relpath(os.path.join(BASE_DIR, "build/packages"))},
745- ext_modules=[745+ ext_modules=[
746- CppExtension(746+ CppExtension(
747- 'torch_npu._C',747+ 'torch_npu._C',
748- sources=["torch_npu/csrc/InitNpuBindings.cpp"],748+ sources=["torch_npu/csrc/InitNpuBindings.cpp"],
749- libraries=["torch_npu"],749+ libraries=["torch_npu"],
750- include_dirs=include_directories,750+ include_dirs=include_directories,
751- extra_compile_args=extra_compile_args + ['-fstack-protector-all'] + ['-D__FILENAME__=\"InitNpuBindings.cpp\"'],751+ extra_compile_args=extra_compile_args + ['-fstack-protector-all'] + ['-D__FILENAME__=\"InitNpuBindings.cpp\"'],
752- library_dirs=["lib"],752+ library_dirs=["lib"],
753- extra_link_args=extra_link_args + ['-Wl,-rpath,$ORIGIN/lib', '-Wl,-Bsymbolic-functions'],753+ extra_link_args=extra_link_args + ['-Wl,-rpath,$ORIGIN/lib', '-Wl,-Bsymbolic-functions'],
754- define_macros=[('_GLIBCXX_USE_CXX11_ABI', '1' if USE_CXX11_ABI else '0'), ('GLIBCXX_USE_CXX11_ABI', '1' if USE_CXX11_ABI else '0')]754+ define_macros=[('_GLIBCXX_USE_CXX11_ABI', '1' if USE_CXX11_ABI else '0'), ('GLIBCXX_USE_CXX11_ABI', '1' if USE_CXX11_ABI else '0')]
755- ),755+ ),
756- ],756+ ],
757- install_requires=[757+ install_requires=[
758- *_get_torch_requires(),758+ *_get_torch_requires(),
759- ],759+ ],
760- extras_require={760+ extras_require={
761- },761+ },
762- package_data={762+ package_data={
763- 'torch_npu': [763+ 'torch_npu': [
764- '*.so', 'lib/*.so*',764+ '*.so', 'lib/*.so*',
765- ],765+ ],
766- 'torchnpugen': [766+ 'torchnpugen': [
767- '*.py', '**/*.py',767+ '*.py', '**/*.py',
768- '*.yaml', '**/*.yaml',768+ '*.yaml', '**/*.yaml',
769- '*.json', '**/*.json',769+ '*.json', '**/*.json',
770- '*.cpp', '**/*.cpp',770+ '*.cpp', '**/*.cpp',
771- '*.h', '**/*.h',771+ '*.h', '**/*.h',
772- ],772+ ],
773- },773+ },
774- cmdclass={774+ cmdclass={
775- 'build_clib': CPPLibBuild,775+ 'build_clib': CPPLibBuild,
776- 'build_ext': Build,776+ 'build_ext': Build,
777- 'build_py': PythonPackageBuild,777+ 'build_py': PythonPackageBuild,
778- 'bdist_wheel': BdistWheelBuild,778+ 'bdist_wheel': BdistWheelBuild,
779- 'install': InstallCmd,779+ 'install': InstallCmd,
780- 'clean': Clean780+ 'clean': Clean
781- },781+ },
782- entry_points={782+ entry_points={
783- 'console_scripts': [783+ 'console_scripts': [
784- 'torch_npu_run = torch_npu.distributed.run:_main',784+ 'torch_npu_run = torch_npu.distributed.run:_main',
785- ],785+ ],
786- 'torch.backends': [786+ 'torch.backends': [
787- 'torch_npu = torch_npu:_autoload',787+ 'torch_npu = torch_npu:_autoload',
788- ],788+ ],
789- }789+ }
790-)790+)
@@ -42,4 +42,3 @@ instantiate_parametrized_tests(TestEmpty)
42 42 
43if __name__ == "__main__":43if __name__ == "__main__":
44 run_tests()44 run_tests()
45- 
@@ -25,4 +25,3 @@ instantiate_parametrized_tests(TestExp)
25 25 
26if __name__ == "__main__":26if __name__ == "__main__":
27 run_tests()27 run_tests()
28- 
@@ -27,4 +27,3 @@ instantiate_parametrized_tests(TestGt)
27 27 
28if __name__ == "__main__":28if __name__ == "__main__":
29 run_tests()29 run_tests()
30- 
@@ -1,35 +1,35 @@
1-import unittest1+import unittest
2-import torch2+import torch
3- 3+ 
4-from testutils import TestUtils4+from testutils import TestUtils
5-from torch.testing._internal.common_utils import run_tests, parametrize, instantiate_parametrized_tests5+from torch.testing._internal.common_utils import run_tests, parametrize, instantiate_parametrized_tests
6-from torch._inductor import config6+from torch._inductor import config
7-from torch._inductor.utils import run_and_get_code7+from torch._inductor.utils import run_and_get_code
8- 8+ 
9-import torch_npu9+import torch_npu
10-import torch_npu._inductor10+import torch_npu._inductor
11- 11+ 
12-DEVICE = "npu"12+DEVICE = "npu"
13- 13+ 
14- 14+ 
15-class TestCodegenUpcastToFP32(TestUtils):15+class TestCodegenUpcastToFP32(TestUtils):
16- @parametrize("dtype", [torch.float16, torch.bfloat16])16+ @parametrize("dtype", [torch.float16, torch.bfloat16])
17- @parametrize("upcast_flag", [True, False])17+ @parametrize("upcast_flag", [True, False])
18- def test_codegen_upcast_to_fp32_emits_cast(self, dtype, upcast_flag):18+ def test_codegen_upcast_to_fp32_emits_cast(self, dtype, upcast_flag):
19- @torch.compile(backend="inductor")19+ @torch.compile(backend="inductor")
20- def func(x):20+ def func(x):
21- return torch.abs(x)21+ return torch.abs(x)
22- 22+ 
23- x = torch.randn((1024, 1024), device=DEVICE, dtype=dtype)23+ x = torch.randn((1024, 1024), device=DEVICE, dtype=dtype)
24- 24+ 
25- with config.patch("triton.codegen_upcast_to_fp32", upcast_flag):25+ with config.patch("triton.codegen_upcast_to_fp32", upcast_flag):
26- opt_func = torch._dynamo.optimize("inductor")(func)26+ opt_func = torch._dynamo.optimize("inductor")(func)
27- out, code = run_and_get_code(opt_func, x)27+ out, code = run_and_get_code(opt_func, x)
28- 28+ 
29- self.assertTrue(".to(tl.float32)" in code[0])29+ self.assertTrue(".to(tl.float32)" in code[0])
30- self.assertEqual(func(x), opt_func(x))30+ self.assertEqual(func(x), opt_func(x))
31- 31+ 
32-instantiate_parametrized_tests(TestCodegenUpcastToFP32)32+instantiate_parametrized_tests(TestCodegenUpcastToFP32)
33- 33+ 
34-if __name__ == "__main__":34+if __name__ == "__main__":
35 run_tests()35 run_tests()
@@ -1,50 +1,50 @@
1-import unittest1+import unittest
2-import torch2+import torch
3-import torch_npu3+import torch_npu
4- 4+ 
5-from torch.testing._internal.common_utils import (5+from torch.testing._internal.common_utils import (
6- run_tests,6+ run_tests,
7- parametrize,7+ parametrize,
8- instantiate_parametrized_tests,8+ instantiate_parametrized_tests,
9-)9+)
10-from testutils import TestUtils10+from testutils import TestUtils
11- 11+ 
12- 12+ 
13-class TestInductorStaticKernel(TestUtils):13+class TestInductorStaticKernel(TestUtils):
14- 14+ 
15- def simple_op(self, x):15+ def simple_op(self, x):
16- return torch.neg(x)16+ return torch.neg(x)
17- 17+ 
18- @parametrize("shape", [(1024, 1024), (4096,)])18+ @parametrize("shape", [(1024, 1024), (4096,)])
19- @parametrize("dtype", [torch.float16, torch.float32])19+ @parametrize("dtype", [torch.float16, torch.float32])
20- def test_inductor_static_kernel(self, shape, dtype):20+ def test_inductor_static_kernel(self, shape, dtype):
21- device = "npu"21+ device = "npu"
22- 22+ 
23- x = torch.randn(shape, dtype=dtype, device=device)23+ x = torch.randn(shape, dtype=dtype, device=device)
24- 24+ 
25- ref = self.simple_op(x)25+ ref = self.simple_op(x)
26- 26+ 
27- torch._inductor.config.triton.cudagraph_trees = False27+ torch._inductor.config.triton.cudagraph_trees = False
28- torch_npu.npu.aclnn._use_static_aclnn_kernel = True28+ torch_npu.npu.aclnn._use_static_aclnn_kernel = True
29- 29+ 
30- compiled_fn = torch.compile(30+ compiled_fn = torch.compile(
31- self.simple_op,31+ self.simple_op,
32- backend="inductor",32+ backend="inductor",
33- dynamic=False33+ dynamic=False
34- )34+ )
35- 35+ 
36- for _ in range(3):36+ for _ in range(3):
37- compiled_fn(x)37+ compiled_fn(x)
38- 38+ 
39- torch.npu.synchronize()39+ torch.npu.synchronize()
40- 40+ 
41- out = compiled_fn(x)41+ out = compiled_fn(x)
42- torch.npu.synchronize()42+ torch.npu.synchronize()
43- 43+ 
44- self.assertEqual(ref, out)44+ self.assertEqual(ref, out)
45- 45+ 
46-instantiate_parametrized_tests(TestInductorStaticKernel)46+instantiate_parametrized_tests(TestInductorStaticKernel)
47- 47+ 
48-if __name__ == "__main__":48+if __name__ == "__main__":
49- torch.npu.config.allow_internal_format = False49+ torch.npu.config.allow_internal_format = False
50 run_tests()50 run_tests()
@@ -1,30 +1,30 @@
1-import torch1+import torch
2-from torch.testing._internal.common_utils import (2+from torch.testing._internal.common_utils import (
3- run_tests,3+ run_tests,
4- TestCase,4+ TestCase,
5-)5+)
6-import torch_npu6+import torch_npu
7- 7+ 
8-class TestAutogradFallback(TestCase):8+class TestAutogradFallback(TestCase):
9- 9+ 
10- def test_pad_backward_warn(self):10+ def test_pad_backward_warn(self):
11- 11+ 
12- def _exec_npu_pad():12+ def _exec_npu_pad():
13- npu_input = torch.randn(2, 3).npu()13+ npu_input = torch.randn(2, 3).npu()
14- npu_input.requires_grad = True14+ npu_input.requires_grad = True
15- pads = (1, 1, 1, 1)15+ pads = (1, 1, 1, 1)
16- output = torch_npu.npu_pad(npu_input, pads)16+ output = torch_npu.npu_pad(npu_input, pads)
17- output.backward(torch.ones_like(output))17+ output.backward(torch.ones_like(output))
18- 18+ 
19- # When set to "nothing," calling the reverse function directly causes an error.19+ # When set to "nothing," calling the reverse function directly causes an error.
20- torch._C._set_autograd_fallback_mode("nothing")20+ torch._C._set_autograd_fallback_mode("nothing")
21- with self.assertRaisesRegex(RuntimeError, "does not require grad"):21+ with self.assertRaisesRegex(RuntimeError, "does not require grad"):
22- _exec_npu_pad()22+ _exec_npu_pad()
23- 23+ 
24- # When set to "warn," calling the print function emits a warning.24+ # When set to "warn," calling the print function emits a warning.
25- torch._C._set_autograd_fallback_mode("warn")25+ torch._C._set_autograd_fallback_mode("warn")
26- _exec_npu_pad()26+ _exec_npu_pad()
27- 27+ 
28- 28+ 
29-if __name__ == "__main__":29+if __name__ == "__main__":
30- run_tests()30+ run_tests()