StarPU Handbook
sc_hypervisor.h
Go to the documentation of this file.
1 /* StarPU --- Runtime system for heterogeneous multicore architectures.
2  *
3  * Copyright (C) 2011-2014 Inria
4  * Copyright (C) 2012-2013,2015,2017 CNRS
5  *
6  * StarPU is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or (at
9  * your option) any later version.
10  *
11  * StarPU is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  *
15  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
16  */
17 
18 #ifndef SC_HYPERVISOR_H
19 #define SC_HYPERVISOR_H
20 
21 #include <starpu.h>
23 #include <sc_hypervisor_config.h>
25 #include <math.h>
26 
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31 
32 /* synchronise the hypervisor when several workers try to update its information */
33 starpu_pthread_mutex_t act_hypervisor_mutex;
34 
35 /* platform of resizing contexts */
37 {
38  /* name of the strategy */
39  const char* name;
40 
41  /* indicate if it is a policiy create by the user or not */
42  unsigned custom;
43 
44  /* Distribute workers to contexts even at the begining of the program */
45  void (*size_ctxs)(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
46 
47  /* Require explicit resizing */
48  void (*resize_ctxs)(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
49 
50  /* the hypervisor takes a decision when the worker was idle for another cyle in this ctx */
51  void (*handle_idle_cycle)(unsigned sched_ctx, int worker);
52 
53  /* the hypervisor takes a decision when another task was pushed on this worker in this ctx */
54  void (*handle_pushed_task)(unsigned sched_ctx, int worker);
55 
56  /* the hypervisor takes a decision when another task was poped from this worker in this ctx */
57  void (*handle_poped_task)(unsigned sched_ctx, int worker,struct starpu_task *task, uint32_t footprint);
58 
59  /* the hypervisor takes a decision when the worker stoped being idle in this ctx */
60  void (*handle_idle_end)(unsigned sched_ctx, int worker);
61 
62  /* the hypervisor takes a decision when a certain task finished executing in this ctx */
63  void (*handle_post_exec_hook)(unsigned sched_ctx, int task_tag);
64 
65  /* the hypervisor takes a decision when a job was submitted in this ctx */
66  void (*handle_submitted_job)(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
67 
68  /* the hypervisor takes a decision when a certain ctx was deleted */
69  void (*end_ctx)(unsigned sched_ctx);
70 };
71 
72 /* start the hypervisor indicating the resizing policy to user */
73 void* sc_hypervisor_init(struct sc_hypervisor_policy *policy);
74 
75 /* shutdown the hypervisor */
76 void sc_hypervisor_shutdown(void);
77 
78 /* only registered contexts are resized by the hypervisor */
79 void sc_hypervisor_register_ctx(unsigned sched_ctx, double total_flops);
80 
81 /* remove a worker from the hypervisor's list */
82 void sc_hypervisor_unregister_ctx(unsigned sched_ctx);
83 
84 /* submit a requirement of resizing when a task taged with task_tag is executed */
85 void sc_hypervisor_post_resize_request(unsigned sched_ctx, int task_tag);
86 
87 /* reevaluate the distribution of the resources and eventually resize if needed */
88 void sc_hypervisor_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs , int *workers, int nworkers);
89 
90 /* don't allow the hypervisor to resize a context */
91 void sc_hypervisor_stop_resize(unsigned sched_ctx);
92 
93 /* allow the hypervisor to resize a context */
94 void sc_hypervisor_start_resize(unsigned sched_ctx);
95 
96 /* check out the current policy of the hypervisor */
97 const char *sc_hypervisor_get_policy();
98 
99 /* ask the hypervisor to add workers to a sched_ctx */
100 void sc_hypervisor_add_workers_to_sched_ctx(int* workers_to_add, unsigned nworkers_to_add, unsigned sched_ctx);
101 
102 /* ask the hypervisor to remove workers from a sched_ctx */
103 void sc_hypervisor_remove_workers_from_sched_ctx(int* workers_to_remove, unsigned nworkers_to_remove, unsigned sched_ctx, unsigned now);
104 
105 /* ask the hypervisor to move workers from one context to another */
106 void sc_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now);
107 
108 /* ask the hypervisor to chose a distribution of workers in the required contexts */
109 void sc_hypervisor_size_ctxs(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
110 
111 /* check if there are pending demands of resizing */
112 unsigned sc_hypervisor_get_size_req(unsigned **sched_ctxs, int* nsched_ctxs, int **workers, int *nworkers);
113 
114 /* save a demand of resizing */
115 void sc_hypervisor_save_size_req(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers);
116 
117 /* clear the list of pending demands of resizing */
118 void sc_hypervisor_free_size_req(void);
119 
120 /* check out if a context can be resized */
121 unsigned sc_hypervisor_can_resize(unsigned sched_ctx);
122 
123 /* indicate the types of tasks a context will execute in order to better decide the sizing of ctxs */
124 void sc_hypervisor_set_type_of_task(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size);
125 
126 /* change dynamically the total number of flops of a context, move the deadline of the finishing time of the context */
127 void sc_hypervisor_update_diff_total_flops(unsigned sched_ctx, double diff_total_flops);
128 
129 /* change dynamically the number of the elapsed flops in a context, modify the past in order to better compute the speed */
130 void sc_hypervisor_update_diff_elapsed_flops(unsigned sched_ctx, double diff_task_flops);
131 
132 /* updates the min and max workers needed by each context */
133 void sc_hypervisor_update_resize_interval(unsigned *sched_ctxs, int nsched_ctxs, int max_nworkers);
134 
135 /* returns a list of contexts that are on the same level in the hierarchy of contexts */
136 void sc_hypervisor_get_ctxs_on_level(unsigned **sched_ctxs, int *nsched_ctxs, unsigned hierarchy_level, unsigned father_sched_ctx_id);
137 
138 /* returns the number of levels of ctxs registered to the hyp */
139 unsigned sc_hypervisor_get_nhierarchy_levels(void);
140 
141 /* return the leaves ctxs from the list of ctxs */
142 void sc_hypervisor_get_leaves(unsigned *sched_ctxs, int nsched_ctxs, unsigned *leaves, int *nleaves);
143 
144 /* returns the nready flops of all ctxs below in hierachy of sched_ctx */
145 double sc_hypervisor_get_nready_flops_of_all_sons_of_sched_ctx(unsigned sched_ctx);
146 
147 void sc_hypervisor_print_overhead();
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif
void(* handle_poped_task)(unsigned sched_ctx, int worker, struct starpu_task *task, uint32_t footprint)
Definition: sc_hypervisor.h:57
Definition: starpu_task.h:89
void sc_hypervisor_unregister_ctx(unsigned sched_ctx)
void sc_hypervisor_stop_resize(unsigned sched_ctx)
void(* resize_ctxs)(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
Definition: sc_hypervisor.h:48
void sc_hypervisor_set_type_of_task(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size)
void(* end_ctx)(unsigned sched_ctx)
Definition: sc_hypervisor.h:69
void(* handle_post_exec_hook)(unsigned sched_ctx, int task_tag)
Definition: sc_hypervisor.h:63
void sc_hypervisor_shutdown(void)
unsigned sc_hypervisor_can_resize(unsigned sched_ctx)
void sc_hypervisor_size_ctxs(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
void sc_hypervisor_update_diff_total_flops(unsigned sched_ctx, double diff_total_flops)
unsigned sched_ctx
Definition: starpu_task.h:192
const char * sc_hypervisor_get_policy()
void(* size_ctxs)(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
Definition: sc_hypervisor.h:45
void sc_hypervisor_free_size_req(void)
void(* handle_idle_end)(unsigned sched_ctx, int worker)
Definition: sc_hypervisor.h:60
Definition: starpu_task.h:129
Definition: sc_hypervisor.h:36
void * sc_hypervisor_init(struct sc_hypervisor_policy *policy)
void sc_hypervisor_move_workers(unsigned sender_sched_ctx, unsigned receiver_sched_ctx, int *workers_to_move, unsigned nworkers_to_move, unsigned now)
void sc_hypervisor_remove_workers_from_sched_ctx(int *workers_to_remove, unsigned nworkers_to_remove, unsigned sched_ctx, unsigned now)
void(* handle_idle_cycle)(unsigned sched_ctx, int worker)
Definition: sc_hypervisor.h:51
void(* handle_submitted_job)(struct starpu_codelet *cl, unsigned sched_ctx, uint32_t footprint, size_t data_size)
Definition: sc_hypervisor.h:66
unsigned custom
Definition: sc_hypervisor.h:42
unsigned sc_hypervisor_get_size_req(unsigned **sched_ctxs, int *nsched_ctxs, int **workers, int *nworkers)
void sc_hypervisor_resize_ctxs(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
const char * name
Definition: sc_hypervisor.h:39
void sc_hypervisor_post_resize_request(unsigned sched_ctx, int task_tag)
void sc_hypervisor_save_size_req(unsigned *sched_ctxs, int nsched_ctxs, int *workers, int nworkers)
void sc_hypervisor_add_workers_to_sched_ctx(int *workers_to_add, unsigned nworkers_to_add, unsigned sched_ctx)
void sc_hypervisor_register_ctx(unsigned sched_ctx, double total_flops)
void(* handle_pushed_task)(unsigned sched_ctx, int worker)
Definition: sc_hypervisor.h:54
void sc_hypervisor_update_diff_elapsed_flops(unsigned sched_ctx, double diff_task_flops)
void sc_hypervisor_start_resize(unsigned sched_ctx)