From 0a20a6187fd148c340a27033b3a297e12f27563a Mon Sep 17 00:00:00 2001 From: superjomn Date: Mon, 13 May 2019 19:32:48 +0800 Subject: [PATCH] fix ARM compile error test=develop --- CMakeLists.txt | 5 ++-- paddle/fluid/framework/CMakeLists.txt | 2 +- paddle/fluid/lite/CMakeLists.txt | 25 +++++++++++++++- paddle/fluid/lite/api/CMakeLists.txt | 20 +++++++++++-- paddle/fluid/lite/api/cxx_api_test.cc | 7 +++-- paddle/fluid/lite/api/light_api.h | 9 +++--- paddle/fluid/lite/api/light_api_test.cc | 21 +++++++------ paddle/fluid/lite/core/CMakeLists.txt | 6 ++-- paddle/fluid/lite/core/memory.h | 2 ++ paddle/fluid/lite/core/mir/CMakeLists.txt | 7 +++-- paddle/fluid/lite/core/mir/ssa_graph_test.cc | 6 ++-- .../core/mir/variable_place_inference_pass.h | 6 ---- .../mir/variable_place_inference_pass_test.cc | 2 +- paddle/fluid/lite/core/op_registry.h | 3 +- paddle/fluid/lite/core/optimizer_test.cc | 8 ++++- paddle/fluid/lite/core/program.h | 2 +- paddle/fluid/lite/core/program_fake_utils.h | 21 ++++++------- paddle/fluid/lite/kernels/host/CMakeLists.txt | 23 +++++++------- .../lite/kernels/host/fc_compute_test.cc | 22 +++++++------- paddle/fluid/lite/model_parser/CMakeLists.txt | 12 ++++++-- .../fluid/lite/model_parser/compatible_pb.h | 2 +- paddle/fluid/lite/model_parser/model_parser.h | 2 +- .../lite/model_parser/model_parser_test.cc | 13 ++++---- paddle/fluid/lite/model_parser/pb/op_desc.h | 2 +- paddle/fluid/lite/model_parser/pb/var_desc.h | 2 +- paddle/fluid/lite/operators/fc_op.h | 3 -- paddle/fluid/lite/operators/fc_op_test.cc | 30 ++++++++----------- paddle/fluid/lite/utils/CMakeLists.txt | 4 +-- 28 files changed, 156 insertions(+), 111 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 254fb6c3dfb..d0a5bdc46d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,9 +80,10 @@ option(WITH_FAST_MATH "Make use of fast math library, might affect the precisi option(WITH_DGC "Use DGC(Deep Gradient Compression) or not" ON) # for lite, both server and mobile framework. -option(LITE_WITH_CUDA "Enable CUDA in lite mode" ON) +option(WITH_LITE "Enable lite framework" ON) +option(LITE_WITH_CUDA "Enable CUDA in lite mode" OFF) option(LITE_WITH_X86 "Enable X86 in lite mode" ON) -option(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK "Enable light-weight framework" ON) +option(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK "Enable light-weight framework" OFF) set(THIRD_PARTY_PATH "${CMAKE_BINARY_DIR}/third_party" CACHE STRING diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index 4e00630bb12..ce33a70c549 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -124,7 +124,7 @@ cc_library(shape_inference SRCS shape_inference.cc DEPS ddim attribute device_co cc_library(transfer_scope_cache SRCS transfer_scope_cache.cc DEPS scope framework_proto device_context) cc_library(op_kernel_type SRCS op_kernel_type.cc DEPS device_context place) cc_library(operator SRCS operator.cc DEPS op_info device_context tensor scope glog - shape_inference data_transform lod_tensor profiler transfer_scope_cache op_kernel_type) + shape_inference data_transform lod_tensor profiler transfer_scope_cache op_kernel_type data_feed_proto) cc_test(operator_test SRCS operator_test.cc DEPS operator op_registry device_context) diff --git a/paddle/fluid/lite/CMakeLists.txt b/paddle/fluid/lite/CMakeLists.txt index 13d64ca0e20..3b9a6756953 100644 --- a/paddle/fluid/lite/CMakeLists.txt +++ b/paddle/fluid/lite/CMakeLists.txt @@ -2,11 +2,34 @@ if (NOT WITH_LITE) return() endif() -message(WARNING "Enable Lite") +message(WARNING "Lite enabled!") message(STATUS "LIGHT_FRAMEWORK: ${LITE_WITH_LIGHT_WEIGHT_FRAMEWORK}") message(STATUS "LITE_WITH_CUDA: ${LITE_WITH_CUDA}") message(STATUS "LITE_WITH_X86: ${LITE_WITH_X86}") +set(LITE_MODEL_DIR "${THIRD_PARTY_PATH}/install") + +function(lite_download_and_uncompress INSTALL_DIR URL FILENAME) + message(STATUS "Download inference test stuff from ${URL}/${FILENAME}") + string(REGEX REPLACE "[-%.]" "_" FILENAME_EX ${FILENAME}) + set(EXTERNAL_PROJECT_NAME "extern_lite_download_${FILENAME_EX}") + set(UNPACK_DIR "${INSTALL_DIR}/src/${EXTERNAL_PROJECT_NAME}") + ExternalProject_Add( + ${EXTERNAL_PROJECT_NAME} + ${EXTERNAL_PROJECT_LOG_ARGS} + PREFIX ${INSTALL_DIR} + DOWNLOAD_COMMAND wget --no-check-certificate -q -O ${INSTALL_DIR}/${FILENAME} ${URL}/${FILENAME} && + ${CMAKE_COMMAND} -E tar xzf ${INSTALL_DIR}/${FILENAME} + DOWNLOAD_DIR ${INSTALL_DIR} + DOWNLOAD_NO_PROGRESS 1 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + UPDATE_COMMAND "" + INSTALL_COMMAND "" + ) +endfunction() + + add_subdirectory(core) add_subdirectory(x86) add_subdirectory(host) diff --git a/paddle/fluid/lite/api/CMakeLists.txt b/paddle/fluid/lite/api/CMakeLists.txt index 5806bf5c67b..1de5d09394d 100644 --- a/paddle/fluid/lite/api/CMakeLists.txt +++ b/paddle/fluid/lite/api/CMakeLists.txt @@ -18,8 +18,22 @@ cc_library(light_api_lite SRCS light_api.cc DEPS ${light_api_deps} ${ops_lite} $ message(STATUS "get ops ${ops_lite}") 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) + +include(ExternalProject) +set(LITE_URL "http://paddle-inference-dist.bj.bcebos.com" CACHE STRING "inference download url") +set(LITE_DEMO_INSTALL_DIR "${THIRD_PARTY_PATH}/inference_demo" CACHE STRING + "A path setting inference demo download directories.") + + +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} ARGS --model_dir=${LITE_MODEL_DIR}/lite_naive_model + --optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL) +if(WITH_TESTING) +lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "lite_naive_model.tar.gz") +add_dependencies(test_cxx_api_lite extern_lite_download_lite_naive_model_tar_gz) +endif(WITH_TESTING) + +lite_cc_test(test_light_api SRCS light_api_test.cc DEPS light_api_lite ARGS --optimized_model=${LITE_MODEL_DIR}/lite_naive_model_opt SERIAL) 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}) diff --git a/paddle/fluid/lite/api/cxx_api_test.cc b/paddle/fluid/lite/api/cxx_api_test.cc index daa3d1734e8..373cd070407 100644 --- a/paddle/fluid/lite/api/cxx_api_test.cc +++ b/paddle/fluid/lite/api/cxx_api_test.cc @@ -19,6 +19,7 @@ #include "paddle/fluid/lite/core/op_registry.h" DEFINE_string(model_dir, "", ""); +DEFINE_string(optimized_model, "", ""); namespace paddle { namespace lite { @@ -48,7 +49,7 @@ TEST(CXXApi, test) { data[i] = i; } - LOG(INFO) << "input " << *input_tensor; + // LOG(INFO) << "input " << *input_tensor; predictor.Run(); @@ -57,7 +58,7 @@ TEST(CXXApi, test) { LOG(INFO) << "out " << out->data()[0]; LOG(INFO) << "out " << out->data()[1]; LOG(INFO) << "dims " << out->dims(); - LOG(INFO) << "out " << *out; + // LOG(INFO) << "out " << *out; } #ifndef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK @@ -67,7 +68,7 @@ TEST(CXXApi, save_model) { predictor.Build(FLAGS_model_dir, Place{TARGET(kCUDA), PRECISION(kFloat)}, valid_places); - predictor.SaveModel("./optimized_model"); + predictor.SaveModel(FLAGS_optimized_model); } #endif diff --git a/paddle/fluid/lite/api/light_api.h b/paddle/fluid/lite/api/light_api.h index ec07b8c979d..484af4d339b 100644 --- a/paddle/fluid/lite/api/light_api.h +++ b/paddle/fluid/lite/api/light_api.h @@ -41,21 +41,20 @@ class LightPredictor { void Run() { program_->Run(); } // Get offset-th col of feed. - TensorBase* GetInput(size_t offset) { + Tensor* GetInput(size_t offset) { auto* _feed_list = program_->exec_scope()->FindVar("feed"); CHECK(_feed_list) << "no feed variable in exec_scope"; - auto* feed_list = _feed_list->GetMutable>(); + auto* feed_list = _feed_list->GetMutable>(); if (offset >= feed_list->size()) { feed_list->resize(offset + 1); } return &feed_list->at(offset); } - const TensorBase* GetOutput(size_t offset) { + const Tensor* GetOutput(size_t offset) { auto* _fetch_list = program_->exec_scope()->FindVar("fetch"); CHECK(_fetch_list) << "no fatch variable in exec_scope"; - auto& fetch_list = - *_fetch_list->GetMutable>(); + auto& fetch_list = *_fetch_list->GetMutable>(); CHECK_LT(offset, fetch_list.size()) << "offset " << offset << " overflow"; return &fetch_list.at(offset); } diff --git a/paddle/fluid/lite/api/light_api_test.cc b/paddle/fluid/lite/api/light_api_test.cc index e5f577dc911..6dd596bbee5 100644 --- a/paddle/fluid/lite/api/light_api_test.cc +++ b/paddle/fluid/lite/api/light_api_test.cc @@ -13,21 +13,20 @@ // limitations under the License. #include "paddle/fluid/lite/api/light_api.h" +#include #include +DEFINE_string(optimized_model, "", ""); + namespace paddle { namespace lite { -const std::string model_dir = - "/home/chunwei/project/Paddle/cmake-build-relwithdebinfo/paddle/fluid/lite/" - "api/optimized_model"; - TEST(LightAPI, load) { LightPredictor predictor; - predictor.Build(model_dir); + predictor.Build(FLAGS_optimized_model); auto* input_tensor = predictor.GetInput(0); - input_tensor->Resize({100, 100}); + input_tensor->Resize(DDimLite(std::vector({100, 100}))); auto* data = input_tensor->mutable_data(); for (int i = 0; i < 100 * 100; i++) { data[i] = i; @@ -40,13 +39,13 @@ TEST(LightAPI, load) { } // namespace paddle USE_LITE_OP(mul); -USE_LITE_OP(fc); -USE_LITE_OP(scale); +// USE_LITE_OP(fc); +// USE_LITE_OP(scale); USE_LITE_OP(feed); USE_LITE_OP(fetch); USE_LITE_OP(io_copy); -USE_LITE_KERNEL(fc, kHost, kFloat, kNCHW, def); -USE_LITE_KERNEL(mul, kHost, kFloat, kNCHW, def); -USE_LITE_KERNEL(scale, kHost, kFloat, kNCHW, def); +// USE_LITE_KERNEL(fc, kHost, kFloat, kNCHW, def); +// USE_LITE_KERNEL(mul, kHost, kFloat, kNCHW, def); +// USE_LITE_KERNEL(scale, kHost, kFloat, kNCHW, def); USE_LITE_KERNEL(feed, kHost, kAny, kAny, def); USE_LITE_KERNEL(fetch, kHost, kAny, kAny, def); diff --git a/paddle/fluid/lite/core/CMakeLists.txt b/paddle/fluid/lite/core/CMakeLists.txt index f039f92bf83..e5b118aa66a 100644 --- a/paddle/fluid/lite/core/CMakeLists.txt +++ b/paddle/fluid/lite/core/CMakeLists.txt @@ -1,5 +1,5 @@ cc_library(lite_gtest_main SRCS lite_gtest_main.cc) -cc_library(memory_lite SRCS memory.cc) +cc_library(memory_lite SRCS memory.cc DEPS target_wrapper_lite target_wrapper_host) cc_library(target_wrapper_lite SRCS target_wrapper.cc) cc_library(lite_tensor SRCS lite_tensor.cc DEPS memory_lite target_wrapper_lite) @@ -24,7 +24,7 @@ cc_library(op_lite SRCS op_lite.cc DEPS scope_lite op_registry_lite compatible_p cc_library(types_lite SRCS types.cc) cc_library(type_system SRCS type_system.cc DEPS ${tensor_lite} target_wrapper_lite) -cc_library(kernel_executor_lite SRCS kernel_executor.cc DEPS mir_ssa_graph kernel_lite) +#cc_library(kernel_executor_lite SRCS kernel_executor.cc DEPS mir_ssa_graph kernel_lite) cc_library(program_lite SRCS program.cc DEPS op_lite kernel_lite) cc_library(optimizer_lite SRCS optimizer.cc DEPS mir_pass_manager model_parser_lite program_lite) @@ -46,5 +46,5 @@ lite_cc_test(test_kernel_lite SRCS kernel_test.cc DEPS kernel_lite target_wrappe lite_cc_test(test_op_lite SRCS op_lite_test.cc DEPS op_lite) lite_cc_test(test_tensor_lite SRCS lite_tensor_test.cc DEPS lite_tensor) lite_cc_test(test_type_system SRCS type_system_test.cc DEPS type_system utils_lite) -lite_cc_test(test_optimizer_lite SRCS optimizer_test.cc DEPS mir_pass_manager program_fake_utils mir_passes) +#lite_cc_test(test_optimizer_lite SRCS optimizer_test.cc DEPS mir_pass_manager program_fake_utils mir_passes optimizer_lite fc_op_lite) lite_cc_test(test_types_lite SRCS types_test.cc DEPS types_lite) diff --git a/paddle/fluid/lite/core/memory.h b/paddle/fluid/lite/core/memory.h index 4d601df10d8..0b364f0b3a5 100644 --- a/paddle/fluid/lite/core/memory.h +++ b/paddle/fluid/lite/core/memory.h @@ -22,9 +22,11 @@ static void* TargetMalloc(TargetType target, size_t size) { void* data{nullptr}; switch (target) { case TargetType::kHost: +#ifdef LITE_WITH_X86 case TargetType::kX86: data = TargetWrapper::Malloc(size); break; +#endif #ifdef LITE_WITH_CUDA case TargetType::kCUDA: data = diff --git a/paddle/fluid/lite/core/mir/CMakeLists.txt b/paddle/fluid/lite/core/mir/CMakeLists.txt index dd2428906d2..db31aeb58e1 100644 --- a/paddle/fluid/lite/core/mir/CMakeLists.txt +++ b/paddle/fluid/lite/core/mir/CMakeLists.txt @@ -22,14 +22,17 @@ endif() cc_test(test_mir_pass_manager SRCS pass_manager_test.cc DEPS mir_pass_manager mir_passes) cc_test(test_ssa_graph SRCS ssa_graph_test.cc DEPS mir_ssa_graph scope_lite op_lite - ${ops_lite} + fc_op_lite ${host_kernels} mir_passes mir_pass_manager program_fake_utils ) set(test_variable_place_infrence_pass_DEPS - ${ops_lite} + mul_op_lite + feed_op_lite + fetch_op_lite + io_copy_op_lite ${host_kernels} mir_passes mir_pass_manager diff --git a/paddle/fluid/lite/core/mir/ssa_graph_test.cc b/paddle/fluid/lite/core/mir/ssa_graph_test.cc index 2bf44759349..f24ab854d38 100644 --- a/paddle/fluid/lite/core/mir/ssa_graph_test.cc +++ b/paddle/fluid/lite/core/mir/ssa_graph_test.cc @@ -35,10 +35,12 @@ void BuildFc(framework::ProgramDesc* desc, const std::string& x, } TEST(SSAGraph, test) { - auto program = ProgramFaker(); + auto program_faker = ProgramFaker(); SSAGraph graph; std::vector places{{TARGET(kHost), PRECISION(kFloat)}}; + auto scope = std::make_shared(); + lite::Program program(*program_faker.program()->Proto(), scope, places); graph.Build(program, places); Visualize(&graph); @@ -49,4 +51,4 @@ TEST(SSAGraph, test) { } // namespace paddle USE_LITE_OP(fc); -USE_LITE_KERNEL(fc, kHost, kFloat); +USE_LITE_KERNEL(fc, kHost, kFloat, kNCHW, def); diff --git a/paddle/fluid/lite/core/mir/variable_place_inference_pass.h b/paddle/fluid/lite/core/mir/variable_place_inference_pass.h index eb32111fdf6..ff129600ea6 100644 --- a/paddle/fluid/lite/core/mir/variable_place_inference_pass.h +++ b/paddle/fluid/lite/core/mir/variable_place_inference_pass.h @@ -38,12 +38,6 @@ class VariablePlaceInferencePass : public DebugPass { LOG(INFO) << "found kernel in inputs " << v->AsStmt().op_type; continue; } - - // auto& arg = v->AsArgument(); - // LOG(INFO) << "get graph input " << arg.name << " " << *arg.type; - // arg.type.target = argument_default_target_; - // the other place description can't be determined yet, until their first - // usage by some kernel. } } diff --git a/paddle/fluid/lite/core/mir/variable_place_inference_pass_test.cc b/paddle/fluid/lite/core/mir/variable_place_inference_pass_test.cc index 8a71bbd2a39..9c33ff698ac 100644 --- a/paddle/fluid/lite/core/mir/variable_place_inference_pass_test.cc +++ b/paddle/fluid/lite/core/mir/variable_place_inference_pass_test.cc @@ -44,7 +44,7 @@ TEST(variable_place_inference_pass, test) { }, }); - Program program(*desc, scope, places); + Program program(*desc->Proto(), scope, places); core::KernelPickFactor factor; factor.ConsiderTarget(); diff --git a/paddle/fluid/lite/core/op_registry.h b/paddle/fluid/lite/core/op_registry.h index 4de6df1c72b..1a66ed89443 100644 --- a/paddle/fluid/lite/core/op_registry.h +++ b/paddle/fluid/lite/core/op_registry.h @@ -93,7 +93,8 @@ class KernelRegistry final { std::move(creator)); } - template + template std::list> Create(const std::string &op_type) { using kernel_registor_t = KernelRegistryForTarget; diff --git a/paddle/fluid/lite/core/optimizer_test.cc b/paddle/fluid/lite/core/optimizer_test.cc index 19a73a62cff..ab9a9cd0240 100644 --- a/paddle/fluid/lite/core/optimizer_test.cc +++ b/paddle/fluid/lite/core/optimizer_test.cc @@ -25,12 +25,18 @@ namespace lite { TEST(Optimizer, test) { Optimizer optimizer; - auto program = ProgramFaker(); + auto program_faker = ProgramFaker(); + program_faker.AddFeed("X", 0); + program_faker.AddFetch("X", 0); + std::vector places({Place{TARGET(kHost), PRECISION(kFloat)}}); core::KernelPickFactor factor; factor.ConsiderTarget(); + auto scope = std::make_shared(); + auto program_proto = *program_faker.program()->Proto(); + Program program(program_proto, scope, places); optimizer.Run(std::move(program), places, factor); auto runtime_program = optimizer.GenRuntimeProgram(); LOG(INFO) << "num statements " << runtime_program->num_instructions(); diff --git a/paddle/fluid/lite/core/program.h b/paddle/fluid/lite/core/program.h index 585deeb33ed..c38bf0630f5 100644 --- a/paddle/fluid/lite/core/program.h +++ b/paddle/fluid/lite/core/program.h @@ -70,7 +70,7 @@ struct Program { VLOG(4) << "create Op [" << op_type << "]"; auto op = LiteOpRegistry::Global().Create(op_type); CHECK(op) << "no Op found for " << op_type; - ops.emplace_back(op); + ops.emplace_back(std::move(op)); ops.back()->Attach(op_desc, exec_scope); } } diff --git a/paddle/fluid/lite/core/program_fake_utils.h b/paddle/fluid/lite/core/program_fake_utils.h index 55e3d4663b8..7d01c5a467e 100644 --- a/paddle/fluid/lite/core/program_fake_utils.h +++ b/paddle/fluid/lite/core/program_fake_utils.h @@ -14,6 +14,7 @@ #pragma once #include +#include "paddle/fluid/framework/program_desc.h" #include "paddle/fluid/lite/core/mir/ssa_graph.h" #include "paddle/fluid/lite/core/op_registry.h" @@ -28,9 +29,9 @@ Program FakeProgram() { std::string w1 = "w" + std::to_string(id); std::string b1 = "b" + std::to_string(id); std::string out1 = "out" + std::to_string(id); - auto w1v = program.scope->Var(w1)->GetMutable(); - auto b1v = program.scope->Var(b1)->GetMutable(); - auto out1v = program.scope->Var(out1)->GetMutable(); + auto w1v = program.scope->Var(w1)->GetMutable(); + auto b1v = program.scope->Var(b1)->GetMutable(); + auto out1v = program.scope->Var(out1)->GetMutable(); lite::OpDesc desc; desc.SetInput("Input", {x}); @@ -38,7 +39,7 @@ Program FakeProgram() { desc.SetInput("Bias", {b1}); desc.SetOutput("Out", {out1}); desc.SetType("fc"); - desc.SetAttr("in_num_col_dims", 1); + desc.SetAttr("in_num_col_dims", 1); // add to input program.tmp_vars.push_back(w1); @@ -48,9 +49,9 @@ Program FakeProgram() { fc_op->Attach(desc, program.scope.get()); program.ops.emplace_back(std::move(fc_op)); - w1v->Resize({100, 100}); - b1v->Resize({100, 1}); - out1v->Resize({100, 100}); + w1v->Resize(DDimHvy(std::vector({100, 100}))); + b1v->Resize(DDimHvy(std::vector({100, 1}))); + out1v->Resize(DDimHvy(std::vector({100, 100}))); return out1; }; @@ -60,8 +61,8 @@ Program FakeProgram() { std::string x = "x"; program.tmp_vars.push_back(x); - auto* xv = program.scope->Var(x)->GetMutable(); - xv->Resize({100, 100}); + auto* xv = program.scope->Var(x)->GetMutable(); + xv->Resize(DDimHvy(std::vector({100, 100}))); for (int i = 0; i < 3; i++) { x = add_fc(i, x); @@ -81,7 +82,7 @@ class ProgramFaker { void CreateVars(lite::Scope* scope) { for (auto& var : tmp_vars_) { auto* x = scope->Var(var); - x->GetMutable(); + x->GetMutable(); } for (auto& x : tmp_vars_) { diff --git a/paddle/fluid/lite/kernels/host/CMakeLists.txt b/paddle/fluid/lite/kernels/host/CMakeLists.txt index 6f39ee0c541..9bd2120457a 100644 --- a/paddle/fluid/lite/kernels/host/CMakeLists.txt +++ b/paddle/fluid/lite/kernels/host/CMakeLists.txt @@ -1,20 +1,19 @@ message(STATUS "compile with lite host kernels") -cc_library(fc_compute_host SRCS fc_compute.cc DEPS ${lite_kernel_deps}) +cc_library(fc_compute_host SRCS fc_compute.cc DEPS ${lite_kernel_deps} eigen3) cc_library(relu_compute_host SRCS relu_compute.cc DEPS ${lite_kernel_deps}) -cc_library(mul_compute_host SRCS mul_compute.cc DEPS ${lite_kernel_deps}) -cc_library(scale_compute_host SRCS scale_compute.cc DEPS ${lite_kernel_deps}) +cc_library(mul_compute_host SRCS mul_compute.cc DEPS ${lite_kernel_deps} eigen3) +cc_library(scale_compute_host SRCS scale_compute.cc DEPS ${lite_kernel_deps} eigen3) + cc_library(feed_compute_host SRCS feed_compute.cc DEPS ${lite_kernel_deps}) cc_library(fetch_compute_host SRCS fetch_compute.cc DEPS ${lite_kernel_deps}) set(host_kernels - feed_compute_host - fetch_compute_host - fc_compute_host - relu_compute_host - mul_compute_host - scale_compute_host - ) + feed_compute_host + fetch_compute_host + fc_compute_host + relu_compute_host + mul_compute_host + scale_compute_host + ) set(host_kernels "${host_kernels}" CACHE INTERNAL "host kernels") - -lite_cc_test(test_fc_compute SRCS fc_compute_test.cc DEPS fc_compute_host fc_op_lite) diff --git a/paddle/fluid/lite/kernels/host/fc_compute_test.cc b/paddle/fluid/lite/kernels/host/fc_compute_test.cc index 56871fb30db..69b0450900e 100644 --- a/paddle/fluid/lite/kernels/host/fc_compute_test.cc +++ b/paddle/fluid/lite/kernels/host/fc_compute_test.cc @@ -23,7 +23,7 @@ namespace kernels { namespace host { TEST(fc_compute_naive, test) { - TensorBase x, w, b, out, out1; + lite::Tensor x, w, b, out, out1; const int batch_size = 2; x.Resize({batch_size, 3}); w.Resize({4, 3}); @@ -79,15 +79,15 @@ TEST(fc_host, compute) { FcCompute fc; operators::FcParam param; - TensorBase x; - TensorBase w; - TensorBase bias; - TensorBase output; + lite::Tensor x; + lite::Tensor w; + lite::Tensor bias; + lite::Tensor output; - x.Resize({1, 10, 20}); - w.Resize({20, 20}); - bias.Resize({1, 10}); - output.Resize({10, 20}); + x.Resize(DDim(std::vector({1, 10, 20}))); + w.Resize(DDim(std::vector({20, 20}))); + bias.Resize(DDim(std::vector({1, 10}))); + output.Resize(DDim(std::vector({10, 20}))); auto* x_data = x.mutable_data(); auto* w_data = w.mutable_data(); @@ -119,7 +119,7 @@ TEST(fc_host, compute) { TEST(fc, retrive_op) { auto fc = KernelRegistry::Global().Create("fc"); - ASSERT_TRUE(fc.get()); + ASSERT_TRUE(fc); } } // namespace host @@ -127,4 +127,4 @@ TEST(fc, retrive_op) { } // namespace lite } // namespace paddle -USE_LITE_KERNEL(fc, kHost, kFloat); +USE_LITE_KERNEL(fc, kHost, kFloat, kNCHW, def); diff --git a/paddle/fluid/lite/model_parser/CMakeLists.txt b/paddle/fluid/lite/model_parser/CMakeLists.txt index 5a0c4e92977..95d67c32c51 100644 --- a/paddle/fluid/lite/model_parser/CMakeLists.txt +++ b/paddle/fluid/lite/model_parser/CMakeLists.txt @@ -1,5 +1,13 @@ -cc_library(runtime_lite SRCS runtime.cc) -lite_cc_test(test_model_parser_lite SRCS model_parser_test.cc DEPS model_parser_lite) +#cc_library(runtime_lite SRCS runtime.cc) + +lite_cc_test(test_model_parser_lite SRCS model_parser_test.cc + DEPS model_parser_lite framework_proto_lite + ARGS --model_dir=${LITE_MODEL_DIR}/lite_naive_model) +if(WITH_TESTING) +add_dependencies(test_model_parser_lite extern_lite_download_lite_naive_model_tar_gz) +endif(WITH_TESTING) + + if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) cc_library(compatible_pb_lite SRCS compatible_pb.cc DEPS op_desc_lite var_desc_lite) else() diff --git a/paddle/fluid/lite/model_parser/compatible_pb.h b/paddle/fluid/lite/model_parser/compatible_pb.h index 49db1e4d897..cef1406f985 100644 --- a/paddle/fluid/lite/model_parser/compatible_pb.h +++ b/paddle/fluid/lite/model_parser/compatible_pb.h @@ -20,8 +20,8 @@ * lite::pb::XXDesc. */ -#include "paddle/fluid/framework/framework.pb.h" #ifdef LITE_WITH_LIGHT_WEIGHT_FRAMEWORK +#include "paddle/fluid/lite/core/framework.pb.h" #include "paddle/fluid/lite/model_parser/pb/op_desc.h" #include "paddle/fluid/lite/model_parser/pb/var_desc.h" #else diff --git a/paddle/fluid/lite/model_parser/model_parser.h b/paddle/fluid/lite/model_parser/model_parser.h index 003d335c1b3..8cea4df2c86 100644 --- a/paddle/fluid/lite/model_parser/model_parser.h +++ b/paddle/fluid/lite/model_parser/model_parser.h @@ -18,7 +18,7 @@ #include #include #include -#include "paddle/fluid/framework/framework.pb.h" +#include "paddle/fluid/lite/core/framework.pb.h" #include "paddle/fluid/lite/core/scope.h" #include "paddle/fluid/lite/core/variable.h" diff --git a/paddle/fluid/lite/model_parser/model_parser_test.cc b/paddle/fluid/lite/model_parser/model_parser_test.cc index bab10dee409..d831ff4bacc 100644 --- a/paddle/fluid/lite/model_parser/model_parser_test.cc +++ b/paddle/fluid/lite/model_parser/model_parser_test.cc @@ -13,22 +13,25 @@ // limitations under the License. #include "paddle/fluid/lite/model_parser/model_parser.h" +#include #include #include "paddle/fluid/lite/core/scope.h" +DEFINE_string(model_dir, "", ""); + namespace paddle { namespace lite { TEST(ModelParser, LoadProgram) { - auto program = LoadProgram( - "/home/chunwei/project2/models/fc/fluid_checkpoint/__model__"); + CHECK(!FLAGS_model_dir.empty()); + auto program = LoadProgram(FLAGS_model_dir + "/__model__"); } TEST(ModelParser, LoadParam) { Scope scope; auto* v = scope.Var("xxx"); - LoadParam("/home/chunwei/project2/models/fc/fluid_checkpoint/b1", v); - const auto& t = v->Get(); + LoadParam(FLAGS_model_dir + "/fc_0.b_0", v); + const auto& t = v->Get(); LOG(INFO) << "loaded\n"; LOG(INFO) << t; } @@ -36,7 +39,7 @@ TEST(ModelParser, LoadParam) { TEST(ModelParser, LoadModel) { Scope scope; framework::proto::ProgramDesc prog; - LoadModel("/home/chunwei/project2/models/fc/fluid_checkpoint", &scope, &prog); + LoadModel(FLAGS_model_dir, &scope, &prog); } } // namespace lite diff --git a/paddle/fluid/lite/model_parser/pb/op_desc.h b/paddle/fluid/lite/model_parser/pb/op_desc.h index 054deec09e3..fd1613f78f0 100644 --- a/paddle/fluid/lite/model_parser/pb/op_desc.h +++ b/paddle/fluid/lite/model_parser/pb/op_desc.h @@ -24,7 +24,7 @@ #include #include #include -#include "paddle/fluid/framework/framework.pb.h" +#include "paddle/fluid/lite/core/framework.pb.h" #include "paddle/fluid/lite/utils/all.h" namespace paddle { diff --git a/paddle/fluid/lite/model_parser/pb/var_desc.h b/paddle/fluid/lite/model_parser/pb/var_desc.h index 52a6caed411..a29bd223928 100644 --- a/paddle/fluid/lite/model_parser/pb/var_desc.h +++ b/paddle/fluid/lite/model_parser/pb/var_desc.h @@ -17,7 +17,7 @@ #include #include #include -#include "paddle/fluid/framework/framework.pb.h" +#include "paddle/fluid/lite/core/framework.pb.h" #include "paddle/fluid/lite/utils/cp_logging.h" namespace paddle { diff --git a/paddle/fluid/lite/operators/fc_op.h b/paddle/fluid/lite/operators/fc_op.h index c24e5cd25df..c85bb0e8ee2 100644 --- a/paddle/fluid/lite/operators/fc_op.h +++ b/paddle/fluid/lite/operators/fc_op.h @@ -59,9 +59,6 @@ class FcOpLite : public OpLite { param_.output = scope->FindVar(out)->GetMutable(); param_.in_num_col_dims = GetAttr(op_desc.GetAttr("in_num_col_dims")); - CHECK(kernel_); - kernel_->SetParam(param_); - return true; } diff --git a/paddle/fluid/lite/operators/fc_op_test.cc b/paddle/fluid/lite/operators/fc_op_test.cc index 278f8d8f8f9..dccb53f3be1 100644 --- a/paddle/fluid/lite/operators/fc_op_test.cc +++ b/paddle/fluid/lite/operators/fc_op_test.cc @@ -21,17 +21,16 @@ namespace lite { namespace operators { TEST(fc_op_lite, test) { - LOG(INFO) << "\n" << KernelRegistry::Global().DebugString(); // prepare variables Scope scope; - auto* x = scope.Var("x")->GetMutable(); - auto* w = scope.Var("w")->GetMutable(); - auto* bias = scope.Var("bias")->GetMutable(); - auto* output = scope.Var("output")->GetMutable(); - x->Resize({1, 10, 20}); - w->Resize({20, 20}); - bias->Resize({1, 10}); - output->Resize({10, 20}); + auto* x = scope.Var("x")->GetMutable(); + auto* w = scope.Var("w")->GetMutable(); + auto* bias = scope.Var("bias")->GetMutable(); + auto* output = scope.Var("output")->GetMutable(); + x->Resize(DDim(std::vector({1, 10, 20}))); + w->Resize(DDim(std::vector{20, 20})); + bias->Resize(DDim(std::vector{1, 10})); + output->Resize(DDim(std::vector{10, 20})); // set data for (int i = 0; i < 10 * 20; i++) { @@ -59,18 +58,13 @@ TEST(fc_op_lite, test) { FcOpLite fc("fc"); fc.SetValidPlaces({Place{TARGET(kHost), PRECISION(kFloat)}}); - fc.PickKernel({Place{TARGET(kHost), PRECISION(kFloat)}}); - - fc.AttachImpl(desc, &scope); - fc.Run(); - - for (int i = 0; i < 10 * 20; i++) { - LOG(INFO) << output->data()[i]; - } + fc.Attach(desc, &scope); + auto kernels = fc.CreateKernels({Place{TARGET(kHost), PRECISION(kFloat)}}); + ASSERT_FALSE(kernels.empty()); } } // namespace operators } // namespace lite } // namespace paddle -USE_LITE_KERNEL(fc, kHost, kFloat); +USE_LITE_KERNEL(fc, kHost, kFloat, kNCHW, def); diff --git a/paddle/fluid/lite/utils/CMakeLists.txt b/paddle/fluid/lite/utils/CMakeLists.txt index 0c24ab31395..1d299367d23 100644 --- a/paddle/fluid/lite/utils/CMakeLists.txt +++ b/paddle/fluid/lite/utils/CMakeLists.txt @@ -1,12 +1,10 @@ if(LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) set(utils_DEPS) + lite_cc_test(test_logging_lite SRCS logging_test.cc) else() set(utils_DEPS glog) endif() -lite_cc_test(test_logging_lite SRCS logging_test.cc) - lite_cc_test(test_varient SRCS varient_test.cc DEPS utils_lite) - cc_library(any_lite SRCS any.cc) cc_library(utils_lite SRCS cp_logging.cc DEPS ${utils_DEPS} any_lite) -- GitLab