Skip to content

Commit 73bf1c7

Browse files
authored
Add modern logging utils (#4486)
* add a modern logger * replace the old logger * lint * Refactor logging statements to remove prefixes * update * Refactor logging * check using logger * fix * fix lint * fix msvc build * fix MSVC build * fix MSVC build
1 parent f7f7546 commit 73bf1c7

61 files changed

Lines changed: 1272 additions & 420 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ if (MSVC)
2121
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:preprocessor>)
2222
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
2323
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=/Zc:preprocessor -Xcompiler=/Zc:__cplusplus")
24+
# nvcc's front-end has a known bug (fixed in NVCC 13.1) where the fmt 11.x
25+
# literal-encoding probe (fmt/base.h:is_utf8_enabled) always returns false,
26+
# causing a static_assert failure. Disable fmt's Unicode check project-wide;
27+
# without /utf-8 the MSVC host compiler also sees use_utf8=false, so all TUs
28+
# agree and there is no ODR inconsistency.
29+
add_compile_definitions(FMT_UNICODE=0)
2430
endif ()
2531

2632
find_package(CUDAToolkit REQUIRED)
@@ -39,6 +45,19 @@ option(BUILD_FAST_MATH "Build in fast math mode" ON)
3945

4046
include(FetchContent)
4147

48+
FetchContent_Declare(
49+
fmt
50+
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
51+
GIT_TAG 11.1.4
52+
GIT_SHALLOW ON
53+
GIT_PROGRESS TRUE
54+
USES_TERMINAL_DOWNLOAD TRUE
55+
EXCLUDE_FROM_ALL
56+
)
57+
FetchContent_MakeAvailable(fmt)
58+
set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON)
59+
include_directories(${fmt_SOURCE_DIR}/include)
60+
4261
if (BUILD_TEST)
4362
FetchContent_Declare(
4463
Catch2
@@ -269,6 +288,11 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
269288
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda")
270289
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
271290
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --std=c++${CXX_STD}")
291+
# Suppress nvcc warning 128 (loop not reachable) in fmt headers - nvcc false positive
292+
# Suppress nvcc warning 27 (character value out of range) from fmt/format.h's
293+
# fractional_part_rounding_thresholds which uses U32 string literals with values
294+
# exceeding 0x10FFFF - harmless, pending fix in fmtlib (PR #4719)
295+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --diag-suppress=128 --diag-suppress=27")
272296

273297
string(REPLACE "-O2" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
274298
string(REPLACE "-O2" "" CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE}")

src/turbomind/comm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ cmake_minimum_required(VERSION 3.11)
55
find_package(Threads)
66

77
add_library(host_comm STATIC host_comm.cc thread_comm.cc)
8-
target_link_libraries(host_comm PRIVATE core logger Threads::Threads)
8+
target_link_libraries(host_comm PRIVATE core Threads::Threads)
99
set_property(TARGET host_comm PROPERTY POSITION_INDEPENDENT_CODE ON)
1010

1111
add_library(device_comm STATIC device_comm.cc)
12-
target_link_libraries(device_comm PRIVATE core logger)
12+
target_link_libraries(device_comm PRIVATE core)
1313
set_property(TARGET device_comm PROPERTY POSITION_INDEPENDENT_CODE ON)
1414
set_property(TARGET device_comm PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON)
1515

src/turbomind/comm/cuda_ipc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ target_link_libraries(cuda_ipc_comm PRIVATE
1616
core
1717
cuda_utils
1818
CUDA::cuda_driver
19-
logger)
19+
)
2020

2121
set_property(TARGET cuda_ipc_comm PROPERTY POSITION_INDEPENDENT_CODE ON)
2222
set_property(TARGET cuda_ipc_comm PROPERTY CUDA_RESOLVE_DEVICE_SYMBOLS ON)

src/turbomind/comm/cuda_ipc/cuda_ipc_comm.cu

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
#include "src/turbomind/comm/cuda_ipc/semaphore.h"
1919

20+
#include "src/turbomind/core/logger.h"
2021
#include "src/turbomind/utils/cuda_utils.h"
21-
#include "src/turbomind/utils/logger.h"
2222

2323
namespace turbomind::comm {
2424

@@ -156,7 +156,7 @@ CudaIpcCommImpl::~CudaIpcCommImpl()
156156
}
157157

158158
for (const auto& a : allocation_) {
159-
TM_LOG_WARNING("[COMM][%d] Allocation (%p, %lu) is not freed", global_rank_, a.uc_beg, a.size);
159+
TM_LOG_WARN("Rank {}: Allocation ({}, {}) is not freed", global_rank_, a.uc_beg, a.size);
160160
}
161161

162162
cudaStreamSynchronize(0);
@@ -220,7 +220,7 @@ void CudaIpcCommImpl::Free(void* ptr)
220220
allocation_.erase(it);
221221
}
222222
else {
223-
TM_LOG_WARNING("[TM][COMM][%d] Freeing %p which is not allocated by this module", global_rank_, ptr);
223+
TM_LOG_WARN("Rank {}: Freeing {} which is not allocated by this module", global_rank_, ptr);
224224
}
225225
}
226226

@@ -230,7 +230,7 @@ void CudaIpcCommImpl::Register(void* ptr, size_t size)
230230
auto& symm = groups_.at(0).symmetric;
231231

232232
if (symm.find(ptr) != symm.end()) {
233-
TM_LOG_WARNING("[TM][COMM][%d] Duplicated registration on (%p, %lu)", global_rank_, ptr, size);
233+
TM_LOG_WARN("Rank {}: Duplicated registration on ({}, {})", global_rank_, ptr, size);
234234
return;
235235
}
236236

@@ -317,7 +317,7 @@ void CudaIpcCommImpl::Deregister(void* ptr)
317317
Deregister(s.extract(it).value());
318318
}
319319
else {
320-
TM_LOG_WARNING("[TM][COMM][%d] Deregistering non-registered address %p", global_rank_, ptr);
320+
TM_LOG_WARN("Rank {}: Deregistering non-registered address {}", global_rank_, ptr);
321321
}
322322
}
323323
}

src/turbomind/comm/env.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <string>
88
#include <type_traits>
99

10-
#include "src/turbomind/utils/logger.h"
10+
#include "src/turbomind/core/logger.h"
1111

1212
namespace turbomind {
1313

@@ -40,7 +40,7 @@ auto GetEnv()
4040
if (is_set) {
4141
std::stringstream ss;
4242
ss << x;
43-
TM_LOG_INFO("[%s] %s=%s", E::prefix, E::name, ss.str().c_str());
43+
TM_LOG_INFO("{} {}={}", E::prefix, E::name, ss.str());
4444
}
4545
return x;
4646
}();

src/turbomind/comm/gloo/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ add_library(gloo_comm STATIC
3333
tcp_store.cc
3434
)
3535
set_property(TARGET gloo_comm PROPERTY POSITION_INDEPENDENT_CODE ON)
36-
target_link_libraries(gloo_comm PUBLIC gloo host_comm logger xgrammar)
36+
target_link_libraries(gloo_comm PUBLIC gloo host_comm xgrammar)
3737

3838
add_executable(test_ipc_comm test_ipc_comm.cc)
3939
target_link_libraries(test_ipc_comm PRIVATE gloo_comm Threads::Threads)

src/turbomind/comm/gloo/gloo_comm.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include "src/turbomind/comm/gloo/tcp_store.h"
2525
#include "src/turbomind/comm/host_comm.h"
26-
#include "src/turbomind/utils/logger.h"
26+
#include "src/turbomind/core/logger.h"
2727

2828
namespace turbomind::comm {
2929

@@ -346,7 +346,7 @@ class GlooGroupId: public HostGroupId {
346346
void Initialize() override
347347
{
348348
info_ = GlobalStoreFactory::Instance().New();
349-
TM_LOG_INFO("[TM][COMM] GlooGroupId=%s", info_.c_str());
349+
TM_LOG_INFO("GlooGroupId={}", info_);
350350
}
351351

352352
void Export(std::ostream& os) override

src/turbomind/comm/gloo/tcp_store.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <gloo/transport/tcp/socket.h>
1010

1111
#include "src/turbomind/comm/gloo/tcp_store.h"
12-
#include "src/turbomind/utils/logger.h"
12+
#include "src/turbomind/core/logger.h"
1313

1414
namespace turbomind::comm {
1515

@@ -148,7 +148,7 @@ TCPStore::TCPStore(const std::string& host, int port)
148148
}
149149
}
150150
catch (const std::exception& e) {
151-
TM_LOG_WARNING("[TM][COMM] Failed to connect to store after %d retries: %s", retry, e.what());
151+
TM_LOG_WARN("Failed to connect to store after {} retries: {}", retry, e.what());
152152
std::this_thread::sleep_for(std::chrono::seconds(1));
153153
retry += 1;
154154
}
@@ -209,7 +209,7 @@ void TCPStore::wait(const std::vector<std::string>& keys, const std::chrono::mil
209209
ss << key << " ";
210210
}
211211
ss << "]";
212-
TM_LOG_ERROR("[TM][COMM] %s, elapsed %lld s", ss.str().c_str(), elapsed.count());
212+
TM_LOG_ERROR("{}, elapsed {} s", ss.str(), elapsed.count());
213213
throw std::runtime_error("Wait timeout for key(s): " + ss.str());
214214
}
215215
std::this_thread::sleep_for(std::chrono::milliseconds(1000));

src/turbomind/comm/host_comm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include <vector>
1212

1313
#include "src/turbomind/core/data_type.h"
14+
#include "src/turbomind/core/logger.h"
1415
#include "src/turbomind/core/serdes.h"
15-
#include "src/turbomind/utils/logger.h"
1616

1717
namespace turbomind::comm {
1818

src/turbomind/comm/nccl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
cmake_minimum_required(VERSION 3.11)
44

55
add_library(nccl_comm STATIC nccl.cu)
6-
target_link_libraries(nccl_comm PRIVATE rms_norm core ${NCCL_LIBRARIES} logger)
6+
target_link_libraries(nccl_comm PRIVATE rms_norm core ${NCCL_LIBRARIES})
77
target_include_directories(nccl_comm PRIVATE ${NCCL_INCLUDE_DIRS})
88

99
set_property(TARGET nccl_comm PROPERTY POSITION_INDEPENDENT_CODE ON)

0 commit comments

Comments
 (0)