From dc68e7c44b198acbdf588e97d219822602dc90db Mon Sep 17 00:00:00 2001 From: Kexin Zhao <zhaokexin01@baidu.com> Date: Mon, 5 Feb 2018 15:36:54 -0800 Subject: [PATCH] fix constructor bug --- paddle/framework/op_desc.cc | 9 +++------ paddle/framework/program_desc.cc | 26 ++++++++++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/paddle/framework/op_desc.cc b/paddle/framework/op_desc.cc index 5ebd2b3ad5e..7859c391fa3 100644 --- a/paddle/framework/op_desc.cc +++ b/paddle/framework/op_desc.cc @@ -133,13 +133,10 @@ OpDesc::OpDesc(const proto::OpDesc &desc, ProgramDesc *prog, BlockDesc *block) size_t blk_idx = attr.block_idx(); if (blk_idx < prog->Size()) { attrs_[attr_name] = prog->MutableBlock(blk_idx); - } else { - std::cout << "Setting blockdesc attribute for id " << blk_idx + std::cout << "In OpDesc: set up attr block idx " << blk_idx << std::endl; - attrs_[attr_name] = reinterpret_cast<BlockDesc *>(blk_idx); - std::cout << "Testing reinterpret_cast result is " - << reinterpret_cast<size_t>( - boost::get<BlockDesc *>(attrs_[attr_name])) + } else { + std::cout << "In OpDesc: We don't have this block idx " << blk_idx << std::endl; } } diff --git a/paddle/framework/program_desc.cc b/paddle/framework/program_desc.cc index 9124607623b..ba461b09339 100644 --- a/paddle/framework/program_desc.cc +++ b/paddle/framework/program_desc.cc @@ -48,6 +48,18 @@ ProgramDesc::ProgramDesc(const ProgramDesc &o) { auto *block = desc_.mutable_blocks(i); blocks_.emplace_back(new BlockDesc(*o.blocks_[i], block, this)); } + for (auto &block : blocks_) { + for (auto *op : block->AllOps()) { + for (const auto &attr : op->Proto()->attrs()) { + if (attr.type() == proto::AttrType::BLOCK) { + size_t blk_idx = attr.block_idx(); + op->SetBlockAttr(attr.name(), *this->MutableBlock(blk_idx)); + std::cout << "In ProgramDesc 1: set block attr idx " << blk_idx + << std::endl; + } + } + } + } } ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) { @@ -60,14 +72,12 @@ ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) { } for (auto &block : blocks_) { for (auto *op : block->AllOps()) { - for (auto &name : op->AttrNames()) { - if (op->GetAttrType(name) == proto::AttrType::BLOCK) { - auto attr = op->GetAttr(name); - size_t blk_idx = - reinterpret_cast<size_t>(boost::get<BlockDesc *>(attr)); - op->SetBlockAttr(name, *this->MutableBlock(blk_idx)); - std::cout << "Update attr name " << name << " for block idx " - << blk_idx << std::endl; + for (const auto &attr : op->Proto()->attrs()) { + if (attr.type() == proto::AttrType::BLOCK) { + size_t blk_idx = attr.block_idx(); + op->SetBlockAttr(attr.name(), *this->MutableBlock(blk_idx)); + std::cout << "In ProgramDesc 2: set block attr idx " << blk_idx + << std::endl; } } } -- GitLab