3D-ICE 3.0.0
floorplan.c
1/******************************************************************************
2 * This file is part of 3D-ICE, version 3.1.0 . *
3 * *
4 * 3D-ICE is free software: you can redistribute it and/or modify it under *
5 * the terms of the GNU General Public License as published by the Free *
6 * Software Foundation, either version 3 of the License, or any later *
7 * version. *
8 * *
9 * 3D-ICE is distributed in the hope that it will be useful, but WITHOUT *
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
12 * more details. *
13 * *
14 * You should have received a copy of the GNU General Public License along *
15 * with 3D-ICE. If not, see <http://www.gnu.org/licenses/>. *
16 * *
17 * Copyright (C) 2021 *
18 * Embedded Systems Laboratory - Ecole Polytechnique Federale de Lausanne *
19 * All Rights Reserved. *
20 * *
21 * Authors: Arvind Sridhar Alessandro Vincenzi *
22 * Giseong Bak Martino Ruggiero *
23 * Thomas Brunschwiler Eder Zulian *
24 * Federico Terraneo Darong Huang *
25 * Luis Costero Marina Zapater *
26 * David Atienza *
27 * *
28 * For any comment, suggestion or request about 3D-ICE, please register and *
29 * write to the mailing list (see http://listes.epfl.ch/doc.cgi?liste=3d-ice) *
30 * Any usage of 3D-ICE for research, commercial or other purposes must be *
31 * properly acknowledged in the resulting products or publications. *
32 * *
33 * EPFL-STI-IEL-ESL Mail : 3d-ice@listes.epfl.ch *
34 * Batiment ELG, ELG 130 (SUBSCRIPTION IS NECESSARY) *
35 * Station 11 *
36 * 1015 Lausanne, Switzerland Url : http://esl.epfl.ch/3d-ice *
37 ******************************************************************************/
38
39#include <stdlib.h> // For the memory functions malloc/free
40#include <string.h> // For the memory function memcpy
41
42#include "floorplan.h"
44
45/******************************************************************************/
46
47void floorplan_init (Floorplan_t *floorplan)
48{
49 string_init (&floorplan->FileName) ;
50
51 floorplan->NElements = (Quantity_t) 0u ;
52 floorplan->Bpowers = NULL ;
53
54 floorplan_element_list_init (&floorplan->ElementsList) ;
56}
57
58/******************************************************************************/
59
61{
62 floorplan_destroy (dst) ;
63
64 string_copy (&dst->FileName, &src->FileName) ;
65
66 dst->NElements = src->NElements ;
67
68 floorplan_element_list_copy (&dst->ElementsList, &src->ElementsList) ;
69
70 floorplan_matrix_copy (&dst->SurfaceCoefficients, &src->SurfaceCoefficients) ;
71
72 if (src->Bpowers == NULL)
73 {
74 dst->Bpowers = NULL ;
75
76 return ;
77 }
78
79 dst->Bpowers = (Power_t *) malloc (sizeof (Power_t) * src->NElements) ;
80
81 if (dst->Bpowers == NULL)
82 {
83 fprintf (stderr, "ERROR: malloc Bpowers in floorplan copy\n") ;
84
85 return ;
86 }
87
88 memcpy (dst->Bpowers, src->Bpowers, sizeof (Power_t) * src->NElements) ;
89}
90
91/******************************************************************************/
92
94{
95 string_destroy (&floorplan->FileName) ;
96
97 if (floorplan->Bpowers != NULL)
98
99 free (floorplan->Bpowers) ;
100
101 floorplan_element_list_destroy (&floorplan->ElementsList) ;
103
104 floorplan_init (floorplan) ;
105}
106
107/******************************************************************************/
108
110{
111 Floorplan_t *floorplan = (Floorplan_t *) malloc (sizeof(Floorplan_t));
112
113 if (floorplan != NULL)
114
115 floorplan_init (floorplan) ;
116
117 return floorplan ;
118}
119
120/******************************************************************************/
121
123{
124 if (floorplan == NULL)
125
126 return NULL ;
127
128 Floorplan_t *newf = floorplan_calloc ( ) ;
129
130 if (newf != NULL)
131
132 floorplan_copy (newf, floorplan) ;
133
134 return newf ;
135}
136
137/******************************************************************************/
138
140{
141 if (floorplan == NULL)
142
143 return ;
144
145 floorplan_destroy (floorplan) ;
146
147 free (floorplan) ;
148}
149
150/******************************************************************************/
151
152void floorplan_print (Floorplan_t *floorplan, FILE *stream, String_t prefix)
153{
154 FloorplanElementListNode_t *flpeln ;
155
156 for (flpeln = floorplan_element_list_begin (&floorplan->ElementsList) ;
157 flpeln != NULL ;
158 flpeln = floorplan_element_list_next (flpeln))
159 {
160 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
161
162 floorplan_element_print (flpel, stream, prefix) ;
163
164 fprintf (stream, "%s\n", prefix) ;
165 }
166}
167
168/******************************************************************************/
169
171(
172 Floorplan_t *floorplan,
173 Dimensions_t *dimensions,
174 String_t filename
175)
176{
177 Error_t result ;
178
179 result = parse_floorplan_file (filename, floorplan, dimensions) ;
180
181 if (result == TDICE_FAILURE)
182
183 return TDICE_FAILURE ;
184
185 floorplan->Bpowers =
186
187 (Power_t *) malloc (sizeof (Power_t) * floorplan->NElements) ;
188
189 if (floorplan->Bpowers == NULL)
190 {
191 fprintf (stderr, "Malloc Bpowers failed\n") ;
192
193 return TDICE_FAILURE ;
194 }
195
196 CellIndex_t nnz = 0u ;
197
198 FloorplanElementListNode_t *flpeln ;
199
200 for (flpeln = floorplan_element_list_begin (&floorplan->ElementsList) ;
201 flpeln != NULL ;
202 flpeln = floorplan_element_list_next (flpeln))
203 {
204 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
205
206 ICElementListNode_t *iceln ;
207
208 for (iceln = ic_element_list_begin(&flpel->ICElements) ;
209 iceln != NULL ;
210 iceln = ic_element_list_next (iceln))
211 {
212 ICElement_t *icel = ic_element_list_data(iceln) ;
213
214 nnz += (icel->NE_Row - icel->SW_Row + 1)
215 * (icel->NE_Column - icel->SW_Column + 1) ;
216 }
217 }
218
220
221 (&floorplan->SurfaceCoefficients, get_layer_area (dimensions),
222 floorplan->NElements, nnz) ;
223
224 if (result == TDICE_FAILURE)
225
226 return TDICE_FAILURE ;
227
229
230 (&floorplan->SurfaceCoefficients, &floorplan->ElementsList, dimensions) ;
231
232 return TDICE_SUCCESS ;
233}
234
235/******************************************************************************/
236
238{
239 return floorplan->NElements ;
240}
241
242/******************************************************************************/
243
245(
246 Floorplan_t *floorplan,
247 String_t floorplan_element_id
248)
249{
250 FloorplanElement_t flpel ;
251
252 floorplan_element_init (&flpel) ;
253
254 string_copy (&flpel.Id, &floorplan_element_id) ;
255
256 FloorplanElement_t *tmp =
257
258 floorplan_element_list_find (&floorplan->ElementsList, &flpel) ;
259
261
262 return tmp ;
263}
264
265/******************************************************************************/
266
268{
269 Quantity_t index = 0u ;
270
271 FloorplanElementListNode_t *flpeln ;
272
273 for (flpeln = floorplan_element_list_begin (&floorplan->ElementsList) ;
274 flpeln != NULL ;
275 flpeln = floorplan_element_list_next (flpeln))
276 {
277 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
278
279 if (is_empty_powers_queue (flpel->PowerValues) == true)
280
281 return TDICE_FAILURE ;
282
283 floorplan->Bpowers [ index++ ] = get_from_powers_queue (flpel->PowerValues) ;
284 }
285
286 // Does the mv multiplication to compute the source vector
287
289
290 (&floorplan->SurfaceCoefficients, sources, floorplan->Bpowers) ;
291
292 return TDICE_SUCCESS ;
293}
294
295/******************************************************************************/
296
298(
299 Floorplan_t *floorplan,
300 PowersQueue_t *pvalues
301)
302{
303 Error_t result ;
304
305 FloorplanElementListNode_t *flpeln ;
306
307 for (flpeln = floorplan_element_list_begin (&floorplan->ElementsList) ;
308 flpeln != NULL ;
309 flpeln = floorplan_element_list_next (flpeln))
310 {
311 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
312
313 result = insert_power_values_floorplan_element (flpel, pvalues) ;
314
315 if (result == TDICE_FAILURE)
316
317 return TDICE_FAILURE ;
318 }
319
320 return TDICE_SUCCESS ;
321}
322
323/******************************************************************************/
324
326(
327 Floorplan_t *floorplan,
328 Dimensions_t *dimensions,
329 Temperature_t *temperatures,
330 Quantity_t *n_floorplan_elements,
331 Temperature_t *max_temperatures
332)
333{
334 if (max_temperatures == NULL)
335 {
336 *n_floorplan_elements =
337
339
340 max_temperatures =
341
342 (Temperature_t *) malloc (sizeof (Temperature_t) * *n_floorplan_elements) ;
343 }
344
345 Temperature_t *tmp = max_temperatures ;
346
347 FloorplanElementListNode_t *flpeln ;
348
349 for (flpeln = floorplan_element_list_begin (&floorplan->ElementsList) ;
350 flpeln != NULL ;
351 flpeln = floorplan_element_list_next (flpeln))
352 {
353 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
354
356
357 (flpel, dimensions, temperatures) ;
358 }
359
360 return max_temperatures ;
361}
362
363/******************************************************************************/
364
366(
367 Floorplan_t *floorplan,
368 Dimensions_t *dimensions,
369 Temperature_t *temperatures,
370 Quantity_t *n_floorplan_elements,
371 Temperature_t *min_temperatures
372)
373{
374 if (min_temperatures == NULL)
375 {
376 *n_floorplan_elements =
377
379
380 min_temperatures =
381
382 (Temperature_t *) malloc (sizeof (Temperature_t) * *n_floorplan_elements) ;
383 }
384
385 Temperature_t *tmp = min_temperatures ;
386
387 FloorplanElementListNode_t *flpeln ;
388
389 for (flpeln = floorplan_element_list_begin (&floorplan->ElementsList) ;
390 flpeln != NULL ;
391 flpeln = floorplan_element_list_next (flpeln))
392 {
393 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
394
396
397 (flpel, dimensions, temperatures) ;
398 }
399
400 return min_temperatures ;
401}
402
403/******************************************************************************/
404
406(
407 Floorplan_t *floorplan,
408 Dimensions_t *dimensions,
409 Temperature_t *temperatures,
410 Quantity_t *n_floorplan_elements,
411 Temperature_t *avg_temperatures
412)
413{
414 if (avg_temperatures == NULL)
415 {
416 *n_floorplan_elements =
417
419
420 avg_temperatures =
421
422 (Temperature_t *) malloc (sizeof (Temperature_t) * *n_floorplan_elements) ;
423 }
424
425 Temperature_t *tmp = avg_temperatures ;
426
427
428 FloorplanElementListNode_t *flpeln ;
429
430 for (flpeln = floorplan_element_list_begin (&floorplan->ElementsList) ;
431 flpeln != NULL ;
432 flpeln = floorplan_element_list_next (flpeln))
433 {
434 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
435
437
438 (flpel, dimensions, temperatures) ;
439 }
440
441 return avg_temperatures ;
442}
443
444/******************************************************************************/
445
447(
448 Floorplan_t *floorplan,
449 Dimensions_t *dimensions,
450 Temperature_t *temperatures,
451 Quantity_t *n_floorplan_elements,
452 Temperature_t *gradient_temperatures
453)
454{
455 if (gradient_temperatures == NULL)
456 {
457 *n_floorplan_elements =
458
460
461 gradient_temperatures =
462
463 (Temperature_t *) malloc (sizeof (Temperature_t) * *n_floorplan_elements) ;
464 }
465
466 Temperature_t *tmp = gradient_temperatures ;
467
468 FloorplanElementListNode_t *flpeln ;
469
470 for (flpeln = floorplan_element_list_begin (&floorplan->ElementsList) ;
471 flpeln != NULL ;
472 flpeln = floorplan_element_list_next (flpeln))
473 {
474 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
475
477
478 (flpel, dimensions, temperatures) ;
479 }
480
481 return gradient_temperatures ;
482}
483
484/******************************************************************************/
CellIndex_t get_layer_area(Dimensions_t *dimensions)
Definition: dimensions.c:666
Floorplan_t * floorplan_calloc(void)
Definition: floorplan.c:109
FloorplanElement_t * get_floorplan_element(Floorplan_t *floorplan, String_t floorplan_element_id)
Definition: floorplan.c:245
void floorplan_print(Floorplan_t *floorplan, FILE *stream, String_t prefix)
Definition: floorplan.c:152
Error_t fill_sources_floorplan(Floorplan_t *floorplan, Source_t *sources)
Definition: floorplan.c:267
void floorplan_free(Floorplan_t *floorplan)
Definition: floorplan.c:139
void floorplan_copy(Floorplan_t *dst, Floorplan_t *src)
Definition: floorplan.c:60
Temperature_t * get_all_gradient_temperatures_floorplan(Floorplan_t *floorplan, Dimensions_t *dimensions, Temperature_t *temperatures, Quantity_t *n_floorplan_elements, Temperature_t *gradient_temperatures)
Definition: floorplan.c:447
Quantity_t get_number_of_floorplan_elements_floorplan(Floorplan_t *floorplan)
Definition: floorplan.c:237
void floorplan_destroy(Floorplan_t *floorplan)
Definition: floorplan.c:93
Floorplan_t * floorplan_clone(Floorplan_t *floorplan)
Definition: floorplan.c:122
Error_t insert_power_values_floorplan(Floorplan_t *floorplan, PowersQueue_t *pvalues)
Definition: floorplan.c:298
Temperature_t * get_all_min_temperatures_floorplan(Floorplan_t *floorplan, Dimensions_t *dimensions, Temperature_t *temperatures, Quantity_t *n_floorplan_elements, Temperature_t *min_temperatures)
Definition: floorplan.c:366
Temperature_t * get_all_avg_temperatures_floorplan(Floorplan_t *floorplan, Dimensions_t *dimensions, Temperature_t *temperatures, Quantity_t *n_floorplan_elements, Temperature_t *avg_temperatures)
Definition: floorplan.c:406
Error_t fill_floorplan(Floorplan_t *floorplan, Dimensions_t *dimensions, String_t file_name)
Definition: floorplan.c:171
void floorplan_init(Floorplan_t *floorplan)
Definition: floorplan.c:47
Temperature_t * get_all_max_temperatures_floorplan(Floorplan_t *floorplan, Dimensions_t *dimensions, Temperature_t *temperatures, Quantity_t *n_floorplan_elements, Temperature_t *max_temperatures)
Definition: floorplan.c:326
Temperature_t get_gradient_temperature_floorplan_element(FloorplanElement_t *flpel, Dimensions_t *dimensions, Temperature_t *temperatures)
Temperature_t get_min_temperature_floorplan_element(FloorplanElement_t *flpel, Dimensions_t *dimensions, Temperature_t *temperatures)
void floorplan_element_print(FloorplanElement_t *flpel, FILE *stream, String_t prefix)
void floorplan_element_init(FloorplanElement_t *flpel)
Error_t insert_power_values_floorplan_element(FloorplanElement_t *flpel, PowersQueue_t *pvalues)
Temperature_t get_avg_temperature_floorplan_element(FloorplanElement_t *flpel, Dimensions_t *dimensions, Temperature_t *temperatures)
void floorplan_element_destroy(FloorplanElement_t *flpel)
Temperature_t get_max_temperature_floorplan_element(FloorplanElement_t *flpel, Dimensions_t *dimensions, Temperature_t *temperatures)
Error_t parse_floorplan_file(String_t filename, Floorplan_t *floorplan, Dimensions_t *dimensions)
void floorplan_matrix_copy(FloorplanMatrix_t *dst, FloorplanMatrix_t *src)
void floorplan_matrix_init(FloorplanMatrix_t *flpmatrix)
Error_t floorplan_matrix_build(FloorplanMatrix_t *flpmatrix, CellIndex_t nrows, CellIndex_t ncolumns, CellIndex_t nnz)
void floorplan_matrix_fill(FloorplanMatrix_t *flpmatrix, FloorplanElementList_t *list, Dimensions_t *dimensions)
void floorplan_matrix_multiply(FloorplanMatrix_t *flpmatrix, Source_t *x, Source_t *b)
void floorplan_matrix_destroy(FloorplanMatrix_t *flpmatrix)
bool is_empty_powers_queue(PowersQueue_t *pqueue)
Definition: powers_queue.c:190
Power_t get_from_powers_queue(PowersQueue_t *pqueue)
Definition: powers_queue.c:244
char * String_t
Definition: string_t.h:55
void string_init(String_t *string)
Definition: string_t.c:46
void string_destroy(String_t *string)
Definition: string_t.c:78
void string_copy(String_t *dst, String_t *src)
Definition: string_t.c:53
Collections of all the structures that are needed for the thermal simulation.
Definition: dimensions.h:311
Structure containing information about a floorplan element.
PowersQueue_t * PowerValues
ICElementList_t ICElements
The floorplan representing the IC as a set of floorplan elements.
Definition: floorplan.h:69
FloorplanMatrix_t SurfaceCoefficients
Definition: floorplan.h:85
Quantity_t NElements
Definition: floorplan.h:76
String_t FileName
Definition: floorplan.h:72
Power_t * Bpowers
Definition: floorplan.h:90
FloorplanElementList_t ElementsList
Definition: floorplan.h:80
CellIndex_t NE_Column
Definition: ic_element.h:109
CellIndex_t SW_Row
Definition: ic_element.h:94
CellIndex_t NE_Row
Definition: ic_element.h:104
CellIndex_t SW_Column
Definition: ic_element.h:99
A First In - First Out circular queue to store power values.
Definition: powers_queue.h:63
Error_t
Definition: types.h:401
@ TDICE_SUCCESS
The function returns with success.
Definition: types.h:402
@ TDICE_FAILURE
The function retuerns with a generic error.
Definition: types.h:403
double Temperature_t
Definition: types.h:71
double Source_t
Definition: types.h:77
uint32_t Quantity_t
Definition: types.h:59
double Power_t
Definition: types.h:83
uint32_t CellIndex_t
Definition: types.h:213