From 596b9e1e5e1e9d243782c3d6213ee8fa65c1719c Mon Sep 17 00:00:00 2001 From: Mark Dokter Date: Thu, 3 Oct 2024 10:25:07 +0200 Subject: [PATCH] [DAPHNE-#842] Split fmt and spdlog dependencies In order for nvcc (CUDA compiler) to not fail the DAPHNE build after switching to C++20, we introduce fmt as a separate dependency and upgrade the spdlog to the tip of the spdlog default branch as of 2024-10-03 for the time being (we'll switch back to a release once that compiles without troubles) because the released spdlog 1.14.1 did not compile with the newer fmt 11.0.2. Closes #842 --- CMakeLists.txt | 3 + build.sh | 55 +++++++++++++------ software-package-versions.txt | 7 ++- src/api/internal/daphne_internal.cpp | 18 +++--- src/parser/config/ConfigParser.cpp | 2 +- src/runtime/local/context/CUDAContext.h | 3 + .../local/datastructures/DenseMatrix.cpp | 1 + src/runtime/local/kernels/CMakeLists.txt | 2 +- src/runtime/local/kernels/CUDA/HostUtils.h | 8 +++ src/util/CMakeLists.txt | 2 +- src/util/DaphneLogger.cpp | 2 + src/util/DaphneLogger.h | 1 + src/util/Statistics.cpp | 18 +++++- src/util/Statistics.h | 16 ++++++ 14 files changed, 103 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69366ffea..b806d4c84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,9 @@ if(USE_PAPI) endif() ########## +find_package(fmt) +add_definitions(-DSPDLOG_FMT_EXTERNAL) + option(USE_CUDA "Whether to activate compilation of CUDA features" OFF) include(CheckLanguage) check_language(CUDA) diff --git a/build.sh b/build.sh index c2f54ac36..1e1747fbe 100755 --- a/build.sh +++ b/build.sh @@ -659,7 +659,7 @@ if [ $WITH_DEPS -gt 0 ]; then fi #------------------------------------------------------------------------------ - # #8.1 Antlr4 (parser) + # Antlr4 (parser) #------------------------------------------------------------------------------ antlrJarName="antlr-${antlrVersion}-complete.jar" antlrCppRuntimeDirName="antlr4-cpp-runtime-${antlrVersion}-source" @@ -711,7 +711,7 @@ if [ $WITH_DEPS -gt 0 ]; then fi #------------------------------------------------------------------------------ - # #8.2 catch2 (unit test framework) + # catch2 (unit test framework) #------------------------------------------------------------------------------ # Download catch2 release zip (if necessary), and unpack the single header file # (if necessary). @@ -736,7 +736,7 @@ if [ $WITH_DEPS -gt 0 ]; then fi #------------------------------------------------------------------------------ - # #8.3 OpenBLAS (basic linear algebra subprograms) + # OpenBLAS (basic linear algebra subprograms) #------------------------------------------------------------------------------ openBlasDirName="OpenBLAS-$openBlasVersion" openBlasZipName="${openBlasDirName}.zip" @@ -762,7 +762,7 @@ if [ $WITH_DEPS -gt 0 ]; then fi #------------------------------------------------------------------------------ - # #8.4 nlohmann/json (library for JSON parsing) + # nlohmann/json (library for JSON parsing) #------------------------------------------------------------------------------ nlohmannjsonDirName=nlohmannjson nlohmannjsonSingleHeaderName=json.hpp @@ -779,7 +779,7 @@ if [ $WITH_DEPS -gt 0 ]; then fi #------------------------------------------------------------------------------ - # #8.5 abseil (compiled separately to apply a patch) + # abseil (compiled separately to apply a patch) #------------------------------------------------------------------------------ abslPath=$sourcePrefix/abseil-cpp if [ $(arch) == 'armv64' ] || [ $(arch) == 'aarch64' ]; then @@ -807,7 +807,7 @@ if [ $WITH_DEPS -gt 0 ]; then fi #------------------------------------------------------------------------------ - # #8.6 MPI (Default is MPI library is OpenMPI but cut can be any) + # MPI (Default is MPI library is OpenMPI but cut can be any) #------------------------------------------------------------------------------ MPIZipName=openmpi-$openMPIVersion.tar.gz MPIInstDirName=$installPrefix @@ -831,7 +831,7 @@ if [ $WITH_DEPS -gt 0 ]; then daphne_msg "No need to build OpenMPI again" fi #------------------------------------------------------------------------------ - # #8.7 gRPC + # gRPC #------------------------------------------------------------------------------ grpcDirName="grpc" grpcInstDir=$installPrefix @@ -870,7 +870,7 @@ if [ $WITH_DEPS -gt 0 ]; then daphne_msg "No need to build GRPC again." fi #------------------------------------------------------------------------------ - # #8.8 Arrow / Parquet + # Arrow / Parquet #------------------------------------------------------------------------------ arrowDirName="apache-arrow-$arrowVersion" arrowArtifactFileName=$arrowDirName.tar.gz @@ -906,28 +906,48 @@ if [ $WITH_DEPS -gt 0 ]; then daphne_msg "No need to build Arrow again." fi #------------------------------------------------------------------------------ - # #8.9 spdlog + # fmt + #------------------------------------------------------------------------------ + fmtDirName="fmt-$fmtVersion" + fmtArtifactFileName=$fmtDirName.zip + if ! is_dependency_downloaded "fmt_v${fmtVersion}"; then + rm -rf "${sourcePrefix:?}/${fmtDirName}" + wget "https://github.com/fmtlib/fmt/releases/download/${fmtVersion}/$fmtArtifactFileName" -qO "$cacheDir/$fmtArtifactFileName" + unzip -q "$cacheDir/$fmtArtifactFileName" -d "$sourcePrefix" + dependency_download_success "fmt_v${fmtVersion}" + fi + if ! is_dependency_installed "fmt_v${fmtVersion}"; then + cmake -G Ninja -S "${sourcePrefix}/${fmtDirName}" -B "${buildPrefix}/${fmtDirName}" \ + -DCMAKE_INSTALL_PREFIX="${installPrefix}" -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DFMT_MASTER_PROJECT=OFF + cmake --build "${buildPrefix}/${fmtDirName}" --target install/strip + dependency_install_success "fmt_v${fmtVersion}" + else + daphne_msg "No need to build fmt again." + fi + #------------------------------------------------------------------------------ + # spdlog #------------------------------------------------------------------------------ spdlogDirName="spdlog-$spdlogVersion" spdlogArtifactFileName=$spdlogDirName.tar.gz if ! is_dependency_downloaded "spdlog_v${spdlogVersion}"; then rm -rf "${sourcePrefix:?}/${spdlogDirName}" - wget "https://github.com/gabime/spdlog/archive/refs/tags/v$spdlogVersion.tar.gz" -qO \ + # changed URL scheme due to temporarily use tip of main branch (2024-10-03) +# wget "https://github.com/gabime/spdlog/archive/refs/tags/v$spdlogVersion.tar.gz" -qO \ + wget https://github.com/gabime/spdlog/archive/$spdlogVersion.tar.gz -qO \ "$cacheDir/$spdlogArtifactFileName" tar xzf "$cacheDir/$spdlogArtifactFileName" --directory="$sourcePrefix" dependency_download_success "spdlog_v${spdlogVersion}" fi - if ! is_dependency_installed "spdlog_v${spdlogVersion}"; then cmake -G Ninja -S "${sourcePrefix}/${spdlogDirName}" -B "${buildPrefix}/${spdlogDirName}" \ - -DCMAKE_INSTALL_PREFIX="${installPrefix}" -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DSPDLOG_FMT_EXTERNAL=ON -DCMAKE_INSTALL_PREFIX="${installPrefix}" -DCMAKE_POSITION_INDEPENDENT_CODE=ON cmake --build "${buildPrefix}/${spdlogDirName}" --target install/strip dependency_install_success "spdlog_v${spdlogVersion}" else daphne_msg "No need to build spdlog again." fi #------------------------------------------------------------------------------ - # #8.10 Eigen + # Eigen #------------------------------------------------------------------------------ eigenDirName="eigen-${eigenVersion}" if ! is_dependency_downloaded "eigen_v${eigenVersion}"; then @@ -946,7 +966,7 @@ if [ $WITH_DEPS -gt 0 ]; then daphne_msg "No need to build eigen again." fi #------------------------------------------------------------------------------ - # #8.11 HAWQ (libhdfs3) + # HAWQ (libhdfs3) #------------------------------------------------------------------------------ hawqDirName="hawq-rel-v$hawqVersion" hawqTarName="v${hawqVersion}.tar.gz" @@ -976,7 +996,7 @@ if [ $WITH_DEPS -gt 0 ]; then fi #------------------------------------------------------------------------------ - # #8.12 Build MLIR + # Build MLIR #------------------------------------------------------------------------------ # We rarely need to build MLIR/LLVM, only during the first build of the # prototype and after upgrades of the LLVM sub-module. To avoid unnecessary @@ -1034,7 +1054,7 @@ if [ $WITH_DEPS -gt 0 ]; then daphne_msg "No need to build MLIR/LLVM again." fi #------------------------------------------------------------------------------ - # 8.14 Liburing + # Liburing #------------------------------------------------------------------------------ liburingDirName="liburing-$liburingVersion" liburingTarName="${liburingDirName}.tar.gz" @@ -1063,9 +1083,8 @@ if [ $WITH_DEPS -gt 0 ]; then daphne_msg "No need to build liburing again." fi fi - #------------------------------------------------------------------------------ - # 8.14 Fetch bitstreams + # Fetch bitstreams #------------------------------------------------------------------------------ if [[ $BUILD_FPGAOPENCL = *"ON"* ]]; then FPGAOPENCL_BISTREAM_DIR="$projectRoot/src/runtime/local/kernels/FPGAOPENCL/bitstreams" diff --git a/software-package-versions.txt b/software-package-versions.txt index d092c79e1..9a4244fff 100644 --- a/software-package-versions.txt +++ b/software-package-versions.txt @@ -28,7 +28,10 @@ nlohmannjsonVersion=3.10.5 openBlasVersion=0.3.23 openMPIVersion=4.1.5 papiVersion=7.0.1 -spdlogVersion=1.11.0 +# temporarily (2024-10-03) use tip of default branch for spdlog due to compilation issue of latest +# release 1.14.1 in combination with external fmt 11.0.2 +spdlogVersion=e593f6695c6065e6b345fe2862f04a519ed484e0 ubuntuVersion=24.04 hawqVersion=3.0.0.0 -liburingVersion=2.7 \ No newline at end of file +liburingVersion=2.7 +fmtVersion=11.0.2 diff --git a/src/api/internal/daphne_internal.cpp b/src/api/internal/daphne_internal.cpp index 12fbfd3d0..5b533601b 100644 --- a/src/api/internal/daphne_internal.cpp +++ b/src/api/internal/daphne_internal.cpp @@ -15,10 +15,11 @@ */ #include "runtime/local/datastructures/IAllocationDescriptor.h" -#include + #ifdef USE_MPI #include "runtime/distributed/worker/MPIWorker.h" #endif + #include "compiler/execution/DaphneIrExecutor.h" #include #include @@ -49,7 +50,6 @@ #include #include -#include #include #include @@ -97,8 +97,7 @@ void handleSignals(int signal) { } void logErrorDaphneLibAware(DaphneLibResult *daphneLibRes, std::string msg) { - if (daphneLibRes != nullptr) // For DaphneLib (Python API), error message is - // handled later in script.py. + if (daphneLibRes != nullptr) // For DaphneLib (Python API), error message is handled later in script.py. daphneLibRes->error_message = msg; else spdlog::error(msg); @@ -108,8 +107,7 @@ int startDAPHNE(int argc, const char **argv, DaphneLibResult *daphneLibRes, int using clock = std::chrono::high_resolution_clock; clock::time_point tpBeg = clock::now(); - // install signal handler to catch information from shared libraries (for - // exception handling) + // install signal handler to catch information from shared libraries (for exception handling) std::signal(SIGABRT, handleSignals); std::signal(SIGSEGV, handleSignals); @@ -383,8 +381,7 @@ int startDAPHNE(int argc, const char **argv, DaphneLibResult *daphneLibRes, int if (matmul_fixed_tile_sizes.size() > 0) { user_config.matmul_use_fixed_tile_sizes = true; user_config.matmul_fixed_tile_sizes = matmul_fixed_tile_sizes; - // Specifying a fixed tile size will be interpreted as wanting to use - // tiling. + // Specifying a fixed tile size will be interpreted as wanting to use tiling. user_config.matmul_tile = true; } user_config.use_mlir_hybrid_codegen = performHybridCodegen; @@ -399,9 +396,8 @@ int startDAPHNE(int argc, const char **argv, DaphneLibResult *daphneLibRes, int // only overwrite with non-defaults if (numberOfThreads != 0) { - spdlog::trace("Overwriting config file supplied numberOfThreads={} " - "with command line argument --num-threads={}", - user_config.numberOfThreads, numberOfThreads); + spdlog::trace("Overwriting config file supplied numberOfThreads={} with command line argument --num-threads={}", + user_config.numberOfThreads, static_cast(numberOfThreads)); user_config.numberOfThreads = numberOfThreads; } diff --git a/src/parser/config/ConfigParser.cpp b/src/parser/config/ConfigParser.cpp index bb5fa7a59..49eca2ce6 100644 --- a/src/parser/config/ConfigParser.cpp +++ b/src/parser/config/ConfigParser.cpp @@ -143,7 +143,7 @@ void ConfigParser::readUserConfig(const std::string &filename, DaphneUserConfig // not using spdlog::get() here as loggers are most likely // not configured yet spdlog::error(key2); - spdlog::error(val2); + spdlog::error(static_cast(key2)); } } } diff --git a/src/runtime/local/context/CUDAContext.h b/src/runtime/local/context/CUDAContext.h index 8ce43636d..15c03d9a2 100644 --- a/src/runtime/local/context/CUDAContext.h +++ b/src/runtime/local/context/CUDAContext.h @@ -19,6 +19,9 @@ #include "runtime/local/context/DaphneContext.h" #include "runtime/local/kernels/CUDA/HostUtils.h" +#include +#include + #include #include #include diff --git a/src/runtime/local/datastructures/DenseMatrix.cpp b/src/runtime/local/datastructures/DenseMatrix.cpp index ca267b1e1..73470a94d 100644 --- a/src/runtime/local/datastructures/DenseMatrix.cpp +++ b/src/runtime/local/datastructures/DenseMatrix.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include diff --git a/src/runtime/local/kernels/CMakeLists.txt b/src/runtime/local/kernels/CMakeLists.txt index 20c33129e..418596492 100644 --- a/src/runtime/local/kernels/CMakeLists.txt +++ b/src/runtime/local/kernels/CMakeLists.txt @@ -73,7 +73,7 @@ if(USE_CUDA AND CMAKE_CUDA_COMPILER) PATH_SUFFIXES nvidia/current lib64 lib/x64 lib) target_link_libraries(CUDAKernels PUBLIC DataStructures LLVMSupport MLIRDaphne MLIRDaphneTransforms CUDA::cudart CUDA::cublasLt CUDA::cublas - CUDA::cusparse ${CUDA_cudnn_LIBRARY} CUDA::cusolver Util MLIRDaphneInference) + CUDA::cusparse ${CUDA_cudnn_LIBRARY} CUDA::cusolver Util MLIRDaphneInference fmt::fmt) set_target_properties(CUDAKernels PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib) endif() diff --git a/src/runtime/local/kernels/CUDA/HostUtils.h b/src/runtime/local/kernels/CUDA/HostUtils.h index dd7244f1b..82429af70 100644 --- a/src/runtime/local/kernels/CUDA/HostUtils.h +++ b/src/runtime/local/kernels/CUDA/HostUtils.h @@ -23,9 +23,17 @@ #include #include +#include + #include #include +static auto format_as(cudaError_t e) { return fmt::underlying(e); } +static auto format_as(cublasStatus_t e) { return fmt::underlying(e); } +static auto format_as(cudnnStatus_t e) { return fmt::underlying(e); } +static auto format_as(cusparseStatus_t e) { return fmt::underlying(e); } +static auto format_as(cusolverStatus_t e) { return fmt::underlying(e); } + #define CHECK_CUDART(call) \ do { \ cudaError_t status = call; \ diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index d6bb21f58..de58a9e3a 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -32,7 +32,7 @@ add_library(Util StringRefCount.cpp ) -target_link_libraries(Util PRIVATE spdlog::spdlog) +target_link_libraries(Util PRIVATE spdlog::spdlog fmt::fmt) # Make sure that certain .inc files have been generated by TableGen. add_dependencies(Util diff --git a/src/util/DaphneLogger.cpp b/src/util/DaphneLogger.cpp index 75f20575b..78caa990a 100644 --- a/src/util/DaphneLogger.cpp +++ b/src/util/DaphneLogger.cpp @@ -16,6 +16,8 @@ #include "DaphneLogger.h" +#include + #include "spdlog/async.h" #include "spdlog/sinks/basic_file_sink.h" #include "spdlog/sinks/stdout_color_sinks.h" diff --git a/src/util/DaphneLogger.h b/src/util/DaphneLogger.h index be96d72aa..4d9690ace 100644 --- a/src/util/DaphneLogger.h +++ b/src/util/DaphneLogger.h @@ -16,6 +16,7 @@ #pragma once +#include #include #include diff --git a/src/util/Statistics.cpp b/src/util/Statistics.cpp index 754cf3073..2c6bf7863 100644 --- a/src/util/Statistics.cpp +++ b/src/util/Statistics.cpp @@ -1,8 +1,24 @@ +/* + * Copyright 2024 The DAPHNE Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Statistics.h" +#include #include -#include #include Statistics &Statistics::instance() { diff --git a/src/util/Statistics.h b/src/util/Statistics.h index 312b26965..bd440dac7 100644 --- a/src/util/Statistics.h +++ b/src/util/Statistics.h @@ -1,3 +1,19 @@ +/* + * Copyright 2024 The DAPHNE Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #pragma once #include