3D-ICE 3.0.0
floorplan_matrix.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_matrix.h"
43
44/******************************************************************************/
45
47{
48 flpmatrix->ColumnPointers = NULL ;
49 flpmatrix->RowIndices = NULL ;
50 flpmatrix->Values = NULL ;
51 flpmatrix->NRows = (CellIndex_t) 0u ;
52 flpmatrix->NColumns = (CellIndex_t) 0u ;
53 flpmatrix->NNz = (CellIndex_t) 0u ;
54}
55
56/******************************************************************************/
57
59{
61
62 if (src->NRows == 0u || src->NColumns == 0u || src->NNz == 0u)
63
64 return ;
65
66 floorplan_matrix_build (dst, src->NRows, src->NColumns, src->NNz) ;
67
68 if (src->ColumnPointers != NULL)
69
70 memcpy (dst->ColumnPointers, src->ColumnPointers,
71 sizeof(CellIndex_t) * (src->NColumns + 1)) ;
72
73 if (src->RowIndices != NULL)
74
75 memcpy (dst->RowIndices, src->RowIndices,
76 sizeof(CellIndex_t) * src->NNz) ;
77
78 if (src->Values != NULL)
79
80 memcpy (dst->Values, src->Values,
81 sizeof(Source_t) * src->NNz) ;
82}
83
84/******************************************************************************/
85
87(
88 FloorplanMatrix_t *flpmatrix,
89 CellIndex_t nrows,
90 CellIndex_t ncolumns,
91 CellIndex_t nnz
92)
93{
94 flpmatrix->NRows = nrows ;
95 flpmatrix->NColumns = ncolumns ;
96 flpmatrix->NNz = nnz ;
97
98 flpmatrix->RowIndices = (CellIndex_t *) malloc (sizeof(CellIndex_t) * nnz) ;
99
100 if (flpmatrix->RowIndices == NULL)
101
102 return TDICE_FAILURE ;
103
104 flpmatrix->ColumnPointers = (CellIndex_t *) malloc (sizeof(CellIndex_t) * (ncolumns + 1)) ;
105
106 if (flpmatrix->ColumnPointers == NULL)
107 {
108 free (flpmatrix->RowIndices) ;
109 return TDICE_FAILURE ;
110 }
111
112 flpmatrix->Values = (Source_t *) malloc (sizeof(Source_t) * nnz) ;
113
114 if (flpmatrix->Values == NULL)
115 {
116 free (flpmatrix->ColumnPointers) ;
117 free (flpmatrix->RowIndices) ;
118 return TDICE_FAILURE ;
119 }
120
121 return TDICE_SUCCESS ;
122}
123
124/******************************************************************************/
125
127{
128 if (flpmatrix->ColumnPointers != NULL)
129
130 free (flpmatrix->ColumnPointers) ;
131
132 if (flpmatrix->RowIndices != NULL)
133
134 free (flpmatrix->RowIndices) ;
135
136 if (flpmatrix->Values != NULL)
137
138 free (flpmatrix->Values) ;
139
140 floorplan_matrix_init (flpmatrix) ;
141}
142
143/******************************************************************************/
144
146(
147 FloorplanMatrix_t *flpmatrix,
148 FloorplanElementList_t *list,
149 Dimensions_t *dimensions
150)
151{
152 CellIndex_t *c_pointers = flpmatrix->ColumnPointers ;
153 CellIndex_t *r_indices = flpmatrix->RowIndices ;
154 Source_t *values = flpmatrix->Values ;
155
156 *c_pointers++ = 0u ;
157
158 FloorplanElementListNode_t *flpeln ;
159
160 for (flpeln = floorplan_element_list_begin (list) ;
161 flpeln != NULL ;
162 flpeln = floorplan_element_list_next (flpeln))
163 {
164 FloorplanElement_t *flpel = floorplan_element_list_data (flpeln) ;
165
166 *c_pointers = *(c_pointers - 1) ;
167
168 ICElementListNode_t *iceln ;
169
170 for (iceln = ic_element_list_begin (&flpel->ICElements) ;
171 iceln != NULL ;
172 iceln = ic_element_list_next (iceln))
173 {
174 ICElement_t *icel = ic_element_list_data (iceln) ;
175
176 CellDimension_t width = 0.0 ;
177 CellDimension_t y = icel->SW_Y ;
178
179 CellIndex_t row ;
180 CellIndex_t column ;
181
182 for (row = icel->SW_Row ; row <= icel->NE_Row ; row++)
183 {
184 if (row < icel->NE_Row)
185
186 width = get_cell_location_y (dimensions, row + 1) - y ;
187
188 else
189
190 width = (icel->SW_Y + icel->Width) - y ;
191
192
193 CellDimension_t length = 0.0 ;
194 CellDimension_t x = icel->SW_X ;
195
196 for (column = icel->SW_Column ; column <= icel->NE_Column ; column++)
197 {
198 *r_indices++ = get_cell_offset_in_layer
199
200 (dimensions, row, column) ;
201
202 if (column < icel->NE_Column)
203
204 length = get_cell_location_x (dimensions, column + 1) - x ;
205
206 else
207
208 length = (icel->SW_X + icel->Length) - x ;
209
210 *values++ = (length * width) / flpel->Area ;
211
212 (*c_pointers)++ ;
213
214 x += length ;
215 }
216
217 y += width ;
218 }
219 }
220
221 c_pointers++ ;
222 }
223}
224
225/******************************************************************************/
226
228(
229 FloorplanMatrix_t *flpmatrix,
230 Source_t *x,
231 Source_t *b
232)
233{
234 CellIndex_t j, i;
235
236 if ( flpmatrix->NRows == 0 || flpmatrix->RowIndices == NULL
237 || flpmatrix->NColumns == 0 || flpmatrix->ColumnPointers == NULL
238 || flpmatrix->NNz == 0 || flpmatrix->Values == NULL)
239 {
240 fprintf (stderr, "matrix multiply error: matrix unset\n") ;
241
242 return ;
243 }
244
245 for (j = 0; j < flpmatrix->NColumns; ++j)
246
247 if (b[j] != 0.)
248
249 for (i = flpmatrix->ColumnPointers[j] ;
250 i < flpmatrix->ColumnPointers[j+1] ; ++i)
251
252 x [ flpmatrix->RowIndices [i] ] += b[j] * flpmatrix -> Values [i] ;
253
254 return ;
255}
256
257/******************************************************************************/
258
260{
261 FILE* file = fopen (file_name, "w") ;
262
263 if (file == NULL)
264 {
265 fprintf(stderr, "Cannot open file %s\n", file_name) ;
266 return ;
267 }
268
269 CellIndex_t row, column ;
270
271 for (column = 0 ; column < flpmatrix.NColumns ; column++)
272
273 for (row = flpmatrix.ColumnPointers[column] ;
274 row < flpmatrix.ColumnPointers[column + 1] ;
275 row++)
276
277 fprintf (file, "%9d\t%9d\t%32.24f\n",
278 flpmatrix.RowIndices[row] + 1, column + 1,
279 flpmatrix.Values[row]) ;
280
281 fclose (file) ;
282}
283
284/******************************************************************************/
ChipDimension_t get_cell_location_y(Dimensions_t *dimensions, CellIndex_t row_index)
Definition: dimensions.c:621
ChipDimension_t get_cell_location_x(Dimensions_t *dimensions, CellIndex_t column_index)
Definition: dimensions.c:602
CellIndex_t get_cell_offset_in_layer(Dimensions_t *dimensions, CellIndex_t row_index, CellIndex_t column_index)
Definition: dimensions.c:674
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_print(FloorplanMatrix_t flpmatrix, String_t file_name)
void floorplan_matrix_multiply(FloorplanMatrix_t *flpmatrix, Source_t *x, Source_t *b)
void floorplan_matrix_destroy(FloorplanMatrix_t *flpmatrix)
char * String_t
Definition: string_t.h:55
Collections of all the structures that are needed for the thermal simulation.
Definition: dimensions.h:311
Structure containing information about a floorplan element.
ChipDimension_t Area
ICElementList_t ICElements
Structure representing the matrix storing the coefficients of the floorplans tha scales power values ...
CellIndex_t * ColumnPointers
CellIndex_t * RowIndices
CellIndex_t NColumns
ChipDimension_t SW_Y
Definition: ic_element.h:73
ChipDimension_t SW_X
Definition: ic_element.h:69
ChipDimension_t Width
Definition: ic_element.h:81
ChipDimension_t Length
Definition: ic_element.h:77
CellIndex_t SW_Row
Definition: ic_element.h:94
CellIndex_t SW_Column
Definition: ic_element.h:99
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 Source_t
Definition: types.h:77
double CellDimension_t
Definition: types.h:177
uint32_t CellIndex_t
Definition: types.h:213