#ifndef __TEMPERATURE_GRID_H_1#define __TEMPERATURE_GRID_H_23/* grid model differs from the block model in its use of4* a mesh of cells whose resolution is configurable. unlike5* the block model, it can also model a stacked 3-D chip,6* with each layer having a different floorplan. information7* about the floorplan and the properties of each layer is8* input in the form of a layer configuration file.9*/10#include "temperature.h"11#include "microchannel.h"1213#if SUPERLU > 014/* Lib for SuperLU */15#include "slu_ddefs.h"16#endif1718/* layer configuration file constants */19#define LCF_NPARAMS 7 /* no. of parameters per layer */20#define LCF_SNO 0 /* serial number */21#define LCF_LATERAL 1 /* has lateral heat flow? */22#define LCF_POWER 2 /* dissipates power? */23#define LCF_SP 3 /* specific heat capacity */24#define LCF_RHO 4 /* resistivity */25#define LCF_THICK 5 /* thickness */26#define LCF_FLP 6 /* floorplan file */2728/* vector types - power / temperature */29#define V_POWER 030#define V_TEMP 13132/* default no. of chip layers (excluding spreader33* and sink). used when LCF file is not specified34*/35#define DEFAULT_CHIP_LAYERS 236#define LAYER_SI 037#define LAYER_INT 13839/* layers of secondary path with same area as die */40#define SEC_CHIP_LAYERS 241#define LAYER_C4 042#define LAYER_METAL 14344/* default no. of package layers */45#define DEFAULT_PACK_LAYERS 246#define LAYER_SP 047#define LAYER_SINK 14849/* additional package layers from secondary path */50#define SEC_PACK_LAYERS 351#define LAYER_PCB 052#define LAYER_SOLDER 153#define LAYER_SUB 25455/* Occupancy threshold for border-cell calculation.56Effective only when the detailed 3D modeling is turned on. */57#define OCCUPANCY_THRESHOLD 0.955859/* block list: block to grid mapping data structure.60* list of blocks mapped to a grid cell61*/62typedef struct blist_t_st63{64/* index of the mapped block */65int idx;66/* ratio of this block's area within the grid cell67* to the total area of the grid cell68*/69double occupancy;70/* next block mapped to the same cell */71struct blist_t_st *next;72//BU_3D: The following variables contain the grid specific conductances73int lock, hasRes,hasCap;/*lock: is occupancy >OCCUPANCY_THRESHOLD% lock the thermal resistance values */74/*hasRes: integer(1 or 0) to see if grid has grid specific resistance */75/*hasCap: integer(1 or 0) to see if grid has grid specific Capacitance */76double rx,ry,rz;//Thermal Resistance in x,y,z directions77double capacitance;//Thermal Capacitance78//end->BU_3D79}blist_t;8081/* grid list: grid to block mapping data structure.82* start and end indices of grid cells in a block83* (both in the x and y directions)84*/85typedef struct glist_t_st86{87/* start index in the y direction */88int i1;89/* end index in the y direction + 1 */90int i2;91/* start index in the x direction */92int j1;93/* end index in the x direction + 1 */94int j2;95} glist_t;9697/* one layer of the grid model. a 3-D chip is a stacked98* set of layers99*/100typedef struct layer_t_st101{102/* floorplan */103flp_t *flp;104105/* configuration parameters */106int no; /* serial number */107int has_lateral; /* model lateral spreading of heat? */108int has_power; /* dissipates power? */109double k; /* 1/resistivity */110double thickness;111double sp; /* specific heat capacity */112113/* microchannel parameters */114int is_microchannel; /* is a microchannel layer? */115microchannel_config_t *microchannel_config; /* config information if is_microchannel = 1 */116117/* extracted information */118double rx, ry, rz; /* x, y and z resistors */119double c; /* capacitance */120121/* block-grid map - 2-d array of block lists */122blist_t ***b2gmap;123/* grid-block map - a 1-d array of grid lists */124glist_t *g2bmap;125}layer_t;126127/* grid model's internal vector datatype */128typedef struct grid_model_vector_t_st129{130/* 3-d grid of nodes */131double ***cuboid;132/* extra spreader and sink nodes */133double *extra;134}grid_model_vector_t;135136/* grid thermal model */137typedef struct grid_model_t_st138{139/* configuration */140thermal_config_t config;141142/* layer information */143layer_t *layers;144int n_layers;145146/* grid resolution */147int rows;148int cols;149/* dimensions */150double width;151double height;152153/* package parameters */154package_RC_t pack;155156/* sum total of the functional blocks of all floorplans */157int total_n_blocks;158/* grid-to-block mapping mode */159int map_mode;160161/* flags */162int r_ready; /* are the R's initialized? */163int c_ready; /* are the C's initialized? */164int has_lcf; /* LCF file specified? */165166/* internal state - most recently computed167* steady state temperatures168*/169grid_model_vector_t *last_steady;170/* internal state - most recently computed171* transient temperatures172*/173/* grid cell temperatures */174grid_model_vector_t *last_trans;175/* block temperatures */176double *last_temp;177178/* to allow for resizing */179int base_n_units;180181/* default microchannel config */182int use_microchannels;183microchannel_config_t *default_microchannel_config;184185/* Variables used in simulation with SuperLU */186#if SUPERLU > 0187SuperMatrix G;188diagonal_matrix_t *C;189#endif190}grid_model_t;191192//BU_3D: Functions used to retrieve data from the det3D_grid_reference structure193double find_res_3D(int n, int i, int j, grid_model_t *model, int choice);194double find_cap_3D(int n, int i, int j, grid_model_t *model);195/* constructor/destructor */196grid_model_t *alloc_grid_model(thermal_config_t *config, flp_t *flp_default, microchannel_config_t *microchannel_config,197materials_list_t *materials_list, int do_detailed_3D, int use_microchannels);//BU_3D: added do_detailed_3D198void delete_grid_model(grid_model_t *model);199200/* initialization */201void populate_R_model_grid(grid_model_t *model, flp_t *flp);202void populate_C_model_grid(grid_model_t *model, flp_t *flp);203204/* hotspot main interfaces - temperature.c */205void steady_state_temp_grid(grid_model_t *model, double *power, double *temp);206void compute_temp_grid(grid_model_t *model, double *power, double *temp, double time_elapsed);207208/* differs from 'dvector()' in that memory for internal nodes is also allocated */209double *hotspot_vector_grid(grid_model_t *model);210/* copy 'src' to 'dst' except for a window of 'size'211* elements starting at 'at'. useful in floorplan212* compaction213*/214void trim_hotspot_vector_grid(grid_model_t *model, double *dst, double *src,215int at, int size);216/* update the model's node count */217void resize_thermal_model_grid(grid_model_t *model, int n_units);218void set_temp_grid (grid_model_t *model, double *temp, double val);219void dump_steady_temp_grid (grid_model_t *model, char *file);220void dump_temp_grid (grid_model_t *model, double *temp, char *file);221void dump_transient_temp_grid(grid_model_t *model, int trace_num, double sampling_intvl, char *filename);222void copy_temp_grid (grid_model_t *model, double *dst, double *src);223void read_temp_grid (grid_model_t *model, double *temp, char *file, int clip);224void dump_power_grid(grid_model_t *model, double *power, char *file);225void read_power_grid (grid_model_t *model, double *power, char *file);226double find_max_temp_grid(grid_model_t *model, double *temp);227double find_avg_temp_grid(grid_model_t *model, double *temp);228double calc_sink_temp_grid(grid_model_t *model, double *temp, thermal_config_t *config);229230/* grid_model_vector routines */231/* constructor */232grid_model_vector_t *new_grid_model_vector(grid_model_t *model);233/* destructor */234void free_grid_model_vector(grid_model_vector_t *v);235/* translate power/temperature between block and grid vectors */236void xlate_vector_b2g(grid_model_t *model, double *b, grid_model_vector_t *g, int type);237/* translate temperature between grid and block vectors */238void xlate_temp_g2b(grid_model_t *model, double *b, grid_model_vector_t *g);239/* debug print */240void debug_print_grid(grid_model_t *model);241242#if SUPERLU > 0243/* steady-state solver */244void direct_SLU(grid_model_t *model, grid_model_vector_t *power, grid_model_vector_t *temp);245246/* build steady-state matrices */247SuperMatrix build_steady_grid_matrix(grid_model_t *model);248SuperMatrix build_steady_rhs_vector(grid_model_t *model, grid_model_vector_t *power, double **rhs);249250SuperMatrix build_transient_grid_matrix(grid_model_t *model);251double *build_transient_power_vector(grid_model_t *model, grid_model_vector_t *power);252diagonal_matrix_t *build_diagonal_matrix(grid_model_t *model);253#endif254255#endif256257258