提交 cb44cff2 编写于 作者: S superjomn

remove glog and gtest dependency for light framework

上级 82d31503
......@@ -19,11 +19,11 @@
*/
#pragma once
#include <glog/logging.h>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
#include "paddle/fluid/lite/utils/logging.h"
namespace paddle {
namespace inference {
......
......@@ -21,3 +21,5 @@ message(STATUS "get kernels ${host_kernels}")
lite_cc_test(test_cxx_api_lite SRCS cxx_api_test.cc DEPS cxx_api_lite model_parser_lite target_wrapper_host
${ops_lite} ${host_kernels})
lite_cc_test(test_light_api SRCS light_api_test.cc DEPS light_api_lite)
cc_binary(cxx_api_lite_bin SRCS cxx_api_bin.cc DEPS cxx_api_lite model_parser_lite target_wrapper_host ${ops_lite} ${host_kernels})
......@@ -13,15 +13,19 @@
// limitations under the License.
#include "paddle/fluid/lite/api/cxx_api.h"
#ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
#include "paddle/fluid/platform/port.h"
#endif
namespace paddle {
namespace lite {
#ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
void LightPredictor::SaveModel(const std::string &dir) {
MkDirRecursively(dir.c_str());
program_->PersistModel(dir, program_desc_);
}
#endif
} // namespace lite
} // namespace paddle
......@@ -41,7 +41,10 @@ class LightPredictor {
program_ = optimizer_.GenRuntimeProgram();
}
// This method is disabled in mobile, or unnecessary dependencies required.
#ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
void SaveModel(const std::string& dir);
#endif
// Get offset-th col of feed.
lite::Tensor* GetInput(size_t offset) {
......
......@@ -60,6 +60,7 @@ TEST(CXXApi, test) {
LOG(INFO) << "out " << *out;
}
#ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK
TEST(CXXApi, save_model) {
lite::LightPredictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}});
......@@ -68,6 +69,7 @@ TEST(CXXApi, save_model) {
predictor.SaveModel("./optimized_model");
}
#endif
} // namespace lite
} // namespace paddle
......
......@@ -19,6 +19,7 @@ cc_library(kernel_lite SRCS kernel.cc DEPS type_system target_wrapper_lite)
cc_library(variable_lite SRCS variable.cc)
cc_library(op_registry_lite SRCS op_registry.cc)
cc_library(scope_lite SRCS scope.cc)
cc_library(context_lite SRCS context.cc DEPS any_lite)
cc_library(op_lite SRCS op_lite.cc DEPS scope_lite op_registry_lite compatible_pb_lite)
cc_library(types_lite SRCS types.cc)
cc_library(type_system SRCS type_system.cc DEPS ${tensor_lite})
......
......@@ -14,6 +14,7 @@
#pragma once
#include "paddle/fluid/lite/utils/any.h"
#ifdef LITE_WITH_CUDA
#include <paddle/fluid/lite/cuda/blas.h>
#include "paddle/fluid/lite/cuda/cuda_utils.h"
......@@ -25,6 +26,12 @@
namespace paddle {
namespace lite {
struct HostContext {};
#ifdef LITE_WITH_ARM
struct ARMContext {};
#endif
#ifdef LITE_WITH_CUDA
// Only works with CUDA kernels.
struct CUDAContext {
......@@ -44,6 +51,7 @@ struct CUDAContext {
#ifdef LITE_WITH_X86
struct X86Context {
// overall information
// kernel information
};
#endif
......@@ -52,40 +60,16 @@ struct X86Context {
// Holds the necessary resource and information.
class KernelContext {
public:
#ifdef LITE_WITH_CUDA
CUDAContext& AsCudaContext() {
if (target_ != TARGET(kUnk)) {
CHECK(target_ == TARGET(kCUDA));
} else {
target_ = TARGET(kCUDA);
cuda_ctx_.reset(new CUDAContext);
template <typename ContextT>
ContextT& As() {
if (!ctx_.valid()) {
ctx_.set<ContextT>();
}
return *cuda_ctx_;
return *ctx_.get_mutable<ContextT>();
}
#endif // LITE_WITH_CUDA
#ifdef LITE_WITH_X86
X86Context& AsX86Context() {
if (target_ != TARGET(kUnk)) {
CHECK(target_ == TARGET(kX86));
} else {
target_ = TARGET(kX86);
x86_ctx_.reset(new X86Context);
}
return *x86_ctx_;
}
#endif // lite_with_x86
private:
#ifdef LITE_WITH_CUDA
std::unique_ptr<CUDAContext> cuda_ctx_;
#endif
#ifdef LITE_WITH_X86
std::unique_ptr<X86Context> x86_ctx_;
#endif
TargetType target_{TARGET(kUnk)};
Any ctx_;
};
} // namespace lite
......
......@@ -13,7 +13,6 @@
// limitations under the License.
#pragma once
#include <glog/logging.h>
#include "paddle/fluid/lite/core/target_wrapper.h"
namespace paddle {
......
......@@ -13,7 +13,7 @@ cc_library(mir_passes
argument_type_display_pass.cc
demo_pass.cc
runtime_context_assign_pass.cc
DEPS mir_pass types_lite)
DEPS mir_pass types_lite context_lite)
# for mobile, unnecessary to compile the following testings.
if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
......
......@@ -58,7 +58,7 @@ class Node {
}
KernelBase& picked_kernel() {
CHECK(!valid_kernels.empty());
CHECK(!valid_kernels.empty()) << "no kernel for " << op_type;
return *valid_kernels.front();
}
......
......@@ -52,7 +52,7 @@ class RuntimeContextAssignPass : public StmtPass {
std::unique_ptr<KernelContext> NewHostContext() {
std::unique_ptr<KernelContext> ctx(new KernelContext);
ctx->AsX86Context();
ctx->As<HostContext>();
// Some initialization here.
return ctx;
}
......
......@@ -13,7 +13,6 @@
// limitations under the License.
#include "paddle/fluid/lite/core/mir/variable_place_inference_pass.h"
#include <gtest/gtest.h>
#include "paddle/fluid/lite/core/mir/pass_registry.h"
namespace paddle {
......
......@@ -66,7 +66,10 @@ bool OpLite::Run() {
}
bool OpLite::Attach(const OpDesc &opdesc, lite::Scope *scope) {
CHECK(scope);
// valid_places_.clear();
LOG(INFO) << "valid_places " << valid_places_.size();
CHECK(scope != nullptr);
CHECK(!op_info_.get());
scope_ = scope;
op_info_.reset(new OpInfo); // Force clean the out-of-date infomation.
op_info_->Build(opdesc.ReadonlyProto());
......
......@@ -14,7 +14,6 @@
#pragma once
#include <glog/logging.h>
#include <map>
#include <memory>
#include <string>
......@@ -50,11 +49,15 @@ class OpInfo;
class OpLite : public Registry {
public:
OpLite() = default;
OpLite(const std::string &type) : op_type_(type) {}
OpLite(const std::vector<Place> &valid_places)
: valid_places_(valid_places) {}
OpLite(const std::string &type) : op_type_(type) {
LOG(INFO) << "valid places " << valid_places_.size();
}
OpLite(const std::vector<Place> &valid_places) : valid_places_(valid_places) {
LOG(INFO) << "valid places " << valid_places.size();
}
void SetValidPlaces(const std::vector<Place> &places) {
LOG(INFO) << "valid places " << valid_places_.size();
valid_places_ = places;
}
const std::vector<Place> &valid_places() const { return valid_places_; }
......
......@@ -13,9 +13,9 @@
// limitations under the License.
#pragma once
#include <glog/logging.h>
#include <iostream>
#include <sstream>
#include "paddle/fluid/lite/utils/cp_logging.h"
#ifdef LITE_WITH_CUDA
#include <cuda.h>
#include <cuda_runtime.h>
......
......@@ -20,7 +20,6 @@
// the dubious typed Variables in the Operators' inputs and outputs are disaster
// for analysis and runtime.
#include <glog/logging.h>
#include <map>
#include <string>
#include <typeinfo>
......
......@@ -16,8 +16,6 @@
#include <cublasXt.h>
#include <cublas_api.h>
#include <cublas_v2.h>
#include <glog/logging.h>
#include <glog/logging.h>
#include <library_types.h>
#include "paddle/fluid/lite/cuda/cuda_utils.h"
#include "paddle/fluid/lite/utils/all.h"
......
......@@ -17,7 +17,7 @@
#include <cublas_api.h>
#include <cublas_v2.h>
#include <cuda.h>
#include <glog/logging.h>
#include "paddle/fluid/lite/utils/cp_logging.h"
/*
* This file contains some CUDA specific utils.
......
......@@ -13,7 +13,6 @@
// limitations under the License.
#include "paddle/fluid/lite/cuda/target_wrapper.h"
#include <glog/logging.h>
namespace paddle {
namespace lite {
......
......@@ -13,7 +13,6 @@
// limitations under the License.
#pragma once
#include <glog/logging.h>
#include <Eigen/Core>
#include "paddle/fluid/lite/core/kernel.h"
#include "paddle/fluid/lite/operators/fc_op.h"
......
......@@ -14,11 +14,11 @@
#pragma once
#include <glog/logging.h>
#include <algorithm>
#include <string>
#include <vector>
#include "paddle/fluid/framework/framework.pb.h"
#include "paddle/fluid/lite/utils/cp_logging.h"
namespace paddle {
namespace lite {
......
......@@ -13,9 +13,6 @@
// limitations under the License.
#include "paddle/fluid/lite/model_parser/runtime.h"
#include "runtime.h"
#include <glog/logging.h>
namespace paddle {
namespace lite {
......
......@@ -13,7 +13,6 @@
// limitations under the License.
#pragma once
#include <glog/logging.h>
#include "paddle/fluid/framework/framework.pb.h"
#include "paddle/fluid/lite/utils/all.h"
......
lite_cc_test(test_varient SRCS varient_test.cc)
if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
set(utils_DEPS)
else()
set(utils_DEPS glog)
endif()
lite_cc_test(test_logging_lite SRCS logging_test.cc)
cc_library(utils_lite SRCS cp_logging.cc DEPS ${utils_DEPS})
lite_cc_test(test_varient SRCS varient_test.cc DEPS utils_lite)
cc_library(any_lite SRCS any.cc)
......@@ -15,6 +15,7 @@
#pragma once
#include "paddle/fluid/lite/utils/check.h"
#include "paddle/fluid/lite/utils/cp_logging.h"
#include "paddle/fluid/lite/utils/factory.h"
#include "paddle/fluid/lite/utils/hash.h"
#include "paddle/fluid/lite/utils/io.h"
......
// 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.
#include "paddle/fluid/lite/utils/any.h"
namespace paddle {
namespace lite {
size_t Any::kInvalidType{typeid(void).hash_code()};
} // namespace lite
} // namespace paddle
// 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 <functional>
#include <set>
#include "paddle/fluid/lite/utils/cp_logging.h"
namespace paddle {
namespace lite {
class Any {
public:
template <typename T>
void set(const T& v) {
set<T>();
*get_mutable<T>() = v;
}
template <typename T>
void set() {
if (type_ != kInvalidType) {
CHECK(type_ == typeid(T).hash_code());
} else {
type_ = typeid(T).hash_code();
data_ = new T;
deleter_ = [&] { delete static_cast<T*>(data_); };
}
data_ = new T;
}
template <typename T>
const T& get() const {
CHECK(data_);
CHECK(type_ == typeid(T).hash_code());
return *static_cast<T*>(data_);
}
template <typename T>
T* get_mutable() {
CHECK(data_);
CHECK(type_ == typeid(T).hash_code());
return static_cast<T*>(data_);
}
bool valid() const { return data_; }
private:
static size_t kInvalidType;
size_t type_{kInvalidType};
void* data_{};
std::function<void()> deleter_;
};
} // namespace lite
} // namespace paddle
......@@ -13,12 +13,12 @@
// limitations under the License.
#pragma once
#include <glog/logging.h>
#include <iostream>
#include <list>
#include <memory>
#include <sstream>
#include <unordered_map>
#include "paddle/fluid/lite/utils/cp_logging.h"
namespace paddle {
namespace lite {
......
......@@ -14,13 +14,15 @@
#pragma once
#include <sys/stat.h>
#include <fstream>
#include <string>
#include "paddle/fluid/lite/utils/cp_logging.h"
namespace paddle {
namespace lite {
static bool IsFileExists(const std::string& path) {
static bool IsFileExists(const std::string &path) {
std::ifstream file(path);
bool res = file.is_open();
if (res) {
......
// 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.
/*
* This file implements an lightweight alternative for glog, which is more
* friendly for mobile.
*/
#pragma once
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <sstream>
// LOG()
#define LOG(status) LOG_##status.stream()
#define LOG_ERROR LOG_INFO
#define LOG_INFO paddle::lite::LogMessage(__FILE__, __LINE__)
#define LOG_WARNING paddle::lite::LogMessage(__FILE__, __LINE__)
#define LOG_FATAL paddle::lite::LogMessageFatal(__FILE__, __LINE__)
// Not supported yet.
#define VLOG(level) LOG_INFO.stream()
// CHECK()
#define CHECK(x) \
if (!(x)) \
paddle::lite::LogMessageFatal(__FILE__, __LINE__).stream() \
<< "Check failed: " #x << ": "
#define CHECK_EQ(x, y) _CHECK_BINARY(x, ==, y)
#define CHECK_LT(x, y) _CHECK_BINARY(x, <, y)
#define CHECK_LE(x, y) _CHECK_BINARY(x, <=, y)
#define CHECK_GT(x, y) _CHECK_BINARY(x, >, y)
#define CHECK_GE(x, y) _CHECK_BINARY(x, >=, y)
#define _CHECK_BINARY(x, cmp, y) CHECK(x cmp y) << x << "!" #cmp << y << " "
namespace paddle {
namespace lite {
class LogMessage {
public:
LogMessage(const char* file, int lineno) {
const int kMaxLen = 20;
const int len = strlen(file);
if (len > kMaxLen) {
log_stream_ << '[' << "..." << file + len - kMaxLen << ":" << lineno
<< "] ";
} else {
log_stream_ << '[' << file << ":" << lineno << "] ";
}
}
~LogMessage() {
log_stream_ << '\n';
std::cerr << log_stream_.str();
}
std::ostream& stream() { return log_stream_; }
protected:
std::stringstream log_stream_;
LogMessage(const LogMessage&) = delete;
void operator=(const LogMessage&) = delete;
};
class LogMessageFatal : public LogMessage {
public:
LogMessageFatal(const char* file, int lineno) : LogMessage(file, lineno) {}
~LogMessageFatal() {
log_stream_ << '\n';
std::cerr << log_stream_.str();
abort();
}
};
} // namespace lite
} // namespace paddle
// 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.
#include "paddle/fluid/lite/utils/logging.h"
#include <gtest/gtest.h>
namespace paddle {
namespace lite {
TEST(logging, basic) {
CHECK_EQ(1, 1) << "error";
CHECK_EQ(0 + 1, 1) << "error";
CHECK_GT(12, 1);
int a;
CHECK(&a);
}
} // namespace lite
} // namespace paddle
......@@ -13,11 +13,11 @@
// limitations under the License.
#pragma once
#include <glog/logging.h>
#include <exception>
#include <memory>
#include <type_traits>
#include <typeinfo>
#include "paddle/fluid/lite/utils/cp_logging.h"
// This is an equivalent implementation of boost::any. We implement this to
// avoid including the whole boost library and keep the inference library small.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册