From 8310c8f9d2cb88e044162f37727ac0a0cc113aa2 Mon Sep 17 00:00:00 2001 From: superjomn Date: Fri, 21 Jun 2019 20:20:20 +0800 Subject: [PATCH] init --- paddle/fluid/lite/api/cxx_api.cc | 19 +++++++++++++++++++ paddle/fluid/lite/api/cxx_api.h | 18 ++---------------- paddle/fluid/lite/utils/io.h | 10 +++++----- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/paddle/fluid/lite/api/cxx_api.cc b/paddle/fluid/lite/api/cxx_api.cc index 7c6ffccfa0b..145d0a1a861 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 e7b74a04da2..5434bc18eb6 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 4e64ee1d4e4..29044d580d4 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 -- GitLab