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

fix constructor bug

上级 6f0e630c
......@@ -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;
}
}
......
......@@ -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;
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册