diff --git a/paddle/fluid/lite/CMakeLists.txt b/paddle/fluid/lite/CMakeLists.txt index 15f2f30ba4bd2cf24b5a2007f0ef8ee784e856e7..0af924424ac1c37953e2667e3322f0e27859fd7c 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 0000000000000000000000000000000000000000..ddfbc83f6cbe71df7c64e226cfccd1fd73e416fa --- /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 38ad0f80cdd1d835ce94362be3b2c5fa66e22127..a9908922bd8f3f277b97b7aab7de2ebc2c36989c 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 832a257fb150cd3c0310264303aa3575b8f8cbe8..1808a0ddcd8e9397632e96959ccca2b8ae373f1b 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 2b85d763da6b31d27a2d8c9fec30ab9a7dfbaed0..f84eeec2c09ab9983c5c9f8080e559957d174e96 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 2e58dec354ceaea08c294402dcdb4e1a9d46b70c..a540fc8c83caad0fe9b64001c8556ec1c9b696ae 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 1e23d58604561b1e12a3d653c74768857004ced0..3be1ee5a6d34bf53921195864aa7724de6844ac1 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 1c405464e5c0497a213325beaaae056db2e52d85..6e36f72e32c7d53625d558fda6a6e3c3c8ccf4ba 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 11b3f23484e654c27ca73c213e0e359d93b8f9a7..56ded2b65d2f129484cfa79b64083f25560b3570 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 3e1c23172b5d5377ec81ce4a2eae8140c185799e..63c8c2f58a34680731110eb22eb144ae64ac4de8 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 f7bcd3793aea04e285f026c6d691b97bac05e9bf..60de8c224db223727f62fff8f8220493af301ec7 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 d086a0c7971ec7a4320d87acb0758e16fff87b9d..3ef5001f49ec70ac489431cee311f161f73fbe2e 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 bcff0aeef8b11e34571bdfc9f9d83a8024a61ef2..b7eaa9957884beadc5863b32bb4e776d7660f822 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 dda42ba3e1ce1a7ab83a728d66a667a4f260f763..ef0fed843c2512d132e1e02922b2f41a8559d1b0 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 1a7e8ae74db1b93a489a7e1ac513e09918a67685..37316feba14ef1667e667a8bd572ece35a5cd79b 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 e352e493877cda87cbe6c38f59d0d57358bacec7..59b9ccd836410fb3c7cfc15df924222aa767cf7c 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 70e19e3898b112b2e0ada2d72b362b223e8a7326..e4130e36097249c6e098017f5b6d471adcbf6bd4 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 59b518fb28069fc91395a8571653f7ab2315adcc..9b5e676fa12396238b45ad90a5169c681f9eceb2 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 245941832b2f725afde0803383154c6a7fa2f8a3..827e921bb8fd0673a5061c48bbc72c19658dadda 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 1f07f434f5ba2d728dcb1fe3d7946cd7ccff88db..f3a1eaca92b3d5f40c4f0ce7b83cef8b36e846a3 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 675acf61d130df7cc78ceba8574f8a5deb73e49a..189cc16b1c6c151a3dc5bc12c91876475def53d9 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 0a9a6c9399c3ce1e5eb32cc34586b3c705fafce7..b2c32f530fdada81aa97e08a3777c95a93a5a6b0 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 f105f4af83b76520e664e76ff567bbffa968c11f..222eb80f7f39ce42d9ff2a5cf5e4a9b7c1b4e364 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 {