Skip to content

Commit 5bbfb96

Browse files
cyyeverpytorchmergebot
authored andcommitted
[Reland] Upgrade NVTX to NVTX3 (#97582)
PR #90689 replaces NVTX with NVTX3. However, the torch::nvtoolsext is created only when the third party NVTX is used. This is clear a logical error. We now move the creation code out of the branch to cover all cases. This should fix the issues reported in the comments of #90689. It would be better to move configurations of the failed FRL jobs to CI tests so that we can find such issues early before merging. Pull Request resolved: #97582 Approved by: https://github.com/peterbell10
1 parent 461c703 commit 5bbfb96

File tree

11 files changed

+25
-26
lines changed

11 files changed

+25
-26
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,6 @@
157157
[submodule "third_party/mimalloc"]
158158
path = third_party/mimalloc
159159
url = https://github.com/microsoft/mimalloc.git
160+
[submodule "third_party/NVTX"]
161+
path = third_party/NVTX
162+
url = https://github.com/NVIDIA/NVTX.git

caffe2/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,8 @@ if(USE_CUDA)
15161516
target_link_libraries(torch_cpu PRIVATE torch::cudart)
15171517
endif()
15181518
target_link_libraries(torch_cuda INTERFACE torch::cudart)
1519-
target_link_libraries(torch_cuda PUBLIC c10_cuda torch::nvtoolsext)
1519+
target_link_libraries(torch_cuda PUBLIC c10_cuda)
1520+
target_link_libraries(torch_cuda PRIVATE torch::nvtoolsext)
15201521

15211522
target_include_directories(
15221523
torch_cuda INTERFACE $<INSTALL_INTERFACE:include>)
@@ -1571,7 +1572,7 @@ if(BUILD_SHARED_LIBS)
15711572
# not find them, because they're usually in non-standard locations)
15721573
if(USE_CUDA)
15731574
target_link_libraries(torch_global_deps ${Caffe2_PUBLIC_CUDA_DEPENDENCY_LIBS})
1574-
target_link_libraries(torch_global_deps torch::cudart torch::nvtoolsext)
1575+
target_link_libraries(torch_global_deps torch::cudart)
15751576
endif()
15761577
if(USE_TBB)
15771578
target_link_libraries(torch_global_deps TBB::tbb)

cmake/TorchConfig.cmake.in

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,30 +129,18 @@ endif()
129129

130130
if(@USE_CUDA@)
131131
if(MSVC)
132-
if(NOT NVTOOLEXT_HOME)
133-
set(NVTOOLEXT_HOME "C:/Program Files/NVIDIA Corporation/NvToolsExt")
134-
endif()
135-
if(DEFINED ENV{NVTOOLSEXT_PATH})
136-
set(NVTOOLEXT_HOME $ENV{NVTOOLSEXT_PATH})
137-
endif()
138-
set(TORCH_CUDA_LIBRARIES
139-
${NVTOOLEXT_HOME}/lib/x64/nvToolsExt64_1.lib
140-
${CUDA_LIBRARIES})
141-
list(APPEND TORCH_INCLUDE_DIRS ${NVTOOLEXT_HOME}/include)
132+
set(TORCH_CUDA_LIBRARIES ${CUDA_LIBRARIES})
142133
find_library(CAFFE2_NVRTC_LIBRARY caffe2_nvrtc PATHS "${TORCH_INSTALL_PREFIX}/lib")
143134
list(APPEND TORCH_CUDA_LIBRARIES ${CAFFE2_NVRTC_LIBRARY})
144135
elseif(APPLE)
145136
set(TORCH_CUDA_LIBRARIES
146137
${CUDA_TOOLKIT_ROOT_DIR}/lib/libcudart.dylib
147138
${CUDA_TOOLKIT_ROOT_DIR}/lib/libnvrtc.dylib
148-
${CUDA_TOOLKIT_ROOT_DIR}/lib/libnvToolsExt.dylib
149139
${CUDA_LIBRARIES})
150140
else()
151-
find_library(LIBNVTOOLSEXT libnvToolsExt.so PATHS ${CUDA_TOOLKIT_ROOT_DIR}/lib64/)
152141
set(TORCH_CUDA_LIBRARIES
153142
${CUDA_CUDA_LIB}
154143
${CUDA_NVRTC_LIB}
155-
${LIBNVTOOLSEXT}
156144
${CUDA_LIBRARIES})
157145
endif()
158146
if(@BUILD_SHARED_LIBS@)

cmake/public/cuda.cmake

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ if(NOT CMAKE_CUDA_COMPILER_VERSION STREQUAL CUDAToolkit_VERSION OR
6767
"V${CUDAToolkit_VERSION} in '${CUDAToolkit_INCLUDE_DIR}'")
6868
endif()
6969

70-
if(NOT TARGET CUDA::nvToolsExt)
71-
message(FATAL_ERROR "Failed to find nvToolsExt")
72-
endif()
73-
7470
message(STATUS "Caffe2: CUDA detected: " ${CUDA_VERSION})
7571
message(STATUS "Caffe2: CUDA nvcc is: " ${CUDA_NVCC_EXECUTABLE})
7672
message(STATUS "Caffe2: CUDA toolkit directory: " ${CUDA_TOOLKIT_ROOT_DIR})
@@ -216,9 +212,10 @@ endif()
216212

217213
# nvToolsExt
218214
add_library(torch::nvtoolsext INTERFACE IMPORTED)
219-
set_property(
220-
TARGET torch::nvtoolsext PROPERTY INTERFACE_LINK_LIBRARIES
221-
CUDA::nvToolsExt)
215+
find_path(nvtx3_dir NAMES nvtx3 PATHS "${CUDA_INCLUDE_DIRS}" "${CMAKE_CURRENT_LIST_DIR}/../../third_party/NVTX/c/include" NO_DEFAULT_PATH)
216+
find_package_handle_standard_args(nvtx3 DEFAULT_MSG nvtx3_dir)
217+
target_include_directories(torch::nvtoolsext INTERFACE "${nvtx3_dir}")
218+
222219

223220
# cublas
224221
add_library(caffe2::cublas INTERFACE IMPORTED)

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@
186186
# NVFUSER_SOURCE_DIR
187187
# specify nvfuser root directory
188188
#
189-
# NVTOOLSEXT_PATH (Windows only)
190-
# specify where nvtoolsext is installed
191-
#
192189
# ACL_ROOT_DIR
193190
# specify where Compute Library is installed
194191
#

third_party/NVTX

Submodule NVTX added at e170594

third_party/nvfuser/csrc/instrumentation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
#include <utils.h>
44

5+
#ifndef FBCODE_CAFFE2
6+
#include <nvtx3/nvToolsExt.h>
7+
#else
58
#include <nvToolsExt.h>
9+
#endif
610

711
// NOLINTNEXTLINE(modernize-deprecated-headers)
812
#include <stdio.h>

torch/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ if(USE_CUDA)
136136
list(APPEND TORCH_PYTHON_LINK_LIBRARIES torch::cudnn)
137137
list(APPEND TORCH_PYTHON_COMPILE_DEFINITIONS USE_CUDNN)
138138
endif()
139-
140139
list(APPEND TORCH_PYTHON_LINK_LIBRARIES torch::nvtoolsext)
141140
endif()
142141

torch/csrc/cuda/shared/nvtx.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#ifdef _WIN32
22
#include <wchar.h> // _wgetenv for nvtx
33
#endif
4+
#ifndef FBCODE_CAFFE2
5+
#include <nvtx3/nvToolsExt.h>
6+
#else
47
#include <nvToolsExt.h>
8+
#endif
59
#include <torch/csrc/utils/pybind.h>
610

711
namespace torch::cuda::shared {

torch/csrc/profiler/stubs/cuda.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include <sstream>
22

3+
#ifndef FBCODE_CAFFE2
4+
#include <nvtx3/nvToolsExt.h>
5+
#else
36
#include <nvToolsExt.h>
7+
#endif
48

59
#include <c10/cuda/CUDAGuard.h>
610
#include <c10/util/irange.h>

0 commit comments

Comments
 (0)