class BagManager : public PtrManager<Bag>
{
public:
- BagManager(PtrLink<Bag, BagInfo> *link) : _link{link}
- {
- // DO NOTHING
- }
+ BagManager() = default;
public:
Bag *create(uint32_t size);
//
// NOTE A Bag SHOULD BE detached from IR before destruction
void destroy(Bag *b);
-
-private:
- PtrLink<Bag, BagInfo> *const _link;
};
} // namespace coco
class FeatureObject final : public Object
{
public:
- explicit FeatureObject(std::unique_ptr<FeatureObjectInfo> &&info,
- const PtrLink<Bag, BagInfo> *link);
+ explicit FeatureObject(std::unique_ptr<FeatureObjectInfo> &&info);
public:
~FeatureObject();
class Input final : public Arg
{
public:
- // NOTE bag_link is no longer used
- // TODO Do NOT take bag_link as an argument
- Input(const PtrLink<Bag, BagInfo> *bag_link, const nncc::core::ADT::tensor::Shape &shape);
+ Input(const nncc::core::ADT::tensor::Shape &shape);
private:
void onTake(Bag *) override;
struct InputManager final : public PtrManager<Input>
{
public:
- InputManager(const PtrLink<Bag, BagInfo> *bag_link) : _bag_link{bag_link}
- {
- // DO NOTHING
- }
+ InputManager() = default;
public:
Input *create(const nncc::core::ADT::tensor::Shape &);
-
-private:
- const PtrLink<Bag, BagInfo> *const _bag_link;
};
} // namespace coco
{
public:
InstrManager(PtrLink<Op, Instr> *op_link, const PtrLink<Instr, Block> *instr_link,
- const PtrLink<Object, ObjectInfo> *obj_link, const PtrLink<Bag, BagInfo> *bag_link)
- : _op_link{op_link}, _instr_link{instr_link}, _obj_link{obj_link}, _bag_link{bag_link}
+ const PtrLink<Object, ObjectInfo> *obj_link)
+ : _op_link{op_link}, _instr_link{instr_link}, _obj_link{obj_link}
{
// DO NOTHING
}
PtrLink<Op, Instr> *const _op_link;
const PtrLink<Instr, Block> *const _instr_link;
const PtrLink<Object, ObjectInfo> *const _obj_link;
- const PtrLink<Bag, BagInfo> *const _bag_link;
};
} // namespace coco
class KernelObject final : public Object
{
public:
- explicit KernelObject(std::unique_ptr<KernelObjectInfo> &&info,
- const PtrLink<Bag, BagInfo> *link);
+ explicit KernelObject(std::unique_ptr<KernelObjectInfo> &&info);
public:
virtual ~KernelObject();
class ObjectManager : public PtrManager<Object>
{
public:
- ObjectManager(PtrLink<Object, ObjectInfo> *obj_link, const PtrLink<Bag, BagInfo> *link)
- : _obj_link{obj_link}, _link{link}
+ ObjectManager(PtrLink<Object, ObjectInfo> *obj_link) : _obj_link{obj_link}
{
// DO NOTHING
}
private:
PtrLink<Object, ObjectInfo> *const _obj_link;
- const PtrLink<Bag, BagInfo> *const _link;
};
} // namespace coco
class Output final : public Arg
{
public:
- // NOTE bag_link is no longer used
- // TODO Do NOT take bag_link as an argument
- Output(const PtrLink<Bag, BagInfo> *bag_link, const nncc::core::ADT::tensor::Shape &shape);
+ Output(const nncc::core::ADT::tensor::Shape &shape);
private:
void onTake(Bag *) override;
struct OutputManager final : public PtrManager<Output>
{
public:
- OutputManager(const PtrLink<Bag, BagInfo> *bag_link) : _bag_link{bag_link}
- {
- // DO NOTHING
- }
+ OutputManager() = default;
public:
Output *create(const nncc::core::ADT::tensor::Shape &);
-
-private:
- const PtrLink<Bag, BagInfo> *const _bag_link;
};
} // namespace coco
class Read final
{
public:
- // NOTE bag_link is unnecessary
- // TODO Rewrite constructor
- Read(const PtrLink<Bag, BagInfo> *, Bag::Reader *r)
+ Read(Bag::Reader *r)
{
// Initialize link and reader
reader(r);
{
public:
// TODO Update constructor interface
- Shuffle(const PtrLink<Instr, Block> *, const PtrLink<Bag, BagInfo> *bag_link)
- : _from{bag_link, this}, _into{bag_link, this}
+ Shuffle(const PtrLink<Instr, Block> *) : _from{this}, _into{this}
{
// DO NOTHING
}
class Update final
{
public:
- // NOTE Bag-to-BagInfo link is no longer necessary
- // TODO Rewrite constructor
- Update(const PtrLink<Bag, BagInfo> *, Bag::Updater *u) { updater(u); }
+ Update(Bag::Updater *u) { updater(u); }
public:
~Update();
auto bag = nncc::foundation::make_unique<Bag>(std::move(info));
auto bag_ptr = bag.get();
- _link->set(bag_ptr, info_ptr);
-
return take(std::move(bag));
}
TEST(IR_BAG_MANAGER, create)
{
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::BagManager mgr{&bag_link};
+ coco::BagManager mgr;
auto bag = mgr.create(3);
ASSERT_EQ(bag->size(), 3);
-
- // BagManager SHOULD update Bag->BagInfo link properly
- ASSERT_NE(bag_link.find(bag), nullptr);
-
- auto info = bag_link.find(bag);
-
- ASSERT_EQ(info->size(), 3);
}
TEST(IR_BAG_MANAGER, destruct)
{
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::BagManager mgr{&bag_link};
+ coco::BagManager mgr;
auto b = mgr.create(3);
mgr.destroy(b);
}
protected:
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
const coco::PtrLink<coco::Op, coco::Instr> op_link;
protected:
- coco::ObjectManager obj_mgr{&obj_link, &bag_link};
+ coco::ObjectManager obj_mgr{&obj_link};
private:
std::vector<std::unique_ptr<coco::Conv2D>> _allocated;
class DefTest : public ::testing::Test
{
protected:
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
- coco::ObjectManager obj_mgr{&obj_link, &bag_link};
+ coco::ObjectManager obj_mgr{&obj_link};
};
} // namespace
class DepTest : public ::testing::Test
{
protected:
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
- coco::BagManager bag_mgr{&bag_link};
- coco::ObjectManager obj_mgr{&obj_link, &bag_link};
+ coco::BagManager bag_mgr;
+ coco::ObjectManager obj_mgr{&obj_link};
};
} // namespace
namespace coco
{
-FeatureObject::FeatureObject(std::unique_ptr<FeatureObjectInfo> &&info,
- const PtrLink<Bag, BagInfo> *link)
- : _info(std::move(info))
+FeatureObject::FeatureObject(std::unique_ptr<FeatureObjectInfo> &&info) : _info(std::move(info))
{
_map.resize(nncc::core::ADT::feature::num_elements(shape()));
}
coco::FeatureObject *allocate(const feature::Shape &shape)
{
auto info = make_unique<coco::FeatureObjectInfo>(shape);
- auto o = new coco::FeatureObject{std::move(info), &_bag_link};
+ auto o = new coco::FeatureObject{std::move(info)};
_allocated.emplace_back(o);
return o;
}
private:
- coco::PtrLink<coco::Bag, coco::BagInfo> _bag_link;
-
-private:
std::vector<std::unique_ptr<coco::FeatureObject>> _allocated;
};
} // namespace
namespace coco
{
-Input::Input(const PtrLink<Bag, BagInfo> *, const nncc::core::ADT::tensor::Shape &shape)
- : Arg{shape}
+Input::Input(const nncc::core::ADT::tensor::Shape &shape) : Arg{shape}
{
// DO NOT?HING
}
TEST(IR_INPUT, ctor_should_set_shape)
{
- const coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
const nncc::core::ADT::tensor::Shape shape{1, 3, 3, 1};
- coco::Input input{&bag_link, shape};
+ coco::Input input{shape};
ASSERT_EQ(input.shape(), shape);
ASSERT_TRUE(input.name().empty());
TEST(IR_INPUT, bag_update)
{
// Create a bag
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::BagManager bag_mgr{&bag_link};
+ coco::BagManager bag_mgr;
auto bag = bag_mgr.create(9);
- auto bag_info = bag_link.find(bag);
-
- ASSERT_NE(bag_info, nullptr);
const nncc::core::ADT::tensor::Shape shape{1, 3, 3, 1};
- coco::Input input{&bag_link, shape};
+ coco::Input input{shape};
input.bag(bag);
ASSERT_EQ(input.bag(), bag);
TEST(IR_INPUT, name_update)
{
- const coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
const nncc::core::ADT::tensor::Shape shape{1, 3, 3, 1};
- coco::Input input{&bag_link, shape};
+ coco::Input input{shape};
input.name("data");
ASSERT_EQ(input.name(), "data");
TEST(IR_INPUT, at)
{
- const coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
const Shape shape{1, 3, 3, 1};
- coco::Input input{&bag_link, shape};
+ coco::Input input{shape};
coco::Input *mutable_ptr = &input;
const coco::Input *immutable_ptr = &input;
Input *InputManager::create(const nncc::core::ADT::tensor::Shape &shape)
{
- return take(nncc::foundation::make_unique<Input>(_bag_link, shape));
+ return take(nncc::foundation::make_unique<Input>(shape));
}
} // namespace coco
TEST(IR_INPUT_MANAGER, make)
{
- const coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::InputManager mgr{&bag_link};
+ coco::InputManager mgr;
const nncc::core::ADT::tensor::Shape shape{1, 3, 3, 1};
auto input = mgr.create(shape);
protected:
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
coco::PtrLink<coco::Op, coco::Instr> op_link;
// TODO Rename link as instr_link
coco::PtrLink<coco::Instr, coco::Block> link;
- coco::ObjectManager obj_mgr{&obj_link, &bag_link};
+ coco::ObjectManager obj_mgr{&obj_link};
coco::OpManager op_mgr{&op_link, &obj_link};
};
} // namespace
template <> Shuffle *InstrManager::create(void)
{
- return take(nncc::foundation::make_unique<Shuffle>(_instr_link, _bag_link));
+ return take(nncc::foundation::make_unique<Shuffle>(_instr_link));
}
void InstrManager::destroy(Instr *ins)
coco::PtrLink<coco::Op, coco::Instr> op_link;
coco::PtrLink<coco::Instr, coco::Block> ins_link;
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::InstrManager mgr{&op_link, &ins_link, &obj_link, &bag_link};
+ coco::InstrManager mgr{&op_link, &ins_link, &obj_link};
};
} // namespace
coco::PtrLink<coco::Op, coco::Instr> op_link;
coco::PtrLink<coco::Instr, coco::Block> link;
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::InstrManager mgr{&op_link, &link, &obj_link, &bag_link};
+ coco::InstrManager mgr{&op_link, &link, &obj_link};
// Conv2D
{
namespace coco
{
-KernelObject::KernelObject(std::unique_ptr<KernelObjectInfo> &&info,
- const PtrLink<Bag, BagInfo> *link)
- : _info{std::move(info)}
+KernelObject::KernelObject(std::unique_ptr<KernelObjectInfo> &&info) : _info{std::move(info)}
{
_map.resize(nncc::core::ADT::kernel::num_elements(shape()));
}
coco::KernelObject *allocate(const kernel::Shape &shape)
{
auto info = make_unique<coco::KernelObjectInfo>(shape);
- auto o = new coco::KernelObject{std::move(info), &_bag_link};
+ auto o = new coco::KernelObject{std::move(info)};
_allocated.emplace_back(o);
return o;
}
private:
- coco::PtrLink<coco::Bag, coco::BagInfo> _bag_link;
-
-private:
std::vector<std::unique_ptr<coco::KernelObject>> _allocated;
};
} // namespace
class ModuleImpl final : public coco::Module
{
public:
- std::unique_ptr<coco::PtrLink<coco::Bag, coco::BagInfo>> _bag_link;
std::unique_ptr<coco::PtrLink<coco::Object, coco::ObjectInfo>> _obj_link;
std::unique_ptr<coco::PtrLink<coco::Op, coco::Instr>> _op_link;
std::unique_ptr<coco::PtrLink<coco::Instr, coco::Block>> _instr_link;
std::unique_ptr<Module> Module::create(void)
{
- auto bag_link = make_unique<coco::PtrLink<Bag, BagInfo>>();
auto obj_link = make_unique<coco::PtrLink<Object, ObjectInfo>>();
auto op_link = make_unique<coco::PtrLink<Op, Instr>>();
auto ins_link = make_unique<coco::PtrLink<Instr, Block>>();
auto mgr = make_unique<::EntityManagerImpl>();
{
- mgr->_bag = make_unique<coco::BagManager>(bag_link.get());
- mgr->_object = make_unique<coco::ObjectManager>(obj_link.get(), bag_link.get());
+ mgr->_bag = make_unique<coco::BagManager>();
+ mgr->_object = make_unique<coco::ObjectManager>(obj_link.get());
mgr->_op = make_unique<coco::OpManager>(op_link.get(), obj_link.get());
- mgr->_instr = make_unique<coco::InstrManager>(op_link.get(), ins_link.get(), obj_link.get(),
- bag_link.get());
+ mgr->_instr = make_unique<coco::InstrManager>(op_link.get(), ins_link.get(), obj_link.get());
mgr->_block = make_unique<coco::BlockManager>(blk_link.get(), ins_link.get());
- mgr->_input = make_unique<coco::InputManager>(bag_link.get());
- mgr->_output = make_unique<coco::OutputManager>(bag_link.get());
+ mgr->_input = make_unique<coco::InputManager>();
+ mgr->_output = make_unique<coco::OutputManager>();
}
m->_entity = std::move(mgr);
m->_input = make_unique<coco::InputList>();
m->_output = make_unique<coco::OutputList>();
- m->_bag_link = std::move(bag_link);
m->_obj_link = std::move(obj_link);
m->_op_link = std::move(op_link);
m->_instr_link = std::move(ins_link);
class ObjectTest : public ::testing::Test
{
protected:
- // TODO Rename as bag_link
- coco::PtrLink<coco::Bag, coco::BagInfo> link;
-
- coco::BagManager bag_mgr{&link};
+ coco::BagManager bag_mgr;
};
} // namespace
auto info = make_unique<FeatureObjectInfo>(shape);
auto info_ptr = info.get();
- auto feature = make_unique<FeatureObject>(std::move(info), _link);
+ auto feature = make_unique<FeatureObject>(std::move(info));
auto feature_ptr = feature.get();
_obj_link->set(feature_ptr, info_ptr);
auto info = make_unique<KernelObjectInfo>(shape);
auto info_ptr = info.get();
- auto kernel = make_unique<KernelObject>(std::move(info), _link);
+ auto kernel = make_unique<KernelObject>(std::move(info));
auto kernel_ptr = kernel.get();
_obj_link->set(kernel_ptr, info_ptr);
const Shape shape{1, 3, 3};
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::ObjectManager mgr{&obj_link, &bag_link};
+ coco::ObjectManager mgr{&obj_link};
auto o = mgr.create(shape);
const Shape shape{1, 1, 3, 3};
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::ObjectManager mgr{&obj_link, &bag_link};
+ coco::ObjectManager mgr{&obj_link};
auto o = mgr.create(shape);
namespace coco
{
-Output::Output(const PtrLink<Bag, BagInfo> *, const nncc::core::ADT::tensor::Shape &shape)
- : Arg{shape}
+Output::Output(const nncc::core::ADT::tensor::Shape &shape) : Arg{shape}
{
// DO NOTHING
}
TEST(IR_OUTPUT, ctor_should_set_shape)
{
- const coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
const nncc::core::ADT::tensor::Shape shape{1, 3, 3, 1};
- coco::Output output{&bag_link, shape};
+ coco::Output output{shape};
ASSERT_EQ(output.shape(), shape);
}
TEST(IR_OUTPUT, bag_update)
{
// Create a bag for test
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::BagManager bag_mgr{&bag_link};
+ coco::BagManager bag_mgr;
auto bag = bag_mgr.create(9);
- auto bag_info = bag_link.find(bag);
const nncc::core::ADT::tensor::Shape shape{1, 3, 3, 1};
- coco::Output output{&bag_link, shape};
+ coco::Output output{shape};
output.bag(bag);
ASSERT_EQ(output.bag(), bag);
TEST(IR_OUTPUT, name_update)
{
- const coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
const nncc::core::ADT::tensor::Shape shape{1, 3, 3, 1};
- coco::Output output{&bag_link, shape};
+ coco::Output output{shape};
output.name("softmax");
ASSERT_EQ(output.name(), "softmax");
TEST(IR_OUTPUT, at)
{
- const coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
const Shape shape{1, 3, 3, 1};
- coco::Output input{&bag_link, shape};
+ coco::Output input{shape};
coco::Output *mutable_ptr = &input;
const coco::Output *immutable_ptr = &input;
Output *OutputManager::create(const nncc::core::ADT::tensor::Shape &shape)
{
- return take(nncc::foundation::make_unique<Output>(_bag_link, shape));
+ return take(nncc::foundation::make_unique<Output>(shape));
}
} // namespace coco
TEST(IR_OUTPUT_MANAGER, make)
{
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
- coco::OutputManager mgr{&bag_link};
+ coco::OutputManager mgr;
const nncc::core::ADT::tensor::Shape shape{1, 3, 3, 1};
auto output = mgr.create(shape);
class ReadTest : public ::testing::Test
{
protected:
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
- coco::BagManager bag_mgr{&bag_link};
+ coco::BagManager bag_mgr;
};
} // namespace
::mock::Reader read;
// TODO Rename 'slot'
- coco::Read slot{&bag_link, &read};
+ coco::Read slot{&read};
ASSERT_EQ(slot.bag(), nullptr);
}
::mock::Reader read;
// TODO Rename 'slot'
- coco::Read slot{&bag_link, &read};
+ coco::Read slot{&read};
auto bag = bag_mgr.create(16);
auto bag = bag_mgr.create(1);
{
- coco::Read read{&bag_link, &reader};
+ coco::Read read{&reader};
read.bag(bag);
}
protected:
coco::Shuffle *allocate(void)
{
- auto ins = new coco::Shuffle{&instr_link, &bag_link};
+ auto ins = new coco::Shuffle{&instr_link};
_allocated.emplace_back(ins);
return ins;
}
class UpdateTest : public ::testing::Test
{
protected:
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
-
- coco::BagManager bag_mgr{&bag_link};
+ coco::BagManager bag_mgr;
};
} // namespace
::mock::Update update;
// TODO Rename 'slot'
- coco::Update slot{&bag_link, &update};
+ coco::Update slot{&update};
ASSERT_EQ(slot.bag(), nullptr);
}
::mock::Update update;
// TODO Rename 'slot'
- coco::Update slot{&bag_link, &update};
+ coco::Update slot{&update};
auto bag = bag_mgr.create(16);
auto bag = bag_mgr.create(1);
{
- coco::Update update{&bag_link, &updater};
+ coco::Update update{&updater};
update.bag(bag);
ASSERT_EQ(bag->updates()->size(), 1);
}
class UseTest : public ::testing::Test
{
protected:
- coco::PtrLink<coco::Bag, coco::BagInfo> bag_link;
coco::PtrLink<coco::Object, coco::ObjectInfo> obj_link;
- coco::ObjectManager obj_mgr{&obj_link, &bag_link};
+ coco::ObjectManager obj_mgr{&obj_link};
};
} // namespace