Skip to content

Commit

Permalink
Update on "New profiler API"
Browse files Browse the repository at this point in the history
Summary:
Adding new API for the kineto profiler that supports enable predicate
function - better support for profiling of training loops (example in test_profiler_kineto_api)

Test Plan:
python test/test_profiler.py -k test_profiler_kineto_api

Differential Revision: [D25142220](https://our.internmc.facebook.com/intern/diff/D25142220)

[ghstack-poisoned]
  • Loading branch information
ilia-cher committed Dec 18, 2020
2 parents 1c6a8ba + 35dba55 commit 4c5734f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 68 deletions.
22 changes: 20 additions & 2 deletions CMakeLists.txt
Expand Up @@ -159,8 +159,7 @@ cmake_dependent_option(
USE_STATIC_CUDNN "Use cuDNN static libraries" OFF
"USE_CUDNN" OFF)
option(USE_FBGEMM "Use FBGEMM (quantized 8-bit server operators)" ON)
option(USE_KINETO "Use Kineto profiling library" ON)
option(USE_CUPTI_SO "Use CUPTI as a shared library" OFF)
option(USE_KINETO "Use Kineto profiling library" OFF)
option(USE_FAKELOWP "Use FakeLowp operators" OFF)
option(USE_FFMPEG "Use ffmpeg" OFF)
option(USE_GFLAGS "Use GFLAGS" OFF)
Expand Down Expand Up @@ -516,12 +515,31 @@ if(USE_FBGEMM AND ((CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND CMAKE_SIZEOF_VO
set(USE_FBGEMM OFF)
endif()

if(USE_KINETO AND INTERN_BUILD_MOBILE)
message(STATUS "Not using libkineto in a mobile build.")
set(USE_KINETO OFF)
endif()

if(USE_KINETO AND (NOT USE_CUDA))
message(STATUS "Not using libkineto in a non-CUDA build.")
set(USE_KINETO OFF)
endif()

if(USE_KINETO AND MSVC)
message(STATUS "Not using libkineto in a Windows build.")
set(USE_KINETO OFF)
endif()

include(cmake/Dependencies.cmake)

if(USE_FBGEMM)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_FBGEMM")
endif()

if(USE_KINETO)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_KINETO")
endif()

if(USE_QNNPACK)
string(APPEND CMAKE_CXX_FLAGS " -DUSE_QNNPACK")
endif()
Expand Down
93 changes: 33 additions & 60 deletions cmake/Dependencies.cmake
Expand Up @@ -1788,70 +1788,43 @@ list(APPEND Caffe2_DEPENDENCY_LIBS fmt::fmt-header-only)
set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS} CACHE BOOL "Build shared libs" FORCE)

# ---[ Kineto
if(USE_KINETO AND INTERN_BUILD_MOBILE)
message(STATUS "Not using libkineto in a mobile build.")
set(USE_KINETO OFF)
endif()

if(USE_KINETO AND (NOT USE_CUDA))
message(STATUS "Not using libkineto in a non-CUDA build.")
set(USE_KINETO OFF)
endif()

if(USE_KINETO AND MSVC)
message(STATUS "Not using libkineto in a Windows build.")
set(USE_KINETO OFF)
endif()
if(USE_KINETO)
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party" CACHE STRING "")
set(KINETO_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/kineto/libkineto" CACHE STRING "")
set(KINETO_BUILD_TESTS OFF CACHE BOOL "")
set(KINETO_LIBRARY_TYPE "static" CACHE STRING "")
set(CUDA_SOURCE_DIR "${CUDA_TOOLKIT_ROOT_DIR}" CACHE STRING "")

message(STATUS "Configuring Kineto dependency:")
message(STATUS " KINETO_SOURCE_DIR = ${KINETO_SOURCE_DIR}")
message(STATUS " KINETO_BUILD_TESTS = ${KINETO_BUILD_TESTS}")
message(STATUS " KINETO_LIBRARY_TYPE = ${KINETO_LIBRARY_TYPE}")
message(STATUS " CUDA_SOURCE_DIR = ${CUDA_SOURCE_DIR}")

if(EXISTS ${CUDA_SOURCE_DIR}/extras/CUPTI/lib64/libcupti_static.a)
set(CUDA_cupti_LIBRARY "${CUDA_SOURCE_DIR}/extras/CUPTI/lib64/libcupti_static.a")
elseif(EXISTS ${CUDA_SOURCE_DIR}/lib64/libcupti_static.a)
set(CUDA_cupti_LIBRARY "${CUDA_SOURCE_DIR}/lib64/libcupti_static.a")
elseif(USE_CUPTI_SO)
if(EXISTS ${CUDA_SOURCE_DIR}/extras/CUPTI/lib64/libcupti.so)
set(CUDA_cupti_LIBRARY "${CUDA_SOURCE_DIR}/extras/CUPTI/lib64/libcupti.so")
elseif(EXISTS ${CUDA_SOURCE_DIR}/lib64/libcupti.so)
set(CUDA_cupti_LIBRARY "${CUDA_SOURCE_DIR}/lib64/libcupti.so")
endif()
endif()

if(EXISTS ${CUDA_SOURCE_DIR}/extras/CUPTI/include)
set(CUPTI_INCLUDE_DIR "${CUDA_SOURCE_DIR}/extras/CUPTI/include")
elseif(EXISTS ${CUDA_SOURCE_DIR}/include/cupti.h)
set(CUPTI_INCLUDE_DIR "${CUDA_SOURCE_DIR}/include")
endif()

set(FOUND_CUPTI FALSE)
if((DEFINED CUPTI_INCLUDE_DIR) AND (DEFINED CUDA_cupti_LIBRARY))
if((CUDA_cupti_LIBRARY MATCHES "libcupti_static.a") OR ((CUDA_cupti_LIBRARY MATCHES "libcupti.so") AND (USE_CUPTI_SO)))
set(FOUND_CUPTI TRUE)
if(USE_KINETO AND NOT TARGET kineto)
set(CAFFE2_THIRD_PARTY_ROOT "${PROJECT_SOURCE_DIR}/third_party" CACHE STRING "")
set(KINETO_SOURCE_DIR "${CAFFE2_THIRD_PARTY_ROOT}/kineto/libkineto" CACHE STRING "")
set(KINETO_BUILD_TESTS OFF CACHE BOOL "")
set(KINETO_LIBRARY_TYPE "static" CACHE STRING "")
set(CUDA_SOURCE_DIR "${CUDA_TOOLKIT_ROOT_DIR}" CACHE STRING "")

message(STATUS "Configuring Kineto dependency:")
message(STATUS " KINETO_SOURCE_DIR = ${KINETO_SOURCE_DIR}")
message(STATUS " KINETO_BUILD_TESTS = ${KINETO_BUILD_TESTS}")
message(STATUS " KINETO_LIBRARY_TYPE = ${KINETO_LIBRARY_TYPE}")
message(STATUS " CUDA_SOURCE_DIR = ${CUDA_SOURCE_DIR}")

if(EXISTS ${CUDA_SOURCE_DIR}/extras/CUPTI/include)
set(CUPTI_INCLUDE_DIR "${CUDA_SOURCE_DIR}/extras/CUPTI/include")
elseif(EXISTS ${CUDA_SOURCE_DIR}/include/cupti.h)
set(CUPTI_INCLUDE_DIR "${CUDA_SOURCE_DIR}/include")
endif()

if((NOT DEFINED CUDA_cupti_LIBRARY) OR (${CUDA_cupti_LIBRARY} STREQUAL "CUDA_cupti_LIBRARY-NOTFOUND"))
if(EXISTS ${CUDA_SOURCE_DIR}/extras/CUPTI/lib64/libcupti_static.a)
set(CUDA_cupti_LIBRARY "${CUDA_SOURCE_DIR}/extras/CUPTI/lib64/libcupti_static.a")
elseif(EXISTS ${CUDA_SOURCE_DIR}/lib64/libcupti_static.a)
set(CUDA_cupti_LIBRARY "${CUDA_SOURCE_DIR}/lib64/libcupti_static.a")
elseif(EXISTS ${CUDA_SOURCE_DIR}/extras/CUPTI/lib64/libcupti.so)
set(CUDA_cupti_LIBRARY "${CUDA_SOURCE_DIR}/extras/CUPTI/lib64/libcupti.so")
elseif(EXISTS ${CUDA_SOURCE_DIR}/lib64/libcupti.so)
set(CUDA_cupti_LIBRARY "${CUDA_SOURCE_DIR}/lib64/libcupti.so")
endif()
endif()
endif()

if(FOUND_CUPTI)
message(STATUS " CUDA_cupti_LIBRARY = ${CUDA_cupti_LIBRARY}")
message(STATUS " CUPTI_INCLUDE_DIR = ${CUPTI_INCLUDE_DIR}")
if(NOT TARGET kineto)
add_subdirectory("${KINETO_SOURCE_DIR}")
message(STATUS "Configured Kineto as a dependency.")
endif()

string(APPEND CMAKE_CXX_FLAGS " -DUSE_KINETO")
list(APPEND Caffe2_DEPENDENCY_LIBS kineto)
else()
message(STATUS "Could not find CUPTI library, skipping Kineto build")
set(USE_KINETO OFF)
add_subdirectory("${KINETO_SOURCE_DIR}")
message(STATUS "Configured Kineto as a dependency.")
endif()

list(APPEND Caffe2_DEPENDENCY_LIBS kineto)
endif()
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -33,8 +33,8 @@
# USE_FBGEMM=0
# disables the FBGEMM build
#
# USE_KINETO=0
# disables usage of libkineto library for profiling
# USE_KINETO=1
# enables experimental usage of libkineto
#
# USE_NUMPY=0
# disables the NumPy build
Expand Down
2 changes: 1 addition & 1 deletion torch/csrc/autograd/profiler_kineto.cpp
Expand Up @@ -360,7 +360,7 @@ void ProfilerResult::save(const std::string& path) {

bool kinetoAvailable() {
#ifdef USE_KINETO
return at::hasCUDA();
return true;
#else
return false;
#endif
Expand Down
6 changes: 3 additions & 3 deletions torch/profiler/__init__.py
@@ -1,8 +1,8 @@
# type: ignore
r'''
PyTorch Profiler is a tool that allows the collecton of the performance metrics during the model training and inference.
Profiler's context manager API can be used to better understand what model operators are the most expensive, examine their input shapes and
stack traces, study device kernel activity and visualize the execution trace.
PyTorch Profiler is a tool that allows the collecton of the performance metrics during the training and inference.
Profiler's context manager API can be used to better understand what model operators are the most expensive,
examine their input shapes and stack traces, study device kernel activity and visualize the execution trace.
.. note::
An earlier version of the API in ``torch.autograd`` module is considered legacy and will be deprecated.
Expand Down

0 comments on commit 4c5734f

Please sign in to comment.