parent
73b5ffb99c
commit
1cd9445087
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright 2019 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 "tools/optimizer/fusion/quant_dtype_cast_fusion.h"
|
||||
#include <memory>
|
||||
#include "src/ops/primitive_c.h"
|
||||
#include "src/ops/conv2d.h"
|
||||
#include "src/ops/depthwise_conv2d.h"
|
||||
#include "src/ops/activation.h"
|
||||
#include "schema/inner/model_generated.h"
|
||||
#include "tools/optimizer/common/gllo_utils.h"
|
||||
namespace mindspore::opt {
|
||||
namespace {
|
||||
constexpr size_t kActivationInputsLength = 2;
|
||||
}
|
||||
const BaseRef QuantDtypeCastFusion::DefinePattern() const {
|
||||
auto quant_var = std::make_shared<CondVar>(IsQuantNode);
|
||||
auto input_var = std::make_shared<Var>();
|
||||
return VectorRef({quant_var, input_var});
|
||||
}
|
||||
|
||||
const AnfNodePtr QuantDtypeCastFusion::Process(const FuncGraphPtr &func_graph, const AnfNodePtr &node,
|
||||
const EquivPtr &) const {
|
||||
MS_LOG(DEBUG) << "quant dtype cast fusion pass process";
|
||||
CheckIfFuncGraphIsNull(func_graph);
|
||||
|
||||
CheckIfAnfNodeIsNull(node);
|
||||
auto act_node = node->cast<CNodePtr>();
|
||||
CheckIfCNodeIsNull(act_node);
|
||||
CheckInputSize(act_node, kActivationInputsLength);
|
||||
AnfNodePtr pre_node = act_node->input(1);
|
||||
CheckIfAnfNodeIsNull(pre_node);
|
||||
return pre_node;
|
||||
}
|
||||
} // namespace mindspore::opt
|
@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright 2019 Huawei Technologies Co., Ltd
|
||||
*
|
||||
* 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 LITE_QUANT_DTYPE_CAST_FUSION_H
|
||||
#define LITE_QUANT_DTYPE_CAST_FUSION_H
|
||||
|
||||
#include <string>
|
||||
#include "backend/optimizer/common/optimizer.h"
|
||||
#include "schema/inner/model_generated.h"
|
||||
|
||||
namespace mindspore {
|
||||
namespace opt {
|
||||
class QuantDtypeCastFusion : public PatternProcessPass {
|
||||
public:
|
||||
explicit QuantDtypeCastFusion(bool multigraph = true, const std::string &name = "quant_dtype_cast_fusion")
|
||||
: PatternProcessPass(name, multigraph) {}
|
||||
~QuantDtypeCastFusion() override = default;
|
||||
const BaseRef DefinePattern() const override;
|
||||
const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &, const EquivPtr &) const override;
|
||||
};
|
||||
} // namespace opt
|
||||
} // namespace mindspore
|
||||
#endif // LITE_QUANT_DTYPE_CAST_FUSION_H
|
Loading…
Reference in new issue