|
12 | 12 | #include "weight-pager/wp-pool.h" |
13 | 13 |
|
14 | 14 | #include "ggml-backend.h" |
| 15 | +#include "ggml.h" |
15 | 16 |
|
16 | 17 | #include <cerrno> |
17 | 18 | #include <cstdint> |
@@ -1511,6 +1512,28 @@ static int test_is_uma_device_smoke() { |
1511 | 1512 | return fails; |
1512 | 1513 | } |
1513 | 1514 |
|
| 1515 | +static int test_routing_boundary_prepass() { |
| 1516 | + int fails = 0; |
| 1517 | + struct ggml_init_params ip = { /*.mem_size=*/ 16*1024*1024, /*.mem_buffer=*/ nullptr, /*.no_alloc=*/ true }; |
| 1518 | + struct ggml_context * ctx = ggml_init(ip); |
| 1519 | + struct ggml_tensor * ids_producer = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, 8); |
| 1520 | + ggml_set_name(ids_producer, "ids_producer"); |
| 1521 | + struct ggml_tensor * ids_view = ggml_view_1d(ctx, ids_producer, 8, 0); |
| 1522 | + struct ggml_tensor * as = ggml_new_tensor_3d(ctx, GGML_TYPE_F32, 4, 4, 2); |
| 1523 | + struct ggml_tensor * b = ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 4, 8); |
| 1524 | + struct ggml_tensor * mmid = ggml_mul_mat_id(ctx, as, b, ids_view); |
| 1525 | + ggml_set_name(mmid, "mmid"); |
| 1526 | + struct ggml_cgraph * gf = ggml_new_graph(ctx); |
| 1527 | + ggml_build_forward_expand(gf, mmid); |
| 1528 | + wp::WeightPager pager; |
| 1529 | + pager.mark_routing_boundaries(gf); |
| 1530 | + if (!pager.is_routing_break(mmid)) { fprintf(stderr, "FAIL: mmid not marked\n"); fails++; } |
| 1531 | + if (!pager.is_routing_break(ids_producer)) { fprintf(stderr, "FAIL: ids producer (view root) not marked\n"); fails++; } |
| 1532 | + if (pager.is_routing_break(b)) { fprintf(stderr, "FAIL: unrelated tensor marked\n"); fails++; } |
| 1533 | + ggml_free(ctx); |
| 1534 | + return fails; |
| 1535 | +} |
| 1536 | + |
1514 | 1537 | // --------------------------------------------------------------------------- |
1515 | 1538 | // main |
1516 | 1539 | // --------------------------------------------------------------------------- |
@@ -1556,6 +1579,7 @@ int main() { |
1556 | 1579 | { "pool_hot_threshold_protects", test_pool_hot_threshold_protects_in_eviction }, |
1557 | 1580 | { "pool_hot_fallback_when_all_hot", test_pool_hot_fallback_when_all_hot }, |
1558 | 1581 | { "pool_default_threshold_zero_lru", test_pool_default_threshold_zero_is_pure_lru }, |
| 1582 | + { "routing_boundary_prepass", test_routing_boundary_prepass }, |
1559 | 1583 | }; |
1560 | 1584 |
|
1561 | 1585 | for (const auto & t : tests) { |
|
0 commit comments