--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __COCO_IR_GENERIC_KERNEL_LAYOUT_H__
+#define __COCO_IR_GENERIC_KERNEL_LAYOUT_H__
+
+#include "coco/IR/ElemID.h"
+
+#include <nncc/core/ADT/kernel/Layout.h>
+
+#include <vector>
+
+namespace coco
+{
+
+class GenericKernelLayout
+{
+public:
+ GenericKernelLayout(const nncc::core::ADT::kernel::Shape &shape);
+
+public:
+ const nncc::core::ADT::kernel::Shape &shape(void) const { return _shape; }
+
+ ElemID &at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col);
+ ElemID at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const;
+
+ void reorder(const nncc::core::ADT::kernel::Layout &l);
+ template <typename LayoutImpl> void reorder(void) { reorder(LayoutImpl{}); }
+
+private:
+ nncc::core::ADT::kernel::Shape _shape;
+
+private:
+ std::vector<ElemID> _content;
+};
+
+} // namespace coco
+
+#endif // __COCO_IR_GENERIC_KERNEL_LAYOUT_H__
#define __COCO_IR_KERNEL_OBJECT_H__
#include "coco/IR/Object.h"
+#include "coco/IR/GenericKernelLayout.h"
#include "coco/IR/ElemID.h"
#include <nncc/core/ADT/kernel/Shape.h>
#include <nncc/core/ADT/kernel/Layout.h>
-#include <vector>
-
namespace coco
{
const nncc::core::ADT::kernel::Shape &shape(void) const;
public:
+ // Deprecated
ElemID &at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col);
- const ElemID &at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const;
+ ElemID at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const;
public:
+ // Deprecated
void reorder(const nncc::core::ADT::kernel::Layout &l);
+ // Deprecated
template <typename LayoutImpl> void reorder(void) { reorder(LayoutImpl{}); }
+public:
+ const GenericKernelLayout *layout(void) const { return _layout.get(); }
+ void layout(std::unique_ptr<GenericKernelLayout> &&l) { _layout = std::move(l); }
+
private:
- nncc::core::ADT::kernel::Shape _shape;
- std::vector<ElemID> _map;
+ std::unique_ptr<GenericKernelLayout> _layout;
};
} // namespace coco
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "coco/IR/GenericKernelLayout.h"
+
+#include <nncc/core/ADT/kernel/NCHWLayout.h>
+
+#include <cassert>
+
+using nncc::core::ADT::kernel::num_elements;
+
+namespace
+{
+
+nncc::core::ADT::kernel::NCHWLayout l;
+
+} // namespace
+
+namespace coco
+{
+
+GenericKernelLayout::GenericKernelLayout(const nncc::core::ADT::kernel::Shape &shape)
+ : _shape{shape}
+{
+ _content.resize(num_elements(_shape));
+}
+
+ElemID &GenericKernelLayout::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col)
+{
+ return _content.at(l.offset(_shape, n, ch, row, col));
+}
+
+ElemID GenericKernelLayout::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const
+{
+ return _content.at(l.offset(_shape, n, ch, row, col));
+}
+
+void GenericKernelLayout::reorder(const nncc::core::ADT::kernel::Layout &l)
+{
+ for (uint32_t n = 0; n < shape().count(); ++n)
+ {
+ 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(n, ch, row, col) = ElemID{l.offset(shape(), n, ch, row, col)};
+ }
+ }
+ }
+ }
+}
+
+} // namespace coco
#include "coco/IR/KernelObject.h"
#include <nncc/core/ADT/kernel/NCHWLayout.h>
+#include <nncc/foundation/Memory.h>
-namespace
-{
-
-static nncc::core::ADT::kernel::NCHWLayout l{};
-
-} // namespace
+using nncc::foundation::make_unique;
namespace coco
{
-KernelObject::KernelObject(const nncc::core::ADT::kernel::Shape &shape) : _shape{shape}
+KernelObject::KernelObject(const nncc::core::ADT::kernel::Shape &shape)
{
- _map.resize(nncc::core::ADT::kernel::num_elements(shape));
+ _layout = make_unique<GenericKernelLayout>(shape);
}
KernelObject::~KernelObject()
// DO NOTHING
}
-const nncc::core::ADT::kernel::Shape &KernelObject::shape(void) const { return _shape; }
+const nncc::core::ADT::kernel::Shape &KernelObject::shape(void) const { return _layout->shape(); }
ElemID &KernelObject::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col)
{
- return _map.at(l.offset(shape(), n, ch, row, col));
+ return _layout->at(n, ch, row, col);
}
-const ElemID &KernelObject::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const
+ElemID KernelObject::at(uint32_t n, uint32_t ch, uint32_t row, uint32_t col) const
{
- return _map.at(l.offset(shape(), n, ch, row, col));
+ return _layout->at(n, ch, row, col);
}
-void KernelObject::reorder(const nncc::core::ADT::kernel::Layout &l)
-{
- for (uint32_t n = 0; n < shape().count(); ++n)
- {
- 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(n, ch, row, col) = ElemID{l.offset(shape(), n, ch, row, col)};
- }
- }
- }
- }
-}
+void KernelObject::reorder(const nncc::core::ADT::kernel::Layout &l) { _layout->reorder(l); }
} // namespace coco