# Failed to find nvToolsExt

**URL:** <https://discuss.pytorch.org/t/failed-to-find-nvtoolsext/179635>\
**Category:** C++\
**Created:** [May 10, 2023, 8:52pm UTC](https://discuss.pytorch.org/t/failed-to-find-nvtoolsext/179635 "2023-05-10T20:52:28Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![phetdam](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/phetdam/32/72642_2.png) [@phetdam](https://discuss.pytorch.org/u/phetdam)\
**Post date:** [October 22, 2024, 6:11am UTC](https://discuss.pytorch.org/t/failed-to-find-nvtoolsext/179635/13 "2024-10-22T06:11:53Z")

</div>

Good news is that I _did_ find a user workaround that does _not_ require tweaking any of the CMake modules that come with a PyTorch distribution. Assuming that `PYTORCH_VERSION` and `PYTORCH_CUDA_VERSION` are available, with these two CMake variables defined as values from running the following Python script and reading the output:

```python
from torch import version

if __name__ == " __main__":
    print(version. __version__.split("+")[0]) # for PYTORCH_VERSION
    print(version.cuda) # for PYTORCH_CUDA_VERSION

```

Right before your `find_package(Torch CONFIG)` call you can do the following:

```auto
# assumes find_package(CUDAToolkit) was already done
if(
    PYTORCH_VERSION VERSION_GREATER_EQUAL 2.5.0 AND
    PYTORCH_CUDA_VERSION VERSION_GREATER_EQUAL 12
)
    message(STATUS "PyTorch NVTX headers workaround: Yes")
    # only do this if nvToolsExt is not defined and CUDA::nvtx3 exists
    if(NOT TARGET CUDA::nvToolsExt AND TARGET CUDA::nvtx3)
        add_library(CUDA::nvToolsExt INTERFACE IMPORTED)
        # ensure that PyTorch is told to use NVTX3 headers
        target_compile_definitions(
            CUDA::nvToolsExt INTERFACE
            TORCH_CUDA_USE_NVTX3
        )
        target_link_libraries(CUDA::nvToolsExt INTERFACE CUDA::nvtx3)
    endif()
else()
    message(STATUS "PyTorch NVTX headers workaround: No")
endif()
# find Torch C++ as usual
find_package(Torch CONFIG)

```

This has pacified CMake nicely for me so hopefully it will be of help to others too.

---

_[View the full topic](https://discuss.pytorch.org/t/failed-to-find-nvtoolsext/179635)._
