提交 c79f45bf 编写于 作者: S superjomn

update

上级 aac42b9a
cc_library(executor_lite SRCS executor.cc) add_subdirectory(core)
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(x86) add_subdirectory(x86)
add_subdirectory(cuda) add_subdirectory(cuda)
add_subdirectory(operators) add_subdirectory(operators)
add_subdirectory(kernels) add_subdirectory(kernels)
add_subdirectory(model_parser) add_subdirectory(model_parser)
# tests
cc_test(test_scope_lite SRCS scope_test.cc DEPS scope_lite)
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)
...@@ -25,6 +25,7 @@ class Context { ...@@ -25,6 +25,7 @@ class Context {
public: public:
using target_wrapper_t = TargetWrapper<Target>; using target_wrapper_t = TargetWrapper<Target>;
using stream_t = typename TargetWrapper<Target>::stream_t; using stream_t = typename TargetWrapper<Target>::stream_t;
using event_t = typename TargetWrapper<Target>::event_t;
Context() = default; Context() = default;
Context(int device_id, stream_t compute_stream, stream_t data_stream) Context(int device_id, stream_t compute_stream, stream_t data_stream)
...@@ -35,15 +36,20 @@ class Context { ...@@ -35,15 +36,20 @@ class Context {
void SetDeviceId(int device_id) { device_id_ = device_id; } void SetDeviceId(int device_id) { device_id_ = device_id; }
void SetComputeStream(stream_t x) { compute_stream_ = x; } void SetComputeStream(stream_t x) { compute_stream_ = x; }
void SetDataStream(stream_t x) { data_stream_ = x; } void SetDataStream(stream_t x) { data_stream_ = x; }
void SetDependEvents(const std::vector<event_t>& events) {
depend_events_ = events;
}
int device_id() const { return device_id_; } int device_id() const { return device_id_; }
stream_t compute_stream() const { return compute_stream_; } stream_t compute_stream() const { return compute_stream_; }
stream_t data_stream() const { return data_stream_; } stream_t data_stream() const { return data_stream_; }
const std::vector<event_t>& depend_events() const { return depend_events_; }
private: private:
int device_id_; int device_id_{0};
stream_t compute_stream_; stream_t compute_stream_;
stream_t data_stream_; stream_t data_stream_;
std::vector<event_t> depend_events_;
}; };
class OpContext final { class OpContext final {
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
#include <map> #include <map>
#include <string> #include <string>
#include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/lite/context.h" #include "context.h"
#include "paddle/fluid/lite/target_wrapper.h" #include "target_wrapper.h"
#include "paddle/fluid/lite/utils/all.h" #include "paddle/fluid/lite/utils/all.h"
namespace paddle { namespace paddle {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "paddle/fluid/lite/memory.h" #include "memory.h"
namespace paddle { namespace paddle {
namespace framework { namespace framework {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include "context.h" #include "context.h"
#include "op_kernel.h" #include "kernel.h"
#include "paddle/fluid/framework/lod_tensor.h" #include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_desc.h" #include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/variable.h" #include "paddle/fluid/framework/variable.h"
...@@ -40,11 +40,13 @@ struct Registry { ...@@ -40,11 +40,13 @@ struct Registry {
* to eliminate overhead of some operations in current framework. * to eliminate overhead of some operations in current framework.
* *
* The Operator are designed as follows: * The Operator are designed as follows:
* - it can has some members to hold the argument addresses, * - it can has some members to hold the argument and some other computation
* - it should act just like a function call, no more logic should included. * resources,
* - it should act like a function call, no more logic included.
*/ */
class OpLite : public Registry { class OpLite : public Registry {
public: public:
// The strategies to pick a kernel from candidates.
enum class KernelStrategy { enum class KernelStrategy {
// Return the user specified one. // Return the user specified one.
kStatic = 0, kStatic = 0,
...@@ -57,18 +59,25 @@ class OpLite : public Registry { ...@@ -57,18 +59,25 @@ class OpLite : public Registry {
OpLite() {} OpLite() {}
OpLite(std::unique_ptr<OpContext> &&x) : op_context_(std::move(x)) {} OpLite(std::unique_ptr<OpContext> &&x) : op_context_(std::move(x)) {}
// Check the shape.
virtual bool CheckShape() const { return true; } virtual bool CheckShape() const { return true; }
// Inference the outputs' shape.
virtual bool InferShape() const { return true; } virtual bool InferShape() const { return true; }
// Run this operator.
virtual bool Run() = 0; virtual bool Run() = 0;
// Build the operator, attach it with the runtime environment.
virtual bool Build(const framework::OpDesc &opdesc, virtual bool Build(const framework::OpDesc &opdesc,
framework::Scope *scope) = 0; framework::Scope *scope) = 0;
// Human-readable information.
virtual std::string DebugString() const = 0; virtual std::string DebugString() const = 0;
protected:
// Specify the kernel to run by default.
virtual void StaticPickKernel( virtual void StaticPickKernel(
const std::vector<TargetType> &valid_targets) = 0; const std::vector<TargetType> &valid_targets) = 0;
void PickBestKernel(const std::vector<TargetType> &valid_places, void PickKernel(const std::vector<TargetType> &valid_places,
KernelStrategy kernel_strategy = KernelStrategy::kStatic); KernelStrategy kernel_strategy = KernelStrategy::kStatic);
// Create all the kernels for the valid targets. // Create all the kernels for the valid targets.
void CreateKernels(); void CreateKernels();
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include "paddle/fluid/lite/op_kernel.h" #include "kernel.h"
#include "paddle/fluid/lite/op_lite.h" #include "op_lite.h"
#include "paddle/fluid/lite/target_wrapper.h" #include "target_wrapper.h"
#include "paddle/fluid/lite/utils/all.h" #include "paddle/fluid/lite/utils/all.h"
namespace paddle { namespace paddle {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "paddle/fluid/lite/scope.h" #include "scope.h"
#include "scope.h" #include "scope.h"
namespace paddle { namespace paddle {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "paddle/fluid/lite/variable.h" #include "variable.h"
namespace paddle { namespace paddle {
namespace lite { namespace lite {
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "paddle/fluid/lite/scope.h" #include "scope.h"
#include <gtest/gtest.h> #include <gtest/gtest.h>
namespace paddle { namespace paddle {
......
...@@ -19,6 +19,7 @@ namespace paddle { ...@@ -19,6 +19,7 @@ namespace paddle {
namespace lite { namespace lite {
enum class TargetType { kHost = 0, kX86, kCUDA, kARM, kLastAsPlaceHolder }; 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(item__) paddle::lite::TargetType::item__
#define TARGET_VAL(item__) static_cast<int>(TARGET(item__)) #define TARGET_VAL(item__) static_cast<int>(TARGET(item__))
...@@ -36,20 +37,22 @@ using ARM = Target<TargetType::kARM>; ...@@ -36,20 +37,22 @@ using ARM = Target<TargetType::kARM>;
enum class PrecisionType { kFloat = 0, kInt8, kLastAsPlaceHolder }; enum class PrecisionType { kFloat = 0, kInt8, kLastAsPlaceHolder };
// Some helper macro to get a specific PrecisionType.
#define PRECISION(item__) paddle::lite::PrecisionType::item__ #define PRECISION(item__) paddle::lite::PrecisionType::item__
#define PRECISION_VAL(item__) static_cast<int>(PRECISION(item__)) #define PRECISION_VAL(item__) static_cast<int>(PRECISION(item__))
constexpr int kNumPrecisions = constexpr int kNumPrecisions =
PRECISION_VAL(kLastAsPlaceHolder) - PRECISION_VAL(kFloat); PRECISION_VAL(kLastAsPlaceHolder) - PRECISION_VAL(kFloat);
// Event sync for multi-stream devices like CUDA and OpenCL. // Event sync for multi-stream devices like CUDA and OpenCL.
// For the devices without support of stream, leave it empty.
template <TargetType Target> template <TargetType Target>
class Event {}; class Event {};
// Memory copy directions. // Memory copy directions.
enum class IoDirection { enum class IoDirection {
HtoH = 0, HtoH = 0, // Host to host
HtoD, HtoD, // Host to device
DtoH, DtoH, // Device to host
}; };
// This interface should be specified by each kind of target. // This interface should be specified by each kind of target.
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "paddle/fluid/lite/variable.h" #include "variable.h"
namespace paddle { namespace paddle {
namespace lite {} // namespace lite namespace lite {} // namespace lite
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "paddle/fluid/lite/tensor.h" #include "paddle/fluid/lite/core/tensor.h"
#include "paddle/fluid/lite/utils/all.h" #include "paddle/fluid/lite/utils/all.h"
namespace paddle { namespace paddle {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "paddle/fluid/lite/kernels/host/fc_compute.h" #include "paddle/fluid/lite/kernels/host/fc_compute.h"
#include <Eigen/Core> #include <Eigen/Core>
#include "paddle/fluid/lite/op_registry.h" #include "paddle/fluid/lite/core/op_registry.h"
namespace paddle { namespace paddle {
namespace lite { namespace lite {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "paddle/fluid/lite/op_kernel.h" #include "paddle/fluid/lite/core/kernel.h"
#include "paddle/fluid/lite/operators/fc_op.h" #include "paddle/fluid/lite/operators/fc_op.h"
namespace paddle { namespace paddle {
......
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "paddle/fluid/lite/kernels/relu_compute.h" #include "paddle/fluid/lite/kernels/host/relu_compute.h"
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "paddle/fluid/lite/op_kernel.h" #include "paddle/fluid/lite/core/kernel.h"
namespace paddle { namespace paddle {
namespace lite { namespace lite {
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
#include "paddle/fluid/lite/model_parser/model_parser.h" #include "paddle/fluid/lite/model_parser/model_parser.h"
#include <fstream> #include <fstream>
#include "paddle/fluid/lite/scope.h" #include "paddle/fluid/lite/core/scope.h"
#include "paddle/fluid/lite/tensor.h" #include "paddle/fluid/lite/core/tensor.h"
#include "paddle/fluid/lite/variable.h" #include "paddle/fluid/lite/core/variable.h"
namespace paddle { namespace paddle {
namespace lite { namespace lite {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#include "fc_op.h" #include "fc_op.h"
#include "paddle/fluid/lite/op_registry.h" #include "paddle/fluid/lite/core/op_registry.h"
namespace paddle { namespace paddle {
namespace lite { namespace lite {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "paddle/fluid/lite/op_lite.h" #include "paddle/fluid/lite/core/op_lite.h"
#include "paddle/fluid/lite/tensor.h" #include "paddle/fluid/lite/core/tensor.h"
#include "paddle/fluid/lite/utils/all.h" #include "paddle/fluid/lite/utils/all.h"
namespace paddle { namespace paddle {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#include "paddle/fluid/lite/operators/relu_op.h" #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 paddle {
namespace lite { namespace lite {
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "paddle/fluid/lite/op_lite.h" #include "paddle/fluid/lite/core/op_lite.h"
#include "paddle/fluid/lite/tensor.h" #include "paddle/fluid/lite/core/tensor.h"
#include "paddle/fluid/lite/utils/all.h" #include "paddle/fluid/lite/utils/all.h"
namespace paddle { namespace paddle {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
#pragma once #pragma once
#include "paddle/fluid/lite/target_wrapper.h" #include "paddle/fluid/lite/core/target_wrapper.h"
namespace paddle { namespace paddle {
namespace framework { namespace framework {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册