This commit introduces destroy method into OpManager class, which allows
users to destruct Op instances.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
public:
template <typename T> T *create(void);
+public:
+ // @brief Destroy (= deallocate) a Op instance
+ //
+ // NOTE OpManager will invoke dispose before deallocation
+ // NOTE destroy(op) WILL NOT update op->parent(). Client SHOULD detach op before destroy(op) call
+ void destroy(Op *);
+
private:
const PtrLink<Op, Instr> *const _op_link;
const PtrLink<Object, ObjectInfo> *const _obj_link;
#include <nncc/foundation/Memory.h>
+#include <cassert>
+
using nncc::foundation::make_unique;
namespace coco
template <> ReLU *OpManager::create<ReLU>(void) { return take(make_unique<ReLU>(_op_link)); }
+void OpManager::destroy(Op *op)
+{
+ assert(op->parent() == nullptr);
+ op->dispose();
+ release(op);
+}
+
} // namespace coco
ASSERT_NE(obj, nullptr);
}
+
+TEST_F(OpManagerTest, destroy)
+{
+ auto op = mgr.create<coco::Conv2D>();
+ mgr.destroy(op);
+ ASSERT_EQ(mgr.size(), 0);
+}