[37] | 1 | function test_gp_lakshminarayanan |
---|
| 2 | |
---|
| 3 | % Architectural parameters |
---|
| 4 | beta = 4.03 * 10 ^ -4; |
---|
| 5 | alpha = 2.6 * 10 ^ -7; |
---|
| 6 | tau = 2.02 * 10 ^ -7; |
---|
| 7 | |
---|
| 8 | % Number of processors |
---|
| 9 | Procs = 5; |
---|
| 10 | |
---|
| 11 | % ------------- End of Parameters (constants) ----------------------- |
---|
| 12 | |
---|
| 13 | obj3d = 1:5; |
---|
| 14 | obj2d = 1:5; |
---|
| 15 | objstripMP = 1:5; |
---|
| 16 | objstrip1P = 1:5; |
---|
| 17 | N = 1:5; |
---|
| 18 | |
---|
| 19 | MP_tis = 1:5; |
---|
| 20 | |
---|
| 21 | v2d_tis = 1:5; |
---|
| 22 | v2d_tjs = 1:5; |
---|
| 23 | |
---|
| 24 | v3d_tis = 1:5; |
---|
| 25 | v3d_tjs = 1:5; |
---|
| 26 | v3d_tks = 1:5; |
---|
| 27 | |
---|
| 28 | N_i = 1000; |
---|
| 29 | N_j = 1000; |
---|
| 30 | j = 1; |
---|
| 31 | for n = N_i/10: N_i/10 : N_i |
---|
| 32 | Nk(j) = n; |
---|
| 33 | j = j + 1; |
---|
| 34 | end; |
---|
| 35 | for n = 2*N_i : N_i : 10*N_i |
---|
| 36 | Nk(j) = n; |
---|
| 37 | j = j + 1; |
---|
| 38 | end; |
---|
| 39 | |
---|
| 40 | fprintf('Iteration '); |
---|
| 41 | for i = 1:5 |
---|
| 42 | |
---|
| 43 | N_k = Nk(i); |
---|
| 44 | |
---|
| 45 | % Call the 3D model |
---|
| 46 | [obj3d(i), v3d_tis(i), v3d_tjs(i), v3d_tks(i)] = f3D(alpha,beta,tau,Procs,N_i,N_j,N_k); |
---|
| 47 | |
---|
| 48 | % Call the 2D model |
---|
| 49 | [obj2d(i), v2d_tis(i), v2d_tjs(i)] = f2D_SemiOblique_PerPlane(alpha,beta,tau,Procs,N_i,N_j,N_k); |
---|
| 50 | |
---|
| 51 | % Call the Strip Baseline Multi Pass model |
---|
| 52 | [objstripMP(i), MP_tis(i)] = fStrip_MP(alpha,beta,tau,Procs,N_i,N_j,N_k); |
---|
| 53 | |
---|
| 54 | % Call the Strip Baseline One Pass model |
---|
| 55 | objstrip1P(i) = fStrip_1P(alpha,beta,tau,Procs,N_i,N_j,N_k); |
---|
| 56 | |
---|
| 57 | % Save N for plots |
---|
| 58 | N(i) = Nk(i); |
---|
| 59 | % print current iteration. |
---|
| 60 | fprintf('%g ',i); |
---|
| 61 | if mod(i,25) == 0 |
---|
| 62 | fprintf('\n'); |
---|
| 63 | end; |
---|
| 64 | end |
---|
| 65 | mbg_asserttolequal(norm(obj3d) + norm(obj2d) + norm(objstripMP) + norm(objstrip1P),1.742627952792674e+002,1e-5); |
---|
| 66 | |
---|
| 67 | function [obj_val, ti_val, tj_val, tk_val] = f3D( alpha, beta, tau, Procs, Ni, Nj, Nk) |
---|
| 68 | % Computes the optimal tile sizes given architectural parameters and domain sizes. |
---|
| 69 | % |
---|
| 70 | % INPUT ARGUMENTS: (alpha, beta, tau, Procs, Ni, Nj, Nk) |
---|
| 71 | % alpha -- time to compute an iteration |
---|
| 72 | % beta -- time to transfer a word |
---|
| 73 | % tau -- startup cost |
---|
| 74 | % Procs -- number of processors |
---|
| 75 | % Ni -- size of domain along dimension i |
---|
| 76 | % Nj -- size of domain along dimension j |
---|
| 77 | % Nk -- size of domain along dimension k |
---|
| 78 | % |
---|
| 79 | % RETURN VALUES: [obj_val, ti_val, tj_val, tk_val] |
---|
| 80 | % obj_val -- Value of objective function at the optimizer |
---|
| 81 | % ti_val, tj_val, tk_val -- the optimal tile sizes. |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | % Notes |
---|
| 85 | % ----- |
---|
| 86 | % Linear processor array allocation |
---|
| 87 | % Tile and skew along k |
---|
| 88 | % projection along j for every plane |
---|
| 89 | % do the planes sequentially |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | % ------------- Tile Variables ---------------------------- |
---|
| 93 | |
---|
| 94 | % ti, tj, and tk are tile sizes |
---|
| 95 | ti = sdpvar(1,1); |
---|
| 96 | tj = sdpvar(1,1); |
---|
| 97 | tk = sdpvar(1,1); |
---|
| 98 | |
---|
| 99 | % ------------- Execution Time Model ---------------------------- |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | % Latency count |
---|
| 103 | Lambda = (1+ ti/tj) * (Procs-1); |
---|
| 104 | |
---|
| 105 | % Time for computing one tile |
---|
| 106 | TilePeriod = (alpha * ti * tj * tk) + (2 * tau * tj * tk) + ( 2 * beta) ; |
---|
| 107 | |
---|
| 108 | % Number of planes |
---|
| 109 | no_planes = Nk / tk ; |
---|
| 110 | |
---|
| 111 | % Number of passes per plane |
---|
| 112 | no_passes_per_plane = (1/Procs) * ( (Ni + tk) / ti ); |
---|
| 113 | |
---|
| 114 | % Number of tiles per pass per plane -- macro column |
---|
| 115 | no_tiles_per_pass_per_plane = (Nj + ti + 2 * tk) / tj; |
---|
| 116 | |
---|
| 117 | % Total running time |
---|
| 118 | T = ( Lambda + ( no_planes * no_passes_per_plane * no_tiles_per_pass_per_plane ) ) * TilePeriod ; |
---|
| 119 | |
---|
| 120 | % ------------- End of Execution Time Model ---------------------------- |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | % ------------- Constraints ---------------------------- |
---|
| 124 | |
---|
| 125 | % Lower bounds on the tile vars |
---|
| 126 | F = set(ti > 1) ; |
---|
| 127 | F = F + set(tj > 1) ; |
---|
| 128 | F = F + set(tk > 1) ; |
---|
| 129 | |
---|
| 130 | % Upper bounds on the tile vars |
---|
| 131 | F = F + set(ti < ( Ni / Procs)) ; |
---|
| 132 | F = F + set(tj < Nj) ; |
---|
| 133 | % Number of tiles per macro column is atleast 2 |
---|
| 134 | % F = F + set( (Nj+ti+2tk) < 2*tj); |
---|
| 135 | F = F + set(tk < Nk) ; |
---|
| 136 | |
---|
| 137 | % No idle time between passes |
---|
| 138 | %F = F + set ( ((Procs-1)/Nj) * (ti+tj) <= 1) |
---|
| 139 | %F = F + set ( ((Procs-1)/ (2*Nj)) * (ti+tj) < 1) |
---|
| 140 | %F = F + set ( (Procs-1) * ( ti + tj ) * (1/(2*Nj)) < 1 ); |
---|
| 141 | F = F + set( (1/(Nj + 2*Nk) ) * ( (Procs-2) * ti + (Procs-1) * tj ) <= 1); |
---|
| 142 | % Not sure this is correct |
---|
| 143 | %F = F + set( tj <= ( Nj / (Procs-1) ) ) ; |
---|
| 144 | |
---|
| 145 | % solve an integer version of the problem |
---|
| 146 | intConstraints = set (integer(ti)) + set(integer(tj)) + set(integer(tk)); |
---|
| 147 | F = F + intConstraints; |
---|
| 148 | |
---|
| 149 | % + set( (Procs-1) * tj <= Nj + 2*tk) ; |
---|
| 150 | % No idle time between passes |
---|
| 151 | |
---|
| 152 | % ------------- End of Constraints ------------------------- |
---|
| 153 | |
---|
| 154 | %%%%%%% Obective function |
---|
| 155 | obj = T; |
---|
| 156 | |
---|
| 157 | %%%%% Solve the optimization problem |
---|
| 158 | |
---|
| 159 | solvesdp(F,obj, sdpsettings('verbose',0,'solver','bnb','debug',1)); |
---|
| 160 | |
---|
| 161 | %%%%% Print the solutions |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | % Return values |
---|
| 165 | obj_val = double(obj); |
---|
| 166 | ti_val = double(ti); |
---|
| 167 | tj_val = double(tj); |
---|
| 168 | tk_val = double(tk); |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | function [obj_val, ti_val, tj_val] = f2D_SemiOblique_PerPlane( alpha, beta, tau, Procs, Ni, Nj, Nk) |
---|
| 172 | % Computes the optimal tile sizes given architectural parameters and domain sizes. |
---|
| 173 | % |
---|
| 174 | % INPUT ARGUMENTS: (alpha, beta, tau, Procs, Ni, Nj, Nk) |
---|
| 175 | % alpha -- time to compute an iteration |
---|
| 176 | % beta -- time to transfer a word |
---|
| 177 | % tau -- startup cost |
---|
| 178 | % Procs -- number of processors |
---|
| 179 | % Ni -- size of domain along dimension i |
---|
| 180 | % Nj -- size of domain along dimension j |
---|
| 181 | % Nk -- size of domain along dimension k |
---|
| 182 | % |
---|
| 183 | % RETURN VALUES: [obj_val, ti_val, tj_val] |
---|
| 184 | % obj_val -- Value of objective function at the optimizer |
---|
| 185 | % ti_val, tj_val -- the optimal tile sizes. |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | % Notes |
---|
| 189 | % ----- |
---|
| 190 | % In this model we skew the ij plane and do not skew or tile the |
---|
| 191 | % k dimension. We solve for ti and tj. |
---|
| 192 | |
---|
| 193 | % ------------- Tile Variables ---------------------------- |
---|
| 194 | |
---|
| 195 | % ti and tj are tile sizes |
---|
| 196 | ti = sdpvar(1,1); |
---|
| 197 | tj = sdpvar(1,1); |
---|
| 198 | |
---|
| 199 | % ------------- Execution Time Model ---------------------------- |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | % Latency count |
---|
| 203 | Lambda = (1 + (ti/tj)) * (Procs-1); |
---|
| 204 | |
---|
| 205 | % Time for computing one tile |
---|
| 206 | TilePeriod = (alpha * ti * tj) + (2 * tau * tj) + (2 * beta) ; |
---|
| 207 | |
---|
| 208 | % Number of planes |
---|
| 209 | no_planes = Nk; |
---|
| 210 | |
---|
| 211 | % Number of passes per plane |
---|
| 212 | no_passes_per_plane = (1/Procs) * ( Ni / ti ); |
---|
| 213 | |
---|
| 214 | % Number of tiles per pass per plane -- macro column |
---|
| 215 | no_tiles_per_pass_per_plane = (Nj + ti) / tj; |
---|
| 216 | |
---|
| 217 | % Total running time |
---|
| 218 | T = ( Lambda + ( no_planes * no_passes_per_plane * no_tiles_per_pass_per_plane ) ) * TilePeriod ; |
---|
| 219 | |
---|
| 220 | % ------------- End of Execution Time Model ---------------------------- |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | % ------------- Constraints ---------------------------- |
---|
| 224 | |
---|
| 225 | % Lower bounds on the tile vars |
---|
| 226 | F = set(ti > 1) ; |
---|
| 227 | |
---|
| 228 | % To avoid idle time between execution of successive planes |
---|
| 229 | % we need tj >= 2. |
---|
| 230 | F = F + set(tj >= 2 ) ; |
---|
| 231 | |
---|
| 232 | % Upper bounds on the tile vars |
---|
| 233 | F = F + set(ti < ( Ni / Procs)) ; |
---|
| 234 | F = F + set(tj < Nj) ; |
---|
| 235 | |
---|
| 236 | % No idle time between passes |
---|
| 237 | %F = F + set( ( (1/Nj) * tj * (Procs-1) * (ti+tj) ) <= 1 ); |
---|
| 238 | %F = F + set( ( (1/Nj) * (Procs-1) * (ti+tj) ) <= 1 ); |
---|
| 239 | F = F + set( (1/Nj) * ( (Procs-2) * ti + (Procs-1) * tj ) <= 1); |
---|
| 240 | |
---|
| 241 | % solve an integer version of the problem |
---|
| 242 | intConstraints = set (integer(ti)) + set(integer(tj)); |
---|
| 243 | F = F + intConstraints; |
---|
| 244 | |
---|
| 245 | % ------------- End of Constraints ------------------------- |
---|
| 246 | |
---|
| 247 | %%%%%%% Obective function |
---|
| 248 | obj = T; |
---|
| 249 | |
---|
| 250 | %%%%% Solve the optimization problem |
---|
| 251 | |
---|
| 252 | solvesdp(F,obj, sdpsettings('verbose',0,'solver','bnb')); |
---|
| 253 | |
---|
| 254 | %%%%% Print the solutions |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | % Return values |
---|
| 258 | obj_val = double(obj); |
---|
| 259 | ti_val = double(ti); |
---|
| 260 | tj_val = double(tj); |
---|
| 261 | |
---|
| 262 | |
---|
| 263 | function [obj_val, ti_val] = fStrip_MP(alpha, beta, tau, Procs, Ni, Nj, Nk) |
---|
| 264 | % Computes the optimal tile sizes given architectural parameters and domain sizes. |
---|
| 265 | % |
---|
| 266 | % INPUT ARGUMENTS: (alpha, beta, tau, Procs, Ni, Nj, Nk) |
---|
| 267 | % alpha -- time to compute an iteration |
---|
| 268 | % beta -- time to transfer a word |
---|
| 269 | % tau -- startup cost |
---|
| 270 | % Procs -- number of processors |
---|
| 271 | % Ni -- size of domain along dimension i |
---|
| 272 | % Nj -- size of domain along dimension j |
---|
| 273 | % Nk -- size of domain along dimension k |
---|
| 274 | % |
---|
| 275 | % RETURN VALUES: [obj_val, ti_val, tj_val] |
---|
| 276 | % obj_val -- Value of objective function at the optimizer |
---|
| 277 | % ti_val -- the optimal tile size. |
---|
| 278 | |
---|
| 279 | |
---|
| 280 | % Notes |
---|
| 281 | % ----- |
---|
| 282 | % Divide the ij plane into strips. |
---|
| 283 | % In this model we allow the strip width to vary, so that |
---|
| 284 | % there may be multiple passes. |
---|
| 285 | % We solve to ti. |
---|
| 286 | |
---|
| 287 | % ------------- Tile Variables ---------------------------- |
---|
| 288 | |
---|
| 289 | % ti and tj are tile sizes |
---|
| 290 | ti = sdpvar(1,1); |
---|
| 291 | |
---|
| 292 | % ------------- Execution Time Model ---------------------------- |
---|
| 293 | |
---|
| 294 | |
---|
| 295 | % Latency count |
---|
| 296 | Lambda = (Procs-1); |
---|
| 297 | |
---|
| 298 | % Time for computing one tile |
---|
| 299 | TilePeriod = (alpha * ti * Nj) + (2 * tau * Nj) + ( 2 * beta) ; |
---|
| 300 | |
---|
| 301 | % Number of planes |
---|
| 302 | no_planes = Nk; |
---|
| 303 | |
---|
| 304 | % Number of passes per plane |
---|
| 305 | no_passes_per_plane = (1/Procs) * ( Ni / ti ); |
---|
| 306 | |
---|
| 307 | % Total running time |
---|
| 308 | T = ( Lambda + ( no_planes * no_passes_per_plane ) ) * TilePeriod ; |
---|
| 309 | |
---|
| 310 | % ------------- End of Execution Time Model ---------------------------- |
---|
| 311 | |
---|
| 312 | |
---|
| 313 | % ------------- Constraints ---------------------------- |
---|
| 314 | |
---|
| 315 | % Lower bounds on the tile vars |
---|
| 316 | %F = set(ti > 1) ; |
---|
| 317 | % To avoid idle time between execution of successive planes |
---|
| 318 | % we need ti >= 2. |
---|
| 319 | F = set(ti >= 2) ; |
---|
| 320 | |
---|
| 321 | % Upper bounds on the tile vars |
---|
| 322 | F = F + set(ti < ( Ni / Procs)) ; |
---|
| 323 | |
---|
| 324 | % No idle time between passes |
---|
| 325 | %F = F + set( (Procs-1) <= Nk ); |
---|
| 326 | |
---|
| 327 | % solve an integer version of the problem |
---|
| 328 | intConstraints = set (integer(ti)) ; |
---|
| 329 | F = F + intConstraints; |
---|
| 330 | |
---|
| 331 | % ------------- End of Constraints ------------------------- |
---|
| 332 | |
---|
| 333 | %%%%%%% Obective function |
---|
| 334 | obj = T; |
---|
| 335 | |
---|
| 336 | %%%%% Solve the optimization problem |
---|
| 337 | |
---|
| 338 | solvesdp(F,obj, sdpsettings('verbose',0,'solver','bnb')); |
---|
| 339 | |
---|
| 340 | %%%%% Print the solutions |
---|
| 341 | |
---|
| 342 | %fprintf('Objective : %g \n', double(obj)); |
---|
| 343 | %fprintf('ti : %g \n', double(ti)); |
---|
| 344 | |
---|
| 345 | % Return values |
---|
| 346 | obj_val = double(obj); |
---|
| 347 | ti_val = double(ti); |
---|
| 348 | |
---|
| 349 | |
---|
| 350 | |
---|
| 351 | function [obj_val] = fStrip_1P(alpha, beta, tau, Procs, Ni, Nj, Nk) |
---|
| 352 | % Computes the running time given architectural parameters and domain sizes. |
---|
| 353 | % |
---|
| 354 | % INPUT ARGUMENTS: (alpha, beta, tau, Procs, Ni, Nj, Nk) |
---|
| 355 | % alpha -- time to compute an iteration |
---|
| 356 | % beta -- time to transfer a word |
---|
| 357 | % tau -- startup cost |
---|
| 358 | % Procs -- number of processors |
---|
| 359 | % Ni -- size of domain along dimension i |
---|
| 360 | % Nj -- size of domain along dimension j |
---|
| 361 | % Nk -- size of domain along dimension k |
---|
| 362 | % |
---|
| 363 | % RETURN VALUES: [obj_val, ti_val, tj_val] |
---|
| 364 | % obj_val -- the running time. |
---|
| 365 | |
---|
| 366 | |
---|
| 367 | % Notes |
---|
| 368 | % ----- |
---|
| 369 | % Divide the ij plane into strips and do the plane in one pass. |
---|
| 370 | % In this model we DO NOT allow the strip width to vary, so that |
---|
| 371 | % there is only one pass. |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | % ------------- Execution Time Model ---------------------------- |
---|
| 375 | |
---|
| 376 | |
---|
| 377 | % Latency count |
---|
| 378 | Lambda = (Procs-1); |
---|
| 379 | |
---|
| 380 | % Time for computing one tile |
---|
| 381 | TilePeriod = (alpha * Ni * Nj / Procs ) + (2* tau * Nj) + (2*beta) ; |
---|
| 382 | |
---|
| 383 | % Number of planes |
---|
| 384 | no_planes = Nk; |
---|
| 385 | |
---|
| 386 | % Total running time |
---|
| 387 | T = ( Lambda + no_planes ) * TilePeriod ; |
---|
| 388 | |
---|
| 389 | % ------------- End of Execution Time Model ---------------------------- |
---|
| 390 | |
---|
| 391 | if (Ni / Procs) < 2 |
---|
| 392 | fprintf('>>>>> fStrip_1P: Constraint Ni/Procs >= 2 violated\n'); |
---|
| 393 | end; |
---|
| 394 | |
---|
| 395 | % Return values |
---|
| 396 | obj_val = T; |
---|
| 397 | |
---|
| 398 | |
---|