提交 dc68e7c4 编写于 作者: K Kexin Zhao

fix constructor bug

上级 6f0e630c
...@@ -133,13 +133,10 @@ OpDesc::OpDesc(const proto::OpDesc &desc, ProgramDesc *prog, BlockDesc *block) ...@@ -133,13 +133,10 @@ OpDesc::OpDesc(const proto::OpDesc &desc, ProgramDesc *prog, BlockDesc *block)
size_t blk_idx = attr.block_idx(); size_t blk_idx = attr.block_idx();
if (blk_idx < prog->Size()) { if (blk_idx < prog->Size()) {
attrs_[attr_name] = prog->MutableBlock(blk_idx); attrs_[attr_name] = prog->MutableBlock(blk_idx);
} else { std::cout << "In OpDesc: set up attr block idx " << blk_idx
std::cout << "Setting blockdesc attribute for id " << blk_idx
<< std::endl; << std::endl;
attrs_[attr_name] = reinterpret_cast<BlockDesc *>(blk_idx); } else {
std::cout << "Testing reinterpret_cast result is " std::cout << "In OpDesc: We don't have this block idx " << blk_idx
<< reinterpret_cast<size_t>(
boost::get<BlockDesc *>(attrs_[attr_name]))
<< std::endl; << std::endl;
} }
} }
......
...@@ -48,6 +48,18 @@ ProgramDesc::ProgramDesc(const ProgramDesc &o) { ...@@ -48,6 +48,18 @@ ProgramDesc::ProgramDesc(const ProgramDesc &o) {
auto *block = desc_.mutable_blocks(i); auto *block = desc_.mutable_blocks(i);
blocks_.emplace_back(new BlockDesc(*o.blocks_[i], block, this)); 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) { ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) {
...@@ -60,14 +72,12 @@ ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) { ...@@ -60,14 +72,12 @@ ProgramDesc::ProgramDesc(const proto::ProgramDesc &desc) {
} }
for (auto &block : blocks_) { for (auto &block : blocks_) {
for (auto *op : block->AllOps()) { for (auto *op : block->AllOps()) {
for (auto &name : op->AttrNames()) { for (const auto &attr : op->Proto()->attrs()) {
if (op->GetAttrType(name) == proto::AttrType::BLOCK) { if (attr.type() == proto::AttrType::BLOCK) {
auto attr = op->GetAttr(name); size_t blk_idx = attr.block_idx();
size_t blk_idx = op->SetBlockAttr(attr.name(), *this->MutableBlock(blk_idx));
reinterpret_cast<size_t>(boost::get<BlockDesc *>(attr)); std::cout << "In ProgramDesc 2: set block attr idx " << blk_idx
op->SetBlockAttr(name, *this->MutableBlock(blk_idx)); << std::endl;
std::cout << "Update attr name " << name << " for block idx "
<< blk_idx << std::endl;
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册
新手
引导
客服 返回
顶部