Skip to content

Commit ab41f43

Browse files
committed
fix compile error on mac x86
1 parent cfb4285 commit ab41f43

File tree

5 files changed

+55
-12
lines changed

5 files changed

+55
-12
lines changed

cpp/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
22
project(torchserve_cpp VERSION 0.1)
33

44
set(CMAKE_CXX_STANDARD 17)

cpp/build.sh

+49-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function install_folly() {
2828
echo -e "${COLOR_GREEN}[ INFO ] Cloning folly repo ${COLOR_OFF}"
2929
git clone https://github.com/facebook/folly.git "$FOLLY_SRC_DIR"
3030
cd $FOLLY_SRC_DIR
31-
git checkout tags/v2022.06.27.00
31+
git checkout tags/v2024.01.29.00
3232
fi
3333

3434
if [ ! -d "$FOLLY_BUILD_DIR" ] ; then
@@ -75,7 +75,18 @@ function install_kineto() {
7575

7676
function install_libtorch() {
7777
if [ "$PLATFORM" = "Mac" ]; then
78-
echo -e "${COLOR_GREEN}[ INFO ] Skip install libtorch on Mac ${COLOR_OFF}"
78+
cd "$DEPS_DIR" || exit
79+
if [[ $(uname -m) == 'x86_64' ]]; then
80+
echo -e "${COLOR_GREEN}[ INFO ] Install libtorch on Mac x86_64 ${COLOR_OFF}"
81+
wget https://download.pytorch.org/libtorch/cpu/libtorch-macos-x86_64-2.2.0.zip
82+
unzip libtorch-macos-x86_64-2.2.0.zip
83+
rm libtorch-macos-x86_64-2.2.0.zip
84+
else
85+
echo -e "${COLOR_GREEN}[ INFO ] Install libtorch on Mac arm64 ${COLOR_OFF}"
86+
wget https://download.pytorch.org/libtorch/cpu/libtorch-macos-arm64-2.2.0.zip
87+
unzip libtorch-macos-arm64-2.2.0.zip
88+
rm libtorch-macos-arm64-2.2.0.zip
89+
fi
7990
elif [ ! -d "$DEPS_DIR/libtorch" ] ; then
8091
cd "$DEPS_DIR" || exit
8192
if [ "$PLATFORM" = "Linux" ]; then
@@ -113,7 +124,7 @@ function install_yaml_cpp() {
113124
echo -e "${COLOR_GREEN}[ INFO ] Cloning yaml-cpp repo ${COLOR_OFF}"
114125
git clone https://github.com/jbeder/yaml-cpp.git "$YAML_CPP_SRC_DIR"
115126
cd $YAML_CPP_SRC_DIR
116-
git checkout tags/yaml-cpp-0.7.0
127+
git checkout tags/0.8.0
117128
fi
118129

119130
if [ ! -d "$YAML_CPP_BUILD_DIR" ] ; then
@@ -136,11 +147,42 @@ function install_yaml_cpp() {
136147
cd "$BWD" || exit
137148
}
138149

150+
function install_sentencepiece() {
151+
SENTENCEPIECE_SRC_DIR=$BASE_DIR/third-party/sentencepiece
152+
SENTENCEPIECE_BUILD_DIR=$DEPS_DIR/sentencepiece-build
153+
154+
if [ ! -d "$SENTENCEPIECE_SRC_DIR" ] ; then
155+
echo -e "${COLOR_GREEN}[ INFO ] Cloning sentencepiece repo ${COLOR_OFF}"
156+
git clone https://github.com/google/sentencepiece.git "$SENTENCEPIECE_SRC_DIR"
157+
cd $SENTENCEPIECE_SRC_DIR
158+
git checkout tags/v0.1.99
159+
fi
160+
161+
if [ ! -d "$SENTENCEPIECE_BUILD_DIR" ] ; then
162+
echo -e "${COLOR_GREEN}[ INFO ] Building sentencepiece ${COLOR_OFF}"
163+
164+
mkdir $SENTENCEPIECE_BUILD_DIR
165+
cd $SENTENCEPIECE_BUILD_DIR
166+
cmake $SENTENCEPIECE_SRC_DIR
167+
make -i $(nproc)
168+
if [ "$PLATFORM" = "Linux" ]; then
169+
sudo make install
170+
sudo ldconfig -v
171+
elif [ "$PLATFORM" = "Mac" ]; then
172+
make install
173+
fi
174+
175+
echo -e "${COLOR_GREEN}[ INFO ] sentencepiece is installed ${COLOR_OFF}"
176+
fi
177+
178+
cd "$BWD" || exit
179+
}
180+
139181
function build_llama_cpp() {
140182
BWD=$(pwd)
141183
LLAMA_CPP_SRC_DIR=$BASE_DIR/third-party/llama.cpp
142184
cd "${LLAMA_CPP_SRC_DIR}"
143-
make
185+
make LLAMA_METAL=OFF
144186
cd "$BWD" || exit
145187
}
146188

@@ -191,7 +233,7 @@ function build() {
191233
fi
192234
elif [ "$PLATFORM" = "Mac" ]; then
193235
cmake \
194-
-DCMAKE_PREFIX_PATH="$(python -c 'import torch; print(torch.utils.cmake_prefix_path)');$DEPS_DIR;$FOLLY_CMAKE_DIR;$YAML_CPP_CMAKE_DIR" \
236+
-DCMAKE_PREFIX_PATH="$DEPS_DIR;$FOLLY_CMAKE_DIR;$YAML_CPP_CMAKE_DIR;$DEPS_DIR/libtorch" \
195237
-DCMAKE_INSTALL_PREFIX="$PREFIX" \
196238
"$MAYBE_BUILD_QUIC" \
197239
"$MAYBE_BUILD_TESTS" \
@@ -225,7 +267,7 @@ function build() {
225267

226268
function symlink_torch_libs() {
227269
if [ "$PLATFORM" = "Linux" ]; then
228-
ln -sf ${DEPS_DIR}/libtorch/lib/*.so* ${BUILD_DIR}/libs/
270+
ln -sf ${DEPS_DIR}/libtorch/lib/*.so* ${LIBS_DIR}
229271
fi
230272
}
231273

@@ -315,6 +357,7 @@ install_folly
315357
install_kineto
316358
install_libtorch
317359
install_yaml_cpp
360+
install_sentencepiece
318361
build_llama_cpp
319362
build
320363
symlink_torch_libs

cpp/src/backends/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ list(APPEND BACKEND_SOURCE_FILES ${TS_BACKENDS_SRC_DIR}/handler/base_handler.cc)
2222
list(APPEND BACKEND_SOURCE_FILES ${TS_BACKENDS_SRC_DIR}/handler/torch_scripted_handler.cc)
2323
add_library(ts_backends_core SHARED ${BACKEND_SOURCE_FILES})
2424
target_include_directories(ts_backends_core PUBLIC ${TS_BACKENDS_CORE_SRC_DIR})
25-
target_link_libraries(ts_backends_core PUBLIC ts_utils ts_backends_protocol ${FOLLY_LIBRARIES})
25+
target_link_libraries(ts_backends_core PUBLIC ts_utils ts_backends_protocol ${FOLLY_LIBRARIES} ${TORCH_LIBRARIES})
2626
install(TARGETS ts_backends_core DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/libs)
2727

2828
# build exe model_worker_socket

cpp/src/examples/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
add_subdirectory("../../../examples/cpp/babyllama/" "../../../test/resources/examples/babyllama/babyllama_handler/")
2+
add_subdirectory("../../../examples/cpp/babyllama/" "${CMAKE_CURRENT_BINARY_DIR}/../../test/resources/examples/babyllama/babyllama_handler/")
33

4-
add_subdirectory("../../../examples/cpp/llamacpp/" "../../../test/resources/examples/llamacpp/llamacpp_handler/")
4+
add_subdirectory("../../../examples/cpp/llamacpp/" "${CMAKE_CURRENT_BINARY_DIR}/../../test/resources/examples/llamacpp/llamacpp_handler/")
55

6-
add_subdirectory("../../../examples/cpp/mnist/" "../../../test/resources/examples/mnist/mnist_handler/")
6+
add_subdirectory("../../../examples/cpp/mnist/" "${CMAKE_CURRENT_BINARY_DIR}/../../test/resources/examples/mnist/mnist_handler/")

cpp/src/utils/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ list(APPEND TS_UTILS_SOURCE_FILES ${TS_UTILS_SRC_DIR}/metrics/registry.cc)
1212
add_library(ts_utils SHARED ${TS_UTILS_SOURCE_FILES})
1313
target_include_directories(ts_utils PUBLIC ${TS_UTILS_SRC_DIR})
1414
target_include_directories(ts_utils PRIVATE ${Boost_INCLUDE_DIRS})
15-
target_link_libraries(ts_utils ${FOLLY_LIBRARIES} ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} yaml-cpp)
15+
target_link_libraries(ts_utils ${FOLLY_LIBRARIES} ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} yaml-cpp::yaml-cpp)
1616
install(TARGETS ts_utils DESTINATION ${torchserve_cpp_SOURCE_DIR}/_build/libs)
1717

1818
list(APPEND FOO_SOURCE_FILES ${TS_UTILS_SRC_DIR}/ifoo.hh)

0 commit comments

Comments
 (0)