3D-ICE 3.0.0
stack_element.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>
41#include "stack_element.h"
42
43/******************************************************************************/
44
46{
48 stkel->Pointer.Layer = NULL ;
49 stkel->Pointer.Die = NULL ;
50 stkel->Pointer.Channel = NULL ;
51
52 stkel->TopSink = NULL ;
53 stkel->BottomSink = NULL ;
54
55 string_init (&stkel->Id) ;
56
57 stkel->NLayers = (CellIndex_t) 0u ;
58 stkel->Offset = (CellIndex_t) 0u ;
59}
60
61/******************************************************************************/
62
64{
66
67 dst->SEType = src->SEType ;
68 dst->NLayers = src->NLayers ;
69 dst->Offset = src->Offset ;
70
71 string_copy (&dst->Id, &src->Id) ;
72
73 if (src->SEType == TDICE_STACK_ELEMENT_LAYER)
74
75 dst->Pointer.Layer = layer_clone (src->Pointer.Layer) ;
76
77 else if (src->SEType == TDICE_STACK_ELEMENT_DIE)
78
79 dst->Pointer.Die = die_clone (src->Pointer.Die) ;
80
81 else
82
83 // Channel
84
85 dst->Pointer = src->Pointer ;
86
87 if (src->TopSink != NULL) dst->TopSink = heat_sink_clone (src->TopSink) ;
88 if (src->BottomSink != NULL) dst->BottomSink = heat_sink_clone (src->BottomSink) ;
89}
90
91/******************************************************************************/
92
94{
95 string_destroy (&stkel->Id) ;
96
97 if (stkel->SEType == TDICE_STACK_ELEMENT_DIE)
98
99 die_free (stkel->Pointer.Die) ;
100
101 else if (stkel->SEType == TDICE_STACK_ELEMENT_LAYER)
102
103 layer_free (stkel->Pointer.Layer) ;
104
105 if (stkel->TopSink != NULL) heat_sink_free (stkel->TopSink) ;
106 if (stkel->BottomSink != NULL) heat_sink_free (stkel->BottomSink) ;
107
108 stack_element_init (stkel) ;
109}
110
111/******************************************************************************/
112
114{
115 StackElement_t *stkel = (StackElement_t *) malloc (sizeof(StackElement_t)) ;
116
117 if (stkel != NULL)
118
119 stack_element_init (stkel) ;
120
121 return stkel ;
122}
123
124/******************************************************************************/
125
127{
128 if (stkel == NULL)
129
130 return NULL ;
131
133
134 if (news != NULL)
135
136 stack_element_copy (news, stkel) ;
137
138 return news ;
139}
140
141/******************************************************************************/
142
144{
145 if (stkel == NULL)
146
147 return ;
148
149 stack_element_destroy (stkel) ;
150
151 free (stkel) ;
152}
153
154/******************************************************************************/
155
157{
158 return string_equal (&stkel->Id, &other->Id) ;
159}
160
161/******************************************************************************/
162
164(
165 StackElement_t *stkel,
166 FILE *stream,
167 String_t prefix
168)
169{
170 switch (stkel->SEType)
171 {
173
174 fprintf (stream,
175 "%s channel %s ;\n",
176 prefix, stkel->Id) ;
177 break ;
178
180
181 fprintf (stream,
182 "%s die %s %s floorplan \"%s\" ;\n",
183 prefix,
184 stkel->Id,
185 stkel->Pointer.Die->Id,
186 stkel->Pointer.Die->Floorplan.FileName) ;
187
188 break ;
189
191
192 fprintf (stream,
193 "%s layer %s %s ;\n",
194 prefix,
195 stkel->Id, stkel->Pointer.Layer->Id) ;
196
197 break ;
198
200
201 fprintf (stderr, "Warning: found stack element type none\n") ;
202 break ;
203
204 default :
205
206 fprintf (stderr, "Undefined stack element type %d\n", stkel->SEType) ;
207 }
208}
209
210/******************************************************************************/
211
213{
214 CellIndex_t layer_offset = stkel->Offset ;
215
216 if (stkel->SEType == TDICE_STACK_ELEMENT_DIE)
217
218 layer_offset += stkel->Pointer.Die->SourceLayerOffset ;
219
220 else if (stkel->SEType == TDICE_STACK_ELEMENT_CHANNEL)
221
222 layer_offset += stkel->Pointer.Channel->SourceLayerOffset ;
223
224 return layer_offset ;
225}
226
227/******************************************************************************/
228
230(
231 StackElement_t *stkel,
232 Dimensions_t *dimensions,
233 Temperature_t *temperatures,
234 FILE *stream
235)
236{
237
238 if (dimensions->NonUniform == 1)
239 {
240 // write the xyaxis file in the non-uniform scenario
241 char name[50] = "xyaxis_";
242 strcat(name,stkel->Id);
243 strcat(name,".txt");
244 FILE *filexy = fopen (name, "w") ;
245 if (filexy == NULL)
246 {
247 fprintf (stderr, "Cannot create text file for x axis in the non-uniform scenario\n") ;
248 return ;
249 }
250 // output all of the cells' temperature in the layer for non-uniform scenario
251 CellIndex_t counter = 0;
252 CellIndex_t layer_offset = get_source_layer_offset(stkel) ;
253 for (Non_uniform_cellListNode_t* cell_i = dimensions->Cell_list.First; cell_i != NULL; cell_i = cell_i->Next)
254 {
255 if (cell_i->Data.layer_info == layer_offset)
256 {
257 fprintf (stream, "%7.3f ", *(temperatures+counter)) ;
258 fprintf (filexy, "%5.2f\t%5.2f\t%5.2f\t%5.2f\n", cell_i->Data.left_x, cell_i->Data.left_y, cell_i->Data.length,cell_i->Data.width) ;
259 }
260 counter++;
261 }
262 fprintf (stream, "\n") ;
263 fclose (filexy) ;
264 }
265 else
266 {
267 temperatures += get_cell_offset_in_stack
268
269 (dimensions, get_source_layer_offset (stkel),
270 first_row (dimensions), first_column (dimensions)) ;
271
272
273 CellIndex_t row ;
274 CellIndex_t column ;
275
276 for (row = first_row (dimensions) ; row <= last_row (dimensions) ; row++)
277 {
278 for (column = first_column (dimensions) ; column <= last_column (dimensions) ; column++)
279 {
280 fprintf (stream, "%7.3f ", *temperatures++) ;
281 }
282
283 fprintf (stream, "\n") ;
284 }
285 }
286}
287
288/******************************************************************************/
289
291(
292 StackElement_t *stkel,
293 Dimensions_t *dimensions,
294 Source_t *sources,
295 FILE *stream
296)
297{
298
299 if (dimensions->NonUniform == 1)
300 {
301 // write the xyaxis file in the non-uniform scenario
302 char name[50] = "xyaxis_";
303 strcat(name,stkel->Id);
304 strcat(name,".txt");
305 FILE *filexy = fopen (name, "w") ;
306 if (filexy == NULL)
307 {
308 fprintf (stderr, "Cannot create text file for x axis in the non-uniform scenario\n") ;
309 return ;
310 }
311 // output all of the cells' power in the layer for non-uniform scenario
312 CellIndex_t counter = 0;
313 CellIndex_t layer_offset = get_source_layer_offset(stkel) ;
314 for (Non_uniform_cellListNode_t* cell_i = dimensions->Cell_list.First; cell_i != NULL; cell_i = cell_i->Next)
315 {
316 if (cell_i->Data.layer_info == layer_offset)
317 {
318 fprintf (stream, "%7.3f ", *(sources+counter)) ;
319 fprintf (filexy, "%5.2f\t%5.2f\t%5.2f\t%5.2f\n", cell_i->Data.left_x, cell_i->Data.left_y, cell_i->Data.length,cell_i->Data.width) ;
320 }
321 counter++;
322 }
323 fprintf (stream, "\n") ;
324 fclose (filexy) ;
325 }
326 else
327 {
328 sources += get_cell_offset_in_stack
329
330 (dimensions, get_source_layer_offset (stkel),
331 first_row (dimensions), first_column (dimensions)) ;
332
333 CellIndex_t row ;
334 CellIndex_t column ;
335
336 for (row = first_row (dimensions) ; row <= last_row (dimensions) ; row++)
337 {
338 for (column = first_column (dimensions) ; column <= last_column (dimensions) ; column++)
339 {
340 fprintf (stream, "%7.3f ", *sources++) ;
341 }
342
343 fprintf (stream, "\n") ;
344 }
345 }
346}
347
348/******************************************************************************/
349
351(
352 StackElement_t *stkel
353)
354{
355 if (stkel->SEType == TDICE_STACK_ELEMENT_DIE)
356
358
359 (&stkel->Pointer.Die->Floorplan) ;
360
361 else
362
363 return 0u ;
364}
365
366/******************************************************************************/
void die_free(Die_t *die)
Definition: die.c:122
Die_t * die_clone(Die_t *die)
Definition: die.c:105
CellIndex_t get_cell_offset_in_stack(Dimensions_t *dimensions, CellIndex_t layer_index, CellIndex_t row_index, CellIndex_t column_index)
Definition: dimensions.c:686
CellIndex_t last_column(Dimensions_t *dimensions)
Definition: dimensions.c:456
CellIndex_t first_column(Dimensions_t *dimensions)
CellIndex_t first_row(Dimensions_t *dimensions)
CellIndex_t last_row(Dimensions_t *dimensions)
Definition: dimensions.c:442
Quantity_t get_number_of_floorplan_elements_floorplan(Floorplan_t *floorplan)
Definition: floorplan.c:237
HeatSink_t * heat_sink_clone(HeatSink_t *hsink)
Definition: heat_sink.c:141
void heat_sink_free(HeatSink_t *hsink)
Definition: heat_sink.c:158
void layer_free(Layer_t *layer)
Definition: layer.c:124
Layer_t * layer_clone(Layer_t *layer)
Definition: layer.c:107
void stack_element_copy(StackElement_t *dst, StackElement_t *src)
Definition: stack_element.c:63
void stack_element_print_power_map(StackElement_t *stkel, Dimensions_t *dimensions, Source_t *sources, FILE *stream)
void stack_element_destroy(StackElement_t *stkel)
Definition: stack_element.c:93
void stack_element_init(StackElement_t *stkel)
Definition: stack_element.c:45
CellIndex_t get_source_layer_offset(StackElement_t *stkel)
StackElement_t * stack_element_calloc(void)
void stack_element_print_thermal_map(StackElement_t *stkel, Dimensions_t *dimensions, Temperature_t *temperatures, FILE *stream)
Quantity_t get_number_of_floorplan_elements_stack_element(StackElement_t *stkel)
StackElement_t * stack_element_clone(StackElement_t *stkel)
bool stack_element_same_id(StackElement_t *stkel, StackElement_t *other)
void stack_element_print(StackElement_t *stkel, FILE *stream, String_t prefix)
void stack_element_free(StackElement_t *stkel)
char * String_t
Definition: string_t.h:55
void string_init(String_t *string)
Definition: string_t.c:46
bool string_equal(String_t *string, String_t *other)
Definition: string_t.c:71
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
CellIndex_t SourceLayerOffset
Definition: channel.h:102
String_t Id
Definition: die.h:73
CellIndex_t SourceLayerOffset
Definition: die.h:81
Floorplan_t Floorplan
Definition: die.h:94
Collections of all the structures that are needed for the thermal simulation.
Definition: dimensions.h:311
uint8_t NonUniform
Definition: dimensions.h:326
Non_uniform_cellList_t Cell_list
Definition: dimensions.h:337
String_t FileName
Definition: floorplan.h:72
String_t Id
Definition: layer.h:83
Structure used to store data about the stack element that compose the 2D/3D stack.
Definition: stack_element.h:93
StackElement_p Pointer
CellIndex_t NLayers
HeatSink_t * TopSink
CellIndex_t Offset
StackElementType_t SEType
HeatSink_t * BottomSink
double Temperature_t
Definition: types.h:71
double Source_t
Definition: types.h:77
StackElementType_t
Definition: types.h:325
@ TDICE_STACK_ELEMENT_NONE
Undefined type.
Definition: types.h:326
@ TDICE_STACK_ELEMENT_LAYER
Layer.
Definition: types.h:327
@ TDICE_STACK_ELEMENT_CHANNEL
Channel.
Definition: types.h:328
@ TDICE_STACK_ELEMENT_DIE
Die.
Definition: types.h:329
uint32_t Quantity_t
Definition: types.h:59
uint32_t CellIndex_t
Definition: types.h:213
Channel_t * Channel
Definition: stack_element.h:74
Layer_t * Layer
Definition: stack_element.h:72