char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
f280b2698
char/aliceai-t5-moe
1#pragma once 2 3#include "ggml-backend.h" 4#include "ggml-cpp.h" 5#include "ggml.h" 6 7#include <cstdint> 8#include <functional> 9#include <vector> 10 11// A prebuilt graph replicated to amortize dispatch and synchronization overhead. 12struct perf_cell { 13ggml_context_ptr ctx ; 14ggml_backend_buffer_ptr buf ; 15ggml_cgraph * gf = nullptr; 16int n_runs = 0 ; 17}; 18 19using build_graph_fn = std ::function < ggml_tensor * (ggml_context * )> ; 20using init_tensors_fn = std ::function < void (ggml_context * ) > ; 21using op_flops_fn = std::function < uint64_t (ggml_tensor * ) > ; 22 23perf_cell build_perf_cell ( ggml_backend_t backend, 24const build_graph_fn & build, 25const init_tensors_fn & init, 26const op_flops_fn & flops); 27 28double time_cell_median ( ggml_backend_t backend, const perf_cell & cell, int reps); 29 30struct cooldown_opts { 31bool enabled = true; 32double drift = 0.10 ; // anchor drift that triggers a cooldown 33double eps = 0.03 ; // anchor tolerance to call the GPU cool again 34int max_wait = 120 ; // seconds of cooling per cell before giving up 35int max_retry = 2 ; // re-measure rounds per cell before giving up 36}; 37 38using set_candidate_fn = std::function < void (int) > ; 39using clear_candidate_fn = std::function < void () > ; 40 41struct cell_result { 42std :: vector < double > t ; 43bool trusted = true; 44double anchor_min = 0.0 ; 45double anchor_max = 0.0 ; 46}; 47 48// Times candidates in order while using baseline_cand as a thermal-drift anchor. 49cell_result measure_cell ( ggml_backend_t backend, 50const perf_cell & cell, 51int reps, 52const std ::vector < int > & order, 53const set_candidate_fn & set_cand, 54const clear_candidate_fn & clear_cand, 55int baseline_cand, 56const cooldown_opts & cool, 57const char * cell_label );