CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Attributes | Private Attributes
lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I > Class Template Reference

#include <LutNeuronLayerFixedPoint.h>

Public Types

typedef std::array< ap_ufixed< input_W, input_I, AP_TRN, AP_SAT >, inputSize > inputArrayType
 
typedef std::array< ap_fixed< lutOutSum_W, lutOutSum_I >, neurons > lutSumArrayType
 

Public Member Functions

auto & getLutArray ()
 
auto & getLutOutSum ()
 
auto getName ()
 
auto & getOutWithOffset ()
 
void load (boost::property_tree::ptree &tree, std::string keyPath)
 
 LutNeuronLayerFixedPoint ()
 
lutSumArrayTyperunWithInterpolation (const inputArrayType &inputArray)
 
void save (boost::property_tree::ptree &tree, std::string keyPath)
 
void setLutArray (const std::array< std::array< std::array< ap_fixed< output_W, output_I >, lutSize >, neurons >, inputSize > &lutArray)
 
void setName (std::string name)
 
virtual ~LutNeuronLayerFixedPoint ()
 

Static Public Attributes

static constexpr int input_W = input_I + input_F
 
static constexpr int lut_W = lut_I + lut_F
 
static constexpr int lutOutSum_I = lut_I + ceillog2(inputSize)
 
static constexpr int lutOutSum_W = lutOutSum_I + lut_F
 
static constexpr size_t lutSize = 1 << input_I
 
static constexpr int output_W = output_I + lut_F
 

Private Attributes

std::array< std::array< std::array< ap_fixed< lut_W, lut_I >, lutSize >, neurons >, inputSize > lutArray
 
lutSumArrayType lutOutSumArray
 
std::string name
 
ap_uint< output_I > outOffset = 1 << (output_I - 1)
 
std::array< ap_ufixed< output_W, output_I, AP_TRN, AP_SAT >, neurons > outputArray
 

Detailed Description

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
class lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >

Definition at line 42 of file LutNeuronLayerFixedPoint.h.

Member Typedef Documentation

◆ inputArrayType

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
typedef std::array<ap_ufixed<input_W, input_I, AP_TRN, AP_SAT>, inputSize> lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::inputArrayType

Definition at line 57 of file LutNeuronLayerFixedPoint.h.

◆ lutSumArrayType

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
typedef std::array<ap_fixed<lutOutSum_W, lutOutSum_I>, neurons> lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::lutSumArrayType

Definition at line 59 of file LutNeuronLayerFixedPoint.h.

Constructor & Destructor Documentation

◆ LutNeuronLayerFixedPoint()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::LutNeuronLayerFixedPoint ( )
inline

Definition at line 61 of file LutNeuronLayerFixedPoint.h.

61  { //FIXME initialise name(name)
62  //static_assert(lut_I <= (output_I - ceil(log2(inputSize)) ), "not correct lut_I, output_I and inputSize"); //TODO
63 
64  LogTrace("l1tOmtfEventPrint") << "Constructing LutNeuronLayerFixedPoint " << name << "\n input_I "
65  << std::setw(2) << input_I << " input_F " << std::setw(2) << input_F
66  << " input_W " << std::setw(2) << input_W << " inputSize " << std::setw(2)
67  << inputSize << "\n lut_I " << std::setw(2) << lut_I << " lut_F "
68  << std::setw(2) << lut_F << " lut_W " << std::setw(2) << lut_W << " lutSize "
69  << std::setw(2) << lutSize << "\n lutOutSum_I " << std::setw(2) << lutOutSum_I
70  << " lutOutSum_W " << std::setw(2) << lutOutSum_W << "\n output_I "
71  << std::setw(2) << output_I << " output_W " << std::setw(2) << output_W
72  << "\n neurons " << std::setw(2) << neurons << "\n outOffset " << outOffset << " = "
73  << std::hex << outOffset << " width " << outOffset.width << std::dec;
74  }
#define LogTrace(id)
static constexpr int input_I
static constexpr int input_F

◆ ~LutNeuronLayerFixedPoint()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
virtual lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::~LutNeuronLayerFixedPoint ( )
inlinevirtual

Definition at line 76 of file LutNeuronLayerFixedPoint.h.

76 {}

Member Function Documentation

◆ getLutArray()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
auto& lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::getLutArray ( )
inline

Definition at line 80 of file LutNeuronLayerFixedPoint.h.

80 { return lutArray; }
std::array< std::array< std::array< ap_fixed< lut_W, lut_I >, lutSize >, neurons >, inputSize > lutArray

◆ getLutOutSum()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
auto& lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::getLutOutSum ( )
inline

◆ getName()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
auto lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::getName ( void  )
inline

Definition at line 179 of file LutNeuronLayerFixedPoint.h.

Referenced by plotting.Plot::draw().

◆ getOutWithOffset()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
auto& lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::getOutWithOffset ( )
inline

◆ load()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
void lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::load ( boost::property_tree::ptree &  tree,
std::string  keyPath 
)
inline

Definition at line 109 of file LutNeuronLayerFixedPoint.h.

Referenced by lutNN::LutNetworkFixedPointRegression2Outputs< input_I, input_F, inputSize, layer1_lut_I, layer1_lut_F, layer1_neurons, layer1_output_I, layer2_input_I, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I, layer3_0_inputCnt, layer3_0_lut_I, layer3_0_lut_F, output0_I, output0_F, layer3_1_inputCnt, layer3_1_lut_I, layer3_1_lut_F, output1_I, output1_F >::load().

109  {
110  CHECK_VAR(tree, keyPath + "." + name, input_I)
111  CHECK_VAR(tree, keyPath + "." + name, input_F)
112  CHECK_VAR(tree, keyPath + "." + name, inputSize)
113  CHECK_VAR(tree, keyPath + "." + name, lut_I)
114  CHECK_VAR(tree, keyPath + "." + name, lut_F)
115  CHECK_VAR(tree, keyPath + "." + name, neurons)
116  CHECK_VAR(tree, keyPath + "." + name, output_I)
117 
118  for (unsigned int iInput = 0; iInput < lutArray.size(); iInput++) {
119  for (unsigned int iNeuron = 0; iNeuron < lutArray[iInput].size(); iNeuron++) {
120  auto& lut = lutArray.at(iInput).at(iNeuron);
121  auto str = tree.get<std::string>(keyPath + "." + name + ".lutArray." + std::to_string(iInput) + "." +
122  std::to_string(iNeuron));
123 
124  std::stringstream ss(str);
126 
127  for (auto& a : lut) {
128  if (std::getline(ss, item, ',')) {
129  a = std::stof(item, nullptr);
130  } else {
131  throw std::runtime_error(
132  "LutNeuronLayerFixedPoint::read: number of items get from file is smaller than lut size");
133  }
134  }
135  }
136  }
137  }
static std::string to_string(const XMLCh *ch)
static constexpr int input_I
std::array< std::array< std::array< ap_fixed< lut_W, lut_I >, lutSize >, neurons >, inputSize > lutArray
static constexpr int input_F
double a
Definition: hdecay.h:121
#define CHECK_VAR(tree, keyPath, var)
Definition: tree.py:1
#define str(s)

◆ runWithInterpolation()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
lutSumArrayType& lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::runWithInterpolation ( const inputArrayType inputArray)
inline

Definition at line 139 of file LutNeuronLayerFixedPoint.h.

Referenced by lutNN::LutNetworkFixedPointRegression2Outputs< input_I, input_F, inputSize, layer1_lut_I, layer1_lut_F, layer1_neurons, layer1_output_I, layer2_input_I, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I, layer3_0_inputCnt, layer3_0_lut_I, layer3_0_lut_F, output0_I, output0_F, layer3_1_inputCnt, layer3_1_lut_I, layer3_1_lut_F, output1_I, output1_F >::runWithInterpolation().

139  {
140  for (unsigned int iNeuron = 0; iNeuron < lutOutSumArray.size(); iNeuron++) {
141  auto& lutOutSum = lutOutSumArray.at(iNeuron);
142  lutOutSum = 0;
143  for (unsigned int iInput = 0; iInput < inputArray.size(); iInput++) {
144  auto address = inputArray.at(iInput).to_uint(); //address in principle is unsigned
145  auto& lut = lutArray.at(iInput).at(iNeuron);
146 
147  auto addresPlus1 = address + 1;
148  if (addresPlus1 >= lut.size())
149  addresPlus1 = address;
150 
151  auto derivative = lut.at(addresPlus1) - lut.at(address); // must be signed
152 
153  //N.B. the address and fractionalPart is the same for all neurons, what matters for the firmware
154  ap_ufixed<input_W - input_I, 0> fractionalPart = inputArray.at(iInput);
155 
156  auto result = lut.at(address) + fractionalPart * derivative;
157  lutOutSum += result;
158  }
159 
160  lutOutSumArray.at(iNeuron) = lutOutSum;
161  }
162 
163  return lutOutSumArray;
164  }
Derivative< X, A >::type derivative(const A &_)
Definition: Derivative.h:18
static constexpr int input_I
std::array< std::array< std::array< ap_fixed< lut_W, lut_I >, lutSize >, neurons >, inputSize > lutArray

◆ save()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
void lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::save ( boost::property_tree::ptree &  tree,
std::string  keyPath 
)
inline

Definition at line 87 of file LutNeuronLayerFixedPoint.h.

Referenced by lutNN::LutNetworkFixedPointRegression2Outputs< input_I, input_F, inputSize, layer1_lut_I, layer1_lut_F, layer1_neurons, layer1_output_I, layer2_input_I, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I, layer3_0_inputCnt, layer3_0_lut_I, layer3_0_lut_F, output0_I, output0_F, layer3_1_inputCnt, layer3_1_lut_I, layer3_1_lut_F, output1_I, output1_F >::save().

87  {
88  PUT_VAR(tree, keyPath + "." + name, input_I)
89  PUT_VAR(tree, keyPath + "." + name, input_F)
90  PUT_VAR(tree, keyPath + "." + name, inputSize)
91  PUT_VAR(tree, keyPath + "." + name, lut_I)
92  PUT_VAR(tree, keyPath + "." + name, lut_F)
93  PUT_VAR(tree, keyPath + "." + name, neurons)
94  PUT_VAR(tree, keyPath + "." + name, output_I)
95 
96  for (unsigned int iInput = 0; iInput < lutArray.size(); iInput++) {
97  for (unsigned int iNeuron = 0; iNeuron < lutArray[iInput].size(); iNeuron++) {
98  auto& lut = lutArray.at(iInput).at(iNeuron);
99  std::ostringstream ostr;
100  for (auto& a : lut) {
101  ostr << std::fixed << std::setprecision(19) << a.to_float() << ", ";
102  }
103  tree.put(keyPath + "." + name + ".lutArray." + std::to_string(iInput) + "." + std::to_string(iNeuron),
104  ostr.str());
105  }
106  }
107  }
#define PUT_VAR(tree, keyPath, var)
static std::string to_string(const XMLCh *ch)
static constexpr int input_I
std::array< std::array< std::array< ap_fixed< lut_W, lut_I >, lutSize >, neurons >, inputSize > lutArray
static constexpr int input_F
double a
Definition: hdecay.h:121
Definition: tree.py:1

◆ setLutArray()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
void lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::setLutArray ( const std::array< std::array< std::array< ap_fixed< output_W, output_I >, lutSize >, neurons >, inputSize > &  lutArray)
inline

Definition at line 82 of file LutNeuronLayerFixedPoint.h.

83  {
84  this->lutArray = lutArray;
85  }
std::array< std::array< std::array< ap_fixed< lut_W, lut_I >, lutSize >, neurons >, inputSize > lutArray

◆ setName()

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
void lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::setName ( std::string  name)
inline

Member Data Documentation

◆ input_W

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
constexpr int lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::input_W = input_I + input_F
static

◆ lut_W

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
constexpr int lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::lut_W = lut_I + lut_F
static

◆ lutArray

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
std::array<std::array<std::array<ap_fixed<lut_W, lut_I>, lutSize>, neurons>, inputSize> lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::lutArray
private

◆ lutOutSum_I

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
constexpr int lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::lutOutSum_I = lut_I + ceillog2(inputSize)
static

◆ lutOutSum_W

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
constexpr int lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::lutOutSum_W = lutOutSum_I + lut_F
static

◆ lutOutSumArray

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
lutSumArrayType lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::lutOutSumArray
private

◆ lutSize

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
constexpr size_t lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::lutSize = 1 << input_I
static

◆ name

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
std::string lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::name
private

Definition at line 190 of file LutNeuronLayerFixedPoint.h.

Referenced by ElectronMVAID.ElectronMVAID::__call__(), FWLite.ElectronMVAID::__call__(), dirstructure.Directory::__create_pie_image(), DisplayManager.DisplayManager::__del__(), dqm_interfaces.DirID::__eq__(), dirstructure.Directory::__get_full_path(), dirstructure.Comparison::__get_img_name(), dirstructure.Comparison::__make_image(), core.autovars.NTupleVariable::__repr__(), core.autovars.NTupleObjectType::__repr__(), core.autovars.NTupleObject::__repr__(), core.autovars.NTupleCollection::__repr__(), dirstructure.Directory::__repr__(), dqm_interfaces.DirID::__repr__(), dirstructure.Comparison::__repr__(), config.Service::__setattr__(), config.CFG::__str__(), counter.Counter::__str__(), average.Average::__str__(), FWLite.WorkingPoints::_reformat_cut_definitions(), core.autovars.NTupleObjectType::addSubObjects(), core.autovars.NTupleObjectType::addVariables(), core.autovars.NTupleObjectType::allVars(), dataset.CMSDataset::buildListOfFiles(), dataset.LocalDataset::buildListOfFiles(), dataset.CMSDataset::buildListOfFilesDBS(), dirstructure.Directory::calcStats(), validation.Sample::digest(), python.rootplot.utilities.Hist::divide(), python.rootplot.utilities.Hist::divide_wilson(), DisplayManager.DisplayManager::Draw(), core.autovars.NTupleVariable::fillBranch(), core.autovars.NTupleObject::fillBranches(), core.autovars.NTupleCollection::fillBranchesScalar(), core.autovars.NTupleCollection::fillBranchesVector(), core.autovars.NTupleCollection::get_cpp_declaration(), core.autovars.NTupleCollection::get_cpp_wrapper_class(), core.autovars.NTupleCollection::get_py_wrapper_class(), utils.StatisticalTest::get_status(), production_tasks.Task::getname(), lutNN::LutNeuronLayerFixedPoint< layer2_input_I, layer2_input_F, layer1_neurons, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I >::getName(), dataset.CMSDataset::getPrimaryDatasetEntries(), dataset.PrivateDataset::getPrimaryDatasetEntries(), VIDSelectorBase.VIDSelectorBase::initialize(), lutNN::LutNeuronLayerFixedPoint< layer2_input_I, layer2_input_F, layer1_neurons, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I >::load(), lutNN::LutNeuronLayerFixedPoint< layer2_input_I, layer2_input_F, layer1_neurons, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I >::LutNeuronLayerFixedPoint(), core.autovars.NTupleVariable::makeBranch(), core.autovars.NTupleObject::makeBranches(), core.autovars.NTupleCollection::makeBranchesScalar(), core.autovars.NTupleCollection::makeBranchesVector(), dirstructure.Directory::print_report(), dataset.BaseDataset::printInfo(), dataset.Dataset::printInfo(), production_tasks.MonitorJobs::run(), lutNN::LutNeuronLayerFixedPoint< layer2_input_I, layer2_input_F, layer1_neurons, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I >::save(), lutNN::LutNeuronLayerFixedPoint< layer2_input_I, layer2_input_F, layer1_neurons, layer2_lut_I, layer2_lut_F, layer2_neurons, layer3_input_I >::setName(), python.rootplot.utilities.Hist::TGraph(), python.rootplot.utilities.Hist::TH1F(), counter.Counter::write(), and average.Average::write().

◆ outOffset

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
ap_uint<output_I> lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::outOffset = 1 << (output_I - 1)
private

◆ output_W

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
constexpr int lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::output_W = output_I + lut_F
static

◆ outputArray

template<int input_I, int input_F, size_t inputSize, int lut_I, int lut_F, int neurons, int output_I>
std::array<ap_ufixed<output_W, output_I, AP_TRN, AP_SAT>, neurons> lutNN::LutNeuronLayerFixedPoint< input_I, input_F, inputSize, lut_I, lut_F, neurons, output_I >::outputArray
private