coco::Module *module(void) const { return _module; }
coco::Data *data(void) const { return _data; }
-public:
- ANNContext *ann(void) { return &_ann; }
- const ANNContext *ann(void) const { return &_ann; }
-
private:
coco::Module *const _module;
coco::Data *const _data;
-
-private:
- ANNContext _ann;
};
} // namespace enco
ASSERT_EQ(code.module(), m.get());
ASSERT_EQ(code.data(), d.get());
- ASSERT_NE(code.ann(), nullptr);
}
#include "CppCode.h"
#include "Transforms/GlobalDataGeneration.h"
+#include "Transforms/Split.h"
#include "CppGen/MemoryContext.h"
};
auto is_host_block = [code](const coco::Block *blk) {
- return (blk) ? (code->ann()->find(blk) == nullptr) : false;
+ auto m = blk->module();
+ auto ann_ctx = enco::SubnetManager::context(m);
+ return (blk) ? (ann_ctx->find(blk) == nullptr) : false;
};
for (const auto &updater : coco::updaters(b))
void CppCode::dump(std::ostream &os) const
{
auto m = _code->module();
+ auto ann_ctx = enco::SubnetManager::context(m);
NetworkStruct network;
InvokeFunction invoke;
* };
*
*/
- for (uint32_t n = 0; n < _code->ann()->count(); ++n)
+ for (uint32_t n = 0; n < ann_ctx->count(); ++n)
{
SubnetStructBuilder builder;
- auto subnet_binder = _code->ann()->nth(n);
+ auto subnet_binder = ann_ctx->nth(n);
auto subnet_struct_name = pp::fmt("Subnet_", subnet_ctx.size());
auto subnet_field_name = pp::fmt("_subnet_", subnet_ctx.size());
invoke.body.append("{");
invoke.body.indent();
- if (auto binder = _code->ann()->find(blk))
+ if (auto binder = ann_ctx->find(blk))
{
// Generate code that invokes Android NN sub-network
auto lines = subnet_compiler.compile(binder);
*/
#include "GlobalDataGeneration.h"
+#include "Split.h"
#include "Dims.h"
#include <nncc/foundation/Memory.h>
void generate_global_data(std::ostream &os, enco::Code *code)
{
auto m = code->module();
+ auto ann_ctx = enco::SubnetManager::context(m);
+
auto global = make_unique<Global>(os);
- for (uint32_t n = 0; n < code->ann()->count(); ++n)
+ for (uint32_t n = 0; n < ann_ctx->count(); ++n)
{
- auto binder = code->ann()->nth(n);
+ auto binder = ann_ctx->nth(n);
auto emit = [&](const ann::OperandID &id, const ann::Operand *info) {
if (info->weight())
#include <coco/IR.h>
#include <nncc/core/ADT/kernel/NHWCLayout.h>
+#include <nncc/foundation/Memory.h>
+#include <map>
#include <stdexcept>
#include <functional>
+using nncc::foundation::make_unique;
+
+namespace
+{
+
+std::map<const coco::Module *, std::unique_ptr<ANNContext>> _subnet_contexts;
+
+} // namespace
+
+namespace enco
+{
+
+const ANNContext *SubnetManager::context(const coco::Module *m)
+{
+ return _subnet_contexts.at(m).get();
+}
+
+} // namespace enco
+
namespace
{
void SplitPass::runOnCode(enco::Code *code) const
{
- ANNGroupBuilder group_builder{code->ann()};
+ auto ann_ctx = make_unique<ANNContext>();
+
+ ANNGroupBuilder group_builder{ann_ctx.get()};
group_builder.build(code);
ANNModuleBuilder module_builder;
- module_builder.build(code->ann());
+ module_builder.build(ann_ctx.get());
+
+ _subnet_contexts[code->module()] = std::move(ann_ctx);
}
} // namespace enco
namespace enco
{
+struct SubnetManager
+{
+ static const ANNContext *context(const coco::Module *m);
+};
+
/**
* @brief Split instructions into a set of phases
*/