提交 be706306 编写于 作者: S superjomn

enable lite_test with light weight framework

上级 10e64565
......@@ -403,6 +403,44 @@ function(cc_test TARGET_NAME)
endif()
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)
if (WITH_GPU)
set(options STATIC static SHARED shared)
......
add_subdirectory(core)
add_subdirectory(x86)
add_subdirectory(host)
add_subdirectory(cuda)
if(LITE_WITH_CUDA)
add_subdirectory(cuda)
endif()
add_subdirectory(operators)
add_subdirectory(kernels)
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)
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)
nv_test(test_cxx_api_lite_cuda SRCS cxx_api_test.cc DEPS cxx_api_lite_cuda)
endif()
......@@ -15,5 +16,5 @@ endif()
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)
cc_test(test_light_api SRCS light_api_test.cc DEPS light_api_lite)
lite_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_light_api SRCS light_api_test.cc DEPS light_api_lite)
......@@ -18,7 +18,7 @@
namespace paddle {
namespace lite {
void CxxPredictor::SaveModel(const std::string &dir) {
void LightPredictor::SaveModel(const std::string &dir) {
MkDirRecursively(dir.c_str());
program_->PersistModel(dir, program_desc_);
}
......
......@@ -25,9 +25,9 @@ namespace lite {
struct Config {};
class CxxPredictor {
class LightPredictor {
public:
CxxPredictor() { scope_ = std::make_shared<Scope>(); }
LightPredictor() { scope_ = std::make_shared<Scope>(); }
void Build(const std::string& model_path, const Place& prefer_place,
const std::vector<Place>& valid_places) {
......
......@@ -22,7 +22,7 @@ namespace paddle {
namespace lite {
TEST(CXXApi, test) {
lite::CxxPredictor predictor;
lite::LightPredictor predictor;
#ifndef LITE_WITH_CUDA
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}});
#else
......@@ -60,7 +60,7 @@ TEST(CXXApi, test) {
}
TEST(CXXApi, save_model) {
lite::CxxPredictor predictor;
lite::LightPredictor predictor;
std::vector<Place> valid_places({Place{TARGET(kHost), PRECISION(kFloat)}});
predictor.Build("/home/chunwei/project/models/model2",
Place{TARGET(kCUDA), PRECISION(kFloat)}, valid_places);
......
......@@ -28,9 +28,9 @@
namespace paddle {
namespace lite {
class CxxPredictor {
class LightPredictor {
public:
CxxPredictor() { scope_ = std::make_shared<Scope>(); }
LightPredictor() { scope_ = std::make_shared<Scope>(); }
void Build(const std::string& model_dir) {
framework::proto::ProgramDesc desc;
......
......@@ -23,7 +23,7 @@ const std::string model_dir =
"api/optimized_model";
TEST(LightAPI, load) {
CxxPredictor predictor;
LightPredictor predictor;
predictor.Build(model_dir);
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(target_wrapper_lite SRCS target_wrapper.cc)
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
mir_pass_manager
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
host_kernels
kernels_cuda
mir_passes
mir_pass_manager
optimizer_lite
program_fake_utils
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 @@
#pragma once
#include <glog/logging.h>
#include <boost/variant.hpp>
#include <map>
#include <memory>
#include <string>
......@@ -28,9 +27,6 @@
namespace paddle {
namespace lite {
using any_t = boost::variant<int, float, framework::Variable *>;
using anys_t = std::map<std::string, any_t>;
// For registry factory.
struct Registry {
void Touch() {}
......
set(lite_kernel_deps type_system kernel_lite op_registry_lite)
add_subdirectory(host)
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.
先完成此消息的编辑!
想要评论请 注册