From c79f45bf1bf1bc209abfafb9b112537981b24046 Mon Sep 17 00:00:00 2001 From: superjomn Date: Tue, 2 Apr 2019 13:11:19 +0800 Subject: [PATCH] update --- paddle/fluid/lite/CMakeLists.txt | 13 +------------ paddle/fluid/lite/core/CMakeLists.txt | 9 +++++++++ paddle/fluid/lite/{ => core}/context.cc | 0 paddle/fluid/lite/{ => core}/context.h | 8 +++++++- paddle/fluid/lite/{ => core}/executor.cc | 0 paddle/fluid/lite/{ => core}/executor.h | 0 .../fluid/lite/{op_kernel.h => core/kernel.h} | 4 ++-- paddle/fluid/lite/{ => core}/memory.cc | 2 +- paddle/fluid/lite/{ => core}/memory.h | 0 paddle/fluid/lite/{ => core}/op_lite.cc | 0 paddle/fluid/lite/{ => core}/op_lite.h | 19 ++++++++++++++----- paddle/fluid/lite/{ => core}/op_registry.cc | 0 paddle/fluid/lite/{ => core}/op_registry.h | 6 +++--- paddle/fluid/lite/{ => core}/scope.cc | 2 +- paddle/fluid/lite/{ => core}/scope.h | 2 +- paddle/fluid/lite/{ => core}/scope_test.cc | 2 +- paddle/fluid/lite/{ => core}/target_wrapper.h | 9 ++++++--- paddle/fluid/lite/{ => core}/tensor.cc | 0 paddle/fluid/lite/{ => core}/tensor.h | 0 paddle/fluid/lite/{ => core}/variable.cc | 2 +- paddle/fluid/lite/{ => core}/variable.h | 2 +- paddle/fluid/lite/kernels/host/fc_compute.cc | 2 +- paddle/fluid/lite/kernels/host/fc_compute.h | 2 +- .../fluid/lite/kernels/host/relu_compute.cc | 2 +- paddle/fluid/lite/kernels/host/relu_compute.h | 2 +- .../fluid/lite/model_parser/model_parser.cc | 6 +++--- paddle/fluid/lite/operators/fc_op.cc | 2 +- paddle/fluid/lite/operators/fc_op.h | 4 ++-- paddle/fluid/lite/operators/relu_op.cc | 2 +- paddle/fluid/lite/operators/relu_op.h | 4 ++-- paddle/fluid/lite/x86/target_wrapper.h | 2 +- 31 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 paddle/fluid/lite/core/CMakeLists.txt rename paddle/fluid/lite/{ => core}/context.cc (100%) rename paddle/fluid/lite/{ => core}/context.h (88%) rename paddle/fluid/lite/{ => core}/executor.cc (100%) rename paddle/fluid/lite/{ => core}/executor.h (100%) rename paddle/fluid/lite/{op_kernel.h => core/kernel.h} (94%) rename paddle/fluid/lite/{ => core}/memory.cc (95%) rename paddle/fluid/lite/{ => core}/memory.h (100%) rename paddle/fluid/lite/{ => core}/op_lite.cc (100%) rename paddle/fluid/lite/{ => core}/op_lite.h (78%) rename paddle/fluid/lite/{ => core}/op_registry.cc (100%) rename paddle/fluid/lite/{ => core}/op_registry.h (97%) rename paddle/fluid/lite/{ => core}/scope.cc (97%) rename paddle/fluid/lite/{ => core}/scope.h (97%) rename paddle/fluid/lite/{ => core}/scope_test.cc (96%) rename paddle/fluid/lite/{ => core}/target_wrapper.h (91%) rename paddle/fluid/lite/{ => core}/tensor.cc (100%) rename paddle/fluid/lite/{ => core}/tensor.h (100%) rename paddle/fluid/lite/{ => core}/variable.cc (94%) rename paddle/fluid/lite/{ => core}/variable.h (96%) diff --git a/paddle/fluid/lite/CMakeLists.txt b/paddle/fluid/lite/CMakeLists.txt index 15f2f30ba..0af924424 100644 --- a/paddle/fluid/lite/CMakeLists.txt +++ b/paddle/fluid/lite/CMakeLists.txt @@ -1,17 +1,6 @@ -cc_library(executor_lite SRCS executor.cc) -cc_library(op_lite SRCS op_lite.cc) -cc_library(memory_lite SRCS memory.cc) -cc_library(tensor_lite SRCS tensor.cc DEPS memory_lite) -cc_library(variable_lite SRCS variable.cc) -cc_library(op_registry_lite SRCS op_registry.cc) -cc_library(scope_lite SRCS scope.cc) - +add_subdirectory(core) add_subdirectory(x86) add_subdirectory(cuda) add_subdirectory(operators) add_subdirectory(kernels) add_subdirectory(model_parser) - - -# tests -cc_test(test_scope_lite SRCS scope_test.cc DEPS scope_lite) diff --git a/paddle/fluid/lite/core/CMakeLists.txt b/paddle/fluid/lite/core/CMakeLists.txt new file mode 100644 index 000000000..ddfbc83f6 --- /dev/null +++ b/paddle/fluid/lite/core/CMakeLists.txt @@ -0,0 +1,9 @@ +cc_library(executor_lite SRCS executor.cc) +cc_library(op_lite SRCS op_lite.cc) +cc_library(memory_lite SRCS memory.cc) +cc_library(tensor_lite SRCS tensor.cc DEPS memory_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_test(test_scope_lite SRCS scope_test.cc DEPS scope_lite) diff --git a/paddle/fluid/lite/context.cc b/paddle/fluid/lite/core/context.cc similarity index 100% rename from paddle/fluid/lite/context.cc rename to paddle/fluid/lite/core/context.cc diff --git a/paddle/fluid/lite/context.h b/paddle/fluid/lite/core/context.h similarity index 88% rename from paddle/fluid/lite/context.h rename to paddle/fluid/lite/core/context.h index 38ad0f80c..a9908922b 100644 --- a/paddle/fluid/lite/context.h +++ b/paddle/fluid/lite/core/context.h @@ -25,6 +25,7 @@ class Context { public: using target_wrapper_t = TargetWrapper; using stream_t = typename TargetWrapper::stream_t; + using event_t = typename TargetWrapper::event_t; Context() = default; Context(int device_id, stream_t compute_stream, stream_t data_stream) @@ -35,15 +36,20 @@ class Context { void SetDeviceId(int device_id) { device_id_ = device_id; } void SetComputeStream(stream_t x) { compute_stream_ = x; } void SetDataStream(stream_t x) { data_stream_ = x; } + void SetDependEvents(const std::vector& events) { + depend_events_ = events; + } int device_id() const { return device_id_; } stream_t compute_stream() const { return compute_stream_; } stream_t data_stream() const { return data_stream_; } + const std::vector& depend_events() const { return depend_events_; } private: - int device_id_; + int device_id_{0}; stream_t compute_stream_; stream_t data_stream_; + std::vector depend_events_; }; class OpContext final { diff --git a/paddle/fluid/lite/executor.cc b/paddle/fluid/lite/core/executor.cc similarity index 100% rename from paddle/fluid/lite/executor.cc rename to paddle/fluid/lite/core/executor.cc diff --git a/paddle/fluid/lite/executor.h b/paddle/fluid/lite/core/executor.h similarity index 100% rename from paddle/fluid/lite/executor.h rename to paddle/fluid/lite/core/executor.h diff --git a/paddle/fluid/lite/op_kernel.h b/paddle/fluid/lite/core/kernel.h similarity index 94% rename from paddle/fluid/lite/op_kernel.h rename to paddle/fluid/lite/core/kernel.h index 832a257fb..1808a0ddc 100644 --- a/paddle/fluid/lite/op_kernel.h +++ b/paddle/fluid/lite/core/kernel.h @@ -19,8 +19,8 @@ #include #include #include "paddle/fluid/framework/op_desc.h" -#include "paddle/fluid/lite/context.h" -#include "paddle/fluid/lite/target_wrapper.h" +#include "context.h" +#include "target_wrapper.h" #include "paddle/fluid/lite/utils/all.h" namespace paddle { diff --git a/paddle/fluid/lite/memory.cc b/paddle/fluid/lite/core/memory.cc similarity index 95% rename from paddle/fluid/lite/memory.cc rename to paddle/fluid/lite/core/memory.cc index 2b85d763d..f84eeec2c 100644 --- a/paddle/fluid/lite/memory.cc +++ b/paddle/fluid/lite/core/memory.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/fluid/lite/memory.h" +#include "memory.h" namespace paddle { namespace framework { diff --git a/paddle/fluid/lite/memory.h b/paddle/fluid/lite/core/memory.h similarity index 100% rename from paddle/fluid/lite/memory.h rename to paddle/fluid/lite/core/memory.h diff --git a/paddle/fluid/lite/op_lite.cc b/paddle/fluid/lite/core/op_lite.cc similarity index 100% rename from paddle/fluid/lite/op_lite.cc rename to paddle/fluid/lite/core/op_lite.cc diff --git a/paddle/fluid/lite/op_lite.h b/paddle/fluid/lite/core/op_lite.h similarity index 78% rename from paddle/fluid/lite/op_lite.h rename to paddle/fluid/lite/core/op_lite.h index 2e58dec35..a540fc8c8 100644 --- a/paddle/fluid/lite/op_lite.h +++ b/paddle/fluid/lite/core/op_lite.h @@ -19,7 +19,7 @@ #include #include #include "context.h" -#include "op_kernel.h" +#include "kernel.h" #include "paddle/fluid/framework/lod_tensor.h" #include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/variable.h" @@ -40,11 +40,13 @@ struct Registry { * to eliminate overhead of some operations in current framework. * * The Operator are designed as follows: - * - it can has some members to hold the argument addresses, - * - it should act just like a function call, no more logic should included. + * - it can has some members to hold the argument and some other computation + * resources, + * - it should act like a function call, no more logic included. */ class OpLite : public Registry { public: + // The strategies to pick a kernel from candidates. enum class KernelStrategy { // Return the user specified one. kStatic = 0, @@ -57,18 +59,25 @@ class OpLite : public Registry { OpLite() {} OpLite(std::unique_ptr &&x) : op_context_(std::move(x)) {} + // Check the shape. virtual bool CheckShape() const { return true; } + // Inference the outputs' shape. virtual bool InferShape() const { return true; } + // Run this operator. virtual bool Run() = 0; + // Build the operator, attach it with the runtime environment. virtual bool Build(const framework::OpDesc &opdesc, framework::Scope *scope) = 0; + // Human-readable information. virtual std::string DebugString() const = 0; + protected: + // Specify the kernel to run by default. virtual void StaticPickKernel( const std::vector &valid_targets) = 0; - void PickBestKernel(const std::vector &valid_places, - KernelStrategy kernel_strategy = KernelStrategy::kStatic); + void PickKernel(const std::vector &valid_places, + KernelStrategy kernel_strategy = KernelStrategy::kStatic); // Create all the kernels for the valid targets. void CreateKernels(); diff --git a/paddle/fluid/lite/op_registry.cc b/paddle/fluid/lite/core/op_registry.cc similarity index 100% rename from paddle/fluid/lite/op_registry.cc rename to paddle/fluid/lite/core/op_registry.cc diff --git a/paddle/fluid/lite/op_registry.h b/paddle/fluid/lite/core/op_registry.h similarity index 97% rename from paddle/fluid/lite/op_registry.h rename to paddle/fluid/lite/core/op_registry.h index 1e23d5860..3be1ee5a6 100644 --- a/paddle/fluid/lite/op_registry.h +++ b/paddle/fluid/lite/core/op_registry.h @@ -15,9 +15,9 @@ #include #include #include -#include "paddle/fluid/lite/op_kernel.h" -#include "paddle/fluid/lite/op_lite.h" -#include "paddle/fluid/lite/target_wrapper.h" +#include "kernel.h" +#include "op_lite.h" +#include "target_wrapper.h" #include "paddle/fluid/lite/utils/all.h" namespace paddle { diff --git a/paddle/fluid/lite/scope.cc b/paddle/fluid/lite/core/scope.cc similarity index 97% rename from paddle/fluid/lite/scope.cc rename to paddle/fluid/lite/core/scope.cc index 1c405464e..6e36f72e3 100644 --- a/paddle/fluid/lite/scope.cc +++ b/paddle/fluid/lite/core/scope.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/fluid/lite/scope.h" +#include "scope.h" #include "scope.h" namespace paddle { diff --git a/paddle/fluid/lite/scope.h b/paddle/fluid/lite/core/scope.h similarity index 97% rename from paddle/fluid/lite/scope.h rename to paddle/fluid/lite/core/scope.h index 11b3f2348..56ded2b65 100644 --- a/paddle/fluid/lite/scope.h +++ b/paddle/fluid/lite/core/scope.h @@ -19,7 +19,7 @@ #include #include #include -#include "paddle/fluid/lite/variable.h" +#include "variable.h" namespace paddle { namespace lite { diff --git a/paddle/fluid/lite/scope_test.cc b/paddle/fluid/lite/core/scope_test.cc similarity index 96% rename from paddle/fluid/lite/scope_test.cc rename to paddle/fluid/lite/core/scope_test.cc index 3e1c23172..63c8c2f58 100644 --- a/paddle/fluid/lite/scope_test.cc +++ b/paddle/fluid/lite/core/scope_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/fluid/lite/scope.h" +#include "scope.h" #include namespace paddle { diff --git a/paddle/fluid/lite/target_wrapper.h b/paddle/fluid/lite/core/target_wrapper.h similarity index 91% rename from paddle/fluid/lite/target_wrapper.h rename to paddle/fluid/lite/core/target_wrapper.h index f7bcd3793..60de8c224 100644 --- a/paddle/fluid/lite/target_wrapper.h +++ b/paddle/fluid/lite/core/target_wrapper.h @@ -19,6 +19,7 @@ namespace paddle { namespace lite { enum class TargetType { kHost = 0, kX86, kCUDA, kARM, kLastAsPlaceHolder }; +// Some helper macro to get a specific TargetType. #define TARGET(item__) paddle::lite::TargetType::item__ #define TARGET_VAL(item__) static_cast(TARGET(item__)) @@ -36,20 +37,22 @@ using ARM = Target; enum class PrecisionType { kFloat = 0, kInt8, kLastAsPlaceHolder }; +// Some helper macro to get a specific PrecisionType. #define PRECISION(item__) paddle::lite::PrecisionType::item__ #define PRECISION_VAL(item__) static_cast(PRECISION(item__)) constexpr int kNumPrecisions = PRECISION_VAL(kLastAsPlaceHolder) - PRECISION_VAL(kFloat); // Event sync for multi-stream devices like CUDA and OpenCL. +// For the devices without support of stream, leave it empty. template class Event {}; // Memory copy directions. enum class IoDirection { - HtoH = 0, - HtoD, - DtoH, + HtoH = 0, // Host to host + HtoD, // Host to device + DtoH, // Device to host }; // This interface should be specified by each kind of target. diff --git a/paddle/fluid/lite/tensor.cc b/paddle/fluid/lite/core/tensor.cc similarity index 100% rename from paddle/fluid/lite/tensor.cc rename to paddle/fluid/lite/core/tensor.cc diff --git a/paddle/fluid/lite/tensor.h b/paddle/fluid/lite/core/tensor.h similarity index 100% rename from paddle/fluid/lite/tensor.h rename to paddle/fluid/lite/core/tensor.h diff --git a/paddle/fluid/lite/variable.cc b/paddle/fluid/lite/core/variable.cc similarity index 94% rename from paddle/fluid/lite/variable.cc rename to paddle/fluid/lite/core/variable.cc index d086a0c79..3ef5001f4 100644 --- a/paddle/fluid/lite/variable.cc +++ b/paddle/fluid/lite/core/variable.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/fluid/lite/variable.h" +#include "variable.h" namespace paddle { namespace lite {} // namespace lite diff --git a/paddle/fluid/lite/variable.h b/paddle/fluid/lite/core/variable.h similarity index 96% rename from paddle/fluid/lite/variable.h rename to paddle/fluid/lite/core/variable.h index bcff0aeef..b7eaa9957 100644 --- a/paddle/fluid/lite/variable.h +++ b/paddle/fluid/lite/core/variable.h @@ -13,7 +13,7 @@ // limitations under the License. #pragma once -#include "paddle/fluid/lite/tensor.h" +#include "paddle/fluid/lite/core/tensor.h" #include "paddle/fluid/lite/utils/all.h" namespace paddle { diff --git a/paddle/fluid/lite/kernels/host/fc_compute.cc b/paddle/fluid/lite/kernels/host/fc_compute.cc index dda42ba3e..ef0fed843 100644 --- a/paddle/fluid/lite/kernels/host/fc_compute.cc +++ b/paddle/fluid/lite/kernels/host/fc_compute.cc @@ -14,7 +14,7 @@ #include "paddle/fluid/lite/kernels/host/fc_compute.h" #include -#include "paddle/fluid/lite/op_registry.h" +#include "paddle/fluid/lite/core/op_registry.h" namespace paddle { namespace lite { diff --git a/paddle/fluid/lite/kernels/host/fc_compute.h b/paddle/fluid/lite/kernels/host/fc_compute.h index 1a7e8ae74..37316feba 100644 --- a/paddle/fluid/lite/kernels/host/fc_compute.h +++ b/paddle/fluid/lite/kernels/host/fc_compute.h @@ -13,7 +13,7 @@ // limitations under the License. #pragma once -#include "paddle/fluid/lite/op_kernel.h" +#include "paddle/fluid/lite/core/kernel.h" #include "paddle/fluid/lite/operators/fc_op.h" namespace paddle { diff --git a/paddle/fluid/lite/kernels/host/relu_compute.cc b/paddle/fluid/lite/kernels/host/relu_compute.cc index e352e4938..59b9ccd83 100644 --- a/paddle/fluid/lite/kernels/host/relu_compute.cc +++ b/paddle/fluid/lite/kernels/host/relu_compute.cc @@ -12,4 +12,4 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/fluid/lite/kernels/relu_compute.h" +#include "paddle/fluid/lite/kernels/host/relu_compute.h" diff --git a/paddle/fluid/lite/kernels/host/relu_compute.h b/paddle/fluid/lite/kernels/host/relu_compute.h index 70e19e389..e4130e360 100644 --- a/paddle/fluid/lite/kernels/host/relu_compute.h +++ b/paddle/fluid/lite/kernels/host/relu_compute.h @@ -13,7 +13,7 @@ // limitations under the License. #pragma once -#include "paddle/fluid/lite/op_kernel.h" +#include "paddle/fluid/lite/core/kernel.h" namespace paddle { namespace lite { diff --git a/paddle/fluid/lite/model_parser/model_parser.cc b/paddle/fluid/lite/model_parser/model_parser.cc index 59b518fb2..9b5e676fa 100644 --- a/paddle/fluid/lite/model_parser/model_parser.cc +++ b/paddle/fluid/lite/model_parser/model_parser.cc @@ -14,9 +14,9 @@ #include "paddle/fluid/lite/model_parser/model_parser.h" #include -#include "paddle/fluid/lite/scope.h" -#include "paddle/fluid/lite/tensor.h" -#include "paddle/fluid/lite/variable.h" +#include "paddle/fluid/lite/core/scope.h" +#include "paddle/fluid/lite/core/tensor.h" +#include "paddle/fluid/lite/core/variable.h" namespace paddle { namespace lite { diff --git a/paddle/fluid/lite/operators/fc_op.cc b/paddle/fluid/lite/operators/fc_op.cc index 245941832..827e921bb 100644 --- a/paddle/fluid/lite/operators/fc_op.cc +++ b/paddle/fluid/lite/operators/fc_op.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "fc_op.h" -#include "paddle/fluid/lite/op_registry.h" +#include "paddle/fluid/lite/core/op_registry.h" namespace paddle { namespace lite { diff --git a/paddle/fluid/lite/operators/fc_op.h b/paddle/fluid/lite/operators/fc_op.h index 1f07f434f..f3a1eaca9 100644 --- a/paddle/fluid/lite/operators/fc_op.h +++ b/paddle/fluid/lite/operators/fc_op.h @@ -14,8 +14,8 @@ #include #include -#include "paddle/fluid/lite/op_lite.h" -#include "paddle/fluid/lite/tensor.h" +#include "paddle/fluid/lite/core/op_lite.h" +#include "paddle/fluid/lite/core/tensor.h" #include "paddle/fluid/lite/utils/all.h" namespace paddle { diff --git a/paddle/fluid/lite/operators/relu_op.cc b/paddle/fluid/lite/operators/relu_op.cc index 675acf61d..189cc16b1 100644 --- a/paddle/fluid/lite/operators/relu_op.cc +++ b/paddle/fluid/lite/operators/relu_op.cc @@ -13,7 +13,7 @@ // limitations under the License. #include "paddle/fluid/lite/operators/relu_op.h" -#include "paddle/fluid/lite/op_registry.h" +#include "paddle/fluid/lite/core/op_registry.h" namespace paddle { namespace lite { diff --git a/paddle/fluid/lite/operators/relu_op.h b/paddle/fluid/lite/operators/relu_op.h index 0a9a6c939..b2c32f530 100644 --- a/paddle/fluid/lite/operators/relu_op.h +++ b/paddle/fluid/lite/operators/relu_op.h @@ -14,8 +14,8 @@ #include #include -#include "paddle/fluid/lite/op_lite.h" -#include "paddle/fluid/lite/tensor.h" +#include "paddle/fluid/lite/core/op_lite.h" +#include "paddle/fluid/lite/core/tensor.h" #include "paddle/fluid/lite/utils/all.h" namespace paddle { diff --git a/paddle/fluid/lite/x86/target_wrapper.h b/paddle/fluid/lite/x86/target_wrapper.h index f105f4af8..222eb80f7 100644 --- a/paddle/fluid/lite/x86/target_wrapper.h +++ b/paddle/fluid/lite/x86/target_wrapper.h @@ -13,7 +13,7 @@ // limitations under the License. #pragma once -#include "paddle/fluid/lite/target_wrapper.h" +#include "paddle/fluid/lite/core/target_wrapper.h" namespace paddle { namespace framework { -- GitLab