CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Attributes
trklet::VarAdjustK Class Reference

#include <imath.h>

Inheritance diagram for trklet::VarAdjustK:
trklet::VarBase

Public Member Functions

void adjust (double Knew, double epsilon=1e-5, bool do_assert=false, int nbits=-1)
 
void local_calculate () override
 
void print (std::ofstream &fs, Verilog, int l1=0, int l2=0, int l3=0) override
 
void print (std::ofstream &fs, HLS, int l1=0, int l2=0, int l3=0) override
 
 VarAdjustK (imathGlobals *globals, std::string name, VarBase *p1, double Knew, double epsilon=1e-5, bool do_assert=false, int nbits=-1)
 
 ~VarAdjustK () override=default
 
- Public Member Functions inherited from trklet::VarBase
void add_cut (VarCut *cut, const bool call_set_cut_var=true)
 
void add_delay (int i)
 
void add_latency (unsigned int l)
 
void analyze ()
 
bool calculate (int debug_level)
 
bool calculate ()
 
VarBasecut_var ()
 
std::string dump ()
 
void dump_msg ()
 
double fval () const
 
bool has_delay (int i)
 
void inputs (std::vector< VarBase *> *vd)
 
long int ival () const
 
double K () const
 
std::map< std::string, int > Kmap () const
 
std::string kstring () const
 
int latency () const
 
bool local_passes () const
 
void makeready ()
 
double maxval () const
 
double minval () const
 
std::string name () const
 
int nbits () const
 
std::string op () const
 
VarBasep1 () const
 
VarBasep2 () const
 
VarBasep3 () const
 
void passes (std::map< const VarBase *, std::vector< bool > > &passes, const std::map< const VarBase *, std::vector< bool > > *const previous_passes=nullptr) const
 
int pipe_counter ()
 
std::string pipe_delays (const int step)
 
void pipe_increment ()
 
void print_all (std::ofstream &fs, Verilog)
 
void print_all (std::ofstream &fs, HLS)
 
void print_cuts (std::map< const VarBase *, std::set< std::string > > &cut_strings, const int step, Verilog, const std::map< const VarBase *, std::set< std::string > > *const previous_cut_strings=nullptr) const
 
void print_cuts (std::map< const VarBase *, std::set< std::string > > &cut_strings, const int step, HLS, const std::map< const VarBase *, std::set< std::string > > *const previous_cut_strings=nullptr) const
 
void print_step (int step, std::ofstream &fs, Verilog)
 
void print_step (int step, std::ofstream &fs, HLS)
 
void print_truncation (std::string &t, const std::string &o1, const int ps, Verilog) const
 
void print_truncation (std::string &t, const std::string &o1, const int ps, HLS) const
 
double range () const
 
void reset ()
 
int shift () const
 
int step () const
 
 VarBase (imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
 
virtual ~VarBase ()
 

Protected Attributes

int lr_
 
- Protected Attributes inherited from trklet::VarBase
VarBasecut_var_
 
std::vector< VarBase * > cuts_
 
double fval_
 
imathGlobalsglobals_
 
long int ival_
 
double K_
 
std::map< std::string, int > Kmap_
 
int latency_
 
double maxval_
 
double minval_
 
std::string name_
 
int nbits_
 
std::string op_
 
VarBasep1_
 
VarBasep2_
 
VarBasep3_
 
int pipe_counter_
 
std::vector< int > pipe_delays_
 
bool readytoanalyze_
 
bool readytoprint_
 
int step_
 
bool usedasinput_
 
double val_
 

Additional Inherited Members

- Static Public Member Functions inherited from trklet::VarBase
static void design_print (const std::vector< VarBase *> &v, std::ofstream &fs, Verilog)
 
static void design_print (const std::vector< VarBase *> &v, std::ofstream &fs, HLS)
 
static void hls_print (const std::vector< VarBase *> &v, std::ofstream &fs)
 
static std::string itos (int i)
 
static std::string pipe_delay (VarBase *v, int nbits, int delay)
 
static std::string pipe_delay_wire (VarBase *v, std::string name_delayed, int nbits, int delay)
 
static void verilog_print (const std::vector< VarBase *> &v, std::ofstream &fs)
 
- Static Public Attributes inherited from trklet::VarBase
static struct trklet::VarBase::HLS hls
 
static struct trklet::VarBase::Verilog verilog
 

Detailed Description

Definition at line 335 of file imath.h.

Constructor & Destructor Documentation

◆ VarAdjustK()

trklet::VarAdjustK::VarAdjustK ( imathGlobals globals,
std::string  name,
VarBase p1,
double  Knew,
double  epsilon = 1e-5,
bool  do_assert = false,
int  nbits = -1 
)
inline

Definition at line 337 of file imath.h.

References funct::abs(), cms::cuda::assert(), geometryDiff::epsilon, trklet::VarBase::K(), trklet::VarBase::K_, trklet::VarBase::Kmap(), trklet::VarBase::Kmap_, lr_, trklet::VarBase::nbits(), trklet::VarBase::nbits_, trklet::VarBase::op_, trklet::VarBase::p1(), funct::pow(), and alignCSCRings::r.

344  : VarBase(globals, name, p1, nullptr, nullptr, 0) {
345  op_ = "adjustK";
346  K_ = p1->K();
347  Kmap_ = p1->Kmap();
348 
349  double r = Knew / K_;
350 
351  lr_ = (r > 1) ? log2(r) + epsilon : log2(r);
352  K_ = K_ * pow(2, lr_);
353  if (do_assert)
354  assert(std::abs(Knew / K_ - 1) < epsilon);
355 
356  if (nbits > 0)
357  nbits_ = nbits;
358  else
359  nbits_ = p1->nbits() - lr_;
360 
361  Kmap_["2"] = Kmap_["2"] + lr_;
362  }
std::string name() const
Definition: imath.h:207
int nbits() const
Definition: imath.h:243
assert(be >=bs)
VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l)
Definition: imath.h:161
std::string op_
Definition: imath.h:300
VarBase * p1() const
Definition: imath.h:209
std::map< std::string, int > Kmap() const
Definition: imath.h:244
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double K() const
Definition: imath.h:246
std::map< std::string, int > Kmap_
Definition: imath.h:313
double K_
Definition: imath.h:312
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ ~VarAdjustK()

trklet::VarAdjustK::~VarAdjustK ( )
overridedefault

Member Function Documentation

◆ adjust()

void VarAdjustK::adjust ( double  Knew,
double  epsilon = 1e-5,
bool  do_assert = false,
int  nbits = -1 
)

Definition at line 120 of file imath.cc.

References funct::abs(), cms::cuda::assert(), geometryDiff::epsilon, trklet::VarBase::K(), trklet::VarBase::K_, trklet::VarBase::Kmap(), trklet::VarBase::Kmap_, lr_, trklet::VarBase::nbits(), trklet::VarBase::nbits_, trklet::VarBase::p1_, funct::pow(), and alignCSCRings::r.

120  {
121  //WARNING!!!
122  //THIS METHID CAN BE USED ONLY FOR THE FINAL ANSWER
123  //THE CHANGE IN CONSTANT CAN NOT BE PROPAGATED UP THE CALCULATION TREE
124 
125  K_ = p1_->K();
126  Kmap_ = p1_->Kmap();
127  double r = Knew / K_;
128 
129  lr_ = (r > 1) ? log2(r) + epsilon : log2(r);
130  K_ = K_ * pow(2, lr_);
131  if (do_assert)
132  assert(std::abs(Knew / K_ - 1) < epsilon);
133 
134  if (nbits > 0)
135  nbits_ = nbits;
136  else
137  nbits_ = p1_->nbits() - lr_;
138 
139  Kmap_["2"] = Kmap_["2"] + lr_;
140 }
int nbits() const
Definition: imath.h:243
VarBase * p1_
Definition: imath.h:297
assert(be >=bs)
std::map< std::string, int > Kmap() const
Definition: imath.h:244
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double K() const
Definition: imath.h:246
std::map< std::string, int > Kmap_
Definition: imath.h:313
double K_
Definition: imath.h:312
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ local_calculate()

void VarAdjustK::local_calculate ( )
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 96 of file imath_calculate.cc.

References trklet::VarBase::fval(), trklet::VarBase::fval_, trklet::VarBase::ival(), trklet::VarBase::ival_, lr_, and trklet::VarBase::p1_.

96  {
97  fval_ = p1_->fval();
98  ival_ = p1_->ival();
99  if (lr_ > 0)
100  ival_ = ival_ >> lr_;
101  else if (lr_ < 0)
102  ival_ = ival_ << (-lr_);
103 }
double fval() const
Definition: imath.h:212
VarBase * p1_
Definition: imath.h:297
long int ival_
Definition: imath.h:305
long int ival() const
Definition: imath.h:213
double fval_
Definition: imath.h:304

◆ print() [1/2]

void VarAdjustK::print ( std::ofstream &  fs,
Verilog  ,
int  l1 = 0,
int  l2 = 0,
int  l3 = 0 
)
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 72 of file imath_Verilog.cc.

References cms::cuda::assert(), compareTotals::fs, trklet::VarBase::itos(), trklet::VarBase::K_, trklet::VarBase::kstring(), lr_, trklet::VarBase::name(), trklet::VarBase::name_, trklet::VarBase::nbits_, trklet::VarBase::p1_, trklet::VarBase::shift(), AlCaHLTBitMon_QueryRunRegistry::string, and submitPVValidationJobs::t.

72  {
73  assert(p1_);
74  assert(l2 == 0);
75  assert(l3 == 0);
76 
77  std::string shift = "";
78  if (lr_ > 0)
79  shift = " >>> " + itos(lr_);
80  else if (lr_ < 0)
81  shift = " << " + itos(-lr_);
82 
83  std::string n1 = p1_->name();
84  if (l1 > 0)
85  n1 = n1 + "_delay" + itos(l1);
86 
87  fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n";
88  std::string t = "wire signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n";
89  t += "assign " + name_ + " = " + n1 + shift;
90  fs << t << "; \n";
91 }
std::string name() const
Definition: imath.h:207
VarBase * p1_
Definition: imath.h:297
std::string kstring() const
Definition: imath.cc:18
assert(be >=bs)
int shift() const
Definition: imath.h:247
static std::string itos(int i)
Definition: imath.cc:16
std::string name_
Definition: imath.h:296
double K_
Definition: imath.h:312

◆ print() [2/2]

void VarAdjustK::print ( std::ofstream &  fs,
HLS  ,
int  l1 = 0,
int  l2 = 0,
int  l3 = 0 
)
overridevirtual

Reimplemented from trklet::VarBase.

Definition at line 64 of file imath_HLS.cc.

References cms::cuda::assert(), compareTotals::fs, trklet::VarBase::itos(), trklet::VarBase::K_, trklet::VarBase::kstring(), lr_, trklet::VarBase::name(), trklet::VarBase::name_, trklet::VarBase::nbits_, trklet::VarBase::p1_, trklet::VarBase::shift(), and AlCaHLTBitMon_QueryRunRegistry::string.

64  {
65  assert(p1_);
66  assert(l1 == 0);
67  assert(l2 == 0);
68  assert(l3 == 0);
69 
70  std::string shift = "";
71  if (lr_ > 0)
72  shift = " >> " + itos(lr_);
73  else if (lr_ < 0)
74  shift = " << " + itos(-lr_);
75 
76  std::string n1 = p1_->name();
77 
78  fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n";
79  fs << "const ap_int<" << nbits_ << "> " << name_ << " = " << n1 << shift << ";\n";
80 }
std::string name() const
Definition: imath.h:207
VarBase * p1_
Definition: imath.h:297
std::string kstring() const
Definition: imath.cc:18
assert(be >=bs)
int shift() const
Definition: imath.h:247
static std::string itos(int i)
Definition: imath.cc:16
std::string name_
Definition: imath.h:296
double K_
Definition: imath.h:312

Member Data Documentation

◆ lr_

int trklet::VarAdjustK::lr_
protected

Definition at line 373 of file imath.h.

Referenced by adjust(), local_calculate(), print(), and VarAdjustK().