-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathtemperature_grid.c
6778 lines (6013 loc) · 269 KB
/
temperature_grid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#else
#include <strings.h>
#endif
#include <math.h>
#include "temperature_grid.h"
#include "flp.h"
#include "util.h"
#include "microchannel.h"
// export some of the matrices into CSV files
// WARNING : only use for small designs, as the files get prohibitively large easily
#define MAKE_CSVS 0
#if SUPERLU > 0
/* Lib for SuperLU */
#include "slu_ddefs.h"
#endif
double find_res(grid_model_t *model, int n1, int i1, int j1, int n2, int i2, int j2) {
double res;
// Testing using Heat Transfer Coefficient instead of thermal conductivities
double htc = 0.0;
double cw = model->width / model->cols;
double ch = model->height / model->rows;
double extra_res = 0;
// Whether or not Cell 1 or Cell 2 is a fluid cell
int is_fluid_cell1 = 0, is_fluid_cell2 = 0;
if(model->layers[n1].is_microchannel) {
htc = model->layers[n1].microchannel_config->htc;
if(IS_FLUID_CELL(model->layers[n1].microchannel_config, i1, j1))
is_fluid_cell1 = 1;
else
is_fluid_cell1 = 0;
}
else
is_fluid_cell1 = 0;
if(model->layers[n2].is_microchannel) {
htc = model->layers[n2].microchannel_config->htc;
if(IS_FLUID_CELL(model->layers[n2].microchannel_config, i2, j2))
is_fluid_cell2 = 1;
else
is_fluid_cell2 = 0;
}
else
is_fluid_cell2 = 0;
//fprintf(stderr, "htc = %e\n", htc);
// If one cell is a fluid cell and the other isn't, use HTC instead
if((is_fluid_cell1 && !is_fluid_cell2) || (!is_fluid_cell1 && is_fluid_cell2)) {
if(n1 == 0) {
// We know that n2 must be the fluid cell
res = find_res_3D(n1, i1, j1, model, 3) + (1.0 / (htc * ch * cw)) + extra_res;
//fprintf(stderr, "Res (%d, %d, %d) -> (%d, %d, %d) = %e\n", n1, i1, j1, n2, i2, j2, res);
}
else if(n2 == 0) {
// We know that n1 must be the fluid cell
res = find_res_3D(n2, i2, j2, model, 3) + (1.0 / (htc * ch * cw)) + extra_res;
//fprintf(stderr, "Res (%d, %d, %d) -> (%d, %d, %d) = %e\n", n1, i1, j1, n2, i2, j2, res);
}
else if(n1 != n2 && i1 == i2 && j1 == j2) {
if(is_fluid_cell1)
res = (find_res_3D(n2, i2, j2, model, 3) / 2.0) + (1.0 / (htc * ch * cw)) + extra_res;
else
res = (find_res_3D(n1, i1, j1, model, 3) / 2.0) + (1.0 / (htc * ch * cw)) + extra_res;
//fprintf(stderr, "Res (%d, %d, %d) -> (%d, %d, %d) = %e\n", n1, i1, j1, n2, i2, j2, res);
}
else if(n1 == n2 && i1 != i2 && j1 == j2) {
if(is_fluid_cell1)
res = (find_res_3D(n2, i2, j2, model, 1) / 2.0) + (1.0 / (htc * cw * model->layers[n1].thickness));
else
res = (find_res_3D(n1, i1, j1, model, 1) / 2.0) + (1.0 / (htc * cw * model->layers[n2].thickness));
//fprintf(stderr, "Res (%d, %d, %d) -> (%d, %d, %d) = %e\n", n1, i1, j1, n2, i2, j2, res);
}
else if(n1 == n2 && i1 == i2 && j1 != j2) {
if(is_fluid_cell1)
res = (find_res_3D(n2, i2, j2, model, 2) / 2.0) + (1.0 / (htc * ch * model->layers[n1].thickness));
else
res = (find_res_3D(n1, i1, j1, model, 2) / 2.0) + (1.0 / (htc * ch * model->layers[n2].thickness));
//fprintf(stderr, "Res (%d, %d, %d) -> (%d, %d, %d) = %e\n", n1, i1, j1, n2, i2, j2, res);
}
else {
fatal("find_res must be called on adjacent grid cells\n");
}
}
else if(model->config.detailed_3D_used == 1) {
if(n1 == 0 && i1 == i2 && j1 == j2) {
res = find_res_3D(n1, i1, j1, model, 3) + (find_res_3D(n2, i2, j2, model, 3) / 2.0);
}
else if(n2 == 0 && i1 == i2 && j1 == j2)
res = find_res_3D(n2, i2, j2, model, 3) + (find_res_3D(n1, i1, j1, model, 3) / 2.0);
else if(n1 != n2 && i1 == i2 && j1 == j2) {
res = (find_res_3D(n1, i1, j1, model, 3) / 2.0) + (find_res_3D(n2, i2, j2, model, 3) / 2.0);
}
else if(n1 == n2 && i1 != i2 && j1 == j2) {
res = (find_res_3D(n1, i1, j1, model, 1) / 2.0) + (find_res_3D(n2, i2, j2, model, 1) / 2.0);
}
else if(n1 == n2 && i1 == i2 && j1 != j2) {
res = (find_res_3D(n1, i1, j1, model, 2) / 2.0) + (find_res_3D(n2, i2, j2, model, 2) / 2.0);
}
else {
fatal("find_res must be called on adjacent grid cells\n");
}
}
else {
if(n1 < n2 && i1 == i2 && j1 == j2) {
res = model->layers[n1].rz;
}
else if(n1 > n2 && i1 == i2 && j1 == j2) {
res = model->layers[n2].rz;
}
else if(n1 == n2 && i1 != i2 && j1 == j2) {
res = (model->layers[n1].rx / 2.0) + (model->layers[n2].rx / 2.0);
}
else if(n1 == n2 && i1 == i2 && j1 != j2) {
res = (model->layers[n1].ry / 2.0) + (model->layers[n2].ry / 2.0);
}
else {
fatal("find_res must be called on adjacent grid cells\n");
}
}
//fprintf(stderr, "Cell (%d, %d, %d) to Cell (%d, %d, %d) : %e\n", n1, i1, j2, n2, i2, j2, res);
return res;
}
/*BU_3D: We modified R-C computations to return resistance or capacitance for a specified grid cell.
* If the grid cell does not have a unique value assigned in the flp file, we return the default values
* for that layer.the find_res_3D function will return the rx,ry,rz value of the grid.
* This function is used with the macros later.
* It will calculate the joint resistance only if there are values defined within the array or rx,ry,rz values. */
double find_res_3D(int n, int i, int j, grid_model_t *model,int choice)
{
int hasRes = model->layers[n].b2gmap[i][j]->hasRes;
//Returns the rx of the grid cell
if(choice==1){
if(!hasRes)
return model->layers[n].rx;
else
return model->layers[n].b2gmap[i][j]->rx;
}
//Returns the ry of the grid cell
else if(choice==2){
if(!hasRes)
return model->layers[n].ry;
else
return model->layers[n].b2gmap[i][j]->ry;
}
//Returns the rz of the grid cell
else if(choice==3){
if(!hasRes)
return model->layers[n].rz;
else
return model->layers[n].b2gmap[i][j]->rz;
}
return 0;
}//end->BU_3D
/* BU_3D: finds capacitance of 3D cell.*/
double find_cap_3D(int n, int i, int j, grid_model_t *model)
{
if (model->layers[n].b2gmap[i][j]->lock == TRUE) {
// Return the capacitance of the unit that meets the occupancy threshold
return model->layers[n].b2gmap[i][j]->capacitance;
} else {
// No unit that meets the occupancy threshold.
// Return the layer's (default) capacitance instead
return model->layers[n].c;
}
}//end->BU_3D
/* constructors */
/*BU_3D:
* - Added parameter do_detailed_3D to this function
* - Assign grid specific resistivty and capacitance if unit occupying the grid have resistivity & capacitance values
* - If occupancy is > OCCUPANCY_THRESHOLD% then use the values obtained from the resistivity & capacitance of the occupying unit */
blist_t *new_blist(int idx, double occupancy, double res, double specificHeat,int first,int do_detailed_3D, double cw, double ch, double thickness)
{
blist_t *ptr = (blist_t *) calloc (1, sizeof(blist_t));
if (!ptr)
fatal("memory allocation error\n");
ptr->idx = idx;
ptr->occupancy = occupancy;
ptr->next = NULL;
/*BU_3D:
* - If occupancy is greater than OCCUPANCY_THRESHOLD% lock in thermal resistance values
* - Else assume 50/50 occupancy*/
if(first && do_detailed_3D){
if(occupancy >= OCCUPANCY_THRESHOLD){
ptr->lock=TRUE;
ptr->rx = getr(1/res, cw, ch * thickness);
ptr->ry = getr(1/res, ch, cw * thickness);
ptr->rz = getr(1/res, thickness, cw * ch);
ptr->capacitance = getcap(specificHeat, thickness, cw * ch);
//fprintf(stderr, "1/res = %e, cw = %e, ch = %e, thickness = %e, occupancy = %e\n", 1/res, cw, ch, thickness, occupancy);
}
else{
ptr->lock=FALSE;
ptr->rx = 1 / ((1 / getr(1 / res, cw, ch * thickness)) * occupancy);
ptr->ry = 1 / ((1 / getr(1 / res, ch, cw * thickness)) * occupancy);
ptr->rz = 1 / ((1 / getr(1 / res, thickness, cw * ch)) * occupancy);
ptr->capacitance = getcap(specificHeat, thickness, cw * ch);
}
return ptr;
}
/*end->BU_3D*/
return ptr;
}
blist_t ***new_b2gmap(int rows, int cols)
{
int i;
blist_t ***b2gmap;
b2gmap = (blist_t ***) calloc (rows, sizeof(blist_t **));
b2gmap[0] = (blist_t **) calloc (rows * cols, sizeof(blist_t *));
if (!b2gmap || !b2gmap[0])
fatal("memory allocation error\n");
for(i=1; i < rows; i++)
b2gmap[i] = b2gmap[0] + cols * i;
return b2gmap;
}
/* destructor */
void delete_b2gmap(blist_t ***b2gmap, int rows, int cols)
{
int i, j;
blist_t *ptr, *temp;
/* free the linked list */
for(i=0; i < rows; i++)
for(j=0; j < cols; j++) {
ptr = b2gmap[i][j];
while(ptr) {
temp = ptr->next;
free(ptr);
ptr = temp;
}
}
/* free the array space */
free(b2gmap[0]);
free(b2gmap);
}
/* re-initialize */
void reset_b2gmap(grid_model_t *model, layer_t *layer)
{
int i, j;
blist_t *ptr, *temp;
/* free the linked list */
for(i=0; i < model->rows; i++)
for(j=0; j < model->cols; j++) {
ptr = layer->b2gmap[i][j];
while(ptr) {
temp = ptr->next;
free(ptr);
ptr = temp;
}
layer->b2gmap[i][j] = NULL;
}
}
/* create a linked list node and append it at the end
* BU_3D: The parameter int do_detailed_3D is added to this function*/
void blist_append(blist_t *head, int idx, double occupancy,double res, double specificHeat,int first, int do_detailed_3D,double cw, double ch, double thickness)
{
/*BU_3D:
* - If a block occupies a grid cell by OCCUPANCY_THRESHOLD% or more, the grid cell gets that blocks thermal resistance values
* otherwise, 50/50 sharing is assumed with whichever block is occupying the other portion.
* - Add resistances in parallel */
if(do_detailed_3D && (head->lock!=TRUE)){
if(occupancy >= OCCUPANCY_THRESHOLD){
head->lock=TRUE;
head->rx = getr(1/res, cw, ch * thickness);
head->ry = getr(1/res, ch, cw * thickness);
head->rz = getr(1/res, thickness, cw * ch);
head->capacitance = getcap(specificHeat, thickness, cw * ch);
}
else{
head->rx = 1/((1/head->rx) + ((1 / getr(1 / res, cw, ch * thickness)) * occupancy));
head->ry = 1/((1/head->ry) + ((1 / getr(1 / res, ch, cw * thickness)) * occupancy));
head->rz = 1/((1/head->rz) + ((1 / getr(1 / res, thickness, cw * ch)) * occupancy));
head->lock=FALSE;
}
}
/*end->BU_3D*/
blist_t *tail = NULL;
if(!head)
fatal("blist_append called with empty list\n");
/* traverse till the end */
for(; head; head = head->next)
tail = head;
/* append
* BU_3D: added do_detailed_3D to this function call*/
tail->next = new_blist(idx, occupancy, res, specificHeat, first, do_detailed_3D, cw, ch, thickness);
}
/* compute the power/temperature average weighted by occupancies */
double blist_avg(blist_t *ptr, flp_t *flp, double *v, int type)
{
double val = 0.0;
for(; ptr; ptr = ptr->next) {
if (type == V_POWER)
val += ptr->occupancy * v[ptr->idx] / (flp->units[ptr->idx].width *
flp->units[ptr->idx].height);
else if (type == V_TEMP)
val += ptr->occupancy * v[ptr->idx];
else
fatal("unknown vector type\n");
}
return val;
}
/* setup the block and grid mapping data structures */
void set_bgmap(grid_model_t *model, layer_t *layer)
{
/* i1, i2, j1 and j2 are indices of the boundary grid cells */
int i, j, u, i1, i2, j1, j2;
/* shortcuts for cell width(cw) and cell height(ch) */
double cw = model->width / model->cols;
double ch = model->height / model->rows;
/* shortcut for unit resistivity & specific heat*/
double sh,res;
/* initialize */
reset_b2gmap(model, layer);
/* for each functional unit */
for(u=0; u < layer->flp->n_units; u++) {
/* shortcuts for unit boundaries */
double lu = layer->flp->units[u].leftx;
double ru = lu + layer->flp->units[u].width;
double bu = layer->flp->units[u].bottomy;
double tu = bu + layer->flp->units[u].height;
/* top index (lesser row) = rows - ceil (topy / cell height) */
i1 = model->rows - tolerant_ceil(tu/ch);
/* bottom index (greater row) = rows - floor (bottomy / cell height) */
i2 = model->rows - tolerant_floor(bu/ch);
/* left index = floor (leftx / cell width) */
j1 = tolerant_floor(lu/cw);
/* right index = ceil (rightx / cell width) */
j2 = tolerant_ceil(ru/cw);
/* sanity check */
if((i1 < 0) || (j1 < 0))
fatal("negative grid cell start index!\n");
if((i2 > model->rows) || (j2 > model->cols))
fatal("grid cell end index out of bounds!\n");
if((i1 >= i2) || (j1 >= j2))
fatal("invalid floorplan spec or grid resolution\n");
/* setup g2bmap */
layer->g2bmap[u].i1 = i1;
layer->g2bmap[u].i2 = i2;
layer->g2bmap[u].j1 = j1;
layer->g2bmap[u].j2 = j2;
/* setup b2gmap */
/* for each grid cell in this unit */
for(i=i1; i < i2; i++) {
for(j=j1; j < j2; j++) {
/* grid cells fully overlapped by this unit */
/*BU_3D*/
// - Load values from floorplan into each grid
if(layer->flp->units[u].hasRes && model->config.detailed_3D_used)
res = layer->flp->units[u].resistivity;
else
res = 1/layer->k;
if(layer->flp->units[u].hasSh && model->config.detailed_3D_used)
sh = layer->flp->units[u].specificheat;
else
sh = layer->sp;
/*end->BU_3D*/
if ((i > i1) && (i < i2-1) && (j > j1) && (j < j2-1)) {
/* first unit in the list */
if (!layer->b2gmap[i][j]){
layer->b2gmap[i][j] = new_blist(u, 1.0,res,sh,1,model->config.detailed_3D_used,cw,ch,layer->thickness);
layer->b2gmap[i][j]->hasRes = TRUE;//BU_3D assign hasRes to the b2gdata structure
layer->b2gmap[i][j]->hasCap = layer->flp->units[u].hasSh;//BU_3D assign hasSh to the b2gdata structure
}
else {
/* this should not occur since the grid cell is
* fully covered and hence, no other unit should
* be sharing it */
blist_append(layer->b2gmap[i][j], u, 1.0,res,sh,1,model->config.detailed_3D_used,cw,ch,layer->thickness);
warning("overlap of functional blocks?\n");
}
/* boundary grid cells partially overlapped by this unit */
} else {
/* shortcuts for cell boundaries */
double lc = j * cw, rc = (j+1) * cw;
double tc = model->height - i * ch;
double bc = model->height - (i+1) * ch;
/* shortcuts for overlap width and height */
double oh = (MIN(tu, tc) - MAX(bu, bc));
double ow = (MIN(ru, rc) - MAX(lu, lc));
double occupancy;
/* overlap tolerance */
if (eq(oh/ch, 0))
oh = 0;
else if (eq(oh/ch, 1))
oh = ch;
if (eq(ow/cw, 0))
ow = 0;
else if (eq(ow/cw, 1))
ow = cw;
occupancy = (oh * ow) / (ch * cw);
if (oh < 0 || ow < 0)
fatal("negative overlap!\n");
/* first unit in the list */
if (!layer->b2gmap[i][j]){
layer->b2gmap[i][j] = new_blist(u, occupancy,res,sh,1,model->config.detailed_3D_used,cw,ch,layer->thickness);
layer->b2gmap[i][j]->hasRes = TRUE;//BU_3D assign hasRes to the b2gdata structure
layer->b2gmap[i][j]->hasCap = layer->flp->units[u].hasSh;//BU_3D assign hasSh to the b2gdata structure
}
else
/* append at the end */
blist_append(layer->b2gmap[i][j], u, occupancy,res,sh,0,model->config.detailed_3D_used,cw,ch,layer->thickness);
}
}
}
}
}
/* populate default set of layers */
void populate_default_layers(grid_model_t *model, flp_t *flp_default)
{
int silidx, intidx, metalidx, c4idx;
if (!model->config.model_secondary) {
silidx = LAYER_SI;
intidx = LAYER_INT;
} else {
silidx = SEC_PACK_LAYERS + SEC_CHIP_LAYERS + LAYER_SI;
intidx = SEC_PACK_LAYERS + SEC_CHIP_LAYERS + LAYER_INT;
c4idx = SEC_PACK_LAYERS + LAYER_C4;
metalidx = SEC_PACK_LAYERS + LAYER_METAL;
}
/* silicon */
model->layers[silidx].no = silidx;
model->layers[silidx].has_lateral = TRUE;
model->layers[silidx].has_power = TRUE;
model->layers[silidx].k = model->config.k_chip;
model->layers[silidx].thickness = model->config.t_chip;
model->layers[silidx].sp = model->config.p_chip;
model->layers[silidx].flp = flp_default;
model->layers[silidx].b2gmap = new_b2gmap(model->rows, model->cols);
model->layers[silidx].g2bmap = (glist_t *) calloc(flp_default->n_units, sizeof(glist_t));
if (!model->layers[silidx].g2bmap)
fatal("memory allocation error\n");
/* interface material */
model->layers[intidx].no = intidx;
model->layers[intidx].has_lateral = TRUE;
model->layers[intidx].has_power = FALSE;
model->layers[intidx].k = model->config.k_interface;
model->layers[intidx].thickness = model->config.t_interface;
model->layers[intidx].sp = model->config.p_interface;
model->layers[intidx].flp = flp_default;
model->layers[intidx].b2gmap = model->layers[silidx].b2gmap;
model->layers[intidx].g2bmap = model->layers[silidx].g2bmap;
if (model->config.model_secondary) {
/* metal layer */
model->layers[metalidx].no = metalidx;
model->layers[metalidx].has_lateral = TRUE;
model->layers[metalidx].has_power = FALSE;
model->layers[metalidx].k = K_METAL;
model->layers[metalidx].thickness = model->config.t_metal;
model->layers[metalidx].sp = SPEC_HEAT_METAL;
model->layers[metalidx].flp = flp_default;
model->layers[metalidx].b2gmap = model->layers[silidx].b2gmap;
model->layers[metalidx].g2bmap = model->layers[silidx].g2bmap;
/* C4/underfill layer*/
model->layers[c4idx].no = c4idx;
model->layers[c4idx].has_lateral = TRUE;
model->layers[c4idx].has_power = FALSE;
model->layers[c4idx].k = K_C4;
model->layers[c4idx].thickness = model->config.t_c4;
model->layers[c4idx].sp = SPEC_HEAT_C4;
model->layers[c4idx].flp = flp_default;
model->layers[c4idx].b2gmap = model->layers[silidx].b2gmap;
model->layers[c4idx].g2bmap = model->layers[silidx].g2bmap;
}
}
/* populate the package layers */
void append_package_layers(grid_model_t *model)
{
/* shortcut */
int nl = model->n_layers;
int silidx, spidx, hsidx, subidx, solderidx, pcbidx;
spidx = nl - DEFAULT_PACK_LAYERS + LAYER_SP;
hsidx = nl - DEFAULT_PACK_LAYERS + LAYER_SINK;
/* spreader */
model->layers[spidx].no = spidx;
model->layers[spidx].has_lateral = TRUE;
model->layers[spidx].has_power = FALSE;
model->layers[spidx].k = model->config.k_spreader;
model->layers[spidx].thickness = model->config.t_spreader;
model->layers[spidx].sp = model->config.p_spreader;
model->layers[spidx].flp = model->layers[spidx-1].flp;
model->layers[spidx].b2gmap = model->layers[spidx-1].b2gmap;
model->layers[spidx].g2bmap = model->layers[spidx-1].g2bmap;
/* heatsink */
model->layers[hsidx].no = hsidx;
model->layers[hsidx].has_lateral = TRUE;
model->layers[hsidx].has_power = FALSE;
model->layers[hsidx].k = model->config.k_sink;
model->layers[hsidx].thickness = model->config.t_sink;
model->layers[hsidx].sp = model->config.p_sink;
model->layers[hsidx].flp = model->layers[spidx-1].flp;
model->layers[hsidx].b2gmap = model->layers[spidx-1].b2gmap;
model->layers[hsidx].g2bmap = model->layers[spidx-1].g2bmap;
/* BU_3D: If detailed_3d option is on, the hasRes & hasCap variables must be set false in the b2gmap*/
if(model->config.detailed_3D_used){
model->layers[spidx].b2gmap = new_b2gmap(model->rows, model->cols);
model->layers[hsidx].b2gmap = model->layers[spidx].b2gmap;
}
/*end->BU_3D*/
if (model->config.model_secondary) {
if(model->has_lcf)
silidx = SEC_PACK_LAYERS;
else
silidx = SEC_PACK_LAYERS + SEC_CHIP_LAYERS + LAYER_SI;
subidx = LAYER_SUB;
solderidx = LAYER_SOLDER;
pcbidx = LAYER_PCB;
/* package substrate */
model->layers[subidx].no = subidx;
model->layers[subidx].has_lateral = TRUE;
model->layers[subidx].has_power = FALSE;
model->layers[subidx].k = K_SUB;
model->layers[subidx].thickness = model->config.t_sub;
model->layers[subidx].sp = SPEC_HEAT_SUB;
model->layers[subidx].flp = model->layers[silidx].flp;
model->layers[subidx].b2gmap = model->layers[silidx].b2gmap;
model->layers[subidx].g2bmap = model->layers[silidx].g2bmap;
/* solder balls */
model->layers[solderidx].no = solderidx;
model->layers[solderidx].has_lateral = TRUE;
model->layers[solderidx].has_power = FALSE;
model->layers[solderidx].k = K_SOLDER;
model->layers[solderidx].thickness = model->config.t_solder;
model->layers[solderidx].sp = SPEC_HEAT_SOLDER;
model->layers[solderidx].flp = model->layers[silidx].flp;
model->layers[solderidx].b2gmap = model->layers[silidx].b2gmap;
model->layers[solderidx].g2bmap = model->layers[silidx].g2bmap;
/* PCB */
model->layers[pcbidx].no = pcbidx;
model->layers[pcbidx].has_lateral = TRUE;
model->layers[pcbidx].has_power = FALSE;
model->layers[pcbidx].k = K_PCB;
model->layers[pcbidx].thickness = model->config.t_pcb;
model->layers[pcbidx].sp = SPEC_HEAT_PCB;
model->layers[pcbidx].flp = model->layers[silidx].flp;
model->layers[pcbidx].b2gmap = model->layers[silidx].b2gmap;
model->layers[pcbidx].g2bmap = model->layers[silidx].g2bmap;
if(model->config.detailed_3D_used){
model->layers[subidx].b2gmap = new_b2gmap(model->rows, model->cols);
model->layers[solderidx].b2gmap = model->layers[subidx].b2gmap;
model->layers[pcbidx].b2gmap = model->layers[subidx].b2gmap;
}
}
}
/* parse the layer file open for reading */
void parse_layer_file(grid_model_t *model, FILE *fp, materials_list_t *materials_list)
{
char line[LINE_SIZE], *ptr, cval;
int count, i = 0, field = LCF_SNO, ival;
double dval;
int base, inner_layers;
if (!model->config.model_secondary){
base = 0;
inner_layers = model->n_layers - DEFAULT_PACK_LAYERS;
}
else{
base = SEC_PACK_LAYERS;
inner_layers = model->n_layers - DEFAULT_PACK_LAYERS - SEC_PACK_LAYERS;
}
fseek(fp, 0, SEEK_SET);
count = 0;
while (!feof(fp)) {
fgets(line, LINE_SIZE, fp);
if (feof(fp))
break;
/* ignore comments and empty lines */
ptr = strtok(line, " \r\t\n");
if (!ptr || ptr[0] == '#')
continue;
switch (field)
{
case LCF_SNO:
if (sscanf(ptr, "%d", &ival) != 1)
fatal("invalid layer number\n");
if(ival >= inner_layers || ival < 0)
fatal("layer number must be >= 0 and < no. of layers specified\n");
if (model->layers[base+ival].no != 0)
fatal("layer numbers must be unique\n");
i = base + ival;
model->layers[i].no = base + ival;
field = LCF_LATERAL;
break;
case LCF_LATERAL:
if (sscanf(ptr, "%c", &cval) != 1)
fatal("invalid layer heat flow indicator\n");
if (cval == 'Y' || cval == 'y')
model->layers[i].has_lateral = TRUE;
else if (cval == 'N' || cval == 'n')
model->layers[i].has_lateral = FALSE;
else
fatal("invalid layer heat flow indicator\n");
field = LCF_POWER;
break;
case LCF_POWER:
if (sscanf(ptr, "%c", &cval) != 1)
fatal("invalid layer power dissipation indicator\n");
if (cval == 'Y' || cval == 'y')
model->layers[i].has_power = TRUE;
else if (cval == 'N' || cval == 'n')
model->layers[i].has_power = FALSE;
else
fatal("invalid layer power dissipation indicator\n");
field = LCF_SP;
break;
case LCF_SP:
if (sscanf(ptr, "%lf", &dval) != 1) {
// check if material was specified instead
char material_name[STR_SIZE];
if(sscanf(ptr, "%s", material_name) != 1)
fatal("invalid: neither specific heat nor material name was specified\n");
model->layers[i].sp = get_material_volumetric_heat_capacity(materials_list, material_name);
model->layers[i].k = get_material_thermal_conductivity(materials_list, material_name);
field = LCF_THICK;
break;
}
else {
model->layers[i].sp = dval;
field = LCF_RHO;
break;
}
case LCF_RHO:
if (sscanf(ptr, "%lf", &dval) != 1)
fatal("invalid resistivity\n");
model->layers[i].k = 1.0 / dval;
field = LCF_THICK;
break;
case LCF_THICK:
if (sscanf(ptr, "%lf", &dval) != 1)
fatal("invalid thickness\n");
model->layers[i].thickness = dval;
field = LCF_FLP;
break;
case LCF_FLP:
/* Check if layer is a microchannel layer */
if(strstr(ptr, NETWORK_EXTENSION) && model->use_microchannels) {
model->layers[i].is_microchannel = TRUE;
model->layers[i].microchannel_config = malloc(sizeof(microchannel_config_t));
// Copy over user-defined parameters
copy_microchannel(model->layers[i].microchannel_config, model->default_microchannel_config);
// Fill in parameters derived from model
model->layers[i].microchannel_config->cell_width = model->width / model->cols;
model->layers[i].microchannel_config->cell_height = model->height / model->rows;
model->layers[i].microchannel_config->cell_thickness = model->layers[i].thickness;
model->layers[i].microchannel_config->num_rows = model->rows;
model->layers[i].microchannel_config->num_columns = model->cols;
// Fill in network file from LCF
strcpy(model->layers[i].microchannel_config->network_file, ptr);
// Build internal representation of microchannel network and create
// floorplan
microchannel_build_network(model->layers[i].microchannel_config);
model->layers[i].flp = read_flp(model->layers[i].microchannel_config->floorplan_file, FALSE, FALSE);
}
else if(strstr(ptr, NETWORK_EXTENSION) && !model->use_microchannels) {
fatal("Floorplan file has microchannel extension but use_microchannels = 0\n");
}
else {
model->layers[i].flp = read_flp(ptr, FALSE, FALSE);
model->layers[i].is_microchannel = FALSE;
}
/* first layer */
if (count < LCF_NPARAMS) {
model->width = get_total_width(model->layers[i].flp);
model->height = get_total_height(model->layers[i].flp);
} else if(!eq(model->width, get_total_width(model->layers[i].flp)) ||
!eq(model->height, get_total_height(model->layers[i].flp)))
fatal("width and height differ across layers\n");
field = LCF_SNO;
break;
default:
fatal("invalid field id\n");
break;
}
count++;
}
/* allocate the block-grid maps */
for(i=base; i < (base+inner_layers); i++) {
model->layers[i].b2gmap = new_b2gmap(model->rows, model->cols);
model->layers[i].g2bmap = (glist_t *) calloc(model->layers[i].flp->n_units,
sizeof(glist_t));
if (!model->layers[i].g2bmap)
fatal("memory allocation error\n");
}
}
/* count number of layers in LCF file and make sure the basic formatting is correct */
int count_num_layers(FILE *fp) {
char line[LINE_SIZE], *ptr, cval, sval[STR_SIZE];
int ival, number_layers = 0, field = LCF_SNO;
double dval;
fseek(fp, 0, SEEK_SET);
while (!feof(fp)) {
fgets(line, LINE_SIZE, fp);
if (feof(fp))
break;
/* ignore comments and empty lines */
ptr = strtok(line, " \r\t\n");
if (!ptr || ptr[0] == '#')
continue;
switch (field) {
case LCF_SNO:
if (sscanf(ptr, "%d", &ival) != 1)
fatal("invalid layer number\n");
field = LCF_LATERAL;
break;
case LCF_LATERAL:
if (sscanf(ptr, "%c", &cval) != 1)
fatal("invalid layer heat flow indicator\n");
field = LCF_POWER;
break;
case LCF_POWER:
if (sscanf(ptr, "%c", &cval) != 1)
fatal("invalid layer power dissipation indicator\n");
field = LCF_SP;
break;
case LCF_SP:
if (sscanf(ptr, "%lf", &dval) != 1) {
// check if material was specified instead
if(sscanf(ptr, "%s", sval) != 1)
fatal("invalid: neither specific heat nor material name was specified\n");
field = LCF_THICK;
break;
}
else {
field = LCF_RHO;
break;
}
case LCF_RHO:
if (sscanf(ptr, "%lf", &dval) != 1)
fatal("invalid resistivity\n");
field = LCF_THICK;
break;
case LCF_THICK:
if (sscanf(ptr, "%lf", &dval) != 1)
fatal("invalid thickness\n");
field = LCF_FLP;
break;
case LCF_FLP:
if(sscanf(ptr, "%s", sval) != 1)
fatal("invalid floorplan file");
number_layers++;
field = LCF_SNO;
break;
default:
fatal("invalid field id\n");
break;
}
}
return number_layers;
}
/* populate layer info either from the default floorplan or from
* the layer configuration file (lcf)
*/
void populate_layers_grid(grid_model_t *model, flp_t *flp_default, materials_list_t *materials_list)
{
char str[STR_SIZE];
FILE *fp = NULL;
/* lcf file specified */
if (model->has_lcf) {
if (!strcasecmp(model->config.grid_layer_file, "stdin"))
fp = stdin;
else
fp = fopen (model->config.grid_layer_file, "r");
if (!fp) {
strncpy(str, "Unable to open file ", STR_SIZE);
strncat(str, model->config.grid_layer_file, STR_SIZE - strlen(str));
strncat(str, "\n", STR_SIZE - strlen(str));
fatal(str);
}
}
/* compute the no. of layers */
if (!model->config.model_secondary) {
if (model->has_lcf) {
model->n_layers = count_num_layers(fp);
} else
model->n_layers = DEFAULT_CHIP_LAYERS;
} else {
if (model->has_lcf) {
model->n_layers = count_num_layers(fp);
} else
model->n_layers = DEFAULT_CHIP_LAYERS + SEC_CHIP_LAYERS;
}
/* allocate initial memory including package layers */
if (!model->config.model_secondary) {
model->n_layers += DEFAULT_PACK_LAYERS;
model->layers = (layer_t *) calloc (model->n_layers, sizeof(layer_t));
if (!model->layers)
fatal("memory allocation error\n");
} else {
model->n_layers += DEFAULT_PACK_LAYERS + SEC_PACK_LAYERS;
model->layers = (layer_t *) calloc (model->n_layers, sizeof(layer_t));
if (!model->layers)
fatal("memory allocation error\n");
}
/* read in values from the lcf when specified */
if (model->has_lcf) {
parse_layer_file(model, fp, materials_list);
} else {
/* default set of layers */
populate_default_layers(model, flp_default);
}
/* append the package layers */
append_package_layers(model);
if (model->has_lcf && fp != stdin)
fclose(fp);
}
/* constructor */
grid_model_t *alloc_grid_model(thermal_config_t *config, flp_t *flp_default, microchannel_config_t *microchannel_config, materials_list_t *materials_list, int do_detailed_3D, int use_microchannels)
{
int i;
grid_model_t *model;
#if SUPERLU < 1
if (config->grid_rows & (config->grid_rows-1) ||
config->grid_cols & (config->grid_cols-1))
fatal("grid rows and columns should both be powers of two\n");
#endif
model = (grid_model_t *) calloc (1, sizeof(grid_model_t));
if (!model)
fatal("memory allocation error\n");
model->config = *config;
model->rows = config->grid_rows;
model->cols = config->grid_cols;
model->use_microchannels = use_microchannels;
model->default_microchannel_config = microchannel_config;
if(do_detailed_3D) //BU_3D: check if heterogenous RC model is on
model->config.detailed_3D_used = TRUE;
if(!strcasecmp(model->config.grid_map_mode, GRID_AVG_STR))
model->map_mode = GRID_AVG;
else if(!strcasecmp(model->config.grid_map_mode, GRID_MIN_STR))
model->map_mode = GRID_MIN;
else if(!strcasecmp(model->config.grid_map_mode, GRID_MAX_STR))
model->map_mode = GRID_MAX;
else if(!strcasecmp(model->config.grid_map_mode, GRID_CENTER_STR))
model->map_mode = GRID_CENTER;
else
fatal("unknown mapping mode\n");
/* layer configuration file specified? */
if(strcmp(model->config.grid_layer_file, NULLFILE))
model->has_lcf = TRUE;
else {
model->has_lcf = FALSE;
model->base_n_units = flp_default->n_units;
}
/* get layer information */
populate_layers_grid(model, flp_default, materials_list);
/* count the total no. of blocks */
model->total_n_blocks = 0;
for(i=0; i < model->n_layers; i++)
model->total_n_blocks += model->layers[i].flp->n_units;
/* allocate internal state */
model->last_steady = new_grid_model_vector(model);
model->last_trans = new_grid_model_vector(model);
return model;
}
void populate_R_model_grid(grid_model_t *model, flp_t *flp)
{
int i, base;
double cw, ch;
int inner_layers;
int silidx, hsidx;
int model_secondary = model->config.model_secondary;
int nl = model->n_layers;
if(model_secondary){
if(model->has_lcf){
base = SEC_PACK_LAYERS;
inner_layers = nl - DEFAULT_PACK_LAYERS - SEC_PACK_LAYERS;
silidx = SEC_PACK_LAYERS + LAYER_SI;
}
else{
base = SEC_CHIP_LAYERS + SEC_PACK_LAYERS;
inner_layers = nl - DEFAULT_PACK_LAYERS - SEC_PACK_LAYERS - SEC_CHIP_LAYERS;
silidx = SEC_PACK_LAYERS + SEC_CHIP_LAYERS + LAYER_SI;
}
}
else{
base = 0;
inner_layers = nl - DEFAULT_PACK_LAYERS;
silidx = LAYER_SI;
}
/* setup the block-grid maps; flp parameter is ignored */
if(model->has_lcf)
for(i=base; i < (base+inner_layers); i++){
set_bgmap(model, &model->layers[i]);
}
/* only the silicon layer has allocated space for the maps.
* all the rest just point to it. so it is sufficient to
* setup the block-grid map for the silicon layer alone.
* further, for default layer configuration, the `flp'
* parameter should be the same as that of the silicon
* layer. finally, the chip width and height information
* need to be populated for default layer configuration
*/
else {
if (flp != model->layers[silidx].flp)
fatal("mismatch between the floorplan and the thermal model\n");
model->width = get_total_width(flp);
model->height = get_total_height(flp);
set_bgmap(model, &model->layers[silidx]);
}
/* BU_3D: If detailed 3D is used we need to set variables in the b2gmap of the spreader layer*/
if(model->config.detailed_3D_used){