From 743c720b4feaa2f61c19575230937ee208ea5f2b Mon Sep 17 00:00:00 2001 From: Callum Mitchell Date: Tue, 27 Oct 2026 21:37:29 -0600 Subject: [PATCH] server: reset roofline profiler after warmup Add ggml_cuda_roofline_reset() call at the end of load_model(), after all initialization completes (model load, MTP/speculative setup, mmproj load) but before any user requests. This excludes warmup/initialization overhead from TTFT measurements. Following the pattern from PR #42 (llama-mtmd-cli) and llama-bench: - Add roofline header include with #ifdef GGML_HIP_ROOFLINE guard - Call ggml_cuda_roofline_reset() after params propagation - Update CMakeLists.txt with compile definitions and include dirs Co-Authored-By: Claude --- tools/server/CMakeLists.txt | 7 +++++++ tools/server/server-context.cpp | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/tools/server/CMakeLists.txt b/tools/server/CMakeLists.txt index 70b8d7da8eab..7218d76847c5 100644 --- a/tools/server/CMakeLists.txt +++ b/tools/server/CMakeLists.txt @@ -35,6 +35,13 @@ target_include_directories(${TARGET} PRIVATE ../mtmd) target_include_directories(${TARGET} PRIVATE ${PROJECT_SOURCE_DIR}) target_link_libraries(${TARGET} PUBLIC llama-common mtmd ${CMAKE_THREAD_LIBS_INIT}) +# Compile in the post-warmup roofline reset only when the HIP profiler is built +# (ggml-cuda-roofline.cpp, linked via ggml-hip). No-op in every other build. +if (GGML_HIP_ROOFLINE) + target_compile_definitions(${TARGET} PRIVATE GGML_HIP_ROOFLINE) + target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../ggml/src/ggml-cuda) +endif() + # llama-server-impl: server logic, reusable by app set(TARGET llama-server-impl) diff --git a/tools/server/server-context.cpp b/tools/server/server-context.cpp index 60c563345399..5833eebaf151 100644 --- a/tools/server/server-context.cpp +++ b/tools/server/server-context.cpp @@ -18,6 +18,13 @@ #include "mtmd.h" #include "mtmd-helper.h" +// Optional per-op roofline profiler (HIP build with GGML_HIP_ROOFLINE). Used to +// discard warmup so the report covers only measured inference. Compiled out +// otherwise. See ggml/src/ggml-cuda/ggml-cuda-roofline.cpp. +#ifdef GGML_HIP_ROOFLINE +#include "ggml-cuda-roofline.h" +#endif + #include #include #include @@ -1527,6 +1534,12 @@ struct server_context_impl { // propagate new defaults back to caller params = params_base; + // Discard warmup from the per-op roofline profiler so the report covers + // only measured inference. Compiled out unless GGML_HIP_ROOFLINE. +#ifdef GGML_HIP_ROOFLINE + ggml_cuda_roofline_reset(); +#endif + if (!is_resume) { return init(); }