source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/dev/tests-mbg/geometric/test_gp_lakshminarayanan.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 9.8 KB
Line 
1function test_gp_lakshminarayanan
2
3% Architectural parameters
4beta = 4.03 * 10 ^ -4;
5alpha = 2.6 * 10 ^ -7;
6tau = 2.02 * 10 ^ -7;
7
8% Number of processors
9Procs = 5;
10
11% -------------  End of Parameters (constants) -----------------------
12
13obj3d = 1:5;
14obj2d = 1:5;
15objstripMP = 1:5;
16objstrip1P = 1:5;
17N = 1:5;
18
19MP_tis = 1:5;
20
21v2d_tis = 1:5;
22v2d_tjs = 1:5;
23
24v3d_tis = 1:5;
25v3d_tjs = 1:5;
26v3d_tks = 1:5;
27
28N_i = 1000;
29N_j = 1000;
30j = 1;
31for n = N_i/10: N_i/10 : N_i
32    Nk(j)  = n;
33    j = j + 1;
34end;
35for n = 2*N_i : N_i : 10*N_i
36    Nk(j) = n;
37    j = j + 1;
38end;
39
40fprintf('Iteration ');
41for 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;
64end   
65mbg_asserttolequal(norm(obj3d) + norm(obj2d) + norm(objstripMP) + norm(objstrip1P),1.742627952792674e+002,1e-5);
66
67function [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
95ti = sdpvar(1,1);
96tj = sdpvar(1,1);
97tk = sdpvar(1,1);
98
99% ------------- Execution Time  Model ----------------------------
100
101
102% Latency count
103Lambda = (1+ ti/tj) * (Procs-1);
104
105% Time for computing one tile
106TilePeriod = (alpha * ti * tj * tk) + (2 * tau * tj * tk) + ( 2 * beta) ;
107
108% Number of planes
109no_planes = Nk / tk ;
110
111% Number of passes per plane
112no_passes_per_plane = (1/Procs) * ( (Ni + tk) / ti );
113
114% Number of tiles per pass per plane -- macro column
115no_tiles_per_pass_per_plane = (Nj + ti + 2 * tk) / tj;
116
117% Total running time
118T = ( 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
126F = set(ti > 1) ;
127F = F + set(tj > 1) ;
128F = F + set(tk > 1) ;
129
130% Upper bounds on the tile vars
131F = F + set(ti < ( Ni  / Procs)) ;
132F = F + set(tj < Nj) ;
133% Number of tiles per macro column is atleast 2
134% F = F + set( (Nj+ti+2tk) < 2*tj);
135F = 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 );
141F = 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
146intConstraints = set (integer(ti)) + set(integer(tj)) + set(integer(tk));
147F = 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
155obj = T;
156
157%%%%%  Solve the optimization problem
158
159solvesdp(F,obj, sdpsettings('verbose',0,'solver','bnb','debug',1));
160
161%%%%% Print the solutions
162
163
164% Return values
165obj_val = double(obj);
166ti_val = double(ti);
167tj_val = double(tj);
168tk_val = double(tk);
169
170
171function [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
196ti = sdpvar(1,1);
197tj = sdpvar(1,1);
198
199% ------------- Execution Time  Model ----------------------------
200
201
202% Latency count
203Lambda = (1 + (ti/tj)) * (Procs-1);
204
205% Time for computing one tile
206TilePeriod = (alpha * ti * tj) + (2 * tau * tj) + (2 * beta) ;
207
208% Number of planes
209no_planes = Nk;
210
211% Number of passes per plane
212no_passes_per_plane = (1/Procs) * ( Ni / ti );
213
214% Number of tiles per pass per plane -- macro column
215no_tiles_per_pass_per_plane = (Nj + ti) / tj;
216
217% Total running time
218T = ( 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
226F = set(ti > 1) ;
227
228% To avoid idle time between execution of successive planes
229% we need tj >= 2.
230F = F + set(tj >= 2 ) ;
231
232% Upper bounds on the tile vars
233F = F + set(ti < ( Ni  / Procs)) ;
234F = 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 );
239F = F + set(  (1/Nj) * ( (Procs-2) * ti + (Procs-1) * tj ) <= 1);
240
241% solve an integer version of the problem
242intConstraints = set (integer(ti)) + set(integer(tj));
243F = F + intConstraints;
244
245% -------------  End of Constraints -------------------------
246
247%%%%%%% Obective function
248obj = T;
249
250%%%%%  Solve the optimization problem
251
252solvesdp(F,obj, sdpsettings('verbose',0,'solver','bnb'));
253
254%%%%% Print the solutions
255
256
257% Return values
258obj_val = double(obj);
259ti_val = double(ti);
260tj_val = double(tj);
261
262
263function [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
290ti = sdpvar(1,1);
291
292% ------------- Execution Time  Model ----------------------------
293
294
295% Latency count
296Lambda = (Procs-1);
297
298% Time for computing one tile
299TilePeriod = (alpha * ti * Nj) + (2 * tau * Nj) + ( 2 * beta) ;
300
301% Number of planes
302no_planes = Nk;
303
304% Number of passes per plane
305no_passes_per_plane = (1/Procs) * ( Ni / ti );
306
307% Total running time
308T = ( 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.
319F = set(ti >= 2) ;
320
321% Upper bounds on the tile vars
322F = 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
328intConstraints = set (integer(ti)) ;
329F = F + intConstraints;
330
331% -------------  End of Constraints -------------------------
332
333%%%%%%% Obective function
334obj = T;
335
336%%%%%  Solve the optimization problem
337
338solvesdp(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
346obj_val = double(obj);
347ti_val = double(ti);
348
349
350
351function [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
378Lambda = (Procs-1);
379
380% Time for computing one tile
381TilePeriod = (alpha * Ni * Nj / Procs )  + (2* tau * Nj) + (2*beta) ;
382
383% Number of planes
384no_planes = Nk;
385
386% Total running time
387T = ( Lambda +  no_planes ) * TilePeriod ;
388
389% ------------- End of Execution Time  Model ----------------------------
390
391if (Ni / Procs) < 2
392    fprintf('>>>>>  fStrip_1P: Constraint Ni/Procs >= 2 violated\n');
393end;
394
395% Return values
396obj_val = T;
397
398
Note: See TracBrowser for help on using the repository browser.