Skip to content

Commit df85d48

Browse files
committed
Remove build.sh
1 parent c3a4c1d commit df85d48

File tree

6 files changed

+33
-135
lines changed

6 files changed

+33
-135
lines changed

.github/workflows/ci-cpu-cpp.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ jobs:
5353
python ts_scripts/print_env_info.py
5454
- name: Build
5555
run: |
56-
cd cpp && rm -rf _build && sudo mkdir /mnt/_build && sudo chmod 777 /mnt/_build && mkdir _build && sudo mount --bind /mnt/_build _build
57-
./build.sh
56+
cd cpp && rm -rf _build && sudo mkdir /mnt/_build && sudo chmod 777 /mnt/_build && mkdir build && sudo mount --bind /mnt/_build build
57+
cd build && cmake ..
58+
make -j && make install
59+
make test
5860
- name: Run test
5961
run: |
6062
cd test && pytest pytest/test_cpp_backend.py

cpp/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD 17)
77
set(CMAKE_CXX_STANDARD_REQUIRED True)
88
set(CMAKE_CXX_EXTENSIONS OFF)
99
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wextra -fPIC")
10+
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR})
1011

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

2324
endif()
2425

26+
execute_process(COMMAND python -c "import importlib; print(importlib.util.find_spec('nvidia') is not None)"
27+
OUTPUT_VARIABLE NVIDIA_AVAILABLE
28+
OUTPUT_STRIP_TRAILING_WHITESPACE)
29+
if(${NVIDIA_AVAILABLE} STREQUAL "True")
30+
execute_process(COMMAND python -c "import nvidia;from pathlib import Path;print(Path(nvidia.__file__).parent/'nccl'/'lib')"
31+
OUTPUT_VARIABLE NCCL_PATH
32+
OUTPUT_STRIP_TRAILING_WHITESPACE)
33+
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".so.2")
34+
endif()
35+
36+
execute_process(COMMAND python -c "import torch;print(torch.utils.cmake_prefix_path)"
37+
OUTPUT_VARIABLE TORCH_CMAKE_PREFIX_PATH
38+
OUTPUT_STRIP_TRAILING_WHITESPACE)
39+
list(APPEND CMAKE_PREFIX_PATH ${TORCH_CMAKE_PREFIX_PATH})
2540

2641
find_package(Boost REQUIRED)
2742
find_package(Torch REQUIRED)
43+
find_library(NCCL_LIBRARY nccl HINTS ${NCCL_PATH})
2844

2945
include(FetchContent)
3046

cpp/README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ cd serve/docker
1717
Start the container and optionally bind mount a build directory into the container to persist build artifacts across container runs
1818
```
1919
# For CPU support
20-
docker run [-v /path/to/build/dir:/serve/cpp/_build] -it pytorch/torchserve:cpp-dev-cpu /bin/bash
20+
docker run [-v /path/to/build/dir:/serve/cpp/build] -it pytorch/torchserve:cpp-dev-cpu /bin/bash
2121
# For GPU support
22-
docker run --gpus all [-v /path/to/build/dir:/serve/cpp/_build] -it pytorch/torchserve:cpp-dev-gpu /bin/bash
22+
docker run --gpus all [-v /path/to/build/dir:/serve/cpp/build] -it pytorch/torchserve:cpp-dev-gpu /bin/bash
2323
```
2424
`Warning`: The dev docker container does not install all necessary dependencies or build Torchserve CPP. Please follow the steps below after starting the container.
2525

@@ -41,7 +41,12 @@ Then build the backend:
4141
```
4242
## Dev Build
4343
cd cpp
44-
./build.sh
44+
mkdir build && cd build
45+
# Optionally, you can skip building the tests by adding: -DBUILD_TESTS=OFF
46+
cmake ..
47+
make -j && make install
48+
## Optionally, you can run the tests with
49+
make test
4550
```
4651

4752
### Run TorchServe

cpp/build.sh

-125
This file was deleted.

cpp/src/backends/CMakeLists.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ list(APPEND TS_BACKENDS_PROTOCOL_SOURCE_FILES ${TS_BACKENDS_PROTOCOL_SRC_DIR}/so
2626
add_library(ts_backends_protocol SHARED ${TS_BACKENDS_PROTOCOL_SOURCE_FILES})
2727
target_include_directories(ts_backends_protocol PUBLIC ${TS_BACKENDS_PROTOCOL_SRC_DIR})
2828
target_link_libraries(ts_backends_protocol PRIVATE ts_utils)
29-
install(TARGETS ts_backends_protocol DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/libs)
29+
install(TARGETS ts_backends_protocol DESTINATION ${CMAKE_INSTALL_PREFIX}/libs)
3030

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

4242
# build exe model_worker_socket
4343
add_executable(model_worker_socket
@@ -51,5 +51,5 @@ target_include_directories(model_worker_socket PRIVATE
5151
${TS_BACKENDS_TORCH_SCRIPTED_SRC_DIR}
5252
)
5353
target_link_libraries(model_worker_socket
54-
PRIVATE ts_backends_core ts_backends_protocol ${TORCH_LIBRARIES} gflags)
55-
install(TARGETS model_worker_socket DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/bin)
54+
PRIVATE ts_backends_core ts_backends_protocol ${TORCH_LIBRARIES} gflags ${NCCL_LIBRARY})
55+
install(TARGETS model_worker_socket DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

cpp/test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ set(TEST_BINARY ${CMAKE_PROJECT_NAME}_test)
1212
file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false *.cc *.hh)
1313

1414
add_executable(${TEST_BINARY} ${TEST_SOURCES})
15-
target_link_libraries(${TEST_BINARY} gtest_main gmock_main ts_backends_core ts_backends_protocol ts_utils ${TORCH_LIBRARIES})
15+
target_link_libraries(${TEST_BINARY} gtest_main gmock_main ts_backends_core ts_backends_protocol ts_utils ${TORCH_LIBRARIES} ${NCCL_LIBRARY})
1616

1717
include(GoogleTest)
1818
gtest_discover_tests(${TEST_BINARY})

0 commit comments

Comments
 (0)