diff options
| author | Bjoern Brandenburg <bbb@mpi-sws.org> | 2012-08-07 14:28:29 -0400 |
|---|---|---|
| committer | Bjoern Brandenburg <bbb@mpi-sws.org> | 2013-02-12 06:49:40 -0500 |
| commit | 4d45e06a55ad463247edd949e6d0c98a69fcf332 (patch) | |
| tree | e522d252342ca658397323301af1a77c03e515d5 | |
| parent | a4ff45bfbaef292ee1106b759c7ae80213b03cd4 (diff) | |
Add DPCP and DFLP linear program generation
These files implement the generation and evaluation of linear programs
that bound maximum s-aware pi-blocking under the DPCP and the DFLP.
| -rw-r--r-- | native/Makefile | 5 | ||||
| -rw-r--r-- | native/include/linprog/model.h | 7 | ||||
| -rw-r--r-- | native/include/lp_common.h | 159 | ||||
| -rw-r--r-- | native/src/blocking/linprog/lp_common.cpp | 177 | ||||
| -rw-r--r-- | native/src/blocking/linprog/lp_dflp.cpp | 152 | ||||
| -rw-r--r-- | native/src/blocking/linprog/lp_dpcp.cpp | 374 |
6 files changed, 871 insertions, 3 deletions
diff --git a/native/Makefile b/native/Makefile index 71a6835..c2a08e5 100644 --- a/native/Makefile +++ b/native/Makefile | |||
| @@ -81,7 +81,7 @@ LDFLAGS = $(LIBS) | |||
| 81 | SWIGFLAGS = -python -c++ -outdir . -includeall -Iinclude | 81 | SWIGFLAGS = -python -c++ -outdir . -includeall -Iinclude |
| 82 | 82 | ||
| 83 | vpath %.cc interface | 83 | vpath %.cc interface |
| 84 | vpath %.cpp src src/edf src/blocking src/linprog | 84 | vpath %.cpp src src/edf src/blocking src/blocking/linprog src/linprog |
| 85 | 85 | ||
| 86 | # #### Common C++ source files #### | 86 | # #### Common C++ source files #### |
| 87 | 87 | ||
| @@ -100,7 +100,8 @@ ALL = testmain _sched.so _locking.so _sim.so | |||
| 100 | 100 | ||
| 101 | # Compile LP-based code only if we have a solver. | 101 | # Compile LP-based code only if we have a solver. |
| 102 | ifneq ($(CPLEX),) | 102 | ifneq ($(CPLEX),) |
| 103 | LP_OBJ = cplex.o io.o | 103 | LP_OBJ = lp_common.o lp_dflp.o lp_dpcp.o |
| 104 | LP_OBJ += cplex.o io.o | ||
| 104 | endif | 105 | endif |
| 105 | 106 | ||
| 106 | .PHONY: all clean | 107 | .PHONY: all clean |
diff --git a/native/include/linprog/model.h b/native/include/linprog/model.h index 27729dd..22f96e4 100644 --- a/native/include/linprog/model.h +++ b/native/include/linprog/model.h | |||
| @@ -53,7 +53,7 @@ class LinearProgram | |||
| 53 | Constraints inequalities; | 53 | Constraints inequalities; |
| 54 | 54 | ||
| 55 | public: | 55 | public: |
| 56 | LinearProgram() : objective(0) {}; | 56 | LinearProgram() : objective(new LinearExpression()) {}; |
| 57 | 57 | ||
| 58 | ~LinearProgram() | 58 | ~LinearProgram() |
| 59 | { | 59 | { |
| @@ -91,6 +91,11 @@ public: | |||
| 91 | return objective; | 91 | return objective; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | LinearExpression *get_objective() | ||
| 95 | { | ||
| 96 | return objective; | ||
| 97 | } | ||
| 98 | |||
| 94 | const Constraints& get_equalities() const | 99 | const Constraints& get_equalities() const |
| 95 | { | 100 | { |
| 96 | return equalities; | 101 | return equalities; |
diff --git a/native/include/lp_common.h b/native/include/lp_common.h new file mode 100644 index 0000000..06519d1 --- /dev/null +++ b/native/include/lp_common.h | |||
| @@ -0,0 +1,159 @@ | |||
| 1 | #ifndef LP_COMMON_H_ | ||
| 2 | #define LP_COMMON_H_ | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #include "sharedres_types.h" | ||
| 7 | #include "blocking.h" | ||
| 8 | |||
| 9 | #include "stl-helper.h" | ||
| 10 | #include "stl-hashmap.h" | ||
| 11 | |||
| 12 | #include "linprog/model.h" | ||
| 13 | #include "linprog/cplex.h" | ||
| 14 | |||
| 15 | enum blocking_type | ||
| 16 | { | ||
| 17 | BLOCKING_DIRECT, | ||
| 18 | BLOCKING_INDIRECT, | ||
| 19 | BLOCKING_PREEMPT | ||
| 20 | }; | ||
| 21 | |||
| 22 | class VarMapper { | ||
| 23 | private: | ||
| 24 | hashmap<uint64_t, unsigned int> map; | ||
| 25 | |||
| 26 | void insert(uint64_t key) | ||
| 27 | { | ||
| 28 | unsigned int idx = map.size(); | ||
| 29 | map[key] = idx; | ||
| 30 | } | ||
| 31 | |||
| 32 | static uint64_t encode_request(uint64_t task_id, uint64_t res_id, uint64_t req_id, | ||
| 33 | uint64_t blocking_type) | ||
| 34 | { | ||
| 35 | assert(task_id < (1 << 30)); | ||
| 36 | assert(res_id < (1 << 10)); | ||
| 37 | assert(req_id < (1 << 22)); | ||
| 38 | assert(blocking_type < (1 << 2)); | ||
| 39 | |||
| 40 | return (blocking_type << 62) | (task_id << 30) | (req_id << 10) | res_id; | ||
| 41 | } | ||
| 42 | |||
| 43 | public: | ||
| 44 | |||
| 45 | unsigned int lookup(unsigned int task_id, unsigned int res_id, unsigned int req_id, | ||
| 46 | blocking_type type) | ||
| 47 | { | ||
| 48 | uint64_t key = encode_request(task_id, res_id, req_id, type); | ||
| 49 | if (!map.count(key)) | ||
| 50 | insert(key); | ||
| 51 | return map[key]; | ||
| 52 | } | ||
| 53 | |||
| 54 | void clear() | ||
| 55 | { | ||
| 56 | map.clear(); | ||
| 57 | } | ||
| 58 | |||
| 59 | unsigned int get_num_vars() | ||
| 60 | { | ||
| 61 | return map.size(); | ||
| 62 | } | ||
| 63 | }; | ||
| 64 | |||
| 65 | void set_blocking_objective( | ||
| 66 | VarMapper& vars, | ||
| 67 | const ResourceSharingInfo& info, const ResourceLocality&, | ||
| 68 | const TaskInfo& ti, | ||
| 69 | LinearProgram& lp, | ||
| 70 | LinearExpression *local_obj = 0, | ||
| 71 | LinearExpression *remote_obj = 0); | ||
| 72 | |||
| 73 | void add_mutex_constraints(VarMapper& vars, | ||
| 74 | const ResourceSharingInfo& info, | ||
| 75 | const TaskInfo& ti, LinearProgram& lp); | ||
| 76 | |||
| 77 | void add_topology_constraints(VarMapper& vars, | ||
| 78 | const ResourceSharingInfo& info, const ResourceLocality& locality, | ||
| 79 | const TaskInfo& ti, LinearProgram& lp); | ||
| 80 | |||
| 81 | void add_local_lower_priority_constraints( | ||
| 82 | VarMapper& vars, | ||
| 83 | const ResourceSharingInfo& info, | ||
| 84 | const ResourceLocality& locality, | ||
| 85 | const TaskInfo& ti, | ||
| 86 | LinearProgram& lp); | ||
| 87 | |||
| 88 | // A generic for loop that iterates 'request_index_variable' from 0 to the | ||
| 89 | // maximum number of requests issued by task tx while ti is pending. 'tx_request' | ||
| 90 | // should be of type RequestBound&. | ||
| 91 | #define foreach_request_instance(tx_request, task_ti, request_index_variable) \ | ||
| 92 | for ( \ | ||
| 93 | unsigned int __max_num_requests = (tx_request).get_max_num_requests((task_ti).get_response()), \ | ||
| 94 | request_index_variable = 0; \ | ||
| 95 | request_index_variable < __max_num_requests; \ | ||
| 96 | request_index_variable++ \ | ||
| 97 | ) | ||
| 98 | |||
| 99 | // iterate over each task using 'task_iter', skipping 'excluded_task' | ||
| 100 | #define foreach_task_except(tasks, excluded_task, task_iter) \ | ||
| 101 | foreach(tasks, task_iter) \ | ||
| 102 | if (task_iter->get_id() != (excluded_task).get_id()) | ||
| 103 | |||
| 104 | // iterate only over tasks with equal or lower priority | ||
| 105 | #define foreach_lowereq_priority_task(tasks, reference_task, task_iter) \ | ||
| 106 | foreach(tasks, task_iter) \ | ||
| 107 | if (task_iter->get_priority() >= (reference_task).get_priority()) | ||
| 108 | |||
| 109 | // iterate only over tasks with equal or lower priority, excluding 'reference_task' | ||
| 110 | #define foreach_lowereq_priority_task_except(tasks, reference_task, task_iter) \ | ||
| 111 | foreach(tasks, task_iter) \ | ||
| 112 | if (task_iter->get_priority() >= (reference_task).get_priority() && \ | ||
| 113 | task_iter->get_id() != (reference_task).get_id()) | ||
| 114 | |||
| 115 | |||
| 116 | // iterate only over tasks with higher priority | ||
| 117 | #define foreach_higher_priority_task(tasks, reference_task, task_iter) \ | ||
| 118 | foreach(tasks, task_iter) \ | ||
| 119 | if (task_iter->get_priority() < (reference_task).get_priority()) | ||
| 120 | |||
| 121 | // iterate over requests not in the local cluster | ||
| 122 | #define foreach_remote_request(requests, locality, task_ti, request_iter) \ | ||
| 123 | foreach(requests, request_iter) \ | ||
| 124 | if ((locality)[request_iter->get_resource_id()] \ | ||
| 125 | != (int) (task_ti).get_cluster()) | ||
| 126 | |||
| 127 | // iterate over requests for resources in a specific cluster | ||
| 128 | #define foreach_request_in_cluster(requests, locality, cluster, request_iter) \ | ||
| 129 | foreach(requests, request_iter) \ | ||
| 130 | if ((locality)[request_iter->get_resource_id()] \ | ||
| 131 | == (int) (cluster)) | ||
| 132 | |||
| 133 | // iterate over each task using 'task_iter', skipping tasks in the same | ||
| 134 | // cluster as 'local_task' | ||
| 135 | #define foreach_remote_task(tasks, local_task, task_iter) \ | ||
| 136 | foreach(tasks, task_iter) \ | ||
| 137 | if (task_iter->get_cluster() != (local_task).get_cluster()) | ||
| 138 | |||
| 139 | #define foreach_local_task(tasks, local_task, task_iter) \ | ||
| 140 | foreach(tasks, task_iter) \ | ||
| 141 | if (task_iter->get_cluster() == (local_task).get_cluster()) | ||
| 142 | |||
| 143 | #define foreach_local_task_except(tasks, local_task, task_iter) \ | ||
| 144 | foreach(tasks, task_iter) \ | ||
| 145 | if (task_iter->get_cluster() == (local_task).get_cluster() && \ | ||
| 146 | task_iter->get_id() != (local_task).get_id()) | ||
| 147 | |||
| 148 | #define foreach_local_lowereq_priority_task_except(tasks, local_task, task_iter) \ | ||
| 149 | foreach(tasks, task_iter) \ | ||
| 150 | if (task_iter->get_cluster() == (local_task).get_cluster() && \ | ||
| 151 | task_iter->get_id() != (local_task).get_id() && \ | ||
| 152 | task_iter->get_priority() >= (local_task).get_priority()) | ||
| 153 | |||
| 154 | #define foreach_request_for(requests, res_id, req_iter) \ | ||
| 155 | foreach(requests, req_iter) \ | ||
| 156 | if (req_iter->get_resource_id() == res_id) | ||
| 157 | |||
| 158 | |||
