Fix llama-bench -p -n where p<=256

This commit is contained in:
Yu, Zijun 2026-01-22 12:20:50 +08:00
parent 9a15c8b0cf
commit 8fb20b28b7
2 changed files with 8 additions and 13 deletions

View File

@ -768,14 +768,12 @@ graph_key compute_graph_key(ggml_cgraph * cgraph) {
graph_key key; graph_key key;
key.n_nodes = cgraph->n_nodes; key.n_nodes = cgraph->n_nodes;
if (cgraph->n_nodes > 0) { for (int i = 0; i < cgraph->n_nodes; ++i) {
key.first_node_name = std::string(cgraph->nodes[0]->name); const auto * node = cgraph->nodes[i];
key.last_node_name = std::string(cgraph->nodes[cgraph->n_nodes - 1]->name); if (node->op == GGML_OP_SET_ROWS && strncmp(node->src[2]->name, "cache_k_l0", 10) == 0) {
} else { key.cache_k_l0 = node->src[2];
key.first_node_name = ""; }
key.last_node_name = "";
} }
return key; return key;
} }

View File

@ -8,20 +8,17 @@
struct graph_key { struct graph_key {
size_t n_nodes; size_t n_nodes;
std::string first_node_name; void * cache_k_l0;
std::string last_node_name;
bool operator==(const graph_key & other) const { bool operator==(const graph_key & other) const {
return n_nodes == other.n_nodes && first_node_name == other.first_node_name && return n_nodes == other.n_nodes && cache_k_l0 == other.cache_k_l0;
last_node_name == other.last_node_name;
} }
}; };
struct graph_key_hash { struct graph_key_hash {
size_t operator()(const graph_key & key) const { size_t operator()(const graph_key & key) const {
size_t h = std::hash<size_t>{}(key.n_nodes); size_t h = std::hash<size_t>{}(key.n_nodes);
h ^= std::hash<std::string>{}(key.first_node_name) + 0x9e3779b9 + (h << 6) + (h >> 2); h ^= std::hash<void *>{}(key.cache_k_l0) + 0x9e3779b9 + (h << 6) + (h >> 2);
h ^= std::hash<std::string>{}(key.last_node_name) + 0x9e3779b9 + (h << 6) + (h >> 2);
return h; return h;
} }
}; };