#define __COCO_IR_FEATURE_OBJECT_H__
#include "coco/IR/Object.h"
+#include "coco/IR/FeatureObjectInfo.h"
#include "coco/IR/ElemID.h"
#include <nncc/core/ADT/feature/Shape.h>
class FeatureObject final : public Object
{
public:
- explicit FeatureObject(const PtrLink<Bag, BagInfo> *link,
- const nncc::core::ADT::feature::Shape &shape);
+ explicit FeatureObject(std::unique_ptr<FeatureObjectInfo> &&info,
+ const PtrLink<Bag, BagInfo> *link);
public:
- virtual ~FeatureObject() = default;
+ ~FeatureObject();
public:
FeatureObject *asFeature(void) override { return this; }
const FeatureObject *asFeature(void) const override { return this; }
public:
- const nncc::core::ADT::feature::Shape &shape(void) const { return _shape; }
-
-private:
- nncc::core::ADT::feature::Shape const _shape;
+ const nncc::core::ADT::feature::Shape &shape(void) const;
public:
ElemID &at(uint32_t ch, uint32_t row, uint32_t col);
template <typename LayoutImpl> void reorder(void) { reorder(LayoutImpl{}); }
private:
+ std::unique_ptr<FeatureObjectInfo> _info;
+
std::vector<ElemID> _map;
};
--- /dev/null
+#ifndef __COCO_IR_FEATURE_OBJECT_INFO_FORWARD_INFO_H__
+#define __COCO_IR_FEATURE_OBJECT_INFO_FORWARD_INFO_H__
+
+namespace coco
+{
+
+class FeatureObjectInfo;
+
+} // namespace coco
+
+#endif // __COCO_IR_FEATURE_OBJECT_INFO_FORWARD_INFO_H__
--- /dev/null
+#ifndef __COCO_IR_FEATURE_OBJECT_INFO_H__
+#define __COCO_IR_FEATURE_OBJECT_INFO_H__
+
+#include <nncc/core/ADT/feature/Shape.h>
+
+namespace coco
+{
+
+class FeatureObjectInfo final
+{
+public:
+ FeatureObjectInfo(const nncc::core::ADT::feature::Shape &shape) : _shape{shape}
+ {
+ // DO NOTHING
+ }
+
+public:
+ const nncc::core::ADT::feature::Shape &shape(void) const { return _shape; }
+
+private:
+ nncc::core::ADT::feature::Shape const _shape;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_FEATURE_OBJECT_INFO_H__
#include "coco/IR/FeatureObject.h"
+#include "coco/IR/FeatureObjectInfo.h"
#include <nncc/core/ADT/feature/CHWLayout.h>
namespace coco
{
-FeatureObject::FeatureObject(const PtrLink<Bag, BagInfo> *link,
- const nncc::core::ADT::feature::Shape &shape)
- : Object{link}, _shape{shape}
+FeatureObject::FeatureObject(std::unique_ptr<FeatureObjectInfo> &&info,
+ const PtrLink<Bag, BagInfo> *link)
+ : Object{link}, _info(std::move(info))
{
- _map.resize(nncc::core::ADT::feature::num_elements(shape));
+ _map.resize(nncc::core::ADT::feature::num_elements(shape()));
}
+FeatureObject::~FeatureObject()
+{
+ // DO NOTHING
+}
+
+const nncc::core::ADT::feature::Shape &FeatureObject::shape(void) const { return _info->shape(); }
+
ElemID &FeatureObject::at(uint32_t ch, uint32_t row, uint32_t col)
{
- return _map.at(l.offset(_shape, ch, row, col));
+ return _map.at(l.offset(shape(), ch, row, col));
}
const ElemID &FeatureObject::at(uint32_t ch, uint32_t row, uint32_t col) const
{
- return _map.at(l.offset(_shape, ch, row, col));
+ return _map.at(l.offset(shape(), ch, row, col));
}
void FeatureObject::reorder(const nncc::core::ADT::feature::Layout &l)
{
- for (uint32_t ch = 0; ch < _shape.depth(); ++ch)
+ for (uint32_t ch = 0; ch < shape().depth(); ++ch)
{
- for (uint32_t row = 0; row < _shape.height(); ++row)
+ for (uint32_t row = 0; row < shape().height(); ++row)
{
- for (uint32_t col = 0; col < _shape.width(); ++col)
+ for (uint32_t col = 0; col < shape().width(); ++col)
{
- at(ch, row, col) = ElemID{l.offset(_shape, ch, row, col)};
+ at(ch, row, col) = ElemID{l.offset(shape(), ch, row, col)};
}
}
}
#include "coco/IR/FeatureObject.h"
+#include "coco/IR/FeatureObjectInfo.h"
+
+#include <nncc/foundation/Memory.h>
#include <vector>
#include <memory>
#include <gtest/gtest.h>
using namespace nncc::core::ADT;
+using nncc::foundation::make_unique;
namespace
{
protected:
coco::FeatureObject *allocate(const feature::Shape &shape)
{
- auto o = new coco::FeatureObject{&_bag_link, shape};
+ auto info = make_unique<coco::FeatureObjectInfo>(shape);
+ auto o = new coco::FeatureObject{std::move(info), &_bag_link};
_allocated.emplace_back(o);
return o;
}
--- /dev/null
+#include "coco/IR/FeatureObjectInfo.h"
+
+#include <gtest/gtest.h>
+
+TEST(FeatureObjectInfoTest, constructor)
+{
+ const nncc::core::ADT::feature::Shape shape{1, 3, 3};
+ const coco::FeatureObjectInfo info{shape};
+
+ ASSERT_EQ(info.shape(), shape);
+}
#include "coco/IR/ObjectManager.h"
#include "coco/IR/FeatureObject.h"
+#include "coco/IR/FeatureObjectInfo.h"
#include "coco/IR/KernelObject.h"
#include <nncc/foundation/Memory.h>
FeatureObject *ObjectManager::create(const nncc::core::ADT::feature::Shape &shape)
{
- return take(make_unique<FeatureObject>(_link, shape));
+ auto info = make_unique<FeatureObjectInfo>(shape);
+ return take(make_unique<FeatureObject>(std::move(info), _link));
}
KernelObject *ObjectManager::create(const nncc::core::ADT::kernel::Shape &shape)