diff --git a/paddle/fluid/lite/api/cxx_api.cc b/paddle/fluid/lite/api/cxx_api.cc index 7c6ffccfa0bdab393c6870283834c76c5d1a2668..145d0a1a861018b0714f99cdf36253a2cab52104 100644 --- a/paddle/fluid/lite/api/cxx_api.cc +++ b/paddle/fluid/lite/api/cxx_api.cc @@ -61,5 +61,24 @@ const framework::proto::ProgramDesc &Predictor::program_desc() const { return program_desc_; } +void Predictor::Build(const framework::proto::ProgramDesc &desc, + const Place &prefer_place, + const std::vector &valid_places) { + program_desc_ = desc; + Program program(desc, scope_, valid_places); + + optimizer_.KernelPickPreferPlace(prefer_place); + core::KernelPickFactor factor; + factor.ConsiderTarget(); + factor.ConsiderPrecision(); + optimizer_.Run(std::move(program), valid_places, factor); + program_ = optimizer_.GenRuntimeProgram(); +} + +const lite::Tensor *Predictor::GetTensor(const std::string &name) const { + auto *var = program_->exec_scope()->FindVar(name); + return &var->Get(); +} + } // namespace lite } // namespace paddle diff --git a/paddle/fluid/lite/api/cxx_api.h b/paddle/fluid/lite/api/cxx_api.h index e7b74a04da25ba3d228aba78d9a5ce9d0909d708..5434bc18eb634a7c2136a64f4afdb490db92119d 100644 --- a/paddle/fluid/lite/api/cxx_api.h +++ b/paddle/fluid/lite/api/cxx_api.h @@ -42,18 +42,7 @@ class Predictor { const std::vector& valid_places); void Build(const framework::proto::ProgramDesc& desc, - const Place& prefer_place, - const std::vector& valid_places) { - program_desc_ = desc; - Program program(desc, scope_, valid_places); - - optimizer_.KernelPickPreferPlace(prefer_place); - core::KernelPickFactor factor; - factor.ConsiderTarget(); - factor.ConsiderPrecision(); - optimizer_.Run(std::move(program), valid_places, factor); - program_ = optimizer_.GenRuntimeProgram(); - } + const Place& prefer_place, const std::vector& valid_places); // Run the predictor for a single batch of data. void Run() { program_->Run(); } @@ -66,10 +55,7 @@ class Predictor { // Return the program desc for debug. const framework::proto::ProgramDesc& program_desc() const; - const lite::Tensor* GetTensor(const std::string& name) const { - auto* var = program_->exec_scope()->FindVar(name); - return &var->Get(); - } + const lite::Tensor* GetTensor(const std::string& name) const; // This method is disabled in mobile, for unnecessary dependencies required. void SaveModel(const std::string& dir); diff --git a/paddle/fluid/lite/utils/io.h b/paddle/fluid/lite/utils/io.h index 4e64ee1d4e4b016fadf40167fb96557e96061fba..29044d580d4d734929ad34a0e5608133812207bf 100644 --- a/paddle/fluid/lite/utils/io.h +++ b/paddle/fluid/lite/utils/io.h @@ -14,9 +14,7 @@ #pragma once -#ifndef LITE_WITH_ARM -#include -#endif +#include #include #include #include "paddle/fluid/lite/utils/cp_logging.h" @@ -35,12 +33,14 @@ static bool IsFileExists(const std::string& path) { } // ARM mobile not support mkdir in C++ -#ifndef LITE_WITH_ARM static void MkDirRecur(const std::string& path) { +#ifndef LITE_WITH_ARM CHECK_EQ(system(string_format("mkdir -p %s", path.c_str()).c_str()), 0) << "Cann't mkdir " << path; -} +#else // On ARM + CHECK_NE(mkddir(path.c_str(), S_IRWXU), -1) << "Cann't mkdir " << path; #endif +} } // namespace lite } // namespace paddle