MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / test_view_inplace

Function test_view_inplace

subprojects/llama.cpp/tests/test-alloc.cpp:371–389  ·  view source on GitHub ↗

Check that views don't require any extra memory

Source from the content-addressed store, hash-verified

369
370// Check that views don't require any extra memory
371static void test_view_inplace() {
372 dummy_backend backend = dummy_backend_init(32);
373 auto [ctx, graph, ctx_ptr] = make_context();
374
375 ggml_tensor * x[6];
376 x[0] = make_input_1d(ctx, 4); // chunk 0, [0, 16)
377 x[1] = ggml_reshape_2d(ctx, x[0], 2, 2); // view of x0
378 x[2] = ggml_permute(ctx, x[1], 1, 0, 2, 3); // view of x0
379 x[3] = ggml_view_1d(ctx, x[2], 2, 4); // view of x0
380 x[4] = make_input_1d(ctx, 2); // chunk 0, [16, 24)
381 x[5] = ggml_add(ctx, x[3], x[4]); // reuse (inplace add)
382 assign_names(ctx);
383
384 ggml_gallocr_ptr galloc = allocate_graph(graph, x[5], &backend.buffer_type);
385 check_all_allocated(graph);
386 check_no_overlap(graph);
387 check_max_size(ctx);
388 GGML_ASSERT(backend.context->allocated_total() <= 24);
389}
390
391static void test_reuse_and_free() {
392 dummy_backend backend = dummy_backend_init(40);

Callers

nothing calls this directly

Calls 13

dummy_backend_initFunction · 0.85
make_contextFunction · 0.85
make_input_1dFunction · 0.85
ggml_reshape_2dFunction · 0.85
ggml_permuteFunction · 0.85
ggml_view_1dFunction · 0.85
ggml_addFunction · 0.85
assign_namesFunction · 0.85
allocate_graphFunction · 0.85
check_all_allocatedFunction · 0.85
check_no_overlapFunction · 0.85
check_max_sizeFunction · 0.85

Tested by

no test coverage detected