#include "coco/IR/ElemID.h"
#include <nncc/core/ADT/feature/Shape.h>
+#include <nncc/core/ADT/feature/Layout.h>
#include <vector>
ElemID &at(uint32_t ch, uint32_t row, uint32_t col);
const ElemID &at(uint32_t ch, uint32_t row, uint32_t col) const;
+public:
+ void reorder(const nncc::core::ADT::feature::Layout &l);
+ template<typename LayoutImpl> void reorder(void) { reorder(LayoutImpl{}); }
+
private:
std::vector<ElemID> _map;
};
auto ifm_obj = m->entity()->object()->create(ifm_shape);
ifm_obj->bag(ifm_bag);
-
- for (uint32_t ch = 0; ch < ifm_shape.depth(); ++ch)
- {
- for (uint32_t row = 0; row < ifm_shape.height(); ++row)
- {
- for (uint32_t col = 0; col < ifm_shape.width(); ++col)
- {
- const static CHWLayout l{};
- const auto offset = static_cast<uint32_t>(l.offset(ifm_shape, ch, row, col));
-
- ifm_obj->at(ch, row, col) = coco::ElemID{offset};
- }
- }
- }
+ ifm_obj->reorder<CHWLayout>();
const nncc::core::ADT::kernel::Shape ker_shape{1, 1, 3, 3};
auto ker_bag = m->entity()->bag()->create(num_elements(ker_shape));
auto ofm_obj = m->entity()->object()->create(ofm_shape);
ofm_obj->bag(ofm_bag);
-
- for (uint32_t ch = 0; ch < ofm_shape.depth(); ++ch)
- {
- for (uint32_t row = 0; row < ofm_shape.height(); ++row)
- {
- for (uint32_t col = 0; col < ofm_shape.width(); ++col)
- {
- const static CHWLayout l{};
- const auto offset = static_cast<uint32_t>(l.offset(ofm_shape, ch, row, col));
-
- ofm_obj->at(ch, row, col) = coco::ElemID{offset};
- }
- }
- }
+ ofm_obj->reorder<CHWLayout>();
// Create Conv2D operation
//
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 row = 0; row < _shape.height(); ++row)
+ {
+ for (uint32_t col = 0; col < _shape.width(); ++col)
+ {
+ at(ch, row, col) = ElemID{l.offset(_shape, ch, row, col)};
+ }
+ }
+ }
+}
+
} // namespace coco