21#include "Validation.h"
39std::unique_ptr<NodeData> calc(
const NodeData *input_data,
const NodeData *bias_data,
51 validate(bias_add,
"BiasAdd is nullptr");
53 auto input_data = locomotiv::annot_data(bias_add->value());
54 auto bias_data = locomotiv::annot_data(bias_add->bias());
56 validate(input_data && bias_data,
"Input not ready");
59 "Wrong input domain");
61 std::unique_ptr<NodeData> bias_add_data = calc(input_data, bias_data, bias_add->axis());
63 assert(bias_add_data !=
nullptr);
64 annot_data(bias_add, std::move(bias_add_data));
70 validate(bias_add,
"BiasAdd is nullptr");
72 auto input_data = locomotiv::annot_data(bias_add->value());
73 auto bias_data = locomotiv::annot_data(bias_add->bias());
75 validate(input_data && bias_data,
"Input not ready");
78 "Wrong input domain");
80 std::unique_ptr<NodeData> bias_add_data = calc(input_data, bias_data, 3);
82 assert(bias_add_data !=
nullptr);
83 annot_data(bias_add, std::move(bias_add_data));
95std::unique_ptr<NodeData> calc(
const NodeData *input_data,
const NodeData *bias_data, uint32_t axis)
99 std::unique_ptr<NodeData> bias_add_data =
nullptr;
103 case loco::DataType::FLOAT32:
105 auto input_bufptr =
input_data->as_f32_bufptr();
107 auto bias_add_buf = make_buffer<float, LexicalLayout>(*
input_data->shape());
113 const auto &
index = e.current();
115 bias_add_buf.
at(index) = input_bufptr->at(index) + bias_bufptr->at(bias_index);
122 throw std::runtime_error(
"NYI for this DataType");
124 return bias_add_data;
134 execute_node(bias_add);
139 execute_node(bias_add);
Produce a value of domain D from an input value (of domain D) and a bias.
uint32_t & at(uint32_t axis)
uint32_t & dim(uint32_t axis)
bool validate(Code *code)
void validate(bool true_cond, const std::string &&exception_msg)
void annot_domain(loco::Node *node, const loco::Domain &domain)
Wrapper to annotate domain to node. Cannot annotate unknown domain.
std::unique_ptr< NodeData > make_data(const NodeData::Buffer< DT > &buffer)
Copy buffer to make NodeData.
loco::GraphInputIndex index(const TFPlaceholder *node)
Buffer< T > make_buffer(const Shape &shape)
Read-only no-template wrapper for 'Buffer'. Serves interface for input and output of 'Session'.
virtual const Shape * shape() const =0
virtual const Buffer< float > * as_f32_bufptr() const =0