diff --git a/paddle/framework/attribute.cc b/paddle/framework/attribute.cc index 534c0d8d686cf30688078005975dec1bde89bf60..159ed03b92bbc57ab79734de832845ef1f367de9 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 f18123bac7c3ca21df05cabb327380b6f27cde0b..6735ca0a8d70d04dae9dd610742370e83472e9b0 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();