10 #ifndef L1Trigger_L1TMuonOverlapPhase2_LutNeuronlayerFixedPoint_h 11 #define L1Trigger_L1TMuonOverlapPhase2_LutNeuronlayerFixedPoint_h 20 #include <boost/property_tree/ptree.hpp> 31 <<
"Argument of floorlog2 must be grater than 0, while " <<
i <<
" used.\n";
37 <<
"Argument of ceillog2 must be grater than 0, while " <<
i <<
" used.\n";
41 template <
int input_I,
int input_F,
size_t inputSize,
int lut_I,
int lut_F,
int neurons,
int output_I>
57 typedef std::array<ap_ufixed<input_W, input_I, AP_TRN, AP_SAT>, inputSize>
inputArrayType;
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 " 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 <<
" = " 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() <<
", ";
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);
124 std::stringstream
ss(
str);
127 for (
auto&
a : lut) {
128 if (std::getline(
ss,
item,
',')) {
129 a = std::stof(
item,
nullptr);
131 throw std::runtime_error(
132 "LutNeuronLayerFixedPoint::read: number of items get from file is smaller than lut size");
140 for (
unsigned int iNeuron = 0; iNeuron <
lutOutSumArray.size(); iNeuron++) {
143 for (
unsigned int iInput = 0; iInput < inputArray.size(); iInput++) {
144 auto address = inputArray.at(iInput).to_uint();
145 auto& lut =
lutArray.at(iInput).at(iNeuron);
147 auto addresPlus1 = address + 1;
148 if (addresPlus1 >= lut.size())
149 addresPlus1 = address;
151 auto derivative = lut.at(addresPlus1) - lut.at(address);
154 ap_ufixed<
input_W -
input_I, 0> fractionalPart = inputArray.at(iInput);
172 for (
unsigned int iOut = 0; iOut <
lutOutSumArray.size(); iOut++) {
183 std::array<ap_ufixed<output_W, output_I, AP_TRN, AP_SAT>, neurons>
outputArray;
187 std::array<std::array<std::array<ap_fixed<lut_W, lut_I>,
lutSize>, neurons>, inputSize>
static constexpr int lutOutSum_I
std::array< ap_ufixed< input_W, input_I, AP_TRN, AP_SAT >, inputSize > inputArrayType
#define PUT_VAR(tree, keyPath, var)
constexpr size_t floorlog2(size_t i)
Derivative< X, A >::type derivative(const A &_)
std::array< ap_fixed< lutOutSum_W, lutOutSum_I >, neurons > lutSumArrayType
lutSumArrayType & runWithInterpolation(const inputArrayType &inputArray)
static constexpr int output_W
void setLutArray(const std::array< std::array< std::array< ap_fixed< output_W, output_I >, lutSize >, neurons >, inputSize > &lutArray)
void setName(std::string name)
static std::string to_string(const XMLCh *ch)
auto & getOutWithOffset()
static constexpr int lut_W
void load(boost::property_tree::ptree &tree, std::string keyPath)
static constexpr int lutOutSum_W
ap_uint< output_I > outOffset
virtual ~LutNeuronLayerFixedPoint()
static constexpr int input_W
static constexpr int input_I
static constexpr size_t lutSize
std::array< ap_ufixed< output_W, output_I, AP_TRN, AP_SAT >, neurons > outputArray
std::array< std::array< std::array< ap_fixed< lut_W, lut_I >, lutSize >, neurons >, inputSize > lutArray
lutSumArrayType lutOutSumArray
LutNeuronLayerFixedPoint()
static constexpr int input_F
void save(boost::property_tree::ptree &tree, std::string keyPath)
#define CHECK_VAR(tree, keyPath, var)
constexpr size_t ceillog2(size_t i)