{
std::map<const ann::Operand *, enco::GlobalOffset> data_offset_ctx;
+std::map<const coco::Bag *, enco::GlobalOffset> bag_data_offset_ctx;
+
std::map<const coco::Arg *, enco::GlobalOffset> name_offset_ctx;
std::map<const coco::Arg *, enco::GlobalOffset> dims_offset_ctx;
GlobalOffset GlobalData::data_offset(const ann::Operand *o) { return data_offset_ctx.at(o); }
+GlobalOffset GlobalData::data_offset(const coco::Bag *bag)
+{
+ assert(bag_data_offset_ctx.find(bag) != bag_data_offset_ctx.end());
+ return bag_data_offset_ctx.at(bag);
+}
+
GlobalOffset GlobalData::name_offset(const coco::Input *in) { return name_offset_ctx.at(in); }
GlobalOffset GlobalData::dims_offset(const coco::Input *in) { return dims_offset_ctx.at(in); }
void generate_global_data(std::ostream &os, enco::Code *code)
{
auto m = code->module();
+ auto d = code->data();
+
auto ann_ctx = enco::SubnetManager::context(m);
auto global = make_unique<Global>(os);
+ //
+ // Emit Bag's weight
+ //
+ for (uint32_t n = 0; n < m->entity()->bag()->size(); ++n)
+ {
+ auto bag = m->entity()->bag()->at(n);
+
+ if (!d->allocated(bag))
+ {
+ // Skip if the weight value does not exist for a given bag
+ continue;
+ }
+
+ // NOTE The current implementation assumes that all the values are of float(fp32) type
+ // TODO Support non-float values
+ auto span = d->f32()->weight(bag);
+
+ assert(span.data() != nullptr);
+ assert(span.size() > 0);
+
+ auto const base = reinterpret_cast<const uint8_t *>(span.data());
+ uint32_t const size = span.size() * sizeof(float);
+
+ assert(bag_data_offset_ctx.find(bag) == bag_data_offset_ctx.end());
+ bag_data_offset_ctx[bag] = global->constant(base, size);
+ }
+
for (uint32_t n = 0; n < ann_ctx->count(); ++n)
{
auto binder = ann_ctx->nth(n);
struct GlobalData
{
static GlobalOffset data_offset(const ann::Operand *);
+ /**
+ * @brief Return the weight offset of a given bag
+ *
+ * @note The behavior of "data_offset" is undefined if a bag has no weight.
+ */
+ static GlobalOffset data_offset(const coco::Bag *);
+
static GlobalOffset name_offset(const coco::Input *);
static GlobalOffset dims_offset(const coco::Input *);
static GlobalOffset name_offset(const coco::Output *);