|
|
|
@ -27,15 +27,16 @@ class ReadInferShape : public framework::InferShapeBase {
|
|
|
|
|
"The ReadOp must take a reader as input.");
|
|
|
|
|
PADDLE_ENFORCE(ctx->HasOutputs("Out"),
|
|
|
|
|
"The ReadOp should be assigned with output.");
|
|
|
|
|
if (!ctx->IsRuntime() && ctx->Attrs().Get<bool>("infer_out")) {
|
|
|
|
|
std::vector<framework::DDim> reader_dims = ctx->GetReaderDims("Reader");
|
|
|
|
|
std::vector<std::string> out_names = ctx->Outputs("Out");
|
|
|
|
|
PADDLE_ENFORCE_EQ(
|
|
|
|
|
reader_dims.size(), out_names.size(),
|
|
|
|
|
"The reader's dim number doesn't match the output number.");
|
|
|
|
|
ctx->SetOutputsDim("Out", reader_dims);
|
|
|
|
|
if (!ctx->IsRuntime()) {
|
|
|
|
|
auto in_desc =
|
|
|
|
|
boost::get<framework::VarDesc*>(ctx->GetInputVarPtrs("Reader")[0]);
|
|
|
|
|
std::cout << in_desc->Proto()->SerializeAsString() << std::endl;
|
|
|
|
|
auto in_lod_levels = in_desc->GetLoDLevels();
|
|
|
|
|
auto out_var_ptrs = ctx->GetOutputVarPtrs("Out");
|
|
|
|
|
PADDLE_ENFORCE_EQ(in_lod_levels.size(), out_var_ptrs.size(),
|
|
|
|
@ -53,6 +54,8 @@ class ReadInferVarType : public framework::VarTypeInference {
|
|
|
|
|
public:
|
|
|
|
|
void operator()(const framework::OpDesc& op_desc,
|
|
|
|
|
framework::BlockDesc* block) const override {
|
|
|
|
|
bool infer_out = boost::get<bool>(op_desc.GetAttr("infer_out"));
|
|
|
|
|
if (infer_out) {
|
|
|
|
|
std::string reader_name = op_desc.Input("Reader")[0];
|
|
|
|
|
std::vector<std::string> out_names = op_desc.Output("Out");
|
|
|
|
|
framework::VarDesc* reader = block->FindVarRecursive(reader_name);
|
|
|
|
@ -64,6 +67,7 @@ class ReadInferVarType : public framework::VarTypeInference {
|
|
|
|
|
out.SetDataType(dtypes[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReadOp : public framework::OperatorBase {
|
|
|
|
@ -73,6 +77,7 @@ class ReadOp : public framework::OperatorBase {
|
|
|
|
|
private:
|
|
|
|
|
void RunImpl(const framework::Scope& scope,
|
|
|
|
|
const platform::Place& dev_place) const override {
|
|
|
|
|
VLOG(3) << "read op in";
|
|
|
|
|
framework::ReaderHolder* reader =
|
|
|
|
|
detail::Ref(scope.FindVar(Input("Reader")),
|
|
|
|
|
"Cannot find reader variable %s", Input("Reader"))
|
|
|
|
@ -87,7 +92,9 @@ class ReadOp : public framework::OperatorBase {
|
|
|
|
|
|
|
|
|
|
reader->ReadNext(&ins);
|
|
|
|
|
if (ins.empty()) {
|
|
|
|
|
VLOG(3) << "read empty data in";
|
|
|
|
|
if (Attr<bool>("throw_eof_exp")) {
|
|
|
|
|
VLOG(3) << "throw_eof_exp";
|
|
|
|
|
PADDLE_THROW_EOF();
|
|
|
|
|
} else {
|
|
|
|
|
ins.resize(out_arg_names.size());
|
|
|
|
@ -96,6 +103,7 @@ class ReadOp : public framework::OperatorBase {
|
|
|
|
|
tensor.mutable_data<float>(framework::make_ddim({0}), dev_place);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
VLOG(3) << "read empty data out";
|
|
|
|
|
}
|
|
|
|
|
PADDLE_ENFORCE_EQ(ins.size(), out_arg_names.size());
|
|
|
|
|
for (size_t i = 0; i < out_arg_names.size(); ++i) {
|
|
|
|
@ -120,6 +128,7 @@ class ReadOpMaker : public framework::OpProtoAndCheckerMaker {
|
|
|
|
|
" only when the data-balance is enabled in ParallelExecutor"
|
|
|
|
|
" and it is set by ParallelExecutor instance, not users.")
|
|
|
|
|
.SetDefault(true);
|
|
|
|
|
AddAttr<bool>("infer_out", "").SetDefault(true);
|
|
|
|
|
AddComment(R"DOC(
|
|
|
|
|
Read Operator
|
|
|
|
|
|
|
|
|
|