File: profiler-hooks.patch

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (58 lines) | stat: -rw-r--r-- 2,455 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
diff --git a/ggml/include/ggml.h b/ggml/include/ggml.h
index da8813fd2789..86c30dcaaae2 100644
--- a/ggml/include/ggml.h
+++ b/ggml/include/ggml.h
@@ -2452,6 +2452,8 @@ extern "C" {
         uint32_t            poll;                        // polling level (0 - no polling, 100 - aggressive polling)
         bool                strict_cpu;                  // strict cpu placement
         bool                paused;                      // start in paused state
+        void              (*thread_create_callback)(void);  // callback invoked when thread is created
+        void              (*thread_destroy_callback)(void); // callback invoked when thread is destroyed
     };
 
     struct ggml_threadpool;     // forward declaration, see ggml.c
diff --git a/ggml/src/ggml-cpu/ggml-cpu-c.c b/ggml/src/ggml-cpu/ggml-cpu-c.c
index f6bea3df34a0..fbefc0f45ec1 100644
--- a/ggml/src/ggml-cpu/ggml-cpu-c.c
+++ b/ggml/src/ggml-cpu/ggml-cpu-c.c
@@ -463,6 +463,9 @@ struct ggml_threadpool {
     int32_t      prio;        // Scheduling priority
     uint32_t     poll;        // Polling level (0 - no polling)
 
+    void       (*thread_create_callback)(void);
+    void       (*thread_destroy_callback)(void);
+
     enum ggml_status ec;
 };
 
@@ -2959,6 +2962,10 @@ static thread_ret_t ggml_graph_compute_secondary_thread(void* data) {
     struct ggml_compute_state * state = (struct ggml_compute_state *) data;
     struct ggml_threadpool * threadpool = state->threadpool;
 
+    if (threadpool->thread_create_callback) {
+        threadpool->thread_create_callback();
+    }
+
     ggml_thread_apply_priority(threadpool->prio);
     if (ggml_thread_cpumask_is_valid(state->cpumask)) {
         ggml_thread_apply_affinity(state->cpumask);
@@ -2990,6 +2997,10 @@ static thread_ret_t ggml_graph_compute_secondary_thread(void* data) {
         }
     }
 
+    if (threadpool->thread_destroy_callback) {
+        threadpool->thread_destroy_callback();
+    }
+
     return (thread_ret_t) 0;
 }
 
@@ -3049,6 +3060,8 @@ static struct ggml_threadpool * ggml_threadpool_new_impl(
         threadpool->n_threads_cur    = tpp->n_threads;
         threadpool->poll             = tpp->poll;
         threadpool->prio             = tpp->prio;
+        threadpool->thread_create_callback  = tpp->thread_create_callback;
+        threadpool->thread_destroy_callback = tpp->thread_destroy_callback;
         threadpool->ec               = GGML_STATUS_SUCCESS;
     }