From 22f14e74452f748749eb73a12a637b1dac4ee574 Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Tue, 14 Dec 2021 14:38:43 +0800 Subject: [PATCH] Add const in GetInput/OutputVarPtrs in InferShapeContext (#38066) --- paddle/fluid/eager/legacy/infer_shape_context.h | 4 ++-- paddle/fluid/framework/new_executor/new_executor_defs.cc | 5 +++-- paddle/fluid/framework/new_executor/new_executor_defs.h | 4 ++-- paddle/fluid/framework/op_desc.cc | 4 ++-- paddle/fluid/framework/operator.cc | 4 ++-- paddle/fluid/framework/shape_inference.h | 4 ++-- paddle/fluid/imperative/infer_shape_context.h | 4 ++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/paddle/fluid/eager/legacy/infer_shape_context.h b/paddle/fluid/eager/legacy/infer_shape_context.h index bf8ebed36a7..7a05f6a9b35 100644 --- a/paddle/fluid/eager/legacy/infer_shape_context.h +++ b/paddle/fluid/eager/legacy/infer_shape_context.h @@ -216,13 +216,13 @@ class EagerInferShapeContext : public paddle::framework::InferShapeContext { // TODO(paddle-dev): Can this be template? std::vector GetInputVarPtrs( - const std::string& name) override { + const std::string& name) const override { PADDLE_THROW(paddle::platform::errors::PermissionDenied( "GetInputVarPtrs not support in dygraph runtime context")); } std::vector GetOutputVarPtrs( - const std::string& name) override { + const std::string& name) const override { PADDLE_THROW(paddle::platform::errors::PermissionDenied( "GetOutputVarPtrs not support in dygraph runtime context")); } diff --git a/paddle/fluid/framework/new_executor/new_executor_defs.cc b/paddle/fluid/framework/new_executor/new_executor_defs.cc index 0d7c5187e91..73f16fe3e9c 100644 --- a/paddle/fluid/framework/new_executor/new_executor_defs.cc +++ b/paddle/fluid/framework/new_executor/new_executor_defs.cc @@ -309,7 +309,7 @@ bool InterpretercoreInferShapeContext::IsRuntime() const { return true; } // TODO(paddle-dev): Can this be template? std::vector InterpretercoreInferShapeContext::GetInputVarPtrs( - const std::string& name) { + const std::string& name) const { const std::vector& vars = InputVars(name); std::vector res; res.reserve(vars.size()); @@ -318,7 +318,8 @@ std::vector InterpretercoreInferShapeContext::GetInputVarPtrs( } std::vector -InterpretercoreInferShapeContext::GetOutputVarPtrs(const std::string& name) { +InterpretercoreInferShapeContext::GetOutputVarPtrs( + const std::string& name) const { const std::vector& vars = OutputVars(name); std::vector res; res.reserve(vars.size()); diff --git a/paddle/fluid/framework/new_executor/new_executor_defs.h b/paddle/fluid/framework/new_executor/new_executor_defs.h index 76071f21819..d691a75a6d3 100644 --- a/paddle/fluid/framework/new_executor/new_executor_defs.h +++ b/paddle/fluid/framework/new_executor/new_executor_defs.h @@ -86,10 +86,10 @@ class InterpretercoreInferShapeContext : public InferShapeContext { // TODO(paddle-dev): Can this be template? std::vector GetInputVarPtrs( - const std::string& name) override; + const std::string& name) const override; std::vector GetOutputVarPtrs( - const std::string& name) override; + const std::string& name) const override; DDim GetInputDim(const std::string& name) const override; diff --git a/paddle/fluid/framework/op_desc.cc b/paddle/fluid/framework/op_desc.cc index 2c5fcf28106..670a269391a 100644 --- a/paddle/fluid/framework/op_desc.cc +++ b/paddle/fluid/framework/op_desc.cc @@ -200,7 +200,7 @@ class CompileTimeInferShapeContext : public InferShapeContext { } std::vector GetInputVarPtrs( - const std::string &name) override { + const std::string &name) const override { const std::vector arg_names = Inputs(name); std::vector res; res.reserve(arg_names.size()); @@ -212,7 +212,7 @@ class CompileTimeInferShapeContext : public InferShapeContext { } std::vector GetOutputVarPtrs( - const std::string &name) override { + const std::string &name) const override { const std::vector arg_names = Outputs(name); std::vector res; res.reserve(arg_names.size()); diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 3b41eb6c193..2f46ef9d032 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -871,7 +871,7 @@ class RuntimeInferShapeContext : public InferShapeContext { // TODO(paddle-dev): Can this be template? std::vector GetInputVarPtrs( - const std::string& name) override { + const std::string& name) const override { const std::vector& vars = InputVars(name); std::vector res; res.reserve(vars.size()); @@ -880,7 +880,7 @@ class RuntimeInferShapeContext : public InferShapeContext { } std::vector GetOutputVarPtrs( - const std::string& name) override { + const std::string& name) const override { const std::vector& vars = OutputVars(name); std::vector res; res.reserve(vars.size()); diff --git a/paddle/fluid/framework/shape_inference.h b/paddle/fluid/framework/shape_inference.h index cfeaeab52ce..10b0fa6afd7 100644 --- a/paddle/fluid/framework/shape_inference.h +++ b/paddle/fluid/framework/shape_inference.h @@ -103,9 +103,9 @@ class InferShapeContext { virtual bool IsRuntime() const = 0; virtual std::vector GetInputVarPtrs( - const std::string &name) = 0; + const std::string &name) const = 0; virtual std::vector GetOutputVarPtrs( - const std::string &name) = 0; + const std::string &name) const = 0; protected: virtual std::vector GetRepeatedDims(const std::string &name) const = 0; diff --git a/paddle/fluid/imperative/infer_shape_context.h b/paddle/fluid/imperative/infer_shape_context.h index 7efe1177f5d..167d5682cbf 100644 --- a/paddle/fluid/imperative/infer_shape_context.h +++ b/paddle/fluid/imperative/infer_shape_context.h @@ -216,13 +216,13 @@ class DygraphInferShapeContext : public framework::InferShapeContext { // TODO(paddle-dev): Can this be template? std::vector GetInputVarPtrs( - const std::string& name) override { + const std::string& name) const override { PADDLE_THROW(platform::errors::PermissionDenied( "GetInputVarPtrs not support in dygraph runtime context")); } std::vector GetOutputVarPtrs( - const std::string& name) override { + const std::string& name) const override { PADDLE_THROW(platform::errors::PermissionDenied( "GetOutputVarPtrs not support in dygraph runtime context")); } -- GitLab