diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 19110812c240db4cbe3ba73a3a42ab0f1511a115..43350333a5f28e721c623a61297db90a7323dc03 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -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) diff --git a/paddle/fluid/lite/CMakeLists.txt b/paddle/fluid/lite/CMakeLists.txt index 98357922eb8d537b67fb6bec627d172cdf9903ea..75595cc17e13ec7a65da184d6a662f57ea2ea206 100644 --- a/paddle/fluid/lite/CMakeLists.txt +++ b/paddle/fluid/lite/CMakeLists.txt @@ -1,7 +1,9 @@ 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) diff --git a/paddle/fluid/lite/api/CMakeLists.txt b/paddle/fluid/lite/api/CMakeLists.txt index 4fa6b6d34d6ec6313f1d8a2cc38467fbe91d4730..abfdca4815203e6f67cb7ec8b67844cb354638f6 100644 --- a/paddle/fluid/lite/api/CMakeLists.txt +++ b/paddle/fluid/lite/api/CMakeLists.txt @@ -1,5 +1,6 @@ -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) diff --git a/paddle/fluid/lite/api/cxx_api.cc b/paddle/fluid/lite/api/cxx_api.cc index 48ce5f46520b9beb26100f9cc3ddc79626fab3a6..04bcb388f627c97ea549f00f3464b01a9e21dae5 100644 --- a/paddle/fluid/lite/api/cxx_api.cc +++ b/paddle/fluid/lite/api/cxx_api.cc @@ -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_); } diff --git a/paddle/fluid/lite/api/cxx_api.h b/paddle/fluid/lite/api/cxx_api.h index bc3b007d45efaa2b99f5964c5177db5886c55770..81f5694fbae92c31373f3f97879beb46500b0fc4 100644 --- a/paddle/fluid/lite/api/cxx_api.h +++ b/paddle/fluid/lite/api/cxx_api.h @@ -25,9 +25,9 @@ namespace lite { struct Config {}; -class CxxPredictor { +class LightPredictor { public: - CxxPredictor() { scope_ = std::make_shared(); } + LightPredictor() { scope_ = std::make_shared(); } void Build(const std::string& model_path, const Place& prefer_place, const std::vector& valid_places) { diff --git a/paddle/fluid/lite/api/cxx_api_test.cc b/paddle/fluid/lite/api/cxx_api_test.cc index dd44ad937c78fa6ebca88180b3970c54a038231b..cf78a3fe56db00467060ddd3ea9d00e8905e0748 100644 --- a/paddle/fluid/lite/api/cxx_api_test.cc +++ b/paddle/fluid/lite/api/cxx_api_test.cc @@ -22,7 +22,7 @@ namespace paddle { namespace lite { TEST(CXXApi, test) { - lite::CxxPredictor predictor; + lite::LightPredictor predictor; #ifndef LITE_WITH_CUDA std::vector 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 valid_places({Place{TARGET(kHost), PRECISION(kFloat)}}); predictor.Build("/home/chunwei/project/models/model2", Place{TARGET(kCUDA), PRECISION(kFloat)}, valid_places); diff --git a/paddle/fluid/lite/api/light_api.h b/paddle/fluid/lite/api/light_api.h index 78967896b1b744942b07904fca29cdc18fb327a0..484af4d339bc4dac399798a7c7af4040ef43d1f4 100644 --- a/paddle/fluid/lite/api/light_api.h +++ b/paddle/fluid/lite/api/light_api.h @@ -28,9 +28,9 @@ namespace paddle { namespace lite { -class CxxPredictor { +class LightPredictor { public: - CxxPredictor() { scope_ = std::make_shared(); } + LightPredictor() { scope_ = std::make_shared(); } void Build(const std::string& model_dir) { framework::proto::ProgramDesc desc; diff --git a/paddle/fluid/lite/api/light_api_test.cc b/paddle/fluid/lite/api/light_api_test.cc index e0398824b68a7a6d12dff720e0cc0cd704553186..e5f577dc911a02b0b32372f17485da5d4c3e60bb 100644 --- a/paddle/fluid/lite/api/light_api_test.cc +++ b/paddle/fluid/lite/api/light_api_test.cc @@ -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); diff --git a/paddle/fluid/lite/core/CMakeLists.txt b/paddle/fluid/lite/core/CMakeLists.txt index fe84114739a2eba56683ea6b7dfb840137ecc4a7..6eb988385b4a162d5842d6d9928a3d831753eff0 100644 --- a/paddle/fluid/lite/core/CMakeLists.txt +++ b/paddle/fluid/lite/core/CMakeLists.txt @@ -1,3 +1,4 @@ +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) diff --git a/paddle/fluid/lite/core/lite_gtest_main.cc b/paddle/fluid/lite/core/lite_gtest_main.cc new file mode 100644 index 0000000000000000000000000000000000000000..9f9bd7ba467826507e6a69c61c56ff9edcee7b69 --- /dev/null +++ b/paddle/fluid/lite/core/lite_gtest_main.cc @@ -0,0 +1,21 @@ +// 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 + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + + return RUN_ALL_TESTS(); +} diff --git a/paddle/fluid/lite/core/mir/CMakeLists.txt b/paddle/fluid/lite/core/mir/CMakeLists.txt index 1a2a0d3697df6f0a9d33a6761688b80a5e9cca08..1ba5a3dae873fa05dc18db630f9cb0a7e6b9c0d6 100644 --- a/paddle/fluid/lite/core/mir/CMakeLists.txt +++ b/paddle/fluid/lite/core/mir/CMakeLists.txt @@ -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}) diff --git a/paddle/fluid/lite/core/op_lite.h b/paddle/fluid/lite/core/op_lite.h index bfeb32d1a7215185debc1dc6450ea425d2c383fd..8b578c5828282d1555fc9756d9785e11acfaa5d6 100644 --- a/paddle/fluid/lite/core/op_lite.h +++ b/paddle/fluid/lite/core/op_lite.h @@ -15,7 +15,6 @@ #pragma once #include -#include #include #include #include @@ -28,9 +27,6 @@ namespace paddle { namespace lite { -using any_t = boost::variant; -using anys_t = std::map; - // For registry factory. struct Registry { void Touch() {} diff --git a/paddle/fluid/lite/kernels/CMakeLists.txt b/paddle/fluid/lite/kernels/CMakeLists.txt index ebbfb2139e5321bea32dc76dd2617e770b4e483e..5c2883d53794384d65fa2d51c06be2c9b799a0bd 100644 --- a/paddle/fluid/lite/kernels/CMakeLists.txt +++ b/paddle/fluid/lite/kernels/CMakeLists.txt @@ -1,4 +1,6 @@ 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()