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

Function test_active

subprojects/llama.cpp/tests/test-barrier.cpp:82–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82static void test_active(int n_threads, int n_rounds) {
83 struct ggml_init_params params = {
84 /* .mem_size = */ 1024*1024*1024,
85 /* .mem_buffer = */ NULL,
86 /* .no_alloc = */ false,
87 };
88
89 struct ggml_context * ctx = ggml_init(params);
90
91 // Create graph
92 struct ggml_cgraph * gf = ggml_new_graph(ctx);
93
94 // Small graph with, parallel ops with barriers
95 struct ggml_tensor * out = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 64);
96 for (int i = 0; i < 2; i++) {
97 struct ggml_tensor * a = ggml_new_tensor_2d(ctx, GGML_TYPE_Q4_0, 64, 128);
98 out = ggml_mul_mat(ctx, a, out);
99
100 struct ggml_tensor * d = ggml_new_tensor_2d(ctx, GGML_TYPE_Q4_0, 128, 64);
101 out = ggml_mul_mat(ctx, d, out);
102 }
103
104 ggml_build_forward_expand(gf, out);
105 int n_nodes = ggml_graph_n_nodes(gf);
106
107 // Create threadpool
108 struct ggml_threadpool_params tpp = ggml_threadpool_params_default(n_threads);
109 struct ggml_threadpool* threadpool = ggml_threadpool_new(&tpp);
110 if (!threadpool) {
111 fprintf(stderr, "threadpool create failed : n_threads %d\n", n_threads);
112 exit(1);
113 }
114
115 std::cerr << "graph-compute with"
116 << "\n n_threads: " << n_threads
117 << "\n n_nodes: " << n_nodes
118 << "\n n_rounds: " << n_rounds
119 << "\n";
120 // ggml_graph_print(gf);
121
122 // In this test we keep changing the number of threads every 4th iteration
123 // to test for race conditions in that path
124
125 for (int i=0; i < n_rounds; i++) {
126 struct ggml_cplan cplan = ggml_graph_plan(gf, (i % 4) == 0 ? 1 : n_threads, threadpool);
127
128 std::vector<uint8_t> work_data(cplan.work_size);
129 cplan.work_data = work_data.data();
130
131 ggml_graph_compute(gf, &cplan);
132 }
133
134 ggml_threadpool_free(threadpool);
135 ggml_free(ctx);
136}
137
138static void test_multi_graph(int n_threads, int n_rounds) {
139 struct ggml_init_params params = {

Callers 1

mainFunction · 0.85

Calls 14

ggml_initFunction · 0.85
ggml_new_graphFunction · 0.85
ggml_new_tensor_1dFunction · 0.85
ggml_new_tensor_2dFunction · 0.85
ggml_mul_matFunction · 0.85
ggml_graph_n_nodesFunction · 0.85
ggml_threadpool_newFunction · 0.85
ggml_graph_planFunction · 0.85
ggml_graph_computeFunction · 0.85
ggml_threadpool_freeFunction · 0.85

Tested by

no test coverage detected