Skip to content

Commit

Permalink
Fixup cmake build for python clients
Browse files Browse the repository at this point in the history
  • Loading branch information
David Goodwin committed Apr 16, 2021
1 parent fb06138 commit 9671bd1
Show file tree
Hide file tree
Showing 17 changed files with 404 additions and 135 deletions.
110 changes: 69 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ project(tritonclient LANGUAGES C CXX)
#
# Options
#
set(TRITON_VERSION "0.0.0" CACHE STRING "Version for the clients")
option(TRITON_ENABLE_CC_HTTP "Build C++ HTTP client libraries" OFF)
option(TRITON_ENABLE_CC_GRPC "Build C++ GRPC client libraries" OFF)
option(TRITON_ENABLE_PYTHON_HTTP "Enable Python HTTP client libraries" OFF)
option(TRITON_ENABLE_PYTHON_GRPC "Enable Python GRPC client libraries" OFF)
option(TRITON_ENABLE_PERF_ANALYZER "Enable Performance Analyzer" OFF)
option(TRITON_ENABLE_EXAMPLES "Include examples in build" OFF)
option(TRITON_ENABLE_TESTS "Include tests in build" OFF)
Expand Down Expand Up @@ -62,45 +65,45 @@ FetchContent_MakeAvailable(repo-third-party)
# Need to use ExternalProject for our builds so that we can get the
# correct dependencies between our components and the ExternalProject
# dependencies (found in the third_party repo)
if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
include(ExternalProject)

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(TRITON_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/cc-clients/install)
else()
set(TRITON_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
endif()

set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "")
if (OPENSSL_ROOT_DIR)
set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "-DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR}")
endif()

set(_CMAKE_ARGS_CMAKE_TOOLCHAIN_FILE "")
if (CMAKE_TOOLCHAIN_FILE)
set(_CMAKE_ARGS_CMAKE_TOOLCHAIN_FILE "-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}")
endif()

set(_CMAKE_ARGS_VCPKG_TARGET_TRIPLET "")
if (VCPKG_TARGET_TRIPLET)
set(_CMAKE_ARGS_VCPKG_TARGET_TRIPLET "-DVCPKG_TARGET_TRIPLET:STRING=${VCPKG_TARGET_TRIPLET}")
endif()

# Location where protobuf-config.cmake will be installed varies by
# platform
if (WIN32)
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${TRITON_THIRD_PARTY_INSTALL_PREFIX}/protobuf/cmake")
else()
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${TRITON_THIRD_PARTY_INSTALL_PREFIX}/protobuf/lib/cmake/protobuf")
endif()
include(ExternalProject)

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(TRITON_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/cc-clients/install)
else()
set(TRITON_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
endif()

set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "")
if (OPENSSL_ROOT_DIR)
set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "-DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR}")
endif()

set(_CMAKE_ARGS_CMAKE_TOOLCHAIN_FILE "")
if (CMAKE_TOOLCHAIN_FILE)
set(_CMAKE_ARGS_CMAKE_TOOLCHAIN_FILE "-DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE}")
endif()

set(_CMAKE_ARGS_VCPKG_TARGET_TRIPLET "")
if (VCPKG_TARGET_TRIPLET)
set(_CMAKE_ARGS_VCPKG_TARGET_TRIPLET "-DVCPKG_TARGET_TRIPLET:STRING=${VCPKG_TARGET_TRIPLET}")
endif()

# Location where protobuf-config.cmake will be installed varies by
# platform
if (WIN32)
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${TRITON_THIRD_PARTY_INSTALL_PREFIX}/protobuf/cmake")
else()
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${TRITON_THIRD_PARTY_INSTALL_PREFIX}/protobuf/lib/cmake/protobuf")
endif()

if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
set(_cc_client_depends "")
if(${TRITON_ENABLE_CC_HTTP})
set(_cc_client_depends ${_cc_client_depends} curl)
endif() # TRITON_ENABLE_CC_HTTP
if(${TRITON_ENABLE_CC_GRPC})
if(${TRITON_ENABLE_CC_GRPC} OR ${TRITON_ENABLE_PERF_ANALYZER})
set(_cc_client_depends ${_cc_client_depends} grpc protobuf)
endif() # TRITON_ENABLE_CC_GRPC
endif() # TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER

ExternalProject_Add(cc-clients
PREFIX cc-clients
Expand All @@ -127,11 +130,36 @@ if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER
)
endif() # TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER


# fixme
if(TRITON_ENABLE_PYTHON)
add_subdirectory(src/python/library)
if(TRITON_ENABLE_EXAMPLES)
add_subdirectory(src/python/examples)
endif() # TRITON_ENABLE_EXAMPLES
endif() # TRITON_ENABLE_PYTHON
if(TRITON_ENABLE_PYTHON_HTTP OR TRITON_ENABLE_PYTHON_GRPC)
set(_py_client_depends "")
if(${TRITON_ENABLE_PYTHON_GRPC})
set(_py_client_depends ${_py_client_depends} grpc protobuf)
endif() # TRITON_ENABLE_PYTHON_GRPC
if(${TRITON_ENABLE_PERF_ANALYZER})
set(_py_client_depends ${_py_client_depends} cc-clients)
endif() # TRITON_ENABLE_PERF_ANALYZER

ExternalProject_Add(python-clients
PREFIX python-clients
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/python"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/python-clients"
CMAKE_CACHE_ARGS
${_CMAKE_ARGS_OPENSSL_ROOT_DIR}
${_CMAKE_ARGS_CMAKE_TOOLCHAIN_FILE}
${_CMAKE_ARGS_VCPKG_TARGET_TRIPLET}
-DProtobuf_DIR:PATH=${_FINDPACKAGE_PROTOBUF_CONFIG_DIR}
-DgRPC_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/grpc/lib/cmake/grpc
-Dc-ares_DIR:PATH=${TRITON_THIRD_PARTY_INSTALL_PREFIX}/c-ares/lib/cmake/c-ares
-DTRITON_COMMON_REPO_TAG:STRING=${TRITON_COMMON_REPO_TAG}
-DTRITON_VERSION:STRING=${TRITON_VERSION}
-DTRITON_ENABLE_PYTHON_HTTP:BOOL=${TRITON_ENABLE_PYTHON_HTTP}
-DTRITON_ENABLE_PYTHON_GRPC:BOOL=${TRITON_ENABLE_PYTHON_GRPC}
-DTRITON_ENABLE_PERF_ANALYZER:BOOL=${TRITON_ENABLE_PERF_ANALYZER}
-DTRITON_ENABLE_EXAMPLES:BOOL=${TRITON_ENABLE_EXAMPLES}
-DTRITON_ENABLE_TESTS:BOOL=${TRITON_ENABLE_TESTS}
-DTRITON_ENABLE_GPU:BOOL=${TRITON_ENABLE_GPU}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=${TRITON_INSTALL_PREFIX}
DEPENDS ${_py_client_depends}
)
endif() # TRITON_ENABLE_PYTHON_HTTP OR TRITON_ENABLE_PYTHON_GRPC
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@

# Triton Clients

cmake -DCMAKE_INSTALL_PREFIX=`pwd`/install -DTRITON_COMMON_REPO_TAG=davidg-client -DTRITON_THIRD_PARTY_REPO_TAG=davidg-client -DTRITON_ENABLE_CC_HTTP=ON -DTRITON_ENABLE_CC_GRPC=ON -DTRITON_ENABLE_EXAMPLES=ON -DTRITON_ENABLE_TESTS=ON -DTRITON_ENABLE_PERF_ANALYZER=ON /opt/client
cmake -DCMAKE_INSTALL_PREFIX=`pwd`/install -DTRITON_COMMON_REPO_TAG=davidg-client -DTRITON_THIRD_PARTY_REPO_TAG=davidg-client -DTRITON_ENABLE_CC_HTTP=ON -DTRITON_ENABLE_CC_GRPC=ON -DTRITON_ENABLE_EXAMPLES=ON -DTRITON_ENABLE_TESTS=ON -DTRITON_ENABLE_PERF_ANALYZER=ON -DTRITON_ENABLE_PYTHON_HTTP=ON -DTRITON_ENABLE_PYTHON_GRPC=ON -DTRITON_ENABLE_GPU=ON /opt/client
19 changes: 11 additions & 8 deletions src/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ FetchContent_Declare(
GIT_SHALLOW ON
)

if(TRITON_ENABLE_CC_GRPC)
if(TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
set(TRITON_COMMON_ENABLE_PROTOBUF ON)
set(TRITON_COMMON_ENABLE_GRPC ON)
endif() # TRITON_ENABLE_CC_GRPC
endif() # TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER

FetchContent_MakeAvailable(repo-common)

#
# CUDA
#
if(${TRITON_ENABLE_GPU})
if(TRITON_ENABLE_GPU)
find_package(CUDAToolkit REQUIRED)
endif() # TRITON_ENABLE_GPU

Expand All @@ -81,24 +81,27 @@ endif() # TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_PERF_ANALYZER
#
# Protobuf
#
if(TRITON_ENABLE_CC_GRPC)
if(TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
set(protobuf_MODULE_COMPATIBLE TRUE CACHE BOOL "protobuf_MODULE_COMPATIBLE" FORCE)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")
include_directories(${Protobuf_INCLUDE_DIRS})
endif() # TRITON_ENABLE_CC_GRPC
endif() # TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER

#
# GRPC
#
if(TRITON_ENABLE_CC_GRPC)
if(TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
include_directories($<TARGET_PROPERTY:gRPC::grpc,INTERFACE_INCLUDE_DIRECTORIES>)
endif() # TRITON_ENABLE_CC_GRPC
endif() # TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER

if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC)
if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
add_subdirectory(library)
endif() # TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER

if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC)
if(TRITON_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif() # TRITON_ENABLE_EXAMPLES
Expand Down
36 changes: 18 additions & 18 deletions src/c++/library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ target_link_libraries(
client-common-library
)

if(${TRITON_ENABLE_CC_GRPC})
if(TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
#
# libgrpcclient.so and libgrpcclient_static.a
#
Expand Down Expand Up @@ -185,17 +185,17 @@ if(${TRITON_ENABLE_CC_GRPC})
${CMAKE_CURRENT_SOURCE_DIR}
)

if(${TRITON_ENABLE_GPU})
if(TRITON_ENABLE_GPU)
target_compile_definitions(
${_client_target}
PRIVATE TRITON_ENABLE_GPU=1
PUBLIC TRITON_ENABLE_GPU=1
)
endif() # TRITON_ENABLE_GPU

if(${TRITON_ENABLE_GPU})
if(TRITON_ENABLE_GPU)
target_link_libraries(
${_client_target}
PRIVATE CUDA::cudart
PUBLIC CUDA::cudart
)
endif() # TRITON_ENABLE_GPU
endforeach()
Expand Down Expand Up @@ -236,9 +236,9 @@ if(${TRITON_ENABLE_CC_GRPC})
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif() # TRITON_ENABLE_CC_GRPC
endif() # TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER

if(${TRITON_ENABLE_CC_HTTP})
if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_PERF_ANALYZER)
#
# libhttpclient.so and libhttpclient_static.a
#
Expand Down Expand Up @@ -341,17 +341,17 @@ if(${TRITON_ENABLE_CC_HTTP})
${_client_target}
PRIVATE CURL_STATICLIB=1
)
if(${TRITON_ENABLE_GPU})
if(TRITON_ENABLE_GPU)
target_compile_definitions(
${_client_target}
PRIVATE TRITON_ENABLE_GPU=1
PUBLIC TRITON_ENABLE_GPU=1
)
endif() # TRITON_ENABLE_GPU

if(${TRITON_ENABLE_GPU})
if(TRITON_ENABLE_GPU)
target_link_libraries(
${_client_target}
PRIVATE CUDA::cudart
PUBLIC CUDA::cudart
)
endif() # TRITON_ENABLE_GPU
endforeach()
Expand All @@ -370,9 +370,9 @@ if(${TRITON_ENABLE_CC_HTTP})
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif() # TRITON_ENABLE_CC_HTTP
endif() # TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_PERF_ANALYZER

if(${TRITON_ENABLE_CC_HTTP} OR ${TRITON_ENABLE_CC_GRPC})
if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/common.h
Expand All @@ -383,7 +383,7 @@ if(${TRITON_ENABLE_CC_HTTP} OR ${TRITON_ENABLE_CC_GRPC})
include(GNUInstallDirs)
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/TritonClient)

if(${TRITON_ENABLE_CC_GRPC})
if(TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER)
install(
TARGETS
grpcclient
Expand All @@ -394,9 +394,9 @@ if(${TRITON_ENABLE_CC_HTTP} OR ${TRITON_ENABLE_CC_GRPC})
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif() # TRITON_ENABLE_CC_GRPC
endif() # TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER

if(${TRITON_ENABLE_CC_HTTP})
if(TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_PERF_ANALYZER)
install(
TARGETS
httpclient
Expand All @@ -407,7 +407,7 @@ if(${TRITON_ENABLE_CC_HTTP} OR ${TRITON_ENABLE_CC_GRPC})
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif() # TRITON_ENABLE_CC_HTTP
endif() # TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_PERF_ANALYZER

install(
EXPORT
Expand Down Expand Up @@ -448,4 +448,4 @@ if(${TRITON_ENABLE_CC_HTTP} OR ${TRITON_ENABLE_CC_GRPC})

export(PACKAGE TritonClient)

endif() # ${TRITON_ENABLE_CC_HTTP} OR ${TRITON_ENABLE_CC_GRPC}
endif() # TRITON_ENABLE_CC_HTTP OR TRITON_ENABLE_CC_GRPC OR TRITON_ENABLE_PERF_ANALYZER
18 changes: 13 additions & 5 deletions src/c++/perf_analyzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,22 @@ add_executable(
)
target_link_libraries(
perf_analyzer
PRIVATE client-backend-library
PRIVATE -lb64
PRIVATE
client-backend-library
-lb64
)

# If gpu is enabled then compile with CUDA dependencies
if(${TRITON_ENABLE_GPU})
target_include_directories(perf_analyzer PRIVATE ${CUDA_INCLUDE_DIRS})
target_link_libraries(perf_analyzer PRIVATE ${CUDA_LIBRARIES})
if(TRITON_ENABLE_GPU)
target_compile_definitions(
perf_analyzer
PUBLIC TRITON_ENABLE_GPU=1
)

target_link_libraries(
perf_analyzer
PRIVATE CUDA::cudart
)
endif()


Expand Down
6 changes: 4 additions & 2 deletions src/c++/perf_analyzer/client_backend/triton/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ target_link_libraries(
)

if(${TRITON_ENABLE_GPU})
target_include_directories(triton-client-backend-library PUBLIC ${CUDA_INCLUDE_DIRS})
target_link_libraries(triton-client-backend-library PRIVATE ${CUDA_LIBRARIES})
target_link_libraries(
triton-client-backend-library
PRIVATE CUDA::cudart
)
endif() # TRITON_ENABLE_GPU
Loading

0 comments on commit 9671bd1

Please sign in to comment.