diff --git a/BUILD.bazel b/BUILD.bazel index c563c52d861e..78fde9876f26 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -762,6 +762,7 @@ cc_library( ":torch_headers", "@kineto", "@cpp-httplib", + "@nlohmann", ] + if_cuda([ "@cuda//:nvToolsExt", "@cutlass", diff --git a/WORKSPACE b/WORKSPACE index 4169e0dbce1d..1422a6aac031 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -174,6 +174,12 @@ new_local_repository( path = "third_party/cpp-httplib", ) +new_local_repository( + name = "nlohmann", + build_file = "//third_party:nlohmann.BUILD", + path = "third_party/nlohmann", +) + new_local_repository( name = "tensorpipe", build_file = "//third_party:tensorpipe.BUILD", diff --git a/c10/CMakeLists.txt b/c10/CMakeLists.txt index 82eb96903831..3d78e94aed6b 100644 --- a/c10/CMakeLists.txt +++ b/c10/CMakeLists.txt @@ -95,6 +95,7 @@ if(NOT BUILD_LIBTORCHLESS) target_link_libraries(c10 PUBLIC glog::glog) endif() target_link_libraries(c10 PRIVATE fmt::fmt-header-only) + target_link_libraries(c10 PRIVATE nlohmann) if(C10_USE_NUMA) message(STATUS "NUMA paths:") diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index de7fbb01b0ae..3b6119087aa2 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -1193,6 +1193,9 @@ endif() target_include_directories(torch_cpu PRIVATE ${TORCH_ROOT}/third_party/cpp-httplib) +target_include_directories(torch_cpu PRIVATE + ${TORCH_ROOT}/third_party/nlohmann/include) + install(DIRECTORY "${TORCH_SRC_DIR}/csrc" DESTINATION ${TORCH_INSTALL_INCLUDE_DIR}/torch FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp") @@ -1736,7 +1739,7 @@ if(BUILD_TEST) if(NOT MSVC) add_executable(${test_name}_${CPU_CAPABILITY} "${test_src}" ../aten/src/ATen/native/quantized/AffineQuantizerBase.cpp) # TODO: Get rid of c10 dependency (which is only needed for the implementation of AT_ERROR) - target_link_libraries(${test_name}_${CPU_CAPABILITY} c10 sleef gtest_main) + target_link_libraries(${test_name}_${CPU_CAPABILITY} c10 sleef gtest_main nlohmann) if(USE_FBGEMM) target_link_libraries(${test_name}_${CPU_CAPABILITY} fbgemm) endif() diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index d2b8ae43c700..e0e69447fbce 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -1160,6 +1160,7 @@ if(USE_DISTRIBUTED AND USE_TENSORPIPE) add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/tensorpipe) list(APPEND Caffe2_DEPENDENCY_LIBS tensorpipe) + list(APPEND Caffe2_DEPENDENCY_LIBS nlohmann) if(USE_CUDA) list(APPEND Caffe2_CUDA_DEPENDENCY_LIBS tensorpipe_cuda) elseif(USE_ROCM) @@ -1681,3 +1682,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/FlatBuffers.cmake) # Include cpp-httplib add_library(httplib INTERFACE IMPORTED) target_include_directories(httplib SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/cpp-httplib) + +# Include nlohmann-json +add_library(nlohmann INTERFACE IMPORTED) +include_directories(nlohmann SYSTEM INTERFACE ${PROJECT_SOURCE_DIR}/third_party/nlohmann/include) diff --git a/third_party/nlohmann.BUILD b/third_party/nlohmann.BUILD new file mode 100644 index 000000000000..58fd987bcbdb --- /dev/null +++ b/third_party/nlohmann.BUILD @@ -0,0 +1,20 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + +cc_library( + name = "nlohmann", + hdrs = glob(["include/**/*.hpp"]), + includes = [ + "/", + ], + visibility = ["//visibility:public"], +) + +cc_library( + name = "nlohmann_single_include", + hdrs = glob(["single_include/nlohmann/*.hpp"]), + includes = [ + "/", + ], + visibility = ["//visibility:public"], +) + diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index c949937d1794..182147463aa6 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -69,6 +69,7 @@ set(TORCH_PYTHON_INCLUDE_DIRECTORIES ${TORCH_ROOT}/third_party/flatbuffers/include ${TORCH_ROOT}/third_party/kineto/libkineto/include ${TORCH_ROOT}/third_party/cpp-httplib + ${TORCH_ROOT}/third_party/nlohmann/include ${TORCH_SRC_DIR}/csrc ${TORCH_SRC_DIR}/csrc/api/include @@ -82,6 +83,7 @@ set(TORCH_PYTHON_LINK_LIBRARIES pybind::pybind11 opentelemetry::api httplib + nlohmann shm fmt::fmt-header-only ATEN_CPU_FILES_GEN_LIB)