Skip to content

Commit dabcc5b

Browse files
authored
ggml : limit n_threads to the max n_tasks (#5238)
1 parent f8e9140 commit dabcc5b

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ggml.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16985,12 +16985,16 @@ struct ggml_cplan ggml_graph_plan(const struct ggml_cgraph * cgraph, int n_threa
1698516985
struct ggml_cplan cplan;
1698616986
memset(&cplan, 0, sizeof(struct ggml_cplan));
1698716987

16988+
int max_tasks = 1;
16989+
1698816990
// thread scheduling for the different operations + work buffer size estimation
1698916991
for (int i = 0; i < cgraph->n_nodes; i++) {
1699016992
struct ggml_tensor * node = cgraph->nodes[i];
1699116993

1699216994
const int n_tasks = ggml_get_n_tasks(node, n_threads);
1699316995

16996+
max_tasks = MAX(max_tasks, n_tasks);
16997+
1699416998
size_t cur = 0;
1699516999

1699617000
switch (node->op) {
@@ -17157,7 +17161,7 @@ struct ggml_cplan ggml_graph_plan(const struct ggml_cgraph * cgraph, int n_threa
1715717161
work_size += CACHE_LINE_SIZE*(n_threads - 1);
1715817162
}
1715917163

17160-
cplan.n_threads = n_threads;
17164+
cplan.n_threads = MIN(max_tasks, n_threads);
1716117165
cplan.work_size = work_size;
1716217166
cplan.work_data = NULL;
1716317167

0 commit comments

Comments
 (0)