Skip to content

Commit 1fb19a0

Browse files
silehtmergify[bot]
authored andcommitted
fix(build): pytorch with custom spdlog
This change uses by default upstream spdlog 1.8.2 This is required for ubuntu 20.04 and RedHat distro as there hdoesn't ship a working version of libspdlog/libfmt.
1 parent c0dcec9 commit 1fb19a0

File tree

6 files changed

+36
-17
lines changed

6 files changed

+36
-17
lines changed

CMakeLists.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ option(USE_CUDA_CV "use CUDA with OpenCV (Requires OpenCV build for CUDA)" OFF)
2020
option(USE_SIMSEARCH "build index and search services" OFF)
2121
option(USE_ANNOY "use annoy as indexer" OFF)
2222
option(USE_FAISS "use FAISS as indexer" ON)
23-
option(BUILD_SPDLOG "build SPDLOG instead of using system library" OFF)
23+
option(BUILD_SPDLOG "build SPDLOG instead of using system library" ON)
2424
option(USE_BOOST_BACKTRACE "use boost backtrace" ON)
2525

2626
if (USE_CAFFE)
@@ -187,13 +187,16 @@ if (BUILD_SPDLOG)
187187
URL https://github.com/gabime/spdlog/archive/v1.8.2.tar.gz
188188
URL_HASH SHA256=e20e6bd8f57e866eaf25a5417f0a38a116e537f1a77ac7b5409ca2b180cec0d5
189189
BUILD_IN_SOURCE true
190-
INSTALL_COMMAND ""
190+
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/spdlog/build -DCMAKE_POSITION_INDEPENDENT_CODE=ON
191191
)
192-
set(SPDLOG_LIB_DEPS ${CMAKE_BINARY_DIR}/spdlog/src/spdlog/libspdlog.a)
193-
set(SPDLOG_CAFFE_LIB_DIR ${CMAKE_BINARY_DIR}/spdlog/src/spdlog)
192+
set(SPDLOG_LIB_DEPS ${CMAKE_BINARY_DIR}/spdlog/build/lib/libspdlog.a)
193+
set(SPDLOG_LIB_DIR ${CMAKE_BINARY_DIR}/spdlog/build/lib)
194194
set(SPDLOG_CAFFE_LIB_DEPS :libspdlog.a)
195-
set(SPDLOG_INCLUDE_DIR ${CMAKE_BINARY_DIR}/spdlog/src/spdlog/include)
195+
set(SPDLOG_INCLUDE_DIR ${CMAKE_BINARY_DIR}/spdlog/build/include)
196196
include_directories(SYSTEM ${SPDLOG_INCLUDE_DIR})
197+
else()
198+
find_package(spdlog 1.8.2 CONFIG REQUIRED)
199+
set(SPDLOG_LIB_DEPS spdlog::spdlog)
197200
endif()
198201

199202
# hdf5
@@ -627,7 +630,7 @@ elseif(USE_CAFFE)
627630
echo "INCLUDE_DIRS+=${PROTOBUF_INCLUDE_DIR}" >> Makefile.config &&
628631
echo "CUDA_ARCH:=${CUDA_ARCH}" >> Makefile.config &&
629632
echo "LIBRARIES+=${SPDLOG_CAFFE_LIB_DEPS}" >> Makefile.config &&
630-
echo "LIBRARY_DIRS+=${SPDLOG_CAFFE_LIB_DIR}" >> Makefile.config &&
633+
echo "LIBRARY_DIRS+=${SPDLOG_LIB_DIR}" >> Makefile.config &&
631634
echo "LIBRARY_DIRS+=${PROTOBUF_LIB_DIR}" >> Makefile.config
632635
BUILD_COMMAND
633636
${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${PROTOBUF_LIB_DIR}:$ENV{LD_LIBRARY_PATH} PATH=${PROTOBUF_LIB_DIR}:$ENV{PATH} make -j${N} proto &&
@@ -760,7 +763,13 @@ if (USE_TORCH)
760763
PATCH_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || git apply ${PYTORCH_PATCHES} && echo Applying ${PYTORCH_PATCHES}
761764
CONFIGURE_COMMAND ""
762765
BUILD_COMMAND ""
763-
COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || PATH=${PROTOBUF_LIB_DIR}:$ENV{PATH} BUILD_CUSTOM_PROTOBUF=0 GLIBCXX_USE_CXX11_ABI=1 BUILD_TEST=0 USE_CUDA=${PYTORCH_USE_CUDA} BUILD_CAFFE2_OPS=0 USE_DDLOG=1 CAFFE2_LINK_LOCAL_PROTOBUF=0 MAX_JOBS=8 python3 ../pytorch/tools/build_libtorch.py
766+
COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping
767+
|| PATH=${PROTOBUF_LIB_DIR}:$ENV{PATH}
768+
BUILD_CUSTOM_PROTOBUF=0 GLIBCXX_USE_CXX11_ABI=1 BUILD_TEST=0
769+
USE_CUDA=${PYTORCH_USE_CUDA}
770+
BUILD_CAFFE2_OPS=0 USE_DDLOG=1 CAFFE2_LINK_LOCAL_PROTOBUF=0
771+
"CMAKE_CXX_FLAGS=-isystem${SPDLOG_INCLUDE_DIR}"
772+
MAX_JOBS=8 python3 ../pytorch/tools/build_libtorch.py
764773
INSTALL_COMMAND ""
765774
)
766775

@@ -793,7 +802,8 @@ if (USE_TORCH)
793802
GIT_CONFIG advice.detachedHead=false
794803
CMAKE_ARGS -DWITH_CUDA=${PYTORCH_USE_CUDA} -DCMAKE_PREFIX_PATH=${TORCH_LOCATION} -DCMAKE_INSTALL_PREFIX=${TORCHVISION_LOCATION}
795804
-DCMAKE_INCLUDE_PATH=${PROJECT_INCLUDE_DIR} -DCMAKE_LIBRARY_PATH=${PROTOBUF_LIB_DIR}
796-
"-DCMAKE_CXX_FLAGS=-isystem ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/" "-DCMAKE_CUDA_FLAGS=-isystem ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/"
805+
"-DCMAKE_CXX_FLAGS=-isystem ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/ -isystem ${SPDLOG_INCLUDE_DIR}"
806+
"-DCMAKE_CUDA_FLAGS=-isystem ${CMAKE_BINARY_DIR}/pytorch/src/pytorch/ -isystem ${SPDLOG_INCLUDE_DIR}"
797807
-DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc
798808
DEPENDS protobuf pytorch
799809
)
@@ -1042,7 +1052,7 @@ include_directories("${PROJECT_SOURCE_DIR}/src")
10421052
include_directories(${CMAKE_BINARY_DIR}/src)
10431053
add_subdirectory(src)
10441054

1045-
set(COMMON_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${HTTP_INCLUDE_DIR} ${PROTOBUF_INCLUDE_DIR})
1055+
set(COMMON_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${HTTP_INCLUDE_DIR} ${PROTOBUF_INCLUDE_DIR} ${SPDLOG_INCLUDE_DIR})
10461056

10471057
if (CUDA_FOUND)
10481058
list(APPEND COMMON_INCLUDE_DIRS ${CUDA_INCLUDE_DIRS})

ci/Jenkinsfile.prebuilt-cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cmake .. \
3535
-DUSE_TENSORRT=ON \
3636
-DUSE_TENSORRT_OSS=ON \
3737
-DCUDA_ARCH="-gencode arch=compute_61,code=sm_61"
38-
schedtool -B -n 1 -e ionice -n 1 make -j24 protobuf caffe_dd pytorch Multicore-TSNE ncnn xgboost cpp-netlib tensorrt-oss oatpp oatpp-swagger oatpp-zlib
38+
schedtool -B -n 1 -e ionice -n 1 make -j24 protobuf spdlog caffe_dd pytorch Multicore-TSNE ncnn xgboost cpp-netlib tensorrt-oss oatpp oatpp-swagger oatpp-zlib
3939
ccache -s
4040

4141
# Remove cmake files

ci/Jenkinsfile.unittests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ cmake .. \
6969
export PATH="/usr/lib/ccache/:$PATH"
7070
export TMPDIR=$(pwd)/build/tmp
7171
cd build
72-
schedtool -B -n 1 -e ionice -n 1 make -j24 protobuf caffe_dd pytorch Multicore-TSNE faisslib ncnn xgboost cpp-netlib tensorrt-oss oatpp oatpp-swagger oatpp-zlib
72+
schedtool -B -n 1 -e ionice -n 1 make -j24 protobuf spdlog caffe_dd pytorch Multicore-TSNE faisslib ncnn xgboost cpp-netlib tensorrt-oss oatpp oatpp-swagger oatpp-zlib
7373
# TODO(sileht): we should create the prebuilt artefacts here after each successful master branch build
7474
schedtool -B -n 1 -e ionice -n 1 make -j 6
7575
ccache -s

patches/pytorch/pytorch_16_new_logger.patch

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ new file mode 100644
33
index 0000000000..56ebbf9441
44
--- /dev/null
55
+++ b/c10/util/logging_is_dd_log.h
6-
@@ -0,0 +1,60 @@
6+
@@ -0,0 +1,61 @@
77
+#ifndef DD_LOG_H
88
+#define DD_LOG_H
99
+#include <set>
1010
+#include <iomanip>
11+
+#include <map>
1112
+
1213
+#include "caffe/llogging.h"
1314
+
@@ -69,7 +70,7 @@ new file mode 100644
6970
index 0000000000..ff97118ff2
7071
--- /dev/null
7172
+++ b/caffe/llogging.h
72-
@@ -0,0 +1,211 @@
73+
@@ -0,0 +1,217 @@
7374
+/**
7475
+ * Author: Emmanuel Benazera <[email protected]>
7576
+ */
@@ -78,8 +79,14 @@ index 0000000000..ff97118ff2
7879
+#define LLOGGING_H
7980
+
8081
+#include <spdlog/spdlog.h>
82+
+#ifdef USE_SYSLOG
83+
+#include <spdlog/sinks/syslog_sink.h>
84+
+#else
85+
+#include <spdlog/sinks/stdout_sinks.h>
86+
+#endif
8187
+#include <boost/algorithm/string.hpp>
8288
+#include <iostream>
89+
+#include <map>
8390
+
8491
+class DateLogger {
8592
+ public:

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ endif()
121121

122122
add_library(ddetect ${ddetect_SOURCES})
123123
add_dependencies(ddetect protobuf caffe_pb_h)
124+
if (BUILD_SPDLOG)
125+
add_dependencies(ddetect spdlog)
126+
endif()
124127
if (USE_DLIB)
125128
add_dependencies(ddetect dlib)
126129
endif()

src/backends/torch/llogging.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
#endif
1111

1212
#include <spdlog/spdlog.h>
13-
1413
#ifdef USE_DD_SYSLOG
15-
#if SPDLOG_VER_MAJOR > 0
16-
#include <spdlog/sinks/syslog_sinks.h>
17-
#endif
14+
#include <spdlog/sinks/syslog_sink.h>
15+
#else
16+
#include <spdlog/sinks/stdout_sinks.h>
1817
#endif
1918

2019
#include <boost/algorithm/string.hpp>

0 commit comments

Comments
 (0)