-
Notifications
You must be signed in to change notification settings - Fork 352
LLM CPP Benchmark common metrics. #334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
abhisekupadhyaya
wants to merge
2
commits into
RunanywhereAI:main
from
abhisekupadhyaya:Benchmark_Basics
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
sdk/runanywhere-commons/include/rac/core/rac_benchmark.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| /** | ||
| * @file rac_benchmark.h | ||
| * @brief RunAnywhere Commons - Benchmark Timing Support | ||
| * | ||
| * This header provides types and functions for benchmark timing instrumentation. | ||
| * The timing struct captures key timestamps during LLM inference for performance | ||
| * measurement and analysis. | ||
| * | ||
| * Design principles: | ||
| * - Zero overhead when not benchmarking: timing is opt-in via pointer parameter | ||
| * - Monotonic clock: uses steady_clock for accurate cross-platform timing | ||
| * - All timestamps are relative to a process-local epoch (not wall-clock) | ||
| */ | ||
|
|
||
| #ifndef RAC_BENCHMARK_H | ||
| #define RAC_BENCHMARK_H | ||
|
|
||
| #include "rac/core/rac_types.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| // ============================================================================= | ||
| // BENCHMARK TIMING STRUCT | ||
| // ============================================================================= | ||
|
|
||
| /** | ||
| * Benchmark timing structure for LLM inference. | ||
| * | ||
| * Captures timestamps at key points during inference: | ||
| * - t0: Request start (component API entry) | ||
| * - t2: Prefill start (backend, before llama_decode for prompt) | ||
| * - t3: Prefill end (backend, after llama_decode returns) | ||
| * - t4: First token (component, first token callback) | ||
| * - t5: Last token (backend, decode loop exits) | ||
| * - t6: Request end (component, before complete callback) | ||
| * | ||
| * All timestamps are in milliseconds from a process-local epoch. | ||
| * Use rac_monotonic_now_ms() to get comparable timestamps. | ||
| * | ||
| * Note: t1 is intentionally skipped to match the specification. | ||
| */ | ||
| typedef struct rac_benchmark_timing { | ||
| /** t0: Request start - recorded at component API entry */ | ||
| int64_t t0_request_start_ms; | ||
|
|
||
| /** t2: Prefill start - recorded before llama_decode for prompt batch */ | ||
| int64_t t2_prefill_start_ms; | ||
|
|
||
| /** t3: Prefill end - recorded after llama_decode returns for prompt */ | ||
| int64_t t3_prefill_end_ms; | ||
|
|
||
| /** t4: First token - recorded when first token callback is invoked */ | ||
| int64_t t4_first_token_ms; | ||
|
|
||
| /** t5: Last token - recorded when decode loop exits */ | ||
| int64_t t5_last_token_ms; | ||
|
|
||
| /** t6: Request end - recorded before complete callback */ | ||
| int64_t t6_request_end_ms; | ||
|
|
||
| /** Number of tokens in the prompt */ | ||
| int32_t prompt_tokens; | ||
|
|
||
| /** Number of tokens generated */ | ||
| int32_t output_tokens; | ||
|
|
||
| /** | ||
| * Status of the request: | ||
| * - 0: Success | ||
| * - Non-zero: Error code (from rac_result_t) | ||
| */ | ||
| int32_t status; | ||
|
|
||
| } rac_benchmark_timing_t; | ||
|
|
||
| // ============================================================================= | ||
| // BENCHMARK STATUS CODES | ||
| // ============================================================================= | ||
|
|
||
| /** Benchmark request completed successfully */ | ||
| #define RAC_BENCHMARK_STATUS_SUCCESS ((int32_t)0) | ||
|
|
||
| /** Benchmark request failed due to error */ | ||
| #define RAC_BENCHMARK_STATUS_ERROR ((int32_t)1) | ||
|
|
||
| /** Benchmark request timed out */ | ||
| #define RAC_BENCHMARK_STATUS_TIMEOUT ((int32_t)2) | ||
|
|
||
| /** Benchmark request was cancelled */ | ||
| #define RAC_BENCHMARK_STATUS_CANCELLED ((int32_t)3) | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // ============================================================================= | ||
| // MONOTONIC TIME API | ||
| // ============================================================================= | ||
|
|
||
| /** | ||
| * Gets the current monotonic time in milliseconds. | ||
| * | ||
| * Uses std::chrono::steady_clock for accurate, monotonic timing that is not | ||
| * affected by system clock changes. The returned value is relative to a | ||
| * process-local epoch (the first call to this function). | ||
| * | ||
| * This function is thread-safe and lock-free on all supported platforms. | ||
| * | ||
| * @return Current monotonic time in milliseconds from process-local epoch | ||
| */ | ||
| RAC_API int64_t rac_monotonic_now_ms(void); | ||
|
|
||
| // ============================================================================= | ||
| // UTILITY FUNCTIONS | ||
| // ============================================================================= | ||
|
|
||
| /** | ||
| * Initializes a benchmark timing struct to zero values. | ||
| * | ||
| * @param timing Pointer to timing struct to initialize | ||
| */ | ||
| RAC_API void rac_benchmark_timing_init(rac_benchmark_timing_t* timing); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif /* RAC_BENCHMARK_H */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.