includes: sort all includes
[gem5.git] / src / mem / ruby / network / orion / Buffer / Buffer.cc
1 /*
2 * Copyright (c) 2009 Princeton University, and
3 * Regents of the University of California
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;
10 * redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution;
13 * neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Authors: Hangsheng Wang (Orion 1.0, Princeton)
30 * Xinping Zhu (Orion 1.0, Princeton)
31 * Xuning Chen (Orion 1.0, Princeton)
32 * Bin Li (Orion 2.0, Princeton)
33 * Kambiz Samadi (Orion 2.0, UC San Diego)
34 */
35
36 #include <cassert>
37 #include <iostream>
38
39 #include "mem/ruby/network/orion/Buffer/Buffer.hh"
40 #include "mem/ruby/network/orion/Buffer/Register.hh"
41 #include "mem/ruby/network/orion/Buffer/SRAM.hh"
42 #include "mem/ruby/network/orion/OrionConfig.hh"
43 #include "mem/ruby/network/orion/TechParameter.hh"
44
45 using namespace std;
46
47 Buffer::Buffer(
48 const string& buffer_model_str_,
49 bool is_fifo_,
50 bool is_outdrv_,
51 uint32_t num_entry_,
52 uint32_t line_width_,
53 uint32_t num_read_port_,
54 uint32_t num_write_port_,
55 const OrionConfig* orion_cfg_ptr_
56 )
57 {
58 if (buffer_model_str_ == string("SRAM"))
59 {
60 m_buffer_model = BUF_SRAM;
61 }
62 else if(buffer_model_str_ == string("REGISTER"))
63 {
64 m_buffer_model = BUF_REG;
65 }
66 else
67 {
68 m_buffer_model = NO_MODEL;
69 }
70
71 if (m_buffer_model != NO_MODEL)
72 {
73 assert(num_entry_ == num_entry_);
74 assert(line_width_ == line_width_);
75 assert(num_read_port_ == num_read_port_);
76 assert(num_write_port_ == num_write_port_);
77
78 m_num_entry = num_entry_;
79 m_line_width = line_width_;
80 m_is_fifo = is_fifo_;
81 m_is_outdrv = is_outdrv_;
82 m_num_read_port = num_read_port_;
83 m_num_write_port = num_write_port_;
84
85 m_orion_cfg_ptr = orion_cfg_ptr_;
86 m_tech_param_ptr = m_orion_cfg_ptr->get_tech_param_ptr();
87
88 init();
89 }
90 }
91
92 Buffer::~Buffer()
93 {
94 delete m_sram_ptr;
95 }
96
97 double Buffer::get_dynamic_energy(
98 bool is_read_,
99 bool is_max_
100 ) const
101 {
102 if (m_buffer_model == BUF_SRAM)
103 {
104 if (is_read_)
105 {
106 return m_sram_ptr->calc_e_read(is_max_);
107 }
108 else
109 {
110 return m_sram_ptr->calc_e_write(is_max_);
111 }
112 }
113 else if (m_buffer_model == BUF_REG)
114 {
115 if (is_read_)
116 {
117 return m_reg_ptr->calc_e_read();
118 }
119 else
120 {
121 return m_reg_ptr->calc_e_write();
122 }
123 }
124 else
125 {
126 return 0;
127 }
128 }
129
130 double Buffer::get_static_power() const
131 {
132 double vdd = m_tech_param_ptr->get_vdd();
133 double SCALE_S = m_tech_param_ptr->get_SCALE_S();
134 if (m_buffer_model == BUF_SRAM)
135 {
136 return m_sram_ptr->calc_i_static()*vdd*SCALE_S;
137 }
138 else if (m_buffer_model == BUF_REG)
139 {
140 return m_reg_ptr->calc_i_static()*vdd*SCALE_S;
141 }
142 else
143 {
144 return 0;
145 }
146 }
147
148 void Buffer::print_all() const
149 {
150 cout << "Buffer" << endl;
151 cout << "\t" << "Read = " << get_dynamic_energy(true, false) << endl;
152 cout << "\t" << "Write = " << get_dynamic_energy(false, false) << endl;
153 cout << "\t" << "Static power = " << get_static_power() << endl;
154 return;
155 }
156
157 void Buffer::init()
158 {
159 if(m_buffer_model == BUF_SRAM)
160 {
161 uint32_t num_data_end = m_orion_cfg_ptr->get<uint32_t>("SRAM_NUM_DATA_END");
162 const string& rowdec_model_str = m_orion_cfg_ptr->get<string>("SRAM_ROWDEC_MODEL");
163 const string& wl_model_str = m_orion_cfg_ptr->get<string>("SRAM_WORDLINE_MODEL");
164 const string& bl_pre_model_str = m_orion_cfg_ptr->get<string>("SRAM_BITLINE_PRE_MODEL");
165 const string& mem_model_str = "NORMAL_MEM";
166 const string& bl_model_str = m_orion_cfg_ptr->get<string>("SRAM_BITLINE_MODEL");
167 const string& amp_model_str = m_orion_cfg_ptr->get<string>("SRAM_AMP_MODEL");
168 const string& outdrv_model_str = m_orion_cfg_ptr->get<string>("SRAM_OUTDRV_MODEL");
169 m_sram_ptr = new SRAM(
170 m_num_entry, m_line_width, m_is_fifo, m_is_outdrv,
171 m_num_read_port, m_num_write_port, num_data_end,
172 rowdec_model_str, wl_model_str, bl_pre_model_str, mem_model_str,
173 bl_model_str, amp_model_str, outdrv_model_str, m_tech_param_ptr);
174 }
175 else if (m_buffer_model == BUF_REG)
176 {
177 m_sram_ptr = NULL;
178 m_reg_ptr = new Register(m_num_entry, m_line_width, m_tech_param_ptr);
179 }
180 else
181 {
182 m_sram_ptr = NULL;
183 m_reg_ptr = NULL;
184 }
185 return;
186 }
187