From 1c43ef49afb2579cffd651c24bfc597113b1d549 Mon Sep 17 00:00:00 2001 From: chengduozh Date: Tue, 30 Oct 2018 16:17:26 +0800 Subject: [PATCH] fix GetTensorFromVar test=release/1.1 --- paddle/fluid/framework/operator.cc | 9 ++++----- paddle/fluid/framework/operator.h | 2 +- paddle/fluid/operators/sum_op.cc | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 9259bb740..d8251c725 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -358,11 +358,11 @@ static bool VarIsTensor(const Variable* var) { return var->IsType() || var->IsType(); } -const Tensor* GetTensorFromVar(Variable* var) { +const Tensor* GetTensorFromVar(const Variable* var) { if (var->IsType()) { - return var->GetMutable(); + return static_cast(&(var->Get())); } else if (var->IsType()) { - return var->GetMutable()->mutable_value(); + return &(var->Get().value()); } else { PADDLE_THROW("Variable type_id %s, expect LoDTensor/SelectedRows.", var->Type().name()); @@ -415,8 +415,7 @@ bool ExecutionContext::HasOutput(const std::string& name) const { template <> const Tensor* ExecutionContext::Input(const std::string& name) const { auto* var = InputVar(name); - return var == nullptr ? nullptr - : GetTensorFromVar(const_cast(var)); + return var == nullptr ? nullptr : GetTensorFromVar(var); } template <> diff --git a/paddle/fluid/framework/operator.h b/paddle/fluid/framework/operator.h index a04d2834e..be3f06360 100644 --- a/paddle/fluid/framework/operator.h +++ b/paddle/fluid/framework/operator.h @@ -63,7 +63,7 @@ inline std::string GradVarName(const std::string& var_name) { } proto::VarType::Type GetDataTypeOfVar(const Variable* var); -const Tensor* GetTensorFromVar(Variable* var); +const Tensor* GetTensorFromVar(const Variable* var); class OperatorBase; class ExecutionContext; diff --git a/paddle/fluid/operators/sum_op.cc b/paddle/fluid/operators/sum_op.cc index 6fe30630e..416da3b54 100644 --- a/paddle/fluid/operators/sum_op.cc +++ b/paddle/fluid/operators/sum_op.cc @@ -83,8 +83,7 @@ class SumOp : public framework::OperatorWithKernel { int dtype = -1; for (auto& x_var : x_vars) { // FIXME(zcd): The input x_var may be SelectedRows or LoDTensor. - auto tensor = framework::GetTensorFromVar( - const_cast(x_var)); + auto tensor = framework::GetTensorFromVar(x_var); if (tensor->numel() == 0) { continue; } -- GitLab