#ifndef __TEMPERATURE_H_1#define __TEMPERATURE_H_23#include "flp.h"4#include "util.h"5#include "microchannel.h"6#include "materials.h"78/* temperature sanity check threshold for natural convection and thermal runaway*/9#define TEMP_HIGH 500.01011/* model type */12#define BLOCK_MODEL 013#define GRID_MODEL 114#define BLOCK_MODEL_STR "block"15#define GRID_MODEL_STR "grid"1617/* grid to block mapping mode */18#define GRID_AVG 019#define GRID_MIN 120#define GRID_MAX 221#define GRID_CENTER 322#define GRID_AVG_STR "avg"23#define GRID_MIN_STR "min"24#define GRID_MAX_STR "max"25#define GRID_CENTER_STR "center"2627/* temperature-leakage loop constants */28#define LEAKAGE_MAX_ITER 100 /* max thermal-leakage iteration number, if exceeded, report thermal runaway*/29#define LEAK_TOL 0.01 /* thermal-leakage temperature convergence criterion */3031/* number of extra nodes due to the model:32* 4 spreader nodes, 4 heat sink nodes under33* the spreader (center), 4 peripheral heat34* sink nodes (north, south, east and west)35* and a separate node for the ambient36*/37#define EXTRA 1238/* spreader nodes */39#define SP_W 040#define SP_E 141#define SP_N 242#define SP_S 343/* central sink nodes (directly under the spreader) */44#define SINK_C_W 445#define SINK_C_E 546#define SINK_C_N 647#define SINK_C_S 748/* peripheral sink nodes */49#define SINK_W 850#define SINK_E 951#define SINK_N 1052#define SINK_S 115354/* secondary extra nodes */55#define EXTRA_SEC 1656/* package substrate nodes */57#define SUB_W 1258#define SUB_E 1359#define SUB_N 1460#define SUB_S 1561/* solder ball nodes */62#define SOLDER_W 1663#define SOLDER_E 1764#define SOLDER_N 1865#define SOLDER_S 1966/* central PCB nodes (directly under the solder balls) */67#define PCB_C_W 2068#define PCB_C_E 2169#define PCB_C_N 2270#define PCB_C_S 2371/* peripheral PCB nodes */72#define PCB_W 2473#define PCB_E 2574#define PCB_N 2675#define PCB_S 277677/* physical constants, now become configurable in the config file */78//#define RHO_SI 0.01 /* thermal resistivity of silicon between 300K-400K in (mK)/W */79//#define RHO_CU 0.0025 /* thermal resistivity of copper between 300K-400K in (mK)/W */80//#define RHO_INT 0.25 /* thermal resistivity of the interface material in (mK)/W */81//#define K_SI (1.0/RHO_SI) /* thermal conductivity of silicon */82//#define K_CU (1.0/RHO_CU) /* thermal conductivity of copper */83//#define K_INT (1.0/RHO_INT) /* thermal conductivity of the interface material */84//#define SPEC_HEAT_SI 1.75e6 /* specfic heat of silicon in J/(m^3K) */85//#define SPEC_HEAT_CU 3.55e6 /* specific heat of copper in J/(m^3K) */86//#define SPEC_HEAT_INT 4e6 /* specific heat of the interface material in J/(m^3K) */8788/* typical thermal properties for secondary path layers */89/* */90#define RHO_METAL 0.002591#define RHO_DIELECTRIC 1.092#define RHO_C4 0.893#define RHO_UNDERFILL 0.0394#define RHO_SUB 0.595#define RHO_SOLDER 0.0696#define RHO_PCB 0.33397#define K_METAL (1.0/RHO_METAL)98#define K_DIELECTRIC (1.0/RHO_DIELECTRIC)99#define K_C4 (1.0/RHO_C4)100#define K_UNDERFILL (1.0/RHO_UNDERFILL)101#define K_SUB (1.0/RHO_SUB)102#define K_SOLDER (1.0/RHO_SOLDER)103#define K_PCB (1.0/RHO_PCB)104//FIXME! the following values need to be found105#define SPEC_HEAT_METAL 3.55e6 /* specfic heat of silicon in J/(m^3K) */106#define SPEC_HEAT_DIELECTRIC 2.2e6107#define SPEC_HEAT_C4 1.65e6108#define SPEC_HEAT_UNDERFILL 2.65e6109#define SPEC_HEAT_SUB 1.6e6 /* specific heat of copper in J/(m^3K) */110#define SPEC_HEAT_SOLDER 2.1e6 /* specific heat of the interface material in J/(m^3K) */111#define SPEC_HEAT_PCB 1.32e6112113/* model specific constants */114/* changed from 1/2 to 1/3 due to the difference from traditional Elmore Delay scenario */115#define C_FACTOR 0.333 /* fitting factor to match floworks (due to lumping) */116117/* constants related to transient temperature calculation */118#define MIN_STEP 1e-7 /* 0.1 us */119120/* BLAS/LAPACK definitions */121#define MA_NONE 0122#define MA_INTEL 1123#define MA_AMD 2124#define MA_APPLE 3125#define MA_SUN 4126127#if (MATHACCEL == MA_INTEL)128#include <mkl_cblas.h>129#include <mkl_lapack.h>130#elif (MATHACCEL == MA_AMD)131#include <acml.h>132#elif (MATHACCEL == MA_APPLE)133#include <vecLib/cblas.h>134#include <vecLib/clapack.h>135#elif (MATHACCEL == MA_SUN)136#include <sunperf.h>137#endif138139/* thermal model configuration */140typedef struct thermal_config_t_st141{142/* chip specs */143double t_chip; /* chip thickness in meters */144double k_chip; /* chip thermal conductivity */145double p_chip; /* chip specific heat */146double thermal_threshold; /* temperature threshold for DTM (Kelvin)*/147148/* heat sink specs */149double c_convec; /* convection capacitance in J/K */150double r_convec; /* convection resistance in K/W */151double s_sink; /* heatsink side in meters */152double t_sink; /* heatsink thickness in meters */153double k_sink; /* heatsink thermal conductivity */154double p_sink; /* heatsink specific heat */155156/* heat spreader specs */157double s_spreader; /* spreader side in meters */158double t_spreader; /* spreader thickness in meters */159double k_spreader; /* spreader thermal conductivity */160double p_spreader; /* spreader specific heat */161162/* interface material specs */163double t_interface; /* interface material thickness in meters */164double k_interface; /* interface material thermal conductivity */165double p_interface; /* interface material specific heat */166167/* secondary path specs */168int model_secondary;169double r_convec_sec;170double c_convec_sec;171int n_metal;172double t_metal;173double t_c4;174double s_c4;175int n_c4;176double s_sub;177double t_sub;178double s_solder;179double t_solder;180double s_pcb;181double t_pcb;182183/* others */184double ambient; /* ambient temperature in kelvin */185/* initial temperatures from file */186char init_file[STR_SIZE];187double init_temp; /* if init_file is NULL */188/* steady state temperatures to file */189char steady_file[STR_SIZE];190double sampling_intvl; /* interval per call to compute_temp */191double base_proc_freq; /* in Hz */192int dtm_used; /* flag to guide the scaling of init Ts */193/* model type - block or grid */194char model_type[STR_SIZE];195196/* temperature-leakage loop */197int leakage_used;198int leakage_mode;199200/* package model */201int package_model_used; /* flag to indicate whether package model is used */202char package_config_file[STR_SIZE]; /* package/fan configurations */203204/* parameters specific to block model */205int block_omit_lateral; /* omit lateral resistance? */206207/* parameters specific to grid model */208int grid_rows; /* grid resolution - no. of rows */209int grid_cols; /* grid resolution - no. of cols */210/* layer configuration from file */211char grid_layer_file[STR_SIZE];212/* output grid temperatures instead of block temperatures */213char grid_steady_file[STR_SIZE];214/* mapping mode between grid and block models */215char grid_map_mode[STR_SIZE];216/* transient grid temperatures to file */217char grid_transient_file[STR_SIZE];218219int detailed_3D_used; //BU_3D: Added parameter to check for heterogenous R-C model220}thermal_config_t;221222/* defaults */223thermal_config_t default_thermal_config(void);224/*225* parse a table of name-value string pairs and add the configuration226* parameters to 'config'227*/228void thermal_config_add_from_strs(thermal_config_t *config, materials_list_t *materials_list, str_pair *table, int size);229/*230* convert config into a table of name-value pairs. returns the no.231* of parameters converted232*/233int thermal_config_to_strs(thermal_config_t *config, str_pair *table, int max_entries);234235/* package parameters */236typedef struct package_RC_t_st237{238/* lateral resistances */239/* peripheral spreader nodes */240double r_sp1_x;241double r_sp1_y;242/* sink's inner periphery */243double r_hs1_x;244double r_hs1_y;245double r_hs2_x;246double r_hs2_y;247/* sink's outer periphery */248double r_hs;249250/* vertical resistances */251/* peripheral spreader nodes */252double r_sp_per_x;253double r_sp_per_y;254/* sink's inner periphery */255double r_hs_c_per_x;256double r_hs_c_per_y;257/* sink's outer periphery */258double r_hs_per;259260/* vertical capacitances */261/* peripheral spreader nodes */262double c_sp_per_x;263double c_sp_per_y;264/* sink's inner periphery */265double c_hs_c_per_x;266double c_hs_c_per_y;267/* sink's outer periphery */268double c_hs_per;269270/* vertical R's and C's to ambient */271/* sink's inner periphery */272double r_amb_c_per_x;273double c_amb_c_per_x;274double r_amb_c_per_y;275double c_amb_c_per_y;276/* sink's outer periphery */277double r_amb_per;278double c_amb_per;279280/* secondary path R's and C's */281282/* lateral resistances */283/* peripheral package substrate nodes */284double r_sub1_x;285double r_sub1_y;286/* peripheral solder ball nodes */287double r_solder1_x;288double r_solder1_y;289/* PCB's inner periphery */290double r_pcb1_x;291double r_pcb1_y;292double r_pcb2_x;293double r_pcb2_y;294/* PCB's outer periphery */295double r_pcb;296297/* vertical resistances */298/* peripheral package substrate nodes */299double r_sub_per_x;300double r_sub_per_y;301/* peripheral solder ball nodes */302double r_solder_per_x;303double r_solder_per_y;304/* PCB's inner periphery */305double r_pcb_c_per_x;306double r_pcb_c_per_y;307/* PCB's outer periphery */308double r_pcb_per;309310/* vertical capacitances */311/* peripheral package substrate nodes */312double c_sub_per_x;313double c_sub_per_y;314/* peripheral solder ballnodes */315double c_solder_per_x;316double c_solder_per_y;317/* PCB's inner periphery */318double c_pcb_c_per_x;319double c_pcb_c_per_y;320/* PCB's outer periphery */321double c_pcb_per;322323/* vertical R's and C's to ambient at PCB */324/* PCB's inner periphery */325double r_amb_sec_c_per_x;326double c_amb_sec_c_per_x;327double r_amb_sec_c_per_y;328double c_amb_sec_c_per_y;329/* PCB's outer periphery */330double r_amb_sec_per;331double c_amb_sec_per;332333}package_RC_t;334/* package parameter routines */335void populate_package_R(package_RC_t *p, thermal_config_t *config, double width, double height);336void populate_package_C(package_RC_t *p, thermal_config_t *config, double width, double height);337/* debug print */338void debug_print_package_RC(package_RC_t *p);339340/* slope function pointer - used as a call back by the transient solver */341typedef void (*slope_fn_ptr)(void *model, void *y, void *p, void *dy);342343/* hotspot thermal model - can be a block or grid model */344struct block_model_t_st;345struct grid_model_t_st;346typedef struct RC_model_t_st347{348union349{350struct block_model_t_st *block;351struct grid_model_t_st *grid;352};353/* block model or grid model */354int type;355thermal_config_t *config;356}RC_model_t;357358/* constructor/destructor */359/* placeholder is an empty floorplan frame with only the names of the functional units */360RC_model_t *alloc_RC_model(thermal_config_t *config, flp_t *placeholder, microchannel_config_t *microchannel_config, materials_list_t *materials_list,361int do_detailed_3D, int use_microchannels);362void delete_RC_model(RC_model_t *model);363364/* initialization */365void populate_R_model(RC_model_t *model, flp_t *flp);366void populate_C_model(RC_model_t *model, flp_t *flp);367368/* hotspot main interfaces - temperature.c */369void steady_state_temp(RC_model_t *model, double *power, double *temp);370void compute_temp(RC_model_t *model, double *power, double *temp, double time_elapsed);371/* differs from 'dvector()' in that memory for internal nodes is also allocated */372double *hotspot_vector(RC_model_t *model);373/* copy 'src' to 'dst' except for a window of 'size'374* elements starting at 'at'. useful in floorplan375* compaction376*/377void trim_hotspot_vector(RC_model_t *model, double *dst, double *src,378int at, int size);379/* update the model's node count */380void resize_thermal_model(RC_model_t *model, int n_units);381void set_temp (RC_model_t *model, double *temp, double val);382void dump_temp (RC_model_t *model, double *temp, char *file);383void copy_temp (RC_model_t *model, double *dst, double *src);384void read_temp (RC_model_t *model, double *temp, char *file, int clip);385void dump_power(RC_model_t *model, double *power, char *file);386void read_power (RC_model_t *model, double *power, char *file);387double find_max_temp(RC_model_t *model, double *temp);388double find_avg_temp(RC_model_t *model, double *temp);389/* debug print */390void debug_print_model(RC_model_t *model);391392/* other functions used by the above interfaces */393394/* LUP decomposition */395void lupdcmp(double**a, int n, int *p, int spd);396397/* get the thermal resistance and capacitance values */398double getr(double conductivity, double thickness, double area);399double getcap(double sp_heat, double thickness, double area);400401/* LU forward and backward substitution */402void lusolve(double **a, int n, int *p, double *b, double *x, int spd);403404/* 4th order Runge Kutta solver with adaptive step sizing */405double rk4(void *model, double *y, void *p, int n, double *h, double *yout, slope_fn_ptr f);406407#if SUPERLU > 0408/* Backward Euler solver with adaptive step sizing */409double backward_euler(SuperMatrix *G, diagonal_matrix_t *C, double *T, double *P, double *h, double *Tout);410#endif411412/* matrix and vector routines */413void matmult(double **c, double **a, double **b, int n);414/* same as above but 'a' is a diagonal matrix stored as a 1-d array */415void diagmatmult(double **c, double *a, double **b, int n);416void matvectmult(double *vout, double **m, double *vin, int n);417/* same as above but 'm' is a diagonal matrix stored as a 1-d array */418void diagmatvectmult(double *vout, double *m, double *vin, int n);419/*420* inv = m^-1, inv, m are n by n matrices.421* the spd flag indicates that m is symmetric422* and positive definite423*/424void matinv(double **inv, double **m, int n, int spd);425426/* dst = src1 + scale * src2 */427void scaleadd_dvector (double *dst, double *src1, double *src2, int n, double scale);428429/* temperature-aware leakage calculation */430double calc_leakage(int mode, double h, double w, double temp);431432/* calculate average heatsink temperature for natural convection package model */433double calc_sink_temp(RC_model_t *model, double *temp);434435#endif436437438