From 2cebcf4a27362a7f4c904054a87e8958451f69fa Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Wed, 27 Apr 2022 14:24:20 +0800 Subject: [PATCH] Unify utils naming style (#42264) * unify utils naming style * polish details --- paddle/fluid/framework/infershape_utils.cc | 8 +- paddle/fluid/framework/infershape_utils.h | 9 +- .../new_executor/new_executor_defs.cc | 8 +- .../new_executor/new_executor_defs.h | 4 +- paddle/fluid/framework/op_desc.cc | 8 +- paddle/fluid/framework/operator.cc | 12 +- paddle/fluid/framework/operator.h | 4 +- paddle/fluid/framework/phi_utils.cc | 18 +- paddle/fluid/framework/phi_utils.h | 6 +- paddle/fluid/framework/shape_inference.h | 4 +- paddle/fluid/imperative/execution_context.h | 4 +- paddle/fluid/imperative/infer_shape_context.h | 11 +- paddle/fluid/imperative/prepared_operator.h | 4 +- paddle/fluid/pybind/imperative.cc | 58 ++-- .../infrt/dialect/phi/pass/kernel_op_desc.cc | 4 +- paddle/phi/core/compat/arg_map_context.h | 24 +- paddle/phi/core/infermeta_utils.cc | 4 +- paddle/phi/core/infermeta_utils.h | 14 +- paddle/phi/core/kernel_context.cc | 8 +- paddle/phi/core/kernel_context.h | 18 +- paddle/phi/core/kernel_factory.h | 21 +- paddle/phi/ops/compat/adam_sig.cc | 32 +-- paddle/phi/ops/compat/adamw_sig.cc | 32 +-- paddle/phi/ops/compat/clip_sig.cc | 2 +- paddle/phi/ops/compat/strided_slice_sig.cc | 32 +-- paddle/phi/tests/core/test_meta_fn_utils.cc | 2 +- paddle/utils/array_ref.h | 166 ++++++------ paddle/utils/array_ref_test.cc | 34 +-- paddle/utils/small_vector.h | 248 +++++++++--------- paddle/utils/small_vector_test.cc | 4 +- 30 files changed, 408 insertions(+), 395 deletions(-) diff --git a/paddle/fluid/framework/infershape_utils.cc b/paddle/fluid/framework/infershape_utils.cc index f5a3265af4f..01e594a176b 100644 --- a/paddle/fluid/framework/infershape_utils.cc +++ b/paddle/fluid/framework/infershape_utils.cc @@ -323,7 +323,7 @@ void CompatInferMetaContext::EmplaceBackOutput(CompatMetaTensor output) { } void CompatInferMetaContext::EmplaceBackInputs( - paddle::SmallVector inputs) { + paddle::small_vector inputs) { int index = compat_inputs_.size(); input_range_.emplace_back(std::pair(index, index + inputs.size())); compat_inputs_.insert(compat_inputs_.end(), @@ -332,7 +332,7 @@ void CompatInferMetaContext::EmplaceBackInputs( } void CompatInferMetaContext::EmplaceBackOutputs( - paddle::SmallVector + paddle::small_vector outputs) { int index = compat_outputs_.size(); output_range_.emplace_back( @@ -431,7 +431,7 @@ CompatInferMetaContext BuildInferMetaContext(InferShapeContext* ctx, infer_meta_context.EmplaceBackInput( std::move(CompatMetaTensor(input_var[0], ctx->IsRuntime()))); } else { - paddle::SmallVector + paddle::small_vector inputs; for (const auto& in : input_var) { inputs.emplace_back( @@ -672,7 +672,7 @@ CompatInferMetaContext BuildInferMetaContext(InferShapeContext* ctx, infer_meta_context.EmplaceBackOutput( std::move(CompatMetaTensor(output_var[0], ctx->IsRuntime()))); } else { - paddle::SmallVector + paddle::small_vector outputs; for (const auto& out : output_var) { if (ctx->IsRuntime()) { diff --git a/paddle/fluid/framework/infershape_utils.h b/paddle/fluid/framework/infershape_utils.h index e54f2e81e7e..855e873b309 100644 --- a/paddle/fluid/framework/infershape_utils.h +++ b/paddle/fluid/framework/infershape_utils.h @@ -100,9 +100,10 @@ class CompatInferMetaContext : public phi::InferMetaContext { void EmplaceBackOutput(CompatMetaTensor output); void EmplaceBackInputs( - paddle::SmallVector inputs); + paddle::small_vector + inputs); void EmplaceBackOutputs( - paddle::SmallVector + paddle::small_vector outputs); const phi::MetaTensor& InputAt(size_t idx) const override; @@ -121,9 +122,9 @@ class CompatInferMetaContext : public phi::InferMetaContext { virtual ~CompatInferMetaContext() = default; private: - paddle::SmallVector + paddle::small_vector compat_inputs_; - paddle::SmallVector + paddle::small_vector compat_outputs_; }; diff --git a/paddle/fluid/framework/new_executor/new_executor_defs.cc b/paddle/fluid/framework/new_executor/new_executor_defs.cc index 535b7e5baa1..c75a7871d63 100644 --- a/paddle/fluid/framework/new_executor/new_executor_defs.cc +++ b/paddle/fluid/framework/new_executor/new_executor_defs.cc @@ -328,21 +328,21 @@ bool InterpretercoreInferShapeContext::IsRunMKLDNNKernel() const { } // TODO(paddle-dev): Can this be template? -paddle::SmallVector +paddle::small_vector InterpretercoreInferShapeContext::GetInputVarPtrs( const std::string& name) const { const std::vector& vars = InputVars(name); - paddle::SmallVector res; + paddle::small_vector res; res.reserve(vars.size()); res.insert(res.begin(), vars.begin(), vars.end()); return res; } -paddle::SmallVector +paddle::small_vector InterpretercoreInferShapeContext::GetOutputVarPtrs( const std::string& name) const { const std::vector& vars = OutputVars(name); - paddle::SmallVector res; + paddle::small_vector res; res.reserve(vars.size()); res.insert(res.begin(), vars.begin(), vars.end()); return res; diff --git a/paddle/fluid/framework/new_executor/new_executor_defs.h b/paddle/fluid/framework/new_executor/new_executor_defs.h index b7b7d5eef41..20e51145a51 100644 --- a/paddle/fluid/framework/new_executor/new_executor_defs.h +++ b/paddle/fluid/framework/new_executor/new_executor_defs.h @@ -90,10 +90,10 @@ class InterpretercoreInferShapeContext : public InferShapeContext { bool IsRunMKLDNNKernel() const override; // TODO(paddle-dev): Can this be template? - paddle::SmallVector + paddle::small_vector GetInputVarPtrs(const std::string& name) const override; - paddle::SmallVector + paddle::small_vector GetOutputVarPtrs(const std::string& name) const override; DDim GetInputDim(const std::string& name) const override; diff --git a/paddle/fluid/framework/op_desc.cc b/paddle/fluid/framework/op_desc.cc index acd45462489..87d3a048d0b 100644 --- a/paddle/fluid/framework/op_desc.cc +++ b/paddle/fluid/framework/op_desc.cc @@ -202,10 +202,10 @@ class CompileTimeInferShapeContext : public InferShapeContext { } } - paddle::SmallVector + paddle::small_vector GetInputVarPtrs(const std::string &name) const override { const std::vector arg_names = Inputs(name); - paddle::SmallVector res; + paddle::small_vector res; res.reserve(arg_names.size()); std::transform(arg_names.begin(), arg_names.end(), std::back_inserter(res), [this](const std::string &name) { @@ -214,10 +214,10 @@ class CompileTimeInferShapeContext : public InferShapeContext { return res; } - paddle::SmallVector + paddle::small_vector GetOutputVarPtrs(const std::string &name) const override { const std::vector arg_names = Outputs(name); - paddle::SmallVector res; + paddle::small_vector res; res.reserve(arg_names.size()); std::transform(arg_names.begin(), arg_names.end(), std::back_inserter(res), [this](const std::string &name) { diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index 013869c6f3e..e17a5d55f1f 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -946,19 +946,19 @@ class RuntimeInferShapeContext : public InferShapeContext { } // TODO(paddle-dev): Can this be template? - paddle::SmallVector + paddle::small_vector GetInputVarPtrs(const std::string& name) const override { const std::vector& vars = InputVars(name); - paddle::SmallVector res; + paddle::small_vector res; res.reserve(vars.size()); res.insert(res.begin(), vars.begin(), vars.end()); return res; } - paddle::SmallVector + paddle::small_vector GetOutputVarPtrs(const std::string& name) const override { const std::vector& vars = OutputVars(name); - paddle::SmallVector res; + paddle::small_vector res; res.reserve(vars.size()); res.insert(res.begin(), vars.begin(), vars.end()); return res; @@ -2344,7 +2344,7 @@ void OperatorWithKernel::BuildPhiKernelContext( tensor_in = &(var->Get()); pt_kernel_context->EmplaceBackInputWithoutSetRange(tensor_in); } else if (var->IsType()) { - paddle::SmallVector tensor_vector; + paddle::small_vector tensor_vector; auto& tensor_array = var->Get(); for (auto& t : tensor_array) { tensor_vector.emplace_back(&t); @@ -2393,7 +2393,7 @@ void OperatorWithKernel::BuildPhiKernelContext( tensor_out = var->template GetMutable(); pt_kernel_context->EmplaceBackOutputWithoutSetRange(tensor_out); } else if (var->template IsType()) { - paddle::SmallVector tensor_vector; + paddle::small_vector tensor_vector; auto* tensor_array = var->template GetMutable(); // Note: If the input LoDTensorArray size is 0, the output diff --git a/paddle/fluid/framework/operator.h b/paddle/fluid/framework/operator.h index d8a4ac87292..2e00e07535b 100644 --- a/paddle/fluid/framework/operator.h +++ b/paddle/fluid/framework/operator.h @@ -333,8 +333,8 @@ class ExecutionContext { return it->second; } - virtual paddle::SmallVector InNameList() const { - paddle::SmallVector vec_temp; + virtual paddle::small_vector InNameList() const { + paddle::small_vector vec_temp; vec_temp.reserve(ctx_.inputs.size()); for (auto& input : ctx_.inputs) { diff --git a/paddle/fluid/framework/phi_utils.cc b/paddle/fluid/framework/phi_utils.cc index fe7c5682761..6fbb89cc8b5 100644 --- a/paddle/fluid/framework/phi_utils.cc +++ b/paddle/fluid/framework/phi_utils.cc @@ -41,9 +41,9 @@ class KernelArgsNameMakerByOpProto : public KernelArgsNameMaker { ~KernelArgsNameMakerByOpProto() {} - const paddle::SmallVector& GetInputArgsNames() override; - const paddle::SmallVector& GetOutputArgsNames() override; - const paddle::SmallVector& GetAttrsArgsNames() override; + const paddle::small_vector& GetInputArgsNames() override; + const paddle::small_vector& GetOutputArgsNames() override; + const paddle::small_vector& GetAttrsArgsNames() override; phi::KernelSignature GetKernelSignature(); @@ -53,9 +53,9 @@ class KernelArgsNameMakerByOpProto : public KernelArgsNameMaker { private: const framework::proto::OpProto* op_proto_; - paddle::SmallVector input_names_; - paddle::SmallVector output_names_; - paddle::SmallVector attr_names_; + paddle::small_vector input_names_; + paddle::small_vector output_names_; + paddle::small_vector attr_names_; }; OpKernelType TransPhiKernelKeyToOpKernelType(const phi::KernelKey& kernel_key) { @@ -149,7 +149,7 @@ phi::KernelKey FallBackToCpu(const OpKernelType& expected_kernel_key, return phi::KernelKey(); } -const paddle::SmallVector& +const paddle::small_vector& KernelArgsNameMakerByOpProto::GetInputArgsNames() { for (int i = 0; i < op_proto_->inputs_size(); ++i) { auto& in = op_proto_->inputs()[i]; @@ -174,7 +174,7 @@ KernelArgsNameMakerByOpProto::GetInputArgsNames() { return input_names_; } -const paddle::SmallVector& +const paddle::small_vector& KernelArgsNameMakerByOpProto::GetOutputArgsNames() { for (int i = 0; i < op_proto_->outputs_size(); ++i) { auto& out = op_proto_->outputs()[i]; @@ -194,7 +194,7 @@ KernelArgsNameMakerByOpProto::GetOutputArgsNames() { return output_names_; } -const paddle::SmallVector& +const paddle::small_vector& KernelArgsNameMakerByOpProto::GetAttrsArgsNames() { for (int i = 0; i < op_proto_->attrs_size(); ++i) { auto& attr = op_proto_->attrs()[i]; diff --git a/paddle/fluid/framework/phi_utils.h b/paddle/fluid/framework/phi_utils.h index a99abbf0ceb..785ede5c601 100644 --- a/paddle/fluid/framework/phi_utils.h +++ b/paddle/fluid/framework/phi_utils.h @@ -53,9 +53,9 @@ phi::KernelKey FallBackToCpu(const OpKernelType& expected_kernel_key, class KernelArgsNameMaker { public: virtual ~KernelArgsNameMaker() {} - virtual const paddle::SmallVector& GetInputArgsNames() = 0; - virtual const paddle::SmallVector& GetOutputArgsNames() = 0; - virtual const paddle::SmallVector& GetAttrsArgsNames() = 0; + virtual const paddle::small_vector& GetInputArgsNames() = 0; + virtual const paddle::small_vector& GetOutputArgsNames() = 0; + virtual const paddle::small_vector& GetAttrsArgsNames() = 0; }; void InitDefaultKernelSignatureMap(); diff --git a/paddle/fluid/framework/shape_inference.h b/paddle/fluid/framework/shape_inference.h index 850a1093317..44f0ce0165c 100644 --- a/paddle/fluid/framework/shape_inference.h +++ b/paddle/fluid/framework/shape_inference.h @@ -110,9 +110,9 @@ class InferShapeContext { virtual bool IsRunMKLDNNKernel() const = 0; - virtual paddle::SmallVector + virtual paddle::small_vector GetInputVarPtrs(const std::string &name) const = 0; - virtual paddle::SmallVector + virtual paddle::small_vector GetOutputVarPtrs(const std::string &name) const = 0; virtual const phi::ArgumentMappingFn *GetPhiArgumentMappingFn() const = 0; diff --git a/paddle/fluid/imperative/execution_context.h b/paddle/fluid/imperative/execution_context.h index 330a5a0cfa9..124c31df733 100644 --- a/paddle/fluid/imperative/execution_context.h +++ b/paddle/fluid/imperative/execution_context.h @@ -117,8 +117,8 @@ class DygraphExecutionContext : public framework::ExecutionContext { return it->second; } - paddle::SmallVector InNameList() const override { - paddle::SmallVector vec_temp; + paddle::small_vector InNameList() const override { + paddle::small_vector vec_temp; vec_temp.reserve(var_map_in_.size()); for (auto& v : var_map_in_) { diff --git a/paddle/fluid/imperative/infer_shape_context.h b/paddle/fluid/imperative/infer_shape_context.h index a1486638c13..b5df973869a 100644 --- a/paddle/fluid/imperative/infer_shape_context.h +++ b/paddle/fluid/imperative/infer_shape_context.h @@ -239,9 +239,10 @@ class DygraphInferShapeContext : public framework::InferShapeContext { (op_kernel_type_->data_layout_ == framework::DataLayout::kMKLDNN)); } - paddle::SmallVector + paddle::small_vector GetInputVarPtrs(const std::string& name) const override { - paddle::SmallVector + paddle::small_vector res; auto it = var_map_in_->find(name); PADDLE_ENFORCE_NE( @@ -253,10 +254,10 @@ class DygraphInferShapeContext : public framework::InferShapeContext { return res; } - paddle::SmallVector + paddle::small_vector GetOutputVarPtrs(const std::string& name) const override { - paddle::SmallVector + paddle::small_vector res; auto it = var_map_out_->find(name); PADDLE_ENFORCE_NE( diff --git a/paddle/fluid/imperative/prepared_operator.h b/paddle/fluid/imperative/prepared_operator.h index 5c7f337dc6c..8d930d6ed2e 100644 --- a/paddle/fluid/imperative/prepared_operator.h +++ b/paddle/fluid/imperative/prepared_operator.h @@ -311,7 +311,7 @@ void BuildDygraphPhiKernelContext(const phi::KernelSignature& kernel_signature, tensor_in = &(var.template Get()); kernel_ctx->EmplaceBackInputWithoutSetRange(tensor_in); } else if (var.template IsType()) { - paddle::SmallVector tensor_vector; + paddle::small_vector tensor_vector; auto& tensor_array = var.template Get(); for (auto& t : tensor_array) { tensor_vector.emplace_back(&t); @@ -357,7 +357,7 @@ void BuildDygraphPhiKernelContext(const phi::KernelSignature& kernel_signature, tensor_out = var->template GetMutable(); kernel_ctx->EmplaceBackOutputWithoutSetRange(tensor_out); } else if (var->template IsType()) { - paddle::SmallVector tensor_vector; + paddle::small_vector tensor_vector; auto* tensor_array = var->template GetMutable(); for (auto& t : *tensor_array) { diff --git a/paddle/fluid/pybind/imperative.cc b/paddle/fluid/pybind/imperative.cc index 145c116fa14..1da0831fc63 100644 --- a/paddle/fluid/pybind/imperative.cc +++ b/paddle/fluid/pybind/imperative.cc @@ -2028,35 +2028,35 @@ void BindImperative(py::module *m_ptr) { *(imperative::AmpOperators::Instance().GetMutableAllowOps()), *(imperative::AmpOperators::Instance().GetMutableBlockOps())); }) - .def( - "_get_kernel_signature", - [](imperative::Tracer &self, const std::string &type, - const PyNameVarBaseMap &ins, const PyNameVarBaseMap &outs, - framework::AttributeMap attrs) { - // TODO(xiongkun): move this function outside of tracer. - auto ins_map = ConvertToNameTensorMap(ins); - auto outs_map = ConvertToNameTensorMap(outs); - { - auto input_to_vector = - [](paddle::SmallVector &vec) { - return std::vector(vec.begin(), vec.end()); - }; - auto output_to_vector = - [](paddle::SmallVector &vec) { - return std::vector(vec.begin(), vec.end()); - }; - auto attr_to_vector = [](paddle::SmallVector &vec) { - return std::vector(vec.begin(), vec.end()); - }; - auto ret = self.GetExpectedKernelSignature(type, ins_map, - outs_map, attrs); - auto kernelsig_ins = input_to_vector(ret.input_names); - auto kernelsig_attrs = attr_to_vector(ret.attr_names); - auto kernelsig_outs = output_to_vector(ret.output_names); - return std::make_tuple(kernelsig_ins, kernelsig_attrs, - kernelsig_outs); - } - }) + .def("_get_kernel_signature", + [](imperative::Tracer &self, const std::string &type, + const PyNameVarBaseMap &ins, const PyNameVarBaseMap &outs, + framework::AttributeMap attrs) { + // TODO(xiongkun): move this function outside of tracer. + auto ins_map = ConvertToNameTensorMap(ins); + auto outs_map = ConvertToNameTensorMap(outs); + { + auto input_to_vector = + [](paddle::small_vector &vec) { + return std::vector(vec.begin(), vec.end()); + }; + auto output_to_vector = + [](paddle::small_vector &vec) { + return std::vector(vec.begin(), vec.end()); + }; + auto attr_to_vector = + [](paddle::small_vector &vec) { + return std::vector(vec.begin(), vec.end()); + }; + auto ret = self.GetExpectedKernelSignature(type, ins_map, + outs_map, attrs); + auto kernelsig_ins = input_to_vector(ret.input_names); + auto kernelsig_attrs = attr_to_vector(ret.attr_names); + auto kernelsig_outs = output_to_vector(ret.output_names); + return std::make_tuple(kernelsig_ins, kernelsig_attrs, + kernelsig_outs); + } + }) .def("trace", [](imperative::Tracer &self, const std::string &type, const PyNameVarBaseMap &ins, const PyNameVarBaseMap &outs, diff --git a/paddle/infrt/dialect/phi/pass/kernel_op_desc.cc b/paddle/infrt/dialect/phi/pass/kernel_op_desc.cc index b1aa8126096..9425a290142 100644 --- a/paddle/infrt/dialect/phi/pass/kernel_op_desc.cc +++ b/paddle/infrt/dialect/phi/pass/kernel_op_desc.cc @@ -93,9 +93,9 @@ std::vector GetCandidateKernels( phi_kernel_desc.input_types.clear(); phi_kernel_desc.output_types.clear(); phi::KernelArgsDef args_def = kernel_key_map.at(kernel_key).args_def(); - const paddle::SmallVector& + const paddle::small_vector& input_arg = args_def.input_defs(); - const paddle::SmallVector& + const paddle::small_vector& output_arg = args_def.output_defs(); for (auto tensor_arg : input_arg) { phi_kernel_desc.input_types.emplace_back(ConvertPlaceFromPhi(tensor_arg)); diff --git a/paddle/phi/core/compat/arg_map_context.h b/paddle/phi/core/compat/arg_map_context.h index cd7eb419f13..0c6fdcb1391 100644 --- a/paddle/phi/core/compat/arg_map_context.h +++ b/paddle/phi/core/compat/arg_map_context.h @@ -27,30 +27,30 @@ limitations under the License. */ namespace phi { // tuple(input_names, attr_names, output_names) -using KernelArgsTuple = std::tuple, - paddle::SmallVector, - paddle::SmallVector>; +using KernelArgsTuple = std::tuple, + paddle::small_vector, + paddle::small_vector>; struct KernelSignature { const char* name; - paddle::SmallVector input_names; - paddle::SmallVector attr_names; - paddle::SmallVector output_names; + paddle::small_vector input_names; + paddle::small_vector attr_names; + paddle::small_vector output_names; KernelSignature() = default; KernelSignature(const char* kernel_name, - paddle::SmallVector&& inputs, - paddle::SmallVector&& attrs, - paddle::SmallVector&& outputs) + paddle::small_vector&& inputs, + paddle::small_vector&& attrs, + paddle::small_vector&& outputs) : name(kernel_name), input_names(std::move(inputs)), attr_names(std::move(attrs)), output_names(std::move(outputs)) {} KernelSignature(const char* kernel_name, - const paddle::SmallVector& inputs, - const paddle::SmallVector& attrs, - const paddle::SmallVector& outputs) + const paddle::small_vector& inputs, + const paddle::small_vector& attrs, + const paddle::small_vector& outputs) : name(kernel_name), input_names(inputs), attr_names(attrs), diff --git a/paddle/phi/core/infermeta_utils.cc b/paddle/phi/core/infermeta_utils.cc index 8bdad9d6d2b..1d61f55f9dc 100644 --- a/paddle/phi/core/infermeta_utils.cc +++ b/paddle/phi/core/infermeta_utils.cc @@ -35,7 +35,7 @@ void InferMetaContext::EmplaceBackAttr(Attribute attr) { } void InferMetaContext::EmplaceBackInputs( - paddle::SmallVector inputs) { + paddle::small_vector inputs) { int index = inputs_.size(); input_range_.emplace_back(std::pair(index, index + inputs.size())); inputs_.insert(inputs_.end(), @@ -43,7 +43,7 @@ void InferMetaContext::EmplaceBackInputs( std::make_move_iterator(inputs.end())); } void InferMetaContext::EmplaceBackOutputs( - paddle::SmallVector outputs) { + paddle::small_vector outputs) { int index = outputs_.size(); output_range_.emplace_back( std::pair(index, index + outputs.size())); diff --git a/paddle/phi/core/infermeta_utils.h b/paddle/phi/core/infermeta_utils.h index 8c726bffa2f..b974f2c868a 100644 --- a/paddle/phi/core/infermeta_utils.h +++ b/paddle/phi/core/infermeta_utils.h @@ -45,9 +45,9 @@ class InferMetaContext { void EmplaceBackAttr(Attribute attr); void EmplaceBackInputs( - paddle::SmallVector inputs); + paddle::small_vector inputs); void EmplaceBackOutputs( - paddle::SmallVector outputs); + paddle::small_vector outputs); virtual const MetaTensor& InputAt(size_t idx) const; virtual paddle::optional OptionalInputAt(size_t idx) const; @@ -72,16 +72,16 @@ class InferMetaContext { protected: MetaConfig config_; - paddle::SmallVector attrs_; + paddle::small_vector attrs_; - paddle::SmallVector, phi::kInputSmallVectorSize> + paddle::small_vector, phi::kInputSmallVectorSize> input_range_; - paddle::SmallVector, phi::kOutputSmallVectorSize> + paddle::small_vector, phi::kOutputSmallVectorSize> output_range_; private: - paddle::SmallVector inputs_; - paddle::SmallVector outputs_; + paddle::small_vector inputs_; + paddle::small_vector outputs_; }; #define PD_INFER_META(...) \ diff --git a/paddle/phi/core/kernel_context.cc b/paddle/phi/core/kernel_context.cc index 9935a5bf5cd..c902fc824f8 100644 --- a/paddle/phi/core/kernel_context.cc +++ b/paddle/phi/core/kernel_context.cc @@ -28,7 +28,7 @@ void KernelContext::EmplaceBackInputWithoutSetRange(const TensorBase* input) { } void KernelContext::EmplaceBackInputs( - paddle::SmallVector inputs) { + paddle::small_vector inputs) { int index = inputs_.size(); // Record the start and end index of the input input_range_.emplace_back(std::pair(index, index + inputs.size())); @@ -38,7 +38,7 @@ void KernelContext::EmplaceBackInputs( } void KernelContext::EmplaceBackInputsWithoutSetRange( - paddle::SmallVector inputs) { + paddle::small_vector inputs) { inputs_.insert(inputs_.end(), std::make_move_iterator(inputs.begin()), std::make_move_iterator(inputs.end())); @@ -56,7 +56,7 @@ void KernelContext::EmplaceBackOutputWithoutSetRange(TensorBase* output) { } void KernelContext::EmplaceBackOutputs( - paddle::SmallVector outputs) { + paddle::small_vector outputs) { int index = outputs_.size(); // Record the start and end index of the input output_range_.emplace_back( @@ -67,7 +67,7 @@ void KernelContext::EmplaceBackOutputs( } void KernelContext::EmplaceBackOutputsWithoutSetRange( - paddle::SmallVector outputs) { + paddle::small_vector outputs) { outputs_.insert(outputs_.end(), std::make_move_iterator(outputs.begin()), std::make_move_iterator(outputs.end())); diff --git a/paddle/phi/core/kernel_context.h b/paddle/phi/core/kernel_context.h index a06efb573a6..8b43239d352 100644 --- a/paddle/phi/core/kernel_context.h +++ b/paddle/phi/core/kernel_context.h @@ -51,19 +51,19 @@ class KernelContext { void EmplaceBackInputWithoutSetRange(const TensorBase* input); - void EmplaceBackInputs(paddle::SmallVector inputs); + void EmplaceBackInputs(paddle::small_vector inputs); void EmplaceBackInputsWithoutSetRange( - paddle::SmallVector inputs); + paddle::small_vector inputs); void EmplaceBackOutput(TensorBase* output); void EmplaceBackOutputWithoutSetRange(TensorBase* output); - void EmplaceBackOutputs(paddle::SmallVector outputs); + void EmplaceBackOutputs(paddle::small_vector outputs); void EmplaceBackOutputsWithoutSetRange( - paddle::SmallVector outputs); + paddle::small_vector outputs); void EmplaceBackAttr(Attribute attr); @@ -138,12 +138,12 @@ class KernelContext { private: DeviceContext* dev_ctx_; - paddle::SmallVector inputs_; - paddle::SmallVector outputs_; - paddle::SmallVector attrs_; + paddle::small_vector inputs_; + paddle::small_vector outputs_; + paddle::small_vector attrs_; - paddle::SmallVector, kInputSmallVectorSize> input_range_; - paddle::SmallVector, kOutputSmallVectorSize> + paddle::small_vector, kInputSmallVectorSize> input_range_; + paddle::small_vector, kOutputSmallVectorSize> output_range_; }; diff --git a/paddle/phi/core/kernel_factory.h b/paddle/phi/core/kernel_factory.h index 9d7ebd97895..c4c8274db97 100644 --- a/paddle/phi/core/kernel_factory.h +++ b/paddle/phi/core/kernel_factory.h @@ -173,37 +173,38 @@ class KernelArgsDef { attribute_defs_.emplace_back(AttributeArgDef(type_index)); } - const paddle::SmallVector& input_defs() + const paddle::small_vector& input_defs() const { return input_defs_; } - const paddle::SmallVector& output_defs() - const { + const paddle::small_vector& + output_defs() const { return output_defs_; } - const paddle::SmallVector& + const paddle::small_vector& attribute_defs() const { return attribute_defs_; } - paddle::SmallVector& input_defs() { + paddle::small_vector& input_defs() { return input_defs_; } - paddle::SmallVector& output_defs() { + paddle::small_vector& output_defs() { return output_defs_; } - paddle::SmallVector& attribute_defs() { + paddle::small_vector& + attribute_defs() { return attribute_defs_; } private: - paddle::SmallVector input_defs_{{}}; - paddle::SmallVector output_defs_{{}}; - paddle::SmallVector attribute_defs_{ + paddle::small_vector input_defs_{{}}; + paddle::small_vector output_defs_{{}}; + paddle::small_vector attribute_defs_{ {}}; }; diff --git a/paddle/phi/ops/compat/adam_sig.cc b/paddle/phi/ops/compat/adam_sig.cc index 958538cd7df..f3e7eeb6b67 100644 --- a/paddle/phi/ops/compat/adam_sig.cc +++ b/paddle/phi/ops/compat/adam_sig.cc @@ -19,22 +19,22 @@ namespace phi { KernelSignature AdamOpArgumentMapping(const ArgumentMappingContext& ctx) { - paddle::SmallVector in_names = {"Param", - "Grad", - "LearningRate", - "Moment1", - "Moment2", - "Beta1Pow", - "Beta2Pow", - "MasterParam", - "SkipUpdate"}; - paddle::SmallVector out_names = {"ParamOut", - "Moment1Out", - "Moment2Out", - "Beta1PowOut", - "Beta2PowOut", - "MasterParamOut"}; - paddle::SmallVector attr_names; + paddle::small_vector in_names = {"Param", + "Grad", + "LearningRate", + "Moment1", + "Moment2", + "Beta1Pow", + "Beta2Pow", + "MasterParam", + "SkipUpdate"}; + paddle::small_vector out_names = {"ParamOut", + "Moment1Out", + "Moment2Out", + "Beta1PowOut", + "Beta2PowOut", + "MasterParamOut"}; + paddle::small_vector attr_names; attr_names.emplace_back(ctx.HasInput("Beta1Tensor") ? "Beta1Tensor" : "beta1"); diff --git a/paddle/phi/ops/compat/adamw_sig.cc b/paddle/phi/ops/compat/adamw_sig.cc index e417aa30ba4..b4cf6f3cbbe 100644 --- a/paddle/phi/ops/compat/adamw_sig.cc +++ b/paddle/phi/ops/compat/adamw_sig.cc @@ -19,22 +19,22 @@ namespace phi { KernelSignature AdamwOpArgumentMapping(const ArgumentMappingContext& ctx) { - paddle::SmallVector in_names = {"Param", - "Grad", - "LearningRate", - "Moment1", - "Moment2", - "Beta1Pow", - "Beta2Pow", - "MasterParam", - "SkipUpdate"}; - paddle::SmallVector out_names = {"ParamOut", - "Moment1Out", - "Moment2Out", - "Beta1PowOut", - "Beta2PowOut", - "MasterParamOut"}; - paddle::SmallVector attr_names; + paddle::small_vector in_names = {"Param", + "Grad", + "LearningRate", + "Moment1", + "Moment2", + "Beta1Pow", + "Beta2Pow", + "MasterParam", + "SkipUpdate"}; + paddle::small_vector out_names = {"ParamOut", + "Moment1Out", + "Moment2Out", + "Beta1PowOut", + "Beta2PowOut", + "MasterParamOut"}; + paddle::small_vector attr_names; attr_names.emplace_back(ctx.HasInput("Beta1Tensor") ? "Beta1Tensor" : "beta1"); diff --git a/paddle/phi/ops/compat/clip_sig.cc b/paddle/phi/ops/compat/clip_sig.cc index 25a34f2b9c8..889dbf6ef9f 100644 --- a/paddle/phi/ops/compat/clip_sig.cc +++ b/paddle/phi/ops/compat/clip_sig.cc @@ -18,7 +18,7 @@ namespace phi { KernelSignature ClipOpArgumentMapping(const ArgumentMappingContext& ctx) { - paddle::SmallVector attr_names; + paddle::small_vector attr_names; attr_names.emplace_back(ctx.HasInput("Min") ? "Min" : "min"); attr_names.emplace_back(ctx.HasInput("Max") ? "Max" : "max"); if (ctx.IsDenseTensorInput("X")) { diff --git a/paddle/phi/ops/compat/strided_slice_sig.cc b/paddle/phi/ops/compat/strided_slice_sig.cc index 5421fcd616c..02b39147878 100644 --- a/paddle/phi/ops/compat/strided_slice_sig.cc +++ b/paddle/phi/ops/compat/strided_slice_sig.cc @@ -48,14 +48,14 @@ KernelSignature StridedSliceOpArgumentMapping( ? (use_attr_strides ? "strides" : "StridesTensorList") : "strides"); - paddle::SmallVector inputs = {"Input"}; - paddle::SmallVector attrs = {"axes", - starts_key, - ends_key, - strides_key, - "infer_flags", - "decrease_axis"}; - paddle::SmallVector outputs = {"Out"}; + paddle::small_vector inputs = {"Input"}; + paddle::small_vector attrs = {"axes", + starts_key, + ends_key, + strides_key, + "infer_flags", + "decrease_axis"}; + paddle::small_vector outputs = {"Out"}; const char* kernel_name; if (ctx.IsDenseTensorVectorInput("Input")) { @@ -97,14 +97,14 @@ KernelSignature StridedSliceGradOpArgumentMapping( ? (use_attr_strides ? "strides" : "StridesTensorList") : "strides"); - paddle::SmallVector inputs = {"Input", "Out@GRAD"}; - paddle::SmallVector attrs = {"axes", - starts_key, - ends_key, - strides_key, - "infer_flags", - "decrease_axis"}; - paddle::SmallVector outputs = {"Input@GRAD"}; + paddle::small_vector inputs = {"Input", "Out@GRAD"}; + paddle::small_vector attrs = {"axes", + starts_key, + ends_key, + strides_key, + "infer_flags", + "decrease_axis"}; + paddle::small_vector outputs = {"Input@GRAD"}; const char* kernel_name; if (ctx.IsDenseTensorVectorInput("Input")) { diff --git a/paddle/phi/tests/core/test_meta_fn_utils.cc b/paddle/phi/tests/core/test_meta_fn_utils.cc index 07832494d50..afdd3bc0d9a 100644 --- a/paddle/phi/tests/core/test_meta_fn_utils.cc +++ b/paddle/phi/tests/core/test_meta_fn_utils.cc @@ -68,7 +68,7 @@ TEST(MetaFnFactory, SplitInferMetaFn) { phi::DenseTensor dense_out1; phi::DenseTensor dense_out2; - paddle::SmallVector out; + paddle::small_vector out; out.emplace_back(phi::MetaTensor(&dense_out1)); out.emplace_back(phi::MetaTensor(&dense_out2)); diff --git a/paddle/utils/array_ref.h b/paddle/utils/array_ref.h index 78871092593..6731ad80e93 100644 --- a/paddle/utils/array_ref.h +++ b/paddle/utils/array_ref.h @@ -3,8 +3,10 @@ // 1. remove hash_value functions // 2. replace with the llvm::NoneType with paddle::none_t // 3. remove drop_while, drop_until, take_while, take_until methods +// 4. change ArrayRef to array_ref to unify naming style of utils -//===- ArrayRef.h - Array Reference Wrapper ---------------------*- C++ -*-===// +//===- ArrayRef.h - Array Reference Wrapper ---------------------*- C++ +//-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -29,19 +31,19 @@ namespace paddle { -/// ArrayRef - Represent a constant reference to an array (0 or more elements +/// array_ref - Represent a constant reference to an array (0 or more elements /// consecutively in memory), i.e. a start pointer and a length. It allows /// various APIs to take consecutive elements easily and conveniently. /// /// This class does not own the underlying data, it is expected to be used in /// situations where the data resides in some other buffer, whose lifetime -/// extends past that of the ArrayRef. For this reason, it is not in general -/// safe to store an ArrayRef. +/// extends past that of the array_ref. For this reason, it is not in general +/// safe to store an array_ref. /// /// This is intended to be trivially copyable, so it should be passed by /// value. template -class ArrayRef { +class array_ref { public: using iterator = const T *; using const_iterator = const T *; @@ -59,81 +61,81 @@ class ArrayRef { /// @name Constructors /// @{ - /// Construct an empty ArrayRef. - /*implicit*/ ArrayRef() = default; + /// Construct an empty array_ref. + /*implicit*/ array_ref() = default; - /// Construct an empty ArrayRef from None. - /*implicit*/ ArrayRef(none_t) {} + /// Construct an empty array_ref from None. + /*implicit*/ array_ref(none_t) {} - /// Construct an ArrayRef from a single element. - /*implicit*/ ArrayRef(const T &OneElt) : Data(&OneElt), Length(1) {} + /// Construct an array_ref from a single element. + /*implicit*/ array_ref(const T &OneElt) : Data(&OneElt), Length(1) {} - /// Construct an ArrayRef from a pointer and length. - /*implicit*/ ArrayRef(const T *data, size_t length) + /// Construct an array_ref from a pointer and length. + /*implicit*/ array_ref(const T *data, size_t length) : Data(data), Length(length) {} - /// Construct an ArrayRef from a range. - ArrayRef(const T *begin, const T *end) : Data(begin), Length(end - begin) {} + /// Construct an array_ref from a range. + array_ref(const T *begin, const T *end) : Data(begin), Length(end - begin) {} - /// Construct an ArrayRef from a SmallVector. This is templated in order to - /// avoid instantiating SmallVectorTemplateCommon whenever we - /// copy-construct an ArrayRef. + /// Construct an array_ref from a small_vector. This is templated in order to + /// avoid instantiating small_vector_template_common whenever we + /// copy-construct an array_ref. template - /*implicit*/ ArrayRef(const SmallVectorTemplateCommon &Vec) + /*implicit*/ array_ref(const small_vector_template_common &Vec) : Data(Vec.data()), Length(Vec.size()) {} - /// Construct an ArrayRef from a std::vector. + /// Construct an array_ref from a std::vector. template - /*implicit*/ ArrayRef(const std::vector &Vec) + /*implicit*/ array_ref(const std::vector &Vec) : Data(Vec.data()), Length(Vec.size()) {} - /// Construct an ArrayRef from a std::array + /// Construct an array_ref from a std::array template - /*implicit*/ constexpr ArrayRef(const std::array &Arr) + /*implicit*/ constexpr array_ref(const std::array &Arr) : Data(Arr.data()), Length(N) {} - /// Construct an ArrayRef from a C array. + /// Construct an array_ref from a C array. template - /*implicit*/ constexpr ArrayRef(const T (&Arr)[N]) : Data(Arr), Length(N) {} + /*implicit*/ constexpr array_ref(const T (&Arr)[N]) : Data(Arr), Length(N) {} -/// Construct an ArrayRef from a std::initializer_list. +/// Construct an array_ref from a std::initializer_list. #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9 // Disable gcc's warning in this constructor as it generates an enormous // amount -// of messages. Anyone using ArrayRef should already be aware of the fact that +// of messages. Anyone using array_ref should already be aware of the fact that // it does not do lifetime extension. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Winit-list-lifetime" #endif - /*implicit*/ ArrayRef(const std::initializer_list &Vec) + /*implicit*/ array_ref(const std::initializer_list &Vec) : Data(Vec.begin() == Vec.end() ? (T *)nullptr : Vec.begin()), Length(Vec.size()) {} #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 9 #pragma GCC diagnostic pop #endif - /// Construct an ArrayRef from ArrayRef. This uses SFINAE to + /// Construct an array_ref from array_ref. This uses SFINAE to /// ensure that only ArrayRefs of pointers can be converted. template - ArrayRef(const ArrayRef &A, - std::enable_if_t::value> - * = nullptr) + array_ref(const array_ref &A, + std::enable_if_t::value> + * = nullptr) : Data(A.data()), Length(A.size()) {} - /// Construct an ArrayRef from a SmallVector. This is - /// templated in order to avoid instantiating SmallVectorTemplateCommon - /// whenever we copy-construct an ArrayRef. + /// Construct an array_ref from a small_vector. This is + /// templated in order to avoid instantiating small_vector_template_common + /// whenever we copy-construct an array_ref. template - /*implicit*/ ArrayRef( - const SmallVectorTemplateCommon &Vec, + /*implicit*/ array_ref( + const small_vector_template_common &Vec, std::enable_if_t::value> * = nullptr) : Data(Vec.data()), Length(Vec.size()) {} - /// Construct an ArrayRef from std::vector. This uses SFINAE + /// Construct an array_ref from std::vector. This uses SFINAE /// to ensure that only vectors of pointers can be converted. template - ArrayRef( + array_ref( const std::vector &Vec, std::enable_if_t::value> * = 0) : Data(Vec.data()), Length(Vec.size()) {} @@ -168,50 +170,50 @@ class ArrayRef { return Data[Length - 1]; } - // copy - Allocate copy in Allocator and return ArrayRef to it. + // copy - Allocate copy in Allocator and return array_ref to it. template - ArrayRef copy(Allocator &A) { + array_ref copy(Allocator &A) { T *Buff = A.template Allocate(Length); std::uninitialized_copy(begin(), end(), Buff); - return ArrayRef(Buff, Length); + return array_ref(Buff, Length); } /// equals - Check for element-wise equality. - bool equals(ArrayRef RHS) const { + bool equals(array_ref RHS) const { if (Length != RHS.Length) return false; return std::equal(begin(), end(), RHS.begin()); } /// slice(n, m) - Chop off the first N elements of the array, and keep M /// elements in the array. - ArrayRef slice(size_t N, size_t M) const { + array_ref slice(size_t N, size_t M) const { assert(N + M <= size() && "Invalid specifier"); - return ArrayRef(data() + N, M); + return array_ref(data() + N, M); } /// slice(n) - Chop off the first N elements of the array. - ArrayRef slice(size_t N) const { return slice(N, size() - N); } + array_ref slice(size_t N) const { return slice(N, size() - N); } /// Drop the first \p N elements of the array. - ArrayRef drop_front(size_t N = 1) const { + array_ref drop_front(size_t N = 1) const { assert(size() >= N && "Dropping more elements than exist"); return slice(N, size() - N); } /// Drop the last \p N elements of the array. - ArrayRef drop_back(size_t N = 1) const { + array_ref drop_back(size_t N = 1) const { assert(size() >= N && "Dropping more elements than exist"); return slice(0, size() - N); } /// Return a copy of *this with only the first \p N elements. - ArrayRef take_front(size_t N = 1) const { + array_ref take_front(size_t N = 1) const { if (N >= size()) return *this; return drop_back(size() - N); } /// Return a copy of *this with only the last \p N elements. - ArrayRef take_back(size_t N = 1) const { + array_ref take_back(size_t N = 1) const { if (N >= size()) return *this; return drop_front(size() - N); } @@ -229,7 +231,7 @@ class ArrayRef { /// The declaration here is extra complicated so that "arrayRef = {}" /// continues to select the move assignment operator. template - std::enable_if_t::value, ArrayRef> &operator=( + std::enable_if_t::value, array_ref> &operator=( U &&Temporary) = delete; /// Disallow accidental assignment from a temporary. @@ -237,7 +239,7 @@ class ArrayRef { /// The declaration here is extra complicated so that "arrayRef = {}" /// continues to select the move assignment operator. template - std::enable_if_t::value, ArrayRef> &operator=( + std::enable_if_t::value, array_ref> &operator=( std::initializer_list) = delete; /// @} @@ -255,90 +257,90 @@ class ArrayRef { /// @} }; -/// @name ArrayRef Convenience constructors +/// @name array_ref Convenience constructors /// @{ -/// Construct an ArrayRef from a single element. +/// Construct an array_ref from a single element. template -ArrayRef makeArrayRef(const T &OneElt) { +array_ref make_array_ref(const T &OneElt) { return OneElt; } -/// Construct an ArrayRef from a pointer and length. +/// Construct an array_ref from a pointer and length. template -ArrayRef makeArrayRef(const T *data, size_t length) { - return ArrayRef(data, length); +array_ref make_array_ref(const T *data, size_t length) { + return array_ref(data, length); } -/// Construct an ArrayRef from a range. +/// Construct an array_ref from a range. template -ArrayRef makeArrayRef(const T *begin, const T *end) { - return ArrayRef(begin, end); +array_ref make_array_ref(const T *begin, const T *end) { + return array_ref(begin, end); } -/// Construct an ArrayRef from a SmallVector. +/// Construct an array_ref from a small_vector. template -ArrayRef makeArrayRef(const SmallVectorImpl &Vec) { +array_ref make_array_ref(const small_vector_impl &Vec) { return Vec; } -/// Construct an ArrayRef from a SmallVector. +/// Construct an array_ref from a small_vector. template -ArrayRef makeArrayRef(const SmallVector &Vec) { +array_ref make_array_ref(const small_vector &Vec) { return Vec; } -/// Construct an ArrayRef from a std::vector. +/// Construct an array_ref from a std::vector. template -ArrayRef makeArrayRef(const std::vector &Vec) { +array_ref make_array_ref(const std::vector &Vec) { return Vec; } -/// Construct an ArrayRef from a std::array. +/// Construct an array_ref from a std::array. template -ArrayRef makeArrayRef(const std::array &Arr) { +array_ref make_array_ref(const std::array &Arr) { return Arr; } -/// Construct an ArrayRef from an ArrayRef (no-op) (const) +/// Construct an array_ref from an array_ref (no-op) (const) template -ArrayRef makeArrayRef(const ArrayRef &Vec) { +array_ref make_array_ref(const array_ref &Vec) { return Vec; } -/// Construct an ArrayRef from an ArrayRef (no-op) +/// Construct an array_ref from an array_ref (no-op) template -ArrayRef &makeArrayRef(ArrayRef &Vec) { +array_ref &make_array_ref(array_ref &Vec) { return Vec; } -/// Construct an ArrayRef from a C array. +/// Construct an array_ref from a C array. template -ArrayRef makeArrayRef(const T (&Arr)[N]) { - return ArrayRef(Arr); +array_ref make_array_ref(const T (&Arr)[N]) { + return array_ref(Arr); } /// @} -/// @name ArrayRef Comparison Operators +/// @name array_ref Comparison Operators /// @{ template -inline bool operator==(ArrayRef LHS, ArrayRef RHS) { +inline bool operator==(array_ref LHS, array_ref RHS) { return LHS.equals(RHS); } template -inline bool operator==(SmallVectorImpl &LHS, ArrayRef RHS) { - return ArrayRef(LHS).equals(RHS); +inline bool operator==(small_vector_impl &LHS, array_ref RHS) { + return array_ref(LHS).equals(RHS); } template -inline bool operator!=(ArrayRef LHS, ArrayRef RHS) { +inline bool operator!=(array_ref LHS, array_ref RHS) { return !(LHS == RHS); } template -inline bool operator!=(SmallVectorImpl &LHS, ArrayRef RHS) { +inline bool operator!=(small_vector_impl &LHS, array_ref RHS) { return !(LHS == RHS); } diff --git a/paddle/utils/array_ref_test.cc b/paddle/utils/array_ref_test.cc index 33a09c49924..cc4e88a5ee3 100644 --- a/paddle/utils/array_ref_test.cc +++ b/paddle/utils/array_ref_test.cc @@ -21,53 +21,53 @@ #include "gtest/gtest.h" TEST(array_ref, array_ref) { - paddle::ArrayRef a; + paddle::array_ref a; CHECK_EQ(a.size(), size_t(0)); CHECK_EQ(a.data(), static_cast(nullptr)); - paddle::ArrayRef b(paddle::none); + paddle::array_ref b(paddle::none); CHECK_EQ(b.size(), size_t(0)); CHECK_EQ(b.data(), static_cast(nullptr)); int v = 1; - paddle::ArrayRef c(v); + paddle::array_ref c(v); CHECK_EQ(c.size(), size_t(1)); CHECK_EQ(c.data(), &v); - CHECK_EQ(c.equals(paddle::makeArrayRef(v)), true); + CHECK_EQ(c.equals(paddle::make_array_ref(v)), true); int v1[5] = {1, 2, 3, 4, 5}; - paddle::ArrayRef d(v1, 5); + paddle::array_ref d(v1, 5); CHECK_EQ(d.size(), size_t(5)); CHECK_EQ(d.data(), v1); - CHECK_EQ(d.equals(paddle::makeArrayRef(v1, 5)), true); + CHECK_EQ(d.equals(paddle::make_array_ref(v1, 5)), true); - paddle::ArrayRef e(&v1[0], &v1[4]); + paddle::array_ref e(&v1[0], &v1[4]); CHECK_EQ(e.size(), size_t(4)); CHECK_EQ(e.data(), v1); - CHECK_EQ(e.equals(paddle::makeArrayRef(&v1[0], &v1[4])), true); + CHECK_EQ(e.equals(paddle::make_array_ref(&v1[0], &v1[4])), true); - paddle::SmallVector small_vector{1, 2, 3}; - paddle::ArrayRef f(small_vector); + paddle::small_vector small_vector{1, 2, 3}; + paddle::array_ref f(small_vector); CHECK_EQ(f.size(), size_t(3)); CHECK_EQ(f.data(), small_vector.data()); - CHECK_EQ(f.equals(paddle::makeArrayRef(small_vector)), true); + CHECK_EQ(f.equals(paddle::make_array_ref(small_vector)), true); std::vector vector{1, 2, 3}; - paddle::ArrayRef g(vector); + paddle::array_ref g(vector); CHECK_EQ(g.size(), size_t(3)); CHECK_EQ(g.data(), vector.data()); - CHECK_EQ(g.equals(paddle::makeArrayRef(vector)), true); + CHECK_EQ(g.equals(paddle::make_array_ref(vector)), true); std::initializer_list list = {1, 2, 3}; - paddle::ArrayRef h(list); + paddle::array_ref h(list); CHECK_EQ(h.size(), size_t(3)); CHECK_EQ(h.data(), list.begin()); - paddle::ArrayRef i(h); + paddle::array_ref i(h); CHECK_EQ(i.size(), size_t(3)); CHECK_EQ(i.data(), list.begin()); CHECK_EQ(i.equals(h), true); - CHECK_EQ(i.equals(paddle::makeArrayRef(h)), true); + CHECK_EQ(i.equals(paddle::make_array_ref(h)), true); auto slice = i.slice(1, 2); CHECK_EQ(slice.size(), size_t(2)); @@ -78,7 +78,7 @@ TEST(array_ref, array_ref) { CHECK_EQ(drop.size(), size_t(1)); CHECK_EQ(drop[0], 3); - paddle::ArrayRef nums = {1, 2, 3, 4, 5, 6, 7, 8}; + paddle::array_ref nums = {1, 2, 3, 4, 5, 6, 7, 8}; auto front = nums.take_front(3); CHECK_EQ(front.size(), size_t(3)); for (size_t i = 0; i < 3; ++i) { diff --git a/paddle/utils/small_vector.h b/paddle/utils/small_vector.h index 14cb8f410f4..27db9ae1882 100644 --- a/paddle/utils/small_vector.h +++ b/paddle/utils/small_vector.h @@ -5,6 +5,7 @@ // 3. add at(index) method for small vector // 4. wrap the call to max and min with parenthesis to prevent the macro // expansion to fix the build error on windows platform +// 5. change SmallVector to small_vector to unify naming style of utils //===- llvm/ADT/SmallVector.h - 'Normally small' vectors --------*- C++ -*-===// // @@ -79,13 +80,13 @@ iterator_range make_range(std::pair p) { /// This is all the stuff common to all SmallVectors. /// /// The template parameter specifies the type which should be used to hold the -/// Size and Capacity of the SmallVector, so it can be adjusted. -/// Using 32 bit size is desirable to shrink the size of the SmallVector. -/// Using 64 bit size is desirable for cases like SmallVector, where a +/// Size and Capacity of the small_vector, so it can be adjusted. +/// Using 32 bit size is desirable to shrink the size of the small_vector. +/// Using 64 bit size is desirable for cases like small_vector, where a /// 32 bit size would limit the vector to ~4GB. SmallVectors are used for /// buffering bitcode output - which can exceed 4GB. template -class SmallVectorBase { +class small_vector_base { protected: void *BeginX; Size_T Size = 0, Capacity; @@ -95,8 +96,8 @@ class SmallVectorBase { return (std::numeric_limits::max)(); } - SmallVectorBase() = delete; - SmallVectorBase(void *FirstEl, size_t TotalCapacity) + small_vector_base() = delete; + small_vector_base(void *FirstEl, size_t TotalCapacity) : BeginX(FirstEl), Capacity(TotalCapacity) {} /// This is a helper for \a grow() that's out of line to reduce code @@ -139,22 +140,23 @@ using SmallVectorSizeType = /// Figure out the offset of the first element. template struct SmallVectorAlignmentAndSize { - alignas(SmallVectorBase>) char Base[sizeof( - SmallVectorBase>)]; + alignas(small_vector_base>) char Base[sizeof( + small_vector_base>)]; alignas(T) char FirstEl[sizeof(T)]; }; -/// This is the part of SmallVectorTemplateBase which does not depend on whether -/// the type T is a POD. The extra dummy template argument is used by ArrayRef +/// This is the part of small_vector_template_base which does not depend on +/// whether +/// the type T is a POD. The extra dummy template argument is used by array_ref /// to avoid unnecessarily requiring T to be complete. template -class SmallVectorTemplateCommon - : public SmallVectorBase> { - using Base = SmallVectorBase>; +class small_vector_template_common + : public small_vector_base> { + using Base = small_vector_base>; /// Find the address of the first element. For this pointer math to be valid /// with small-size of 0 for T with lots of alignment, it's important that - /// SmallVectorStorage is properly-aligned even for small-size of 0. + /// small_vector_storage is properly-aligned even for small-size of 0. void *getFirstEl() const { return const_cast(reinterpret_cast( reinterpret_cast(this) + @@ -163,7 +165,7 @@ class SmallVectorTemplateCommon // Space after 'FirstEl' is clobbered, do not add any instance vars after it. protected: - SmallVectorTemplateCommon(size_t Size) : Base(getFirstEl(), Size) {} + small_vector_template_common(size_t Size) : Base(getFirstEl(), Size) {} void grow_pod(size_t MinSize, size_t TSize) { Base::grow_pod(getFirstEl(), MinSize, TSize); @@ -358,7 +360,7 @@ class SmallVectorTemplateCommon } }; -/// SmallVectorTemplateBase - This is where we put +/// small_vector_template_base - This is where we put /// method implementations that are designed to work with non-trivial T's. /// /// We approximate is_trivially_copyable with trivial move/copy construction and @@ -370,14 +372,15 @@ template ::value) && (std::is_trivially_move_constructible::value) && std::is_trivially_destructible::value> -class SmallVectorTemplateBase : public SmallVectorTemplateCommon { - friend class SmallVectorTemplateCommon; +class small_vector_template_base : public small_vector_template_common { + friend class small_vector_template_common; protected: static constexpr bool TakesParamByValue = false; using ValueParamT = const T &; - SmallVectorTemplateBase(size_t Size) : SmallVectorTemplateCommon(Size) {} + small_vector_template_base(size_t Size) + : small_vector_template_common(Size) {} static void destroy_range(T *S, T *E) { while (S != E) { @@ -410,7 +413,7 @@ class SmallVectorTemplateBase : public SmallVectorTemplateCommon { /// in \p NewCapacity. This is the first section of \a grow(). T *mallocForGrow(size_t MinSize, size_t &NewCapacity) { return static_cast( - SmallVectorBase>::mallocForGrow( + small_vector_base>::mallocForGrow( MinSize, sizeof(T), NewCapacity)); } @@ -480,7 +483,7 @@ class SmallVectorTemplateBase : public SmallVectorTemplateCommon { // Define this out-of-line to dissuade the C++ compiler from inlining it. template -void SmallVectorTemplateBase::grow(size_t MinSize) { +void small_vector_template_base::grow(size_t MinSize) { size_t NewCapacity; T *NewElts = mallocForGrow(MinSize, NewCapacity); moveElementsForGrow(NewElts); @@ -489,7 +492,7 @@ void SmallVectorTemplateBase::grow(size_t MinSize) { // Define this out-of-line to dissuade the C++ compiler from inlining it. template -void SmallVectorTemplateBase::moveElementsForGrow( +void small_vector_template_base::moveElementsForGrow( T *NewElts) { // Move the elements over. this->uninitialized_move(this->begin(), this->end(), NewElts); @@ -500,7 +503,7 @@ void SmallVectorTemplateBase::moveElementsForGrow( // Define this out-of-line to dissuade the C++ compiler from inlining it. template -void SmallVectorTemplateBase::takeAllocationForGrow( +void small_vector_template_base::takeAllocationForGrow( T *NewElts, size_t NewCapacity) { // If this wasn't grown from the inline copy, deallocate the old space. if (!this->isSmall()) free(this->begin()); @@ -509,13 +512,14 @@ void SmallVectorTemplateBase::takeAllocationForGrow( this->Capacity = NewCapacity; } -/// SmallVectorTemplateBase - This is where we put +/// small_vector_template_base - This is where we put /// method implementations that are designed to work with trivially copyable /// T's. This allows using memcpy in place of copy/move construction and /// skipping destruction. template -class SmallVectorTemplateBase : public SmallVectorTemplateCommon { - friend class SmallVectorTemplateCommon; +class small_vector_template_base + : public small_vector_template_common { + friend class small_vector_template_common; protected: /// True if it's cheap enough to take parameters by value. Doing so avoids @@ -527,7 +531,8 @@ class SmallVectorTemplateBase : public SmallVectorTemplateCommon { using ValueParamT = typename std::conditional::type; - SmallVectorTemplateBase(size_t Size) : SmallVectorTemplateCommon(Size) {} + small_vector_template_base(size_t Size) + : small_vector_template_common(Size) {} // No need to do a destroy loop for POD's. static void destroy_range(T *, T *) {} @@ -557,7 +562,7 @@ class SmallVectorTemplateBase : public SmallVectorTemplateCommon { T2 *Dest, std::enable_if_t::type, T2>::value> * = nullptr) { - // Use memcpy for PODs iterated by pointers (which includes SmallVector + // Use memcpy for PODs iterated by pointers (which includes small_vector // iterators): std::uninitialized_copy optimizes to memmove, but we can // use memcpy here. Note that I and E are iterators and thus might be // invalid for memcpy if they are equal. @@ -612,11 +617,11 @@ class SmallVectorTemplateBase : public SmallVectorTemplateCommon { void pop_back() { this->set_size(this->size() - 1); } }; -/// This class consists of common code factored out of the SmallVector class to -/// reduce code duplication based on the SmallVector 'N' template parameter. +/// This class consists of common code factored out of the small_vector class to +/// reduce code duplication based on the small_vector 'N' template parameter. template -class SmallVectorImpl : public SmallVectorTemplateBase { - using SuperClass = SmallVectorTemplateBase; +class small_vector_impl : public small_vector_template_base { + using SuperClass = small_vector_template_base; public: using iterator = typename SuperClass::iterator; @@ -625,16 +630,16 @@ class SmallVectorImpl : public SmallVectorTemplateBase { using size_type = typename SuperClass::size_type; protected: - using SmallVectorTemplateBase::TakesParamByValue; + using small_vector_template_base::TakesParamByValue; using ValueParamT = typename SuperClass::ValueParamT; // Default ctor - Initialize to empty. - explicit SmallVectorImpl(unsigned N) : SmallVectorTemplateBase(N) {} + explicit small_vector_impl(unsigned N) : small_vector_template_base(N) {} public: - SmallVectorImpl(const SmallVectorImpl &) = delete; + small_vector_impl(const small_vector_impl &) = delete; - ~SmallVectorImpl() { + ~small_vector_impl() { // Subclass has already destructed this vector's elements. // If this wasn't grown from the inline copy, deallocate the old space. if (!this->isSmall()) free(this->begin()); @@ -695,9 +700,9 @@ class SmallVectorImpl : public SmallVectorTemplateBase { return Result; } - void swap(SmallVectorImpl &RHS); + void swap(small_vector_impl &RHS); - /// Add the specified range to the end of the SmallVector. + /// Add the specified range to the end of the small_vector. template ::iterator_category, @@ -719,7 +724,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase { void append(std::initializer_list IL) { append(IL.begin(), IL.end()); } - void append(const SmallVectorImpl &RHS) { append(RHS.begin(), RHS.end()); } + void append(const small_vector_impl &RHS) { append(RHS.begin(), RHS.end()); } void assign(size_type NumElts, ValueParamT Elt) { // Note that Elt could be an internal reference. @@ -755,7 +760,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase { append(IL); } - void assign(const SmallVectorImpl &RHS) { assign(RHS.begin(), RHS.end()); } + void assign(const small_vector_impl &RHS) { assign(RHS.begin(), RHS.end()); } iterator erase(const_iterator CI) { // Just cast away constness because this is a non-const member function. @@ -976,24 +981,26 @@ class SmallVectorImpl : public SmallVectorTemplateBase { return this->back(); } - SmallVectorImpl &operator=(const SmallVectorImpl &RHS); + small_vector_impl &operator=(const small_vector_impl &RHS); - SmallVectorImpl &operator=(SmallVectorImpl &&RHS); + small_vector_impl &operator=(small_vector_impl &&RHS); - bool operator==(const SmallVectorImpl &RHS) const { + bool operator==(const small_vector_impl &RHS) const { if (this->size() != RHS.size()) return false; return std::equal(this->begin(), this->end(), RHS.begin()); } - bool operator!=(const SmallVectorImpl &RHS) const { return !(*this == RHS); } + bool operator!=(const small_vector_impl &RHS) const { + return !(*this == RHS); + } - bool operator<(const SmallVectorImpl &RHS) const { + bool operator<(const small_vector_impl &RHS) const { return std::lexicographical_compare( this->begin(), this->end(), RHS.begin(), RHS.end()); } }; template -void SmallVectorImpl::swap(SmallVectorImpl &RHS) { +void small_vector_impl::swap(small_vector_impl &RHS) { if (this == &RHS) return; // We can only avoid copying elements if neither vector is small. @@ -1028,8 +1035,8 @@ void SmallVectorImpl::swap(SmallVectorImpl &RHS) { } template -SmallVectorImpl &SmallVectorImpl::operator=( - const SmallVectorImpl &RHS) { +small_vector_impl &small_vector_impl::operator=( + const small_vector_impl &RHS) { // Avoid self-assignment. if (this == &RHS) return *this; @@ -1076,7 +1083,8 @@ SmallVectorImpl &SmallVectorImpl::operator=( } template -SmallVectorImpl &SmallVectorImpl::operator=(SmallVectorImpl &&RHS) { +small_vector_impl &small_vector_impl::operator=( + small_vector_impl &&RHS) { // Avoid self-assignment. if (this == &RHS) return *this; @@ -1135,38 +1143,38 @@ SmallVectorImpl &SmallVectorImpl::operator=(SmallVectorImpl &&RHS) { return *this; } -/// Storage for the SmallVector elements. This is specialized for the N=0 case +/// Storage for the small_vector elements. This is specialized for the N=0 case /// to avoid allocating unnecessary storage. template -struct SmallVectorStorage { +struct small_vector_storage { alignas(T) char InlineElts[N * sizeof(T)]; }; /// We need the storage to be properly aligned even for small-size of 0 so that -/// the pointer math in \a SmallVectorTemplateCommon::getFirstEl() is +/// the pointer math in \a small_vector_template_common::getFirstEl() is /// well-defined. template -struct alignas(T) SmallVectorStorage {}; +struct alignas(T) small_vector_storage {}; -/// Forward declaration of SmallVector so that +/// Forward declaration of small_vector so that /// calculateSmallVectorDefaultInlinedElements can reference -/// `sizeof(SmallVector)`. +/// `sizeof(small_vector)`. template -class SmallVector; +class small_vector; /// Helper class for calculating the default number of inline elements for -/// `SmallVector`. +/// `small_vector`. /// /// This should be migrated to a constexpr function when our minimum /// compiler support is enough for multi-statement constexpr functions. template struct CalculateSmallVectorDefaultInlinedElements { // Parameter controlling the default number of inlined elements - // for `SmallVector`. + // for `small_vector`. // // The default number of inlined elements ensures that // 1. There is at least one inlined element. - // 2. `sizeof(SmallVector) <= kPreferredSmallVectorSizeof` unless + // 2. `sizeof(small_vector) <= kPreferredSmallVectorSizeof` unless // it contradicts 1. static constexpr size_t kPreferredSmallVectorSizeof = 64; @@ -1175,14 +1183,14 @@ struct CalculateSmallVectorDefaultInlinedElements { // Because our policy guarantees at least one inlined element, it is possible // for an arbitrarily large inlined element to allocate an arbitrarily large // amount of inline storage. We generally consider it an antipattern for a - // SmallVector to allocate an excessive amount of inline storage, so we want + // small_vector to allocate an excessive amount of inline storage, so we want // to call attention to these cases and make sure that users are making an // intentional decision if they request a lot of inline storage. // // We want this assertion to trigger in pathological cases, but otherwise // not be too easy to hit. To accomplish that, the cutoff is actually somewhat // larger than kPreferredSmallVectorSizeof (otherwise, - // `SmallVector>` would be one easy way to trip it, and that + // `small_vector>` would be one easy way to trip it, and that // pattern seems useful in practice). // // One wrinkle is that this assertion is in theory non-portable, since @@ -1195,14 +1203,14 @@ struct CalculateSmallVectorDefaultInlinedElements { static_assert( sizeof(T) <= 256, "You are trying to use a default number of inlined elements for " - "`SmallVector` but `sizeof(T)` is really big! Please use an " - "explicit number of inlined elements with `SmallVector` to make " + "`small_vector` but `sizeof(T)` is really big! Please use an " + "explicit number of inlined elements with `small_vector` to make " "sure you really want that much inline storage."); // Discount the size of the header itself when calculating the maximum inline // bytes. static constexpr size_t PreferredInlineBytes = - kPreferredSmallVectorSizeof - sizeof(SmallVector); + kPreferredSmallVectorSizeof - sizeof(small_vector); static constexpr size_t NumElementsThatFit = PreferredInlineBytes / sizeof(T); static constexpr size_t value = NumElementsThatFit == 0 ? 1 : NumElementsThatFit; @@ -1216,27 +1224,27 @@ struct CalculateSmallVectorDefaultInlinedElements { /// /// \note /// In the absence of a well-motivated choice for the number of inlined -/// elements \p N, it is recommended to use \c SmallVector (that is, +/// elements \p N, it is recommended to use \c small_vector (that is, /// omitting the \p N). This will choose a default number of inlined elements /// reasonable for allocation on the stack (for example, trying to keep \c -/// sizeof(SmallVector) around 64 bytes). +/// sizeof(small_vector) around 64 bytes). /// /// \warning This does not attempt to be exception safe. /// /// \see https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h template ::value> -class SmallVector : public SmallVectorImpl, SmallVectorStorage { +class small_vector : public small_vector_impl, small_vector_storage { public: - SmallVector() : SmallVectorImpl(N) {} + small_vector() : small_vector_impl(N) {} - ~SmallVector() { + ~small_vector() { // Destroy the constructed elements in the vector. this->destroy_range(this->begin(), this->end()); } - explicit SmallVector(size_t Size, const T &Value = T()) - : SmallVectorImpl(N) { + explicit small_vector(size_t Size, const T &Value = T()) + : small_vector_impl(N) { this->assign(Size, Value); } @@ -1244,65 +1252,65 @@ class SmallVector : public SmallVectorImpl, SmallVectorStorage { typename = std::enable_if_t::iterator_category, std::input_iterator_tag>::value>> - SmallVector(ItTy S, ItTy E) : SmallVectorImpl(N) { + small_vector(ItTy S, ItTy E) : small_vector_impl(N) { this->append(S, E); } template - explicit SmallVector(const iterator_range &R) - : SmallVectorImpl(N) { + explicit small_vector(const iterator_range &R) + : small_vector_impl(N) { this->append(R.begin(), R.end()); } - SmallVector(std::initializer_list IL) : SmallVectorImpl(N) { + small_vector(std::initializer_list IL) : small_vector_impl(N) { this->assign(IL); } - SmallVector(const SmallVector &RHS) : SmallVectorImpl(N) { - if (!RHS.empty()) SmallVectorImpl::operator=(RHS); + small_vector(const small_vector &RHS) : small_vector_impl(N) { + if (!RHS.empty()) small_vector_impl::operator=(RHS); } - SmallVector &operator=(const SmallVector &RHS) { - SmallVectorImpl::operator=(RHS); + small_vector &operator=(const small_vector &RHS) { + small_vector_impl::operator=(RHS); return *this; } - SmallVector(SmallVector &&RHS) : SmallVectorImpl(N) { - if (!RHS.empty()) SmallVectorImpl::operator=(::std::move(RHS)); + small_vector(small_vector &&RHS) : small_vector_impl(N) { + if (!RHS.empty()) small_vector_impl::operator=(::std::move(RHS)); } - SmallVector(SmallVectorImpl &&RHS) : SmallVectorImpl(N) { - if (!RHS.empty()) SmallVectorImpl::operator=(::std::move(RHS)); + small_vector(small_vector_impl &&RHS) : small_vector_impl(N) { + if (!RHS.empty()) small_vector_impl::operator=(::std::move(RHS)); } - SmallVector &operator=(SmallVector &&RHS) { - SmallVectorImpl::operator=(::std::move(RHS)); + small_vector &operator=(small_vector &&RHS) { + small_vector_impl::operator=(::std::move(RHS)); return *this; } - SmallVector &operator=(SmallVectorImpl &&RHS) { - SmallVectorImpl::operator=(::std::move(RHS)); + small_vector &operator=(small_vector_impl &&RHS) { + small_vector_impl::operator=(::std::move(RHS)); return *this; } - SmallVector &operator=(std::initializer_list IL) { + small_vector &operator=(std::initializer_list IL) { this->assign(IL); return *this; } }; template -inline size_t capacity_in_bytes(const SmallVector &X) { +inline size_t capacity_in_bytes(const small_vector &X) { return X.capacity_in_bytes(); } /// Given a range of type R, iterate the entire range and return a -/// SmallVector with elements of the vector. This is useful, for example, +/// small_vector with elements of the vector. This is useful, for example, /// when you want to iterate a range and then sort the results. template -SmallVector()))>::type>::type, - Size> +small_vector()))>::type>::type, + Size> to_vector(R &&Range) { return {std::begin(Range), std::end(Range)}; } @@ -1352,22 +1360,22 @@ struct Struct32B { alignas(32) void *X; }; } -static_assert(sizeof(SmallVector) == +static_assert(sizeof(small_vector) == sizeof(unsigned) * 2 + sizeof(void *), - "wasted space in SmallVector size 0"); -static_assert(alignof(SmallVector) >= alignof(Struct16B), + "wasted space in small_vector size 0"); +static_assert(alignof(small_vector) >= alignof(Struct16B), "wrong alignment for 16-byte aligned T"); -static_assert(alignof(SmallVector) >= alignof(Struct32B), +static_assert(alignof(small_vector) >= alignof(Struct32B), "wrong alignment for 32-byte aligned T"); -static_assert(sizeof(SmallVector) >= alignof(Struct16B), +static_assert(sizeof(small_vector) >= alignof(Struct16B), "missing padding for 16-byte aligned T"); -static_assert(sizeof(SmallVector) >= alignof(Struct32B), +static_assert(sizeof(small_vector) >= alignof(Struct32B), "missing padding for 32-byte aligned T"); -static_assert(sizeof(SmallVector) == +static_assert(sizeof(small_vector) == sizeof(unsigned) * 2 + sizeof(void *) * 2, - "wasted space in SmallVector size 1"); + "wasted space in small_vector size 1"); -static_assert(sizeof(SmallVector) == +static_assert(sizeof(small_vector) == sizeof(void *) * 2 + sizeof(void *), "1 byte elements have word-sized type for size and capacity"); @@ -1375,7 +1383,7 @@ static_assert(sizeof(SmallVector) == /// std::length_error or calls report_fatal_error. static void report_size_overflow(size_t MinSize, size_t MaxSize); static void report_size_overflow(size_t MinSize, size_t MaxSize) { - std::string Reason = "SmallVector unable to grow. Requested capacity (" + + std::string Reason = "small_vector unable to grow. Requested capacity (" + std::to_string(MinSize) + ") is larger than maximum value for size type (" + std::to_string(MaxSize) + ")"; @@ -1387,7 +1395,7 @@ static void report_size_overflow(size_t MinSize, size_t MaxSize) { static void report_at_maximum_capacity(size_t MaxSize); static void report_at_maximum_capacity(size_t MaxSize) { std::string Reason = - "SmallVector capacity unable to grow. Already at maximum size " + + "small_vector capacity unable to grow. Already at maximum size " + std::to_string(MaxSize); throw std::length_error(Reason); } @@ -1415,18 +1423,18 @@ static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) { // Note: Moving this function into the header may cause performance regression. template -void *SmallVectorBase::mallocForGrow(size_t MinSize, - size_t TSize, - size_t &NewCapacity) { +void *small_vector_base::mallocForGrow(size_t MinSize, + size_t TSize, + size_t &NewCapacity) { NewCapacity = getNewCapacity(MinSize, TSize, this->capacity()); return safe_malloc(NewCapacity * TSize); } // Note: Moving this function into the header may cause performance regression. template -void SmallVectorBase::grow_pod(void *FirstEl, - size_t MinSize, - size_t TSize) { +void small_vector_base::grow_pod(void *FirstEl, + size_t MinSize, + size_t TSize) { size_t NewCapacity = getNewCapacity(MinSize, TSize, this->capacity()); void *NewElts; if (BeginX == FirstEl) { @@ -1443,38 +1451,38 @@ void SmallVectorBase::grow_pod(void *FirstEl, this->Capacity = NewCapacity; } -template class paddle::SmallVectorBase; +template class paddle::small_vector_base; // Disable the uint64_t instantiation for 32-bit builds. // Both uint32_t and uint64_t instantiations are needed for 64-bit builds. // This instantiation will never be used in 32-bit builds, and will cause // warnings when sizeof(Size_T) > sizeof(size_t). #if SIZE_MAX > UINT32_MAX -template class paddle::SmallVectorBase; +template class paddle::small_vector_base; // Assertions to ensure this #if stays in sync with SmallVectorSizeType. static_assert(sizeof(SmallVectorSizeType) == sizeof(uint64_t), - "Expected SmallVectorBase variant to be in use."); + "Expected small_vector_base variant to be in use."); #else static_assert(sizeof(SmallVectorSizeType) == sizeof(uint32_t), - "Expected SmallVectorBase variant to be in use."); + "Expected small_vector_base variant to be in use."); #endif } // namespace paddle namespace std { -/// Implement std::swap in terms of SmallVector swap. +/// Implement std::swap in terms of small_vector swap. template -inline void swap(paddle::SmallVectorImpl &LHS, - paddle::SmallVectorImpl &RHS) { +inline void swap(paddle::small_vector_impl &LHS, + paddle::small_vector_impl &RHS) { LHS.swap(RHS); } -/// Implement std::swap in terms of SmallVector swap. +/// Implement std::swap in terms of small_vector swap. template -inline void swap(paddle::SmallVector &LHS, - paddle::SmallVector &RHS) { +inline void swap(paddle::small_vector &LHS, + paddle::small_vector &RHS) { LHS.swap(RHS); } diff --git a/paddle/utils/small_vector_test.cc b/paddle/utils/small_vector_test.cc index 96bcec59400..e061c232152 100644 --- a/paddle/utils/small_vector_test.cc +++ b/paddle/utils/small_vector_test.cc @@ -21,7 +21,7 @@ #include "gtest/gtest.h" template -static std::vector ToStdVector(const paddle::SmallVector &vec) { +static std::vector ToStdVector(const paddle::small_vector &vec) { std::vector std_vec; std_vec.reserve(vec.size()); for (size_t i = 0; i < vec.size(); ++i) { @@ -35,7 +35,7 @@ void SmallVectorCheck(size_t n) { std::srand(std::time(nullptr)); std::vector std_vec; - paddle::SmallVector vec; + paddle::small_vector vec; for (size_t i = 0; i < n; ++i) { int value = rand(); // NOLINT -- GitLab