From a77af98bfadcb07fecc24bf72c127efe7133691d Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Thu, 21 Sep 2017 11:04:06 -0700 Subject: [PATCH] Fix bug of static variable --- paddle/framework/attribute.cc | 11 ++++++++++- paddle/framework/attribute.h | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/paddle/framework/attribute.cc b/paddle/framework/attribute.cc index 534c0d8d686..159ed03b92b 100644 --- a/paddle/framework/attribute.cc +++ b/paddle/framework/attribute.cc @@ -19,6 +19,15 @@ limitations under the License. */ namespace paddle { namespace framework { +static ProgramDesc* g_program_desc = nullptr; + +ProgramDesc& GetProgramDesc() { + if (g_program_desc == nullptr) { + g_program_desc = new ProgramDesc(); + } + return *g_program_desc; +} + template <> AttrType AttrTypeID() { return INT; @@ -93,7 +102,7 @@ Attribute GetAttrValue(const OpDesc::Attr& attr_desc) { return val; } case framework::AttrType::BLOCK: { - return g_program_desc.blocks(attr_desc.block_idx()); + return GetProgramDesc().mutable_blocks(attr_desc.block_idx()); } } PADDLE_ENFORCE(false, "Unknown OpDesc::AttrDesc::type !"); diff --git a/paddle/framework/attribute.h b/paddle/framework/attribute.h index f18123bac7c..6735ca0a8d7 100644 --- a/paddle/framework/attribute.h +++ b/paddle/framework/attribute.h @@ -29,12 +29,12 @@ namespace framework { typedef boost::variant, std::vector, std::vector, - std::vector>, BlockDesc> + std::vector>, BlockDesc*> Attribute; typedef std::unordered_map AttributeMap; -static ProgramDesc g_program_desc; +ProgramDesc& GetProgramDesc(); template AttrType AttrTypeID(); -- GitLab