Skip to content

Commit af1d9ef

Browse files
gdankelfacebook-github-bot
authored andcommitted
Makefile fixes for PyTorch integration
Summary: 1) Rename defs.bzl to libkineto_defs.bzl to avoid naming conflict. 2) Add check for CUDA_SOURCE_DIR env var. 3) Add checks for CUDA_INCLUDE_DIRS (set by PyTorch) and CUPTI_INCLUDE_DIRS. 4) Set CUDA_INCLUDE_DIRS and CUPTI_INCLUDE_DIR to point inside the respective locations in CUDA_SOURCE_DIR if not already set. Reviewed By: ilia-cher Differential Revision: D24169991 fbshipit-source-id: 8a9dd7b8579b4142f35bc17e7bfd1c214efc2fbc
1 parent 1c9802c commit af1d9ef

File tree

3 files changed

+27
-46
lines changed

3 files changed

+27
-46
lines changed

libkineto/CMakeLists.txt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
55
#install libraries into correct locations on all platforms
66
include(GNUInstallDirs)
77

8-
# function to extract filelists from defs.bzl file
8+
# function to extract filelists from libkineto_defs.bzl file
99
find_package(PythonInterp)
1010
function(get_filelist name outputvar)
1111
execute_process(
1212
COMMAND "${PYTHON_EXECUTABLE}" -c
13-
"exec(open('defs.bzl').read());print(';'.join(${name}))"
13+
"exec(open('libkineto_defs.bzl').read());print(';'.join(${name}))"
1414
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
1515
OUTPUT_VARIABLE _tempvar)
1616
string(REPLACE "\n" "" _tempvar "${_tempvar}")
@@ -39,18 +39,14 @@ endif()
3939
get_filelist("get_libkineto_srcs()" LIBKINETO_SRCS)
4040
get_filelist("get_libkineto_public_headers()" LIBKINETO_PUBLIC_HEADERS)
4141
set(LIBKINETO_API_SRCS "${LIBKINETO_SOURCE_DIR}/external_api.cpp")
42-
set(FMT_INCLUDE_DIR "${LIBKINETO_THIRDPARTY_DIR}/fmt/include")
43-
set(CUPTI_INCLUDE_DIR "${LIBKINETO_THIRDPARTY_DIR}/cupti/include")
44-
set(CUDA_INCLUDE_DIR "${LIBKINETO_THIRDPARTY_DIR}/cuda-9.2/include")
4542

46-
message(INFO " CUPTI_INCLUDE_DIR = ${CUPTI_INCLUDE_DIR}")
4743

4844
add_library(kineto_base OBJECT ${LIBKINETO_SRCS})
4945
add_library(kineto_api OBJECT ${LIBKINETO_API_SRCS})
5046

51-
# Make libraries depend on defs.bzl
52-
add_custom_target(defs.bzl DEPENDS defs.bzl)
53-
add_dependencies(kineto_base defs.bzl)
47+
# Make libraries depend on libkineto_defs.bzl
48+
add_custom_target(libkineto_defs.bzl DEPENDS libkineto_defs.bzl)
49+
add_dependencies(kineto_base libkineto_defs.bzl)
5450

5551
set_target_properties(kineto_base kineto_api PROPERTIES
5652
CXX_STANDARD 14
@@ -63,8 +59,7 @@ target_compile_options(kineto_base PRIVATE "-DKINETO_NAMESPACE=libkineto"
6359
target_compile_options(kineto_api PRIVATE "-std=gnu++14")
6460

6561
if(NOT TARGET fmt)
66-
#Download fmt from github if FMT_SOURCE_DIR is not specified.
67-
if(NOT DEFINED FMT_SOURCE_DIR)
62+
if(NOT FMT_SOURCE_DIR)
6863
set(FMT_SOURCE_DIR "${LIBKINETO_THIRDPARTY_DIR}/fmt"
6964
CACHE STRING "fmt source directory from submodules")
7065
endif()
@@ -75,11 +70,25 @@ if(NOT TARGET fmt)
7570
set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON)
7671
endif()
7772

73+
set(FMT_INCLUDE_DIR "${FMT_SOURCE_DIR}/include")
74+
if (NOT CUDA_SOURCE_DIR)
75+
set(CUDA_SOURCE_DIR "$ENV{CUDA_SOURCE_DIR}")
76+
message(INFO " CUDA_SOURCE_DIR = ${CUDA_SOURCE_DIR}")
77+
endif()
78+
if (NOT CUPTI_INCLUDE_DIR)
79+
set(CUPTI_INCLUDE_DIR "${CUDA_SOURCE_DIR}/extras/CUPTI/include")
80+
endif()
81+
if (NOT CUDA_INCLUDE_DIRS)
82+
set(CUDA_INCLUDE_DIRS "${CUDA_SOURCE_DIR}/include")
83+
endif()
84+
85+
message(INFO " CUPTI_INCLUDE_DIR = ${CUPTI_INCLUDE_DIR}")
86+
7887
target_include_directories(kineto_base PUBLIC
7988
$<BUILD_INTERFACE:${LIBKINETO_INCLUDE_DIR}>
8089
$<BUILD_INTERFACE:${FMT_INCLUDE_DIR}>
8190
$<BUILD_INTERFACE:${CUPTI_INCLUDE_DIR}>
82-
$<BUILD_INTERFACE:${CUDA_INCLUDE_DIR}>)
91+
$<BUILD_INTERFACE:${CUDA_INCLUDE_DIRS}>)
8392

8493
target_include_directories(kineto_api PUBLIC
8594
$<BUILD_INTERFACE:${LIBKINETO_INCLUDE_DIR}>)

libkineto/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Libkineto uses the standard CMAKE-based build flow.
1818
### Dependencies
1919
Libkineto requires gcc 5+.
2020

21-
+ ###### CUPTI
21+
+ ###### CUDA
2222
Libkineto uses CUPTI to collect traces and metrics from NVIDIA GPUs.
2323

2424
+ ###### fmt
@@ -29,19 +29,19 @@ googletest is required to build and run Kineto's tests. **googletest is not
2929
required** if you don't want to run Kineto tests. By default, building of tests
3030
is **on**. Turn it off by setting KINETO\_BUILD\_TESTS to off.
3131

32-
You can download [CUPTI][1], [fmt][2], [googletest][3] and set
33-
CUPTI\_SOURCE\_DIR, FMT\_SOURCE\_DIR, GOOGLETEST\_SOURCE\_DIR respectively for
32+
You can download [CUDA][1], [fmt][2], [googletest][3] and set
33+
CUDA\_SOURCE\_DIR, FMT\_SOURCE\_DIR, GOOGLETEST\_SOURCE\_DIR respectively for
3434
cmake to find these libraries. If the fmt and googletest variables are not set, cmake will
3535
build the git submodules found in the third\_party directory.
36+
If CUDA\_SOURCE\_DIR is not set, libkineto will fail to build.
3637

3738
General build instructions are as follows:
3839

3940
```
41+
# Check out repo and sub modules
4042
git clone --recursive https://github.com/pytorch/kineto.git
43+
# Build libkineto with cmake
4144
cd kineto/libkineto
42-
# if you are updating an existing checkout
43-
git submodule sync
44-
git submodule update --init --recursive
4545
mkdir build && cd build
4646
cmake ..
4747
make

libkineto/defs.bzl

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)