提交 be706306 编写于 作者: S superjomn

enable lite_test with light weight framework

上级 10e64565
...@@ -403,6 +403,44 @@ function(cc_test TARGET_NAME) ...@@ -403,6 +403,44 @@ function(cc_test TARGET_NAME)
endif() endif()
endfunction(cc_test) endfunction(cc_test)
# cc_test without default dependencies
function(raw_cc_test TARGET_NAME)
if(WITH_TESTING)
set(options SERIAL)
set(oneValueArgs "")
set(multiValueArgs SRCS DEPS ARGS)
cmake_parse_arguments(cc_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_executable(${TARGET_NAME} ${cc_test_SRCS})
if(WIN32)
if("${cc_test_DEPS};" MATCHES "python;")
list(REMOVE_ITEM cc_test_DEPS python)
target_link_libraries(${TARGET_NAME} ${PYTHON_LIBRARIES})
endif()
endif(WIN32)
get_property(os_dependency_modules GLOBAL PROPERTY OS_DEPENDENCY_MODULES)
target_link_libraries(${TARGET_NAME} ${cc_test_DEPS} ${os_dependency_modules} lite_gtest_main gtest gflags glog)
add_dependencies(${TARGET_NAME} ${cc_test_DEPS} lite_gtest_main gtest gflags glog)
common_link(${TARGET_NAME})
add_test(NAME ${TARGET_NAME}
COMMAND ${TARGET_NAME} ${cc_test_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
if (${cc_test_SERIAL})
set_property(TEST ${TARGET_NAME} PROPERTY RUN_SERIAL 1)
endif()
# No unit test should exceed 10 minutes.
set_tests_properties(${TARGET_NAME} PROPERTIES TIMEOUT 600)
endif()
endfunction(raw_cc_test)
function(lite_cc_test args)
if (LITE_WITH_LIGHT_WEIGHT_FRAMEWORK)
message(STATUS "building lite raw test: ${args}")
raw_cc_test(${args} ${ARGN})
else()
cc_test(${args} ${ARGN})
endif()
endfunction()
function(nv_library TARGET_NAME) function(nv_library TARGET_NAME)
if (WITH_GPU) if (WITH_GPU)
set(options STATIC static SHARED shared) set(options STATIC static SHARED shared)
......
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(x86) add_subdirectory(x86)
add_subdirectory(host) add_subdirectory(host)
add_subdirectory(cuda) if(LITE_WITH_CUDA)
add_subdirectory(cuda)
endif()
add_subdirectory(operators) add_subdirectory(operators)
add_subdirectory(kernels) add_subdirectory(kernels)
add_subdirectory(model_parser) add_subdirectory(model_parser)
......
set(cxx_api_lite_deps scope_lite host_kernels ops_lite optimizer_lite target_wrapper_host kernels_cuda optimizer_lite model_parser_lite) set(cxx_api_lite_deps scope_lite host_kernels ops_lite optimizer_lite target_wrapper_host optimizer_lite model_parser_lite)
if(LITE_WITH_CUDA) if(LITE_WITH_CUDA)
set(cxx_api_lite_deps ${cxx_api_lite_deps} kernels_cuda)
cc_library(cxx_api_lite_cuda SRCS cxx_api.cc DEPS ${cxx_api_lite_deps} target_wrapper_cuda) cc_library(cxx_api_lite_cuda SRCS cxx_api.cc DEPS ${cxx_api_lite_deps} target_wrapper_cuda)
nv_test(test_cxx_api_lite_cuda SRCS cxx_api_test.cc DEPS cxx_api_lite_cuda) nv_test(test_cxx_api_lite_cuda SRCS cxx_api_test.cc DEPS cxx_api_lite_cuda)
endif() endif()
...@@ -15,5 +16,5 @@ endif() ...@@ -15,5 +16,5 @@ endif()
cc_library(light_api_lite SRCS light_api.cc DEPS ${light_api_deps}) cc_library(light_api_lite SRCS light_api.cc DEPS ${light_api_deps})
cc_test(test_cxx_api_lite SRCS cxx_api_test.cc DEPS cxx_api_lite model_parser_lite target_wrapper_host host_kernels) lite_cc_test(test_cxx_api_lite SRCS cxx_api_test.cc DEPS cxx_api_lite model_parser_lite target_wrapper_host host_kernels)
cc_test(test_light_api SRCS light_api_test.cc DEPS light_api_lite) lite_cc_test(test_light_api SRCS light_api_test.cc DEPS light_api_lite)
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
void CxxPredictor::SaveModel(const std::string &dir) { void LightPredictor::SaveModel(const std::string &dir) {
MkDirRecursively(dir.c_str()); MkDirRecursively(dir.c_str());
program_->PersistModel(dir, program_desc_); program_->PersistModel(dir, program_desc_);
} }
......
...@@ -25,9 +25,9 @@ namespace lite { ...@@ -25,9 +25,9 @@ namespace lite {
struct Config {}; struct Config {};
class CxxPredictor { class LightPredictor {
public: public:
CxxPredictor() { scope_ = std::make_shared<Scope>(); } LightPredictor() { scope_ = std::make_shared<Scope>(); }
void Build(const std::string& model_path, const Place& prefer_place, void Build(const std::string& model_path, const Place& prefer_place,
const std::vector<Place>& valid_places) { const std::vector<Place>& valid_places) {
......
...@@ -22,7 +22,7 @@ namespace paddle { ...@@ -22,7 +22,7 @@ namespace paddle {
namespace lite { namespace lite {
TEST(CXXApi, test) { TEST(CXXApi, test) {
lite::CxxPredictor predictor; lite::LightPredictor predictor;
#ifndef LITE_WITH_CUDA #ifndef LITE_WITH_CUDA
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}}); std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}});
#else #else
...@@ -60,7 +60,7 @@ TEST(CXXApi, test) { ...@@ -60,7 +60,7 @@ TEST(CXXApi, test) {
} }
TEST(CXXApi, save_model) { TEST(CXXApi, save_model) {
lite::CxxPredictor predictor; lite::LightPredictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}}); std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}});
predictor.Build("/home/chunwei/project/models/model2", predictor.Build("/home/chunwei/project/models/model2",
Place{TARGET(kCUDA), PRECISION(kFloat)}, valid_places); Place{TARGET(kCUDA), PRECISION(kFloat)}, valid_places);
......
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
class CxxPredictor { class LightPredictor {
public: public:
CxxPredictor() { scope_ = std::make_shared<Scope>(); } LightPredictor() { scope_ = std::make_shared<Scope>(); }
void Build(const std::string& model_dir) { void Build(const std::string& model_dir) {
framework::proto::ProgramDesc desc; framework::proto::ProgramDesc desc;
......
...@@ -23,7 +23,7 @@ const std::string model_dir = ...@@ -23,7 +23,7 @@ const std::string model_dir =
"api/optimized_model"; "api/optimized_model";
TEST(LightAPI, load) { TEST(LightAPI, load) {
CxxPredictor predictor; LightPredictor predictor;
predictor.Build(model_dir); predictor.Build(model_dir);
auto* input_tensor = predictor.GetInput(0); auto* input_tensor = predictor.GetInput(0);
......
cc_library(lite_gtest_main SRCS lite_gtest_main.cc)
cc_library(memory_lite SRCS memory.cc) cc_library(memory_lite SRCS memory.cc)
cc_library(target_wrapper_lite SRCS target_wrapper.cc) cc_library(target_wrapper_lite SRCS target_wrapper.cc)
cc_library(tensor_lite SRCS tensor.cc DEPS memory_lite target_wrapper_lite) cc_library(tensor_lite SRCS tensor.cc DEPS memory_lite target_wrapper_lite)
......
// 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 <gtest/gtest.h>
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
...@@ -24,14 +24,20 @@ cc_test(test_ssa_graph SRCS ssa_graph_test.cc DEPS ...@@ -24,14 +24,20 @@ cc_test(test_ssa_graph SRCS ssa_graph_test.cc DEPS
mir_pass_manager mir_pass_manager
program_fake_utils program_fake_utils
) )
cc_test(test_variable_place_infrence_pass SRCS variable_place_inference_pass_test.cc DEPS set(test_variable_place_infrence_pass_DEPS
ops_lite ops_lite
host_kernels host_kernels
kernels_cuda
mir_passes mir_passes
mir_pass_manager mir_pass_manager
optimizer_lite optimizer_lite
program_fake_utils program_fake_utils
target_wrapper_host target_wrapper_host
target_wrapper_cuda
) )
if (LITE_WITH_CUDA)
set(test_variable_place_infrence_pass_DEPS
${test_variable_place_infrence_pass_DEPS} target_wrapper_cuda
kernels_cuda
)
endif()
cc_test(test_variable_place_infrence_pass SRCS variable_place_inference_pass_test.cc DEPS
${test_variable_place_infrence_pass_DEPS})
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#pragma once #pragma once
#include <glog/logging.h> #include <glog/logging.h>
#include <boost/variant.hpp>
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
...@@ -28,9 +27,6 @@ ...@@ -28,9 +27,6 @@
namespace paddle { namespace paddle {
namespace lite { namespace lite {
using any_t = boost::variant<int, float, framework::Variable *>;
using anys_t = std::map<std::string, any_t>;
// For registry factory. // For registry factory.
struct Registry { struct Registry {
void Touch() {} void Touch() {}
......
set(lite_kernel_deps type_system kernel_lite op_registry_lite) set(lite_kernel_deps type_system kernel_lite op_registry_lite)
add_subdirectory(host) add_subdirectory(host)
add_subdirectory(arm) add_subdirectory(arm)
add_subdirectory(cuda) if(LITE_WITH_CUDA)
add_subdirectory(cuda)
endif()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册