Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
uvahotspot
GitHub Repository: uvahotspot/HotSpot
Path: blob/master/hotfloorplan.c
612 views
1
/*
2
* HotFloorplan is a temperature-aware floorplanning tool
3
* that can be easily modified to optimize for any arbitrary
4
* metric. This program reads in a floorplan description
5
* file that has the area, aspect ratio and connectivity
6
* information of a set of functional blocks. It also reads
7
* in a file with the average power dissipation values for
8
* those blocks and outputs the best floorplan it can find
9
* that optimizes the specified metric.
10
*/
11
#include <stdio.h>
12
#include <string.h>
13
#ifdef _MSC_VER
14
#define strcasecmp _stricmp
15
#define strncasecmp _strnicmp
16
#else
17
#include <strings.h>
18
#endif
19
20
#include "flp.h"
21
#include "temperature.h"
22
#include "materials.h"
23
#include "wire.h"
24
#include "util.h"
25
#include "hotfloorplan.h"
26
27
void usage(int argc, char **argv)
28
{
29
fprintf(stdout, "Usage: %s -f <file> -p <file> -o <file> [-c <file>] [-d <file>] [options]\n", argv[0]);
30
fprintf(stdout, "Finds a thermally-aware floorplan for the given functional blocks.\n");
31
fprintf(stdout, "Options:(may be specified in any order, within \"[]\" means optional)\n");
32
fprintf(stdout, " -f <file>\tfloorplan description input file (e.g. ev6.desc)\n");
33
fprintf(stdout, " -p <file>\tpower input file (e.g. avg.p)\n");
34
fprintf(stdout, " -o <file>\tfloorplan output file\n");
35
fprintf(stdout, " [-c <file>]\tinput configuration parameters from file (e.g. hotspot.config)\n");
36
fprintf(stdout, " [-d <file>]\toutput configuration parameters to file\n");
37
fprintf(stdout, " [options]\tzero or more options of the form \"-<name> <value>\",\n");
38
fprintf(stdout, " \toverride the options from config file\n");
39
}
40
41
/*
42
* parse a table of name-value string pairs and add the configuration
43
* parameters to 'config'
44
*/
45
void global_config_from_strs(global_config_t *config, str_pair *table, int size)
46
{
47
int idx;
48
if ((idx = get_str_index(table, size, "f")) >= 0) {
49
if(sscanf(table[idx].value, "%s", config->flp_desc) != 1)
50
fatal("invalid format for configuration parameter flp_desc\n");
51
} else {
52
fatal("required parameter flp_desc missing. check usage\n");
53
}
54
if ((idx = get_str_index(table, size, "p")) >= 0) {
55
if(sscanf(table[idx].value, "%s", config->power_in) != 1)
56
fatal("invalid format for configuration parameter power_in\n");
57
} else {
58
fatal("required parameter power_in missing. check usage\n");
59
}
60
if ((idx = get_str_index(table, size, "o")) >= 0) {
61
if(sscanf(table[idx].value, "%s", config->flp_out) != 1)
62
fatal("invalid format for configuration parameter flp_out\n");
63
} else {
64
fatal("required parameter flp_out missing. check usage\n");
65
}
66
if ((idx = get_str_index(table, size, "c")) >= 0) {
67
if(sscanf(table[idx].value, "%s", config->config) != 1)
68
fatal("invalid format for configuration parameter config\n");
69
} else {
70
strcpy(config->config, NULLFILE);
71
}
72
if ((idx = get_str_index(table, size, "d")) >= 0) {
73
if(sscanf(table[idx].value, "%s", config->dump_config) != 1)
74
fatal("invalid format for configuration parameter dump_config\n");
75
} else {
76
strcpy(config->dump_config, NULLFILE);
77
}
78
if ((idx = get_str_index(table, size, "materials_file")) >= 0) {
79
if(sscanf(table[idx].value, "%s", config->materials_file) != 1)
80
fatal("invalid format for configuration parameter materials_file\n");
81
} else {
82
strcpy(config->materials_file, NULLFILE);
83
}
84
}
85
86
/*
87
* convert config into a table of name-value pairs. returns the no.
88
* of parameters converted
89
*/
90
int global_config_to_strs(global_config_t *config, str_pair *table, int max_entries)
91
{
92
if (max_entries < 5)
93
fatal("not enough entries in table\n");
94
95
sprintf(table[0].name, "f");
96
sprintf(table[1].name, "p");
97
sprintf(table[2].name, "o");
98
sprintf(table[3].name, "c");
99
sprintf(table[4].name, "d");
100
101
sprintf(table[0].value, "%s", config->flp_desc);
102
sprintf(table[1].value, "%s", config->power_in);
103
sprintf(table[2].value, "%s", config->flp_out);
104
sprintf(table[3].value, "%s", config->config);
105
sprintf(table[4].value, "%s", config->dump_config);
106
107
return 5;
108
}
109
110
void print_wire_delays(flp_t *flp, double frequency)
111
{
112
int i, j;
113
double delay_g, delay_i;
114
fprintf(stdout, "printing wire delay between blocks for global and intermediate metal layers:\n");
115
fprintf(stdout, "(in %.1f GHz cycles)\n", frequency / 1.0e9);
116
fprintf(stdout, "name1\tname2\tglobal\tintermediate\n");
117
for (i=0; i < flp->n_units-1; i++)
118
for (j=i+1; j < flp->n_units; j++)
119
if (flp->wire_density[i][j]) {
120
delay_g = wire_length2delay(get_manhattan_dist(flp, i, j), WIRE_GLOBAL);
121
delay_i = wire_length2delay(get_manhattan_dist(flp, i, j), WIRE_INTER);
122
fprintf(stdout, "%s\t%s\t%.3f\t%.3f\n", flp->units[i].name, flp->units[j].name,
123
frequency * delay_g, frequency * delay_i);
124
}
125
}
126
127
/* main function for the floorplanner */
128
int main(int argc, char **argv)
129
{
130
flp_desc_t *flp_desc;
131
flp_t *flp;
132
RC_model_t *model;
133
double *power;
134
thermal_config_t thermal_config;
135
flp_config_t flp_config;
136
global_config_t global_config;
137
materials_list_t materials_list;
138
str_pair table[MAX_ENTRIES];
139
int size, compacted;
140
141
if (!(argc >= 7 && argc % 2)) {
142
usage(argc, argv);
143
return 1;
144
}
145
146
size = parse_cmdline(table, MAX_ENTRIES, argc, argv);
147
global_config_from_strs(&global_config, table, size);
148
149
/* read configuration file */
150
if (strcmp(global_config.config, NULLFILE))
151
size += read_str_pairs(&table[size], MAX_ENTRIES, global_config.config);
152
153
/*
154
* in the str_pair 'table', earlier entries override later ones.
155
* so, command line options have priority over config file
156
*/
157
size = str_pairs_remove_duplicates(table, size);
158
159
// fill in material properties
160
default_materials(&materials_list);
161
if(strncmp(global_config.materials_file, NULLFILE, STR_SIZE)) {
162
materials_add_from_file(&materials_list, global_config.materials_file);
163
}
164
165
/* get defaults */
166
thermal_config = default_thermal_config();
167
flp_config = default_flp_config();
168
/* modify according to command line / config file */
169
thermal_config_add_from_strs(&thermal_config, &materials_list, table, size);
170
flp_config_add_from_strs(&flp_config, table, size);
171
172
/* dump configuration if specified */
173
if (strcmp(global_config.dump_config, NULLFILE)) {
174
size = global_config_to_strs(&global_config, table, MAX_ENTRIES);
175
size += thermal_config_to_strs(&thermal_config, &table[size], MAX_ENTRIES-size);
176
size += flp_config_to_strs(&flp_config, &table[size], MAX_ENTRIES-size);
177
/* prefix the name of the variable with a '-' */
178
dump_str_pairs(table, size, global_config.dump_config, "-");
179
}
180
181
/* If the grid model is used, things could be really slow!
182
* Also make sure it is not in the 3-d chip mode (specified
183
* with the layer configuration file)
184
*/
185
if (!strcmp(thermal_config.model_type, GRID_MODEL_STR)) {
186
if (strcmp(thermal_config.grid_layer_file, NULLFILE))
187
fatal("lcf file specified with the grid model. 3-d chips not supported\n");
188
warning("grid model is used. HotFloorplan could be REALLY slow\n");
189
}
190
191
/* description of the functional blocks to be floorplanned */
192
flp_desc = read_flp_desc(global_config.flp_desc, &flp_config);
193
/*
194
* just an empty frame with blocks' names.
195
* block positions not known yet.
196
*/
197
flp = flp_placeholder(flp_desc);
198
/* temperature model */
199
model = alloc_RC_model(&thermal_config, flp, NULL, &materials_list, 0, 0);
200
/* input power vector */
201
power = hotspot_vector(model);
202
read_power(model, power, global_config.power_in);
203
204
/* main floorplanning routine */
205
compacted = floorplan(flp, flp_desc, model, power);
206
/*
207
* print the finally selected floorplan in a format that can
208
* be understood by tofig.pl (which converts it to a FIG file)
209
*/
210
print_flp_fig(flp);
211
/* print the floorplan statistics */
212
if (flp_config.wrap_l2 &&
213
!strcasecmp(flp_desc->units[flp_desc->n_units-1].name, flp_config.l2_label))
214
print_flp_stats(flp, model, flp_config.l2_label,
215
global_config.power_in, global_config.flp_desc);
216
217
/* print the wire delays between blocks */
218
print_wire_delays(flp, thermal_config.base_proc_freq);
219
220
/* also output the floorplan to a file readable by hotspot */
221
dump_flp(flp, global_config.flp_out, FALSE);
222
223
free_flp_desc(flp_desc);
224
delete_RC_model(model);
225
free_dvector(power);
226
227
/* while deallocating, free the compacted blocks too */
228
free_flp(flp, compacted, TRUE);
229
230
return 0;
231
}
232
233