Ophidian
 All Classes Namespaces Functions
ceff.h
1 /*
2  * Copyright 2016 Ophidian
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0
12 
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19  */
20 
21 //
22 // This is an implementation of the algorithm presented on paper
23 // "Fast and accurate wire delay estimation for physical synthesis of large ASICs"
24 // by Ruchir Puri, David S. Kung, and Anthony D. Drumm.
25 // published i nProceedings of the 12th ACM Great Lakes symposium on VLSI (GLSVLSI '02).
26 // ACM, New York, NY, USA, 30-36. DOI=http://dx.doi.org/10.1145/505306.505314
27 //
28 //
29 
30 #ifndef OPHIDIAN_TIMING_CEFF_H
31 #define OPHIDIAN_TIMING_CEFF_H
32 
33 #include <deque>
34 #include <boost/units/cmath.hpp>
35 
36 #include "../interconnection/rc_tree.h"
37 #include "elmore.h"
38 #include "elmore_second_moment.h"
39 
40 namespace ophidian {
41 namespace timing {
42 
43 
45  using CapacitanceType = boost::units::quantity < boost::units::si::capacitance >;
46  using SlewType = boost::units::quantity < boost::units::si::time >;
47  std::vector< SlewType > * m_slews;
48  std::vector< SlewType > * m_delays;
49  std::vector< CapacitanceType > * m_ceff;
50  bool m_slews_owner;
51  bool m_delays_owner;
52  bool m_ceff_owner;
53 public:
56  void slew_map(std::vector< SlewType >& sm);
57  void delay_map(std::vector< SlewType >& dm);
58  void ceff_map(std::vector<CapacitanceType> &cm);
59  const std::vector< SlewType >& slews() const {
60  return *m_slews;
61  }
62  const std::vector< SlewType >& delays() const {
63  return *m_delays;
64  }
65  const std::vector< CapacitanceType >& ceffs() const {
66  return *m_ceff;
67  }
68  template <class SlewCalculator>
69  CapacitanceType simulate(const SlewCalculator & slew_calculator, const interconnection::packed_rc_tree & tree)
70  {
71  if(!m_slews)
72  m_slews = new std::vector< SlewType >(tree.node_count());
73  if(!m_delays)
74  m_delays = new std::vector< SlewType >(tree.node_count());
75  if(!m_ceff)
76  m_ceff = new std::vector< CapacitanceType >(tree.node_count());
77 
78  std::vector< SlewType > & slews = *m_slews;
79  std::vector< SlewType > & delays = *m_delays;
80  std::vector< CapacitanceType > & ceff = *m_ceff;
81 
82 
83  CapacitanceType lumped;
84  for(std::size_t i = 0; i < tree.node_count(); ++i)
85  lumped += tree.capacitance(i);
86 
87  auto source_slew = slew_calculator(lumped);
88 
89  packed_elmore delay;
90  delay.tree(tree);
91  delay.run();
92 
93  packed_elmore_second_moment second_moment;
94  second_moment.elmore(delay);
95  second_moment.tree(tree);
96  second_moment.run();
97 
98  for(std::size_t i = 0; i < tree.node_count(); ++i)
99  {
100  delays[i] = delay.at(i);
101  auto step_slew = boost::units::sqrt( second_moment.at(i)*2.0 - boost::units::pow<2>(delay.at(i)) );
102  slews[i] = boost::units::sqrt(boost::units::pow<2>(source_slew) + boost::units::pow<2>(step_slew));
103  }
104 
105  return lumped;
106  }
107 };
108 
109 
111 {
112  using CapacitanceType = boost::units::quantity < boost::units::si::capacitance >;
113  using SlewType = boost::units::quantity < boost::units::si::time >;
114  double m_precision;
115 
116  std::vector< SlewType > * m_slews;
117  std::vector< SlewType > * m_delays;
118  std::vector< CapacitanceType > * m_ceff;
119 
120  bool m_slews_owner;
121  bool m_delays_owner;
122  bool m_ceff_owner;
123 public:
126  void precision(double epsilon);
127 
128  void slew_map(std::vector< SlewType >& sm);
129  void delay_map(std::vector< SlewType >& dm);
130  void ceff_map(std::vector<CapacitanceType> &cm);
131 
132  const std::vector< SlewType >& slews() const {
133  return *m_slews;
134  }
135  const std::vector< SlewType >& delays() const {
136  return *m_delays;
137  }
138  const std::vector< CapacitanceType >& ceffs() const {
139  return *m_ceff;
140  }
141 
142  template <class SlewCalculator>
143  CapacitanceType simulate(const SlewCalculator & slew_calculator, const interconnection::packed_rc_tree & tree)
144  {
145  if(!m_slews)
146  m_slews = new std::vector< SlewType >(tree.node_count());
147  if(!m_delays)
148  m_delays = new std::vector< SlewType >(tree.node_count());
149  if(!m_ceff)
150  m_ceff = new std::vector< CapacitanceType >(tree.node_count());
151 
152  std::vector< SlewType > & slews = *m_slews;
153  std::vector< SlewType > & delays = *m_delays;
154  std::vector< CapacitanceType > & ceff = *m_ceff;
155 
156 
157 
158  double error = 1.0;
159  std::size_t iteration = 0;
160 
161  CapacitanceType current_ceff;
162  delays[0] = SlewType(0.0*boost::units::si::seconds);
163  while (error > m_precision) {
164  current_ceff = ceff[0];
166  slews[0] = slew_calculator(current_ceff);
167  for(std::size_t current = 1; current < tree.node_count(); ++current)
168  {
169  auto parent = tree.pred(current);
170  auto resistance_with_parent = tree.resistance(current);
171 
172  slews[current] = slews[parent];
173  if(slews[parent] > 0.0*boost::units::si::seconds){
174  double x = resistance_with_parent*ceff[current]/slews[parent];
175  slews[current] = slews[parent]/ (1-x*(1-std::exp(-1/x)));
176  }
177  delays[current] = delays[parent] + resistance_with_parent*ceff[current];
178  }
179  for(std::size_t node = 0; node < tree.node_count(); ++node)
180  ceff[node] = tree.capacitance(node);
181  for(std::size_t i = 0; i < tree.node_count()-1; ++i)
182  {
183  std::size_t current = tree.node_count() - (i+1);
184  auto parent = tree.pred(current);
185  auto resistance_with_parent = tree.resistance(current);
186  double x = 2.0 * resistance_with_parent * ceff[current] / slews[parent];
187  double y = 1.0 - std::exp(-1.0/x);
188  double shielding_factor = (slews[parent] > 0.0*boost::units::si::seconds?1.0 - x * y:1.0);
189  ceff[parent] += shielding_factor*ceff[current];
190  }
191  error = boost::units::abs(current_ceff-ceff[0])/std::max(current_ceff, ceff[0]);
192  }
193  return current_ceff;
194  }
195 };
196 
197 }
198 }
199 
200 #endif // OPHIDIAN_TIMING_CEFF_H
Packed RC Tree Class.
Definition: rc_tree.h:39
Definition: elmore.h:55
Definition: elmore_second_moment.h:48