From a68274931b24625f5576ca9ee9d4268cd80fc7c8 Mon Sep 17 00:00:00 2001 From: Jerry Ge Date: Wed, 16 Nov 2022 10:41:55 -0800 Subject: Fix reference model memory leaks for the following ops - OpClamp - OpArithmeticRightShift - OpMul - OpTable - OpTranspose Signed-off-by: Jerry Ge Change-Id: Icb84a8a17c298b471a635310454775977a9133cb --- reference_model/src/ops/activation_funcs.cc | 6 ++++++ reference_model/src/ops/activation_funcs.h | 3 ++- reference_model/src/ops/data_layout.cc | 4 +++- reference_model/src/ops/ewise_binary.cc | 16 +++++++++++++++- reference_model/src/ops/ewise_binary.h | 2 ++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/reference_model/src/ops/activation_funcs.cc b/reference_model/src/ops/activation_funcs.cc index 09ef6f6..dc85088 100644 --- a/reference_model/src/ops/activation_funcs.cc +++ b/reference_model/src/ops/activation_funcs.cc @@ -55,6 +55,12 @@ int OpClamp::register_fcn() return 0; } +template +OpClamp::~OpClamp() +{ + if (attribute) delete attribute; +} + template int OpSigmoid::register_fcn() { diff --git a/reference_model/src/ops/activation_funcs.h b/reference_model/src/ops/activation_funcs.h index 4853971..9a697cd 100644 --- a/reference_model/src/ops/activation_funcs.h +++ b/reference_model/src/ops/activation_funcs.h @@ -1,5 +1,5 @@ -// Copyright (c) 2020, ARM Limited. +// Copyright (c) 2020-2022, ARM Limited. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ public: INIT_ATTRIBUTE(Clamp); register_fcn(); } + virtual ~OpClamp(); static constexpr int32_t QMin = GetQMin::value; static constexpr int32_t QMax = GetQMax::value; using InEigenType = typename GetEigenType::type; diff --git a/reference_model/src/ops/data_layout.cc b/reference_model/src/ops/data_layout.cc index bffd659..b127cba 100644 --- a/reference_model/src/ops/data_layout.cc +++ b/reference_model/src/ops/data_layout.cc @@ -581,7 +581,9 @@ OpTranspose::OpTranspose(SubgraphTraverser* sgt_, template OpTranspose::~OpTranspose() -{} +{ + if (attribute) delete attribute; +} template int OpTranspose::checkTensorAttributes() diff --git a/reference_model/src/ops/ewise_binary.cc b/reference_model/src/ops/ewise_binary.cc index e4c0ee0..7d0c434 100644 --- a/reference_model/src/ops/ewise_binary.cc +++ b/reference_model/src/ops/ewise_binary.cc @@ -191,6 +191,12 @@ int OpArithmeticRightShift::register_fcn() return 0; } +template +OpArithmeticRightShift::~OpArithmeticRightShift() +{ + if (attribute) delete attribute; +} + template int OpBitwiseAnd::register_fcn() { @@ -455,6 +461,12 @@ int OpMul::register_fcn() return 0; } +template +OpMul::~OpMul() +{ + if (attribute) delete attribute; +} + template int OpPow::register_fcn() { @@ -512,7 +524,9 @@ OpTable::OpTable(SubgraphTraverser* sgt_, template OpTable::~OpTable() -{} +{ + if (attribute) delete attribute; +} template int OpTable::checkTensorAttributes() diff --git a/reference_model/src/ops/ewise_binary.h b/reference_model/src/ops/ewise_binary.h index 6b0efaf..020ddb5 100644 --- a/reference_model/src/ops/ewise_binary.h +++ b/reference_model/src/ops/ewise_binary.h @@ -148,6 +148,7 @@ public: using InEigenType = typename GetEigenType::type; using OutEigenType = typename GetEigenType::type; virtual int register_fcn(); + virtual ~OpArithmeticRightShift(); protected: TosaArithmeticRightShiftAttribute* attribute; @@ -163,6 +164,7 @@ public: INIT_ATTRIBUTE(Mul); register_fcn(); } + virtual ~OpMul(); static constexpr int64_t QMin = GetQMin::value; static constexpr int64_t QMax = GetQMax::value; using InEigenType = typename GetEigenType::type; -- cgit v1.2.1