提交 741f9243 编写于 作者: S sangoly 提交者: Yan Chunwei

[cherry-pick] cherry-pick develop(#2047) to release/v2.0.0-beta2 test=develop (#2054)

上级 908fa796
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
// limitations under the License. // limitations under the License.
#include "lite/api/cxx_api.h" #include "lite/api/cxx_api.h"
#include <string>
#include "lite/api/paddle_api.h" #include "lite/api/paddle_api.h"
#include "lite/core/version.h"
namespace paddle { namespace paddle {
namespace lite { namespace lite {
...@@ -31,6 +33,8 @@ class CxxPaddleApiImpl : public lite_api::PaddlePredictor { ...@@ -31,6 +33,8 @@ class CxxPaddleApiImpl : public lite_api::PaddlePredictor {
void Run() override; void Run() override;
std::string GetVersion() const override;
std::unique_ptr<const lite_api::Tensor> GetTensor( std::unique_ptr<const lite_api::Tensor> GetTensor(
const std::string &name) const override; const std::string &name) const override;
...@@ -63,6 +67,8 @@ std::unique_ptr<const lite_api::Tensor> CxxPaddleApiImpl::GetOutput( ...@@ -63,6 +67,8 @@ std::unique_ptr<const lite_api::Tensor> CxxPaddleApiImpl::GetOutput(
void CxxPaddleApiImpl::Run() { raw_predictor_.Run(); } void CxxPaddleApiImpl::Run() { raw_predictor_.Run(); }
std::string CxxPaddleApiImpl::GetVersion() const { return version(); }
std::unique_ptr<const lite_api::Tensor> CxxPaddleApiImpl::GetTensor( std::unique_ptr<const lite_api::Tensor> CxxPaddleApiImpl::GetTensor(
const std::string &name) const { const std::string &name) const {
auto *x = raw_predictor_.GetTensor(name); auto *x = raw_predictor_.GetTensor(name);
......
...@@ -13,7 +13,9 @@ ...@@ -13,7 +13,9 @@
// limitations under the License. // limitations under the License.
#include "lite/api/light_api.h" #include "lite/api/light_api.h"
#include <string>
#include "lite/api/paddle_api.h" #include "lite/api/paddle_api.h"
#include "lite/core/version.h"
#include "lite/model_parser/model_parser.h" #include "lite/model_parser/model_parser.h"
namespace paddle { namespace paddle {
...@@ -29,6 +31,8 @@ class LightPredictorImpl : public PaddlePredictor { ...@@ -29,6 +31,8 @@ class LightPredictorImpl : public PaddlePredictor {
void Run() override; void Run() override;
std::string GetVersion() const override;
std::unique_ptr<const Tensor> GetTensor( std::unique_ptr<const Tensor> GetTensor(
const std::string& name) const override; const std::string& name) const override;
...@@ -61,6 +65,8 @@ std::unique_ptr<const Tensor> LightPredictorImpl::GetOutput(int i) const { ...@@ -61,6 +65,8 @@ std::unique_ptr<const Tensor> LightPredictorImpl::GetOutput(int i) const {
void LightPredictorImpl::Run() { raw_predictor_->Run(); } void LightPredictorImpl::Run() { raw_predictor_->Run(); }
std::string LightPredictorImpl::GetVersion() const { return lite::version(); }
std::unique_ptr<const Tensor> LightPredictorImpl::GetTensor( std::unique_ptr<const Tensor> LightPredictorImpl::GetTensor(
const std::string& name) const { const std::string& name) const {
return std::unique_ptr<const Tensor>( return std::unique_ptr<const Tensor>(
......
...@@ -72,6 +72,8 @@ class LITE_API PaddlePredictor { ...@@ -72,6 +72,8 @@ class LITE_API PaddlePredictor {
virtual void Run() = 0; virtual void Run() = 0;
virtual std::string GetVersion() const = 0;
/// Get a readonly tensor, return null if no one called `name` exists. /// Get a readonly tensor, return null if no one called `name` exists.
virtual std::unique_ptr<const Tensor> GetTensor( virtual std::unique_ptr<const Tensor> GetTensor(
const std::string& name) const = 0; const std::string& name) const = 0;
......
...@@ -36,6 +36,8 @@ TEST(CxxApi, run) { ...@@ -36,6 +36,8 @@ TEST(CxxApi, run) {
auto predictor = lite_api::CreatePaddlePredictor(config); auto predictor = lite_api::CreatePaddlePredictor(config);
LOG(INFO) << "Version: " << predictor->GetVersion();
auto input_tensor = predictor->GetInput(0); auto input_tensor = predictor->GetInput(0);
input_tensor->Resize(std::vector<int64_t>({100, 100})); input_tensor->Resize(std::vector<int64_t>({100, 100}));
auto* data = input_tensor->mutable_data<float>(); auto* data = input_tensor->mutable_data<float>();
...@@ -66,6 +68,8 @@ TEST(LightApi, run) { ...@@ -66,6 +68,8 @@ TEST(LightApi, run) {
auto predictor = lite_api::CreatePaddlePredictor(config); auto predictor = lite_api::CreatePaddlePredictor(config);
LOG(INFO) << "Version: " << predictor->GetVersion();
auto input_tensor = predictor->GetInput(0); auto input_tensor = predictor->GetInput(0);
input_tensor->Resize(std::vector<int64_t>({100, 100})); input_tensor->Resize(std::vector<int64_t>({100, 100}));
auto* data = input_tensor->mutable_data<float>(); auto* data = input_tensor->mutable_data<float>();
......
...@@ -38,6 +38,33 @@ else() ...@@ -38,6 +38,33 @@ else()
lite_cc_library(context SRCS context.cc DEPS tensor any device_info eigen3 CL_DEPS cl_context gflags) lite_cc_library(context SRCS context.cc DEPS tensor any device_info eigen3 CL_DEPS cl_context gflags)
endif() endif()
#-------------------------------------------- GET CODE META INFO ------------------------------------------
execute_process(
COMMAND git describe --tags --exact-match
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE PADDLE_LITE_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE PADDLE_LITE_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE PADDLE_LITE_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "tag: ${PADDLE_LITE_TAG}")
message(STATUS "branch: ${PADDLE_LITE_BRANCH}")
message(STATUS "commit: ${PADDLE_LITE_COMMIT}")
configure_file(version.h.in version.h)
#----------------------------------------------- NOT CHANGE ----------------------------------------------- #----------------------------------------------- NOT CHANGE -----------------------------------------------
# A trick to generate the paddle_use_kernels.h # A trick to generate the paddle_use_kernels.h
add_custom_command( add_custom_command(
......
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <string>
#include "lite/utils/replace_stl/stream.h"
namespace paddle {
namespace lite {
static std::string paddlelite_commit() {
return "@PADDLE_LITE_COMMIT@";
}
static std::string paddlelite_branch() {
return "@PADDLE_LITE_BRANCH@";
}
static std::string paddlelite_tag() {
return "@PADDLE_LITE_TAG@";
}
static std::string version() {
STL::stringstream ss;
std::string tag = paddlelite_tag();
if (tag.empty()) {
ss << paddlelite_branch() << "(" << paddlelite_commit() << ")";
} else {
ss << tag;
}
return ss.str();
}
} // namespace lite
} // namespace paddle
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册