110234Syasuko.eckert@amd.com/*****************************************************************************
210234Syasuko.eckert@amd.com *                                McPAT
310234Syasuko.eckert@amd.com *                      SOFTWARE LICENSE AGREEMENT
410234Syasuko.eckert@amd.com *            Copyright (c) 2010-2013 Advanced Micro Devices, Inc.
510234Syasuko.eckert@amd.com *                          All Rights Reserved
610234Syasuko.eckert@amd.com *
710234Syasuko.eckert@amd.com * Redistribution and use in source and binary forms, with or without
810234Syasuko.eckert@amd.com * modification, are permitted provided that the following conditions are
910234Syasuko.eckert@amd.com * met: redistributions of source code must retain the above copyright
1010234Syasuko.eckert@amd.com * notice, this list of conditions and the following disclaimer;
1110234Syasuko.eckert@amd.com * redistributions in binary form must reproduce the above copyright
1210234Syasuko.eckert@amd.com * notice, this list of conditions and the following disclaimer in the
1310234Syasuko.eckert@amd.com * documentation and/or other materials provided with the distribution;
1410234Syasuko.eckert@amd.com * neither the name of the copyright holders nor the names of its
1510234Syasuko.eckert@amd.com * contributors may be used to endorse or promote products derived from
1610234Syasuko.eckert@amd.com * this software without specific prior written permission.
1710234Syasuko.eckert@amd.com
1810234Syasuko.eckert@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1910234Syasuko.eckert@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2010234Syasuko.eckert@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2110234Syasuko.eckert@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2210234Syasuko.eckert@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2310234Syasuko.eckert@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2410234Syasuko.eckert@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2510234Syasuko.eckert@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2610234Syasuko.eckert@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2710234Syasuko.eckert@amd.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2810234Syasuko.eckert@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2910234Syasuko.eckert@amd.com *
3010234Syasuko.eckert@amd.com * Authors: Joel Hestness
3110234Syasuko.eckert@amd.com *          Yasuko Eckert
3210234Syasuko.eckert@amd.com *
3310234Syasuko.eckert@amd.com ***************************************************************************/
3410234Syasuko.eckert@amd.com
3510234Syasuko.eckert@amd.com#ifndef CACHEUNIT_H_
3610234Syasuko.eckert@amd.com#define CACHEUNIT_H_
3710234Syasuko.eckert@amd.com
3810234Syasuko.eckert@amd.com#include "area.h"
3910234Syasuko.eckert@amd.com#include "array.h"
4010234Syasuko.eckert@amd.com#include "basic_components.h"
4110234Syasuko.eckert@amd.com#include "logic.h"
4210234Syasuko.eckert@amd.com#include "parameter.h"
4310234Syasuko.eckert@amd.com
4410234Syasuko.eckert@amd.comclass CacheParameters {
4510234Syasuko.eckert@amd.compublic:
4610234Syasuko.eckert@amd.com    enum Dir_type dir_ty;
4710234Syasuko.eckert@amd.com    double clockRate;
4810234Syasuko.eckert@amd.com    double capacity;
4910234Syasuko.eckert@amd.com    double blockW;
5010234Syasuko.eckert@amd.com    double assoc;
5110234Syasuko.eckert@amd.com    double nbanks;
5210234Syasuko.eckert@amd.com    double throughput;
5310234Syasuko.eckert@amd.com    double latency;
5410234Syasuko.eckert@amd.com    int missb_size;
5510234Syasuko.eckert@amd.com    int fu_size;
5610234Syasuko.eckert@amd.com    int prefetchb_size;
5710234Syasuko.eckert@amd.com    int wbb_size;
5810234Syasuko.eckert@amd.com    int missb_assoc;
5910234Syasuko.eckert@amd.com    int fu_assoc;
6010234Syasuko.eckert@amd.com    int prefetchb_assoc;
6110234Syasuko.eckert@amd.com    int wbb_assoc;
6210234Syasuko.eckert@amd.com    int missb_banks;
6310234Syasuko.eckert@amd.com    int fu_banks;
6410234Syasuko.eckert@amd.com    int prefetchb_banks;
6510234Syasuko.eckert@amd.com    int wbb_banks;
6610234Syasuko.eckert@amd.com    enum Access_mode cache_access_mode;
6710234Syasuko.eckert@amd.com    enum Access_mode miss_buff_access_mode;
6810234Syasuko.eckert@amd.com    enum Access_mode fetch_buff_access_mode;
6910234Syasuko.eckert@amd.com    enum Access_mode prefetch_buff_access_mode;
7010234Syasuko.eckert@amd.com    enum Access_mode writeback_buff_access_mode;
7110234Syasuko.eckert@amd.com    int cache_rw_ports;
7210234Syasuko.eckert@amd.com    int cache_rd_ports;
7310234Syasuko.eckert@amd.com    int cache_wr_ports;
7410234Syasuko.eckert@amd.com    int cache_se_rd_ports;
7510234Syasuko.eckert@amd.com    int cache_search_ports;
7610234Syasuko.eckert@amd.com    int miss_buff_rw_ports;
7710234Syasuko.eckert@amd.com    int miss_buff_rd_ports;
7810234Syasuko.eckert@amd.com    int miss_buff_wr_ports;
7910234Syasuko.eckert@amd.com    int miss_buff_se_rd_ports;
8010234Syasuko.eckert@amd.com    int miss_buff_search_ports;
8110234Syasuko.eckert@amd.com    int fetch_buff_rw_ports;
8210234Syasuko.eckert@amd.com    int fetch_buff_rd_ports;
8310234Syasuko.eckert@amd.com    int fetch_buff_wr_ports;
8410234Syasuko.eckert@amd.com    int fetch_buff_se_rd_ports;
8510234Syasuko.eckert@amd.com    int fetch_buff_search_ports;
8610234Syasuko.eckert@amd.com    int pf_buff_rw_ports;
8710234Syasuko.eckert@amd.com    int pf_buff_rd_ports;
8810234Syasuko.eckert@amd.com    int pf_buff_wr_ports;
8910234Syasuko.eckert@amd.com    int pf_buff_se_rd_ports;
9010234Syasuko.eckert@amd.com    int pf_buff_search_ports;
9110234Syasuko.eckert@amd.com    int wb_buff_rw_ports;
9210234Syasuko.eckert@amd.com    int wb_buff_rd_ports;
9310234Syasuko.eckert@amd.com    int wb_buff_wr_ports;
9410234Syasuko.eckert@amd.com    int wb_buff_se_rd_ports;
9510234Syasuko.eckert@amd.com    int wb_buff_search_ports;
9610234Syasuko.eckert@amd.com    bool pure_ram;
9710234Syasuko.eckert@amd.com    enum CacheLevel cache_level;
9810234Syasuko.eckert@amd.com    enum Device_ty device_ty;
9910234Syasuko.eckert@amd.com    enum Core_type core_ty;
10010234Syasuko.eckert@amd.com    int num_cores;
10110234Syasuko.eckert@amd.com};
10210234Syasuko.eckert@amd.com
10310234Syasuko.eckert@amd.comclass CacheStatistics {
10410234Syasuko.eckert@amd.compublic:
10510234Syasuko.eckert@amd.com    // Duty cycle is used for estimating TDP. It should reflect the highest
10610234Syasuko.eckert@amd.com    // sustainable rate of access to the cache unit in execution of a benchmark
10710234Syasuko.eckert@amd.com    // Default should be 1.0: one access per cycle
10810234Syasuko.eckert@amd.com    double duty_cycle;
10910234Syasuko.eckert@amd.com    // This duty cycle is only used for SBT directory types
11010234Syasuko.eckert@amd.com    double dir_duty_cycle;
11110234Syasuko.eckert@amd.com    // The following two stats are also used for estimating TDP.
11210234Syasuko.eckert@amd.com    double tdp_read_access_scalar;
11310234Syasuko.eckert@amd.com    double tdp_write_access_scalar;
11410234Syasuko.eckert@amd.com    // There are 2 ways to calculate dynamic power from activity statistics:
11510234Syasuko.eckert@amd.com    // Default is false
11610234Syasuko.eckert@amd.com    bool use_detailed_stats;
11710234Syasuko.eckert@amd.com    // 1) Count the number and type of accesses to each cache array
11810234Syasuko.eckert@amd.com    //    splitting data and tag arrays (use_detailed_stats = true).
11910234Syasuko.eckert@amd.com    //    These are extremely detailed statistics.
12010234Syasuko.eckert@amd.com    //    read_misses and write_misses are still required for this method for
12110234Syasuko.eckert@amd.com    //    various buffers associated with this cache.
12210234Syasuko.eckert@amd.com    double num_data_array_reads;
12310234Syasuko.eckert@amd.com    double num_data_array_writes;
12410234Syasuko.eckert@amd.com    double num_tag_array_reads;
12510234Syasuko.eckert@amd.com    double num_tag_array_writes;
12610234Syasuko.eckert@amd.com    // 2) Count the number and type of access to the cache unit and
12710234Syasuko.eckert@amd.com    //    use them to extrapolate the number of accesses to the other
12810234Syasuko.eckert@amd.com    //    subcomponents (cache arrays and buffers)
12910234Syasuko.eckert@amd.com    double read_accesses;
13010234Syasuko.eckert@amd.com    double write_accesses;
13110234Syasuko.eckert@amd.com    double read_misses;
13210234Syasuko.eckert@amd.com    double write_misses;
13310234Syasuko.eckert@amd.com    double conflicts;
13410234Syasuko.eckert@amd.com    // The following is only used for SBT directory types
13510234Syasuko.eckert@amd.com    int homenode_read_accesses;
13610234Syasuko.eckert@amd.com    int homenode_write_accesses;
13710234Syasuko.eckert@amd.com    int homenode_read_misses;
13810234Syasuko.eckert@amd.com    int homenode_write_misses;
13910234Syasuko.eckert@amd.com    double homenode_access_scalar;
14010234Syasuko.eckert@amd.com    double tdp_sbt_write_access_scalar;
14110234Syasuko.eckert@amd.com};
14210234Syasuko.eckert@amd.com
14310234Syasuko.eckert@amd.comclass CacheUnit : public McPATComponent {
14410234Syasuko.eckert@amd.compublic:
14510234Syasuko.eckert@amd.com    static bool is_cache;
14610234Syasuko.eckert@amd.com    static bool pure_cam;
14710234Syasuko.eckert@amd.com    // This is used for CacheArray objects
14810234Syasuko.eckert@amd.com    static bool opt_local;
14910234Syasuko.eckert@amd.com    static bool force_cache_config;
15010234Syasuko.eckert@amd.com
15110234Syasuko.eckert@amd.com    int ithCache;
15210234Syasuko.eckert@amd.com    CacheParameters cache_params;
15310234Syasuko.eckert@amd.com    CacheStatistics cache_stats;
15410234Syasuko.eckert@amd.com    Cache_type cacheType;
15510234Syasuko.eckert@amd.com    bool calculate_runtime_data_and_tag;
15610234Syasuko.eckert@amd.com    double dir_overhead;
15710234Syasuko.eckert@amd.com
15810234Syasuko.eckert@amd.com    double scktRatio;
15910234Syasuko.eckert@amd.com
16010234Syasuko.eckert@amd.com    // TODO: REMOVE _interface_ip... It promotes a mess. Find a better way...
16110234Syasuko.eckert@amd.com    CacheUnit(XMLNode* _xml_data, InputParameter* _interface_ip);
16210234Syasuko.eckert@amd.com    void set_cache_param_from_xml_data();
16310234Syasuko.eckert@amd.com    void computeEnergy();
16410234Syasuko.eckert@amd.com    ~CacheUnit() {};
16510234Syasuko.eckert@amd.com};
16610234Syasuko.eckert@amd.com
16710234Syasuko.eckert@amd.com#endif /* CACHEUNIT_H_ */
168