未验证 提交 744ebcfa 编写于 作者: A Abhinav Arora 提交者: GitHub

Fix CPPlint issues in fluid/inference (#10075)

上级 7a993ee4
...@@ -14,6 +14,7 @@ limitations under the License. */ ...@@ -14,6 +14,7 @@ limitations under the License. */
#include "paddle/fluid/inference/io.h" #include "paddle/fluid/inference/io.h"
#include <algorithm>
#include <fstream> #include <fstream>
#include "paddle/fluid/framework/block_desc.h" #include "paddle/fluid/framework/block_desc.h"
#include "paddle/fluid/framework/feed_fetch_type.h" #include "paddle/fluid/framework/feed_fetch_type.h"
...@@ -27,14 +28,14 @@ namespace inference { ...@@ -27,14 +28,14 @@ namespace inference {
// linking the inference shared library. // linking the inference shared library.
void Init(bool init_p2p) { framework::InitDevices(init_p2p); } void Init(bool init_p2p) { framework::InitDevices(init_p2p); }
void ReadBinaryFile(const std::string& filename, std::string& contents) { void ReadBinaryFile(const std::string& filename, std::string* contents) {
std::ifstream fin(filename, std::ios::in | std::ios::binary); std::ifstream fin(filename, std::ios::in | std::ios::binary);
PADDLE_ENFORCE(static_cast<bool>(fin), "Cannot open file %s", filename); PADDLE_ENFORCE(static_cast<bool>(fin), "Cannot open file %s", filename);
fin.seekg(0, std::ios::end); fin.seekg(0, std::ios::end);
contents.clear(); contents->clear();
contents.resize(fin.tellg()); contents->resize(fin.tellg());
fin.seekg(0, std::ios::beg); fin.seekg(0, std::ios::beg);
fin.read(&contents[0], contents.size()); fin.read(&(contents->at(0)), contents->size());
fin.close(); fin.close();
} }
...@@ -47,7 +48,7 @@ bool IsPersistable(const framework::VarDesc* var) { ...@@ -47,7 +48,7 @@ bool IsPersistable(const framework::VarDesc* var) {
return false; return false;
} }
void LoadPersistables(framework::Executor& executor, framework::Scope& scope, void LoadPersistables(framework::Executor* executor, framework::Scope* scope,
const framework::ProgramDesc& main_program, const framework::ProgramDesc& main_program,
const std::string& dirname, const std::string& dirname,
const std::string& param_filename) { const std::string& param_filename) {
...@@ -92,18 +93,18 @@ void LoadPersistables(framework::Executor& executor, framework::Scope& scope, ...@@ -92,18 +93,18 @@ void LoadPersistables(framework::Executor& executor, framework::Scope& scope,
op->CheckAttrs(); op->CheckAttrs();
} }
executor.Run(*load_program, &scope, 0, true, true); executor->Run(*load_program, scope, 0, true, true);
delete load_program; delete load_program;
} }
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor, std::unique_ptr<framework::ProgramDesc> Load(framework::Executor* executor,
framework::Scope& scope, framework::Scope* scope,
const std::string& dirname) { const std::string& dirname) {
std::string model_filename = dirname + "/__model__"; std::string model_filename = dirname + "/__model__";
std::string program_desc_str; std::string program_desc_str;
VLOG(3) << "loading model from " << model_filename; VLOG(3) << "loading model from " << model_filename;
ReadBinaryFile(model_filename, program_desc_str); ReadBinaryFile(model_filename, &program_desc_str);
std::unique_ptr<framework::ProgramDesc> main_program( std::unique_ptr<framework::ProgramDesc> main_program(
new framework::ProgramDesc(program_desc_str)); new framework::ProgramDesc(program_desc_str));
...@@ -113,11 +114,11 @@ std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor, ...@@ -113,11 +114,11 @@ std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor,
} }
std::unique_ptr<framework::ProgramDesc> Load( std::unique_ptr<framework::ProgramDesc> Load(
framework::Executor& executor, framework::Scope& scope, framework::Executor* executor, framework::Scope* scope,
const std::string& prog_filename, const std::string& param_filename) { const std::string& prog_filename, const std::string& param_filename) {
std::string model_filename = prog_filename; std::string model_filename = prog_filename;
std::string program_desc_str; std::string program_desc_str;
ReadBinaryFile(model_filename, program_desc_str); ReadBinaryFile(model_filename, &program_desc_str);
std::unique_ptr<framework::ProgramDesc> main_program( std::unique_ptr<framework::ProgramDesc> main_program(
new framework::ProgramDesc(program_desc_str)); new framework::ProgramDesc(program_desc_str));
......
...@@ -27,17 +27,17 @@ namespace inference { ...@@ -27,17 +27,17 @@ namespace inference {
void Init(bool init_p2p); void Init(bool init_p2p);
void LoadPersistables(framework::Executor& executor, framework::Scope& scope, void LoadPersistables(framework::Executor* executor, framework::Scope* scope,
const framework::ProgramDesc& main_program, const framework::ProgramDesc& main_program,
const std::string& dirname, const std::string& dirname,
const std::string& param_filename); const std::string& param_filename);
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor, std::unique_ptr<framework::ProgramDesc> Load(framework::Executor* executor,
framework::Scope& scope, framework::Scope* scope,
const std::string& dirname); const std::string& dirname);
std::unique_ptr<framework::ProgramDesc> Load(framework::Executor& executor, std::unique_ptr<framework::ProgramDesc> Load(framework::Executor* executor,
framework::Scope& scope, framework::Scope* scope,
const std::string& prog_filename, const std::string& prog_filename,
const std::string& param_filename); const std::string& param_filename);
......
...@@ -133,12 +133,12 @@ void TestInference(const std::string& dirname, ...@@ -133,12 +133,12 @@ void TestInference(const std::string& dirname,
std::string prog_filename = "__model_combined__"; std::string prog_filename = "__model_combined__";
std::string param_filename = "__params_combined__"; std::string param_filename = "__params_combined__";
inference_program = paddle::inference::Load( inference_program = paddle::inference::Load(
executor, *scope, dirname + "/" + prog_filename, &executor, scope, dirname + "/" + prog_filename,
dirname + "/" + param_filename); dirname + "/" + param_filename);
} else { } else {
// Parameters are saved in separate files sited in the specified // Parameters are saved in separate files sited in the specified
// `dirname`. // `dirname`.
inference_program = paddle::inference::Load(executor, *scope, dirname); inference_program = paddle::inference::Load(&executor, scope, dirname);
} }
} }
// Disable the profiler and print the timing information // Disable the profiler and print the timing information
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册