diff --git a/paddle/fluid/lite/core/kernel.cc b/paddle/fluid/lite/core/kernel.cc index 34e0198296072c9740b2170c9b95f3f6f0d4b44c..a4268c7837528d93c5e50ef094bb386a173aabb4 100644 --- a/paddle/fluid/lite/core/kernel.cc +++ b/paddle/fluid/lite/core/kernel.cc @@ -34,8 +34,8 @@ bool ParamTypeRegistry::KeyCmp::operator()( return a.kernel_type < b.kernel_type; else if (a.io != b.io) return a.io < b.io; - else if (a.offset != b.offset) - return a.offset < b.offset; + else if (a.arg_name != b.arg_name) + return a.arg_name < b.arg_name; else if (!(a.place == b.place)) { return a.place < b.place; } diff --git a/paddle/fluid/lite/core/kernel.h b/paddle/fluid/lite/core/kernel.h index f83ae0a522248d2d013eb9c5797448abcd6733ac..f5e31233104b1aa9994ab50c8d0c7342ed4f60db 100644 --- a/paddle/fluid/lite/core/kernel.h +++ b/paddle/fluid/lite/core/kernel.h @@ -94,27 +94,22 @@ struct ParamType { * The data types of kernel parameters. It is used to track the type of kernel's * inputs and outputs. */ -struct ParamTypes { - std::vector> inputs; - std::vector> outputs; +struct ParamTypeRecorder { + std::map inputs; + std::map outputs; - void RegisterInputType(int offset, const ParamType& type) { - Register(&inputs, offset, type); + void RegisterInputType(const std::string& arg_name, const ParamType& type) { + Register(&inputs, arg_name, type); } - void RegisterOutputType(int offset, const ParamType& type) { - Register(&outputs, offset, type); + void RegisterOutputType(const std::string& arg_name, const ParamType& type) { + Register(&outputs, arg_name, type); } private: - void Register(std::vector>* ts, int offset, - ParamType type) { - CHECK_GE(offset, 0) << "invalid offset"; - CHECK_GE(offset, 50) << "invalid offset"; - for (size_t i = 0; i < offset - inputs.size() + 1; i++) { - ts->emplace_back(); - } - ts->at(offset).emplace_back(type); + void Register(std::map* ts, + const std::string& arg_name, ParamType type) { + (*ts)[arg_name] = type; } }; @@ -148,14 +143,16 @@ class ParamTypeRegistry { explicit NewInstance(const std::string& kernel_type) : kernel_type_(kernel_type) {} - NewInstance& BindInput(int offset, const ParamType& ptype) { + NewInstance& BindInput(const std::string& arg_name, + const ParamType& ptype) { ParamTypeRegistry::Global().Register( - kernel_type_, Place{target, precision, layout}, offset, ptype); + kernel_type_, Place{target, precision, layout}, arg_name, ptype); return *this; } - NewInstance& BindOutput(int offset, const ParamType& ptype) { + NewInstance& BindOutput(const std::string& arg_name, + const ParamType& ptype) { ParamTypeRegistry::Global().Register( - kernel_type_, Place{target, precision, layout}, offset, ptype); + kernel_type_, Place{target, precision, layout}, arg_name, ptype); return *this; } @@ -166,9 +163,9 @@ class ParamTypeRegistry { }; template - void Register(const std::string& kernel_type, const Place& place, int offset, - ParamType data_type) { - KernelIdTy key{kernel_type, place, io, offset}; + void Register(const std::string& kernel_type, const Place& place, + const std::string& arg_name, ParamType data_type) { + KernelIdTy key{kernel_type, place, io, arg_name}; types_[key] = data_type; } @@ -188,7 +185,7 @@ class ParamTypeRegistry { std::string kernel_type; Place place; IO io; - int offset; + std::string arg_name; }; using key_t = KernelIdTy; diff --git a/paddle/fluid/lite/core/mir/variable_place_inference_pass.cc b/paddle/fluid/lite/core/mir/variable_place_inference_pass.cc new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/paddle/fluid/lite/core/mir/variable_place_inference_pass.h b/paddle/fluid/lite/core/mir/variable_place_inference_pass.h new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/paddle/fluid/lite/core/mir/variable_place_inference_pass.h @@ -0,0 +1 @@ +