Skip to content

Commit

Permalink
Remove build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mreso committed Mar 13, 2024
1 parent c3a4c1d commit df85d48
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 135 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci-cpu-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ jobs:
python ts_scripts/print_env_info.py
- name: Build
run: |
cd cpp && rm -rf _build && sudo mkdir /mnt/_build && sudo chmod 777 /mnt/_build && mkdir _build && sudo mount --bind /mnt/_build _build
./build.sh
cd cpp && rm -rf _build && sudo mkdir /mnt/_build && sudo chmod 777 /mnt/_build && mkdir build && sudo mount --bind /mnt/_build build
cd build && cmake ..
make -j && make install
make test
- name: Run test
run: |
cd test && pytest pytest/test_cpp_backend.py
16 changes: 16 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -fPIC")
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR})

find_program(CLANG_TIDY_EXE NAMES "clang-tidy" REQUIRED)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
Expand All @@ -22,9 +23,24 @@ if(CLANG_FORMAT_EXE)

endif()

execute_process(COMMAND python -c "import importlib; print(importlib.util.find_spec('nvidia') is not None)"
OUTPUT_VARIABLE NVIDIA_AVAILABLE
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${NVIDIA_AVAILABLE} STREQUAL "True")
execute_process(COMMAND python -c "import nvidia;from pathlib import Path;print(Path(nvidia.__file__).parent/'nccl'/'lib')"
OUTPUT_VARIABLE NCCL_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".so.2")
endif()

execute_process(COMMAND python -c "import torch;print(torch.utils.cmake_prefix_path)"
OUTPUT_VARIABLE TORCH_CMAKE_PREFIX_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
list(APPEND CMAKE_PREFIX_PATH ${TORCH_CMAKE_PREFIX_PATH})

find_package(Boost REQUIRED)
find_package(Torch REQUIRED)
find_library(NCCL_LIBRARY nccl HINTS ${NCCL_PATH})

include(FetchContent)

Expand Down
11 changes: 8 additions & 3 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ cd serve/docker
Start the container and optionally bind mount a build directory into the container to persist build artifacts across container runs
```
# For CPU support
docker run [-v /path/to/build/dir:/serve/cpp/_build] -it pytorch/torchserve:cpp-dev-cpu /bin/bash
docker run [-v /path/to/build/dir:/serve/cpp/build] -it pytorch/torchserve:cpp-dev-cpu /bin/bash
# For GPU support
docker run --gpus all [-v /path/to/build/dir:/serve/cpp/_build] -it pytorch/torchserve:cpp-dev-gpu /bin/bash
docker run --gpus all [-v /path/to/build/dir:/serve/cpp/build] -it pytorch/torchserve:cpp-dev-gpu /bin/bash
```
`Warning`: The dev docker container does not install all necessary dependencies or build Torchserve CPP. Please follow the steps below after starting the container.

Expand All @@ -41,7 +41,12 @@ Then build the backend:
```
## Dev Build
cd cpp
./build.sh
mkdir build && cd build
# Optionally, you can skip building the tests by adding: -DBUILD_TESTS=OFF
cmake ..
make -j && make install
## Optionally, you can run the tests with
make test
```

### Run TorchServe
Expand Down
125 changes: 0 additions & 125 deletions cpp/build.sh

This file was deleted.

8 changes: 4 additions & 4 deletions cpp/src/backends/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ list(APPEND TS_BACKENDS_PROTOCOL_SOURCE_FILES ${TS_BACKENDS_PROTOCOL_SRC_DIR}/so
add_library(ts_backends_protocol SHARED ${TS_BACKENDS_PROTOCOL_SOURCE_FILES})
target_include_directories(ts_backends_protocol PUBLIC ${TS_BACKENDS_PROTOCOL_SRC_DIR})
target_link_libraries(ts_backends_protocol PRIVATE ts_utils)
install(TARGETS ts_backends_protocol DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/libs)
install(TARGETS ts_backends_protocol DESTINATION ${CMAKE_INSTALL_PREFIX}/libs)

# build library ts_backend_core
set(BACKEND_SOURCE_FILES "")
Expand All @@ -37,7 +37,7 @@ list(APPEND BACKEND_SOURCE_FILES ${TS_BACKENDS_SRC_DIR}/handler/torch_scripted_h
add_library(ts_backends_core SHARED ${BACKEND_SOURCE_FILES})
target_include_directories(ts_backends_core PUBLIC ${TS_BACKENDS_CORE_SRC_DIR})
target_link_libraries(ts_backends_core PUBLIC ts_utils ts_backends_protocol ${TORCH_LIBRARIES})
install(TARGETS ts_backends_core DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/libs)
install(TARGETS ts_backends_core DESTINATION ${CMAKE_INSTALL_PREFIX}/libs)

# build exe model_worker_socket
add_executable(model_worker_socket
Expand All @@ -51,5 +51,5 @@ target_include_directories(model_worker_socket PRIVATE
${TS_BACKENDS_TORCH_SCRIPTED_SRC_DIR}
)
target_link_libraries(model_worker_socket
PRIVATE ts_backends_core ts_backends_protocol ${TORCH_LIBRARIES} gflags)
install(TARGETS model_worker_socket DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/bin)
PRIVATE ts_backends_core ts_backends_protocol ${TORCH_LIBRARIES} gflags ${NCCL_LIBRARY})
install(TARGETS model_worker_socket DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
2 changes: 1 addition & 1 deletion cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(TEST_BINARY ${CMAKE_PROJECT_NAME}_test)
file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false *.cc *.hh)

add_executable(${TEST_BINARY} ${TEST_SOURCES})
target_link_libraries(${TEST_BINARY} gtest_main gmock_main ts_backends_core ts_backends_protocol ts_utils ${TORCH_LIBRARIES})
target_link_libraries(${TEST_BINARY} gtest_main gmock_main ts_backends_core ts_backends_protocol ts_utils ${TORCH_LIBRARIES} ${NCCL_LIBRARY})

include(GoogleTest)
gtest_discover_tests(${TEST_BINARY})

0 comments on commit df85d48

Please sign in to comment.