Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Hackathon 6th Fundable Projects 2 No.32】 modernize-pass-by-value_2-part #64026

Merged
merged 13 commits into from
May 21, 2024
8 changes: 5 additions & 3 deletions paddle/fluid/memory/allocation/aligned_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

#include "paddle/fluid/memory/allocation/aligned_allocator.h"

#include <utility>

#include "paddle/common/macros.h"
#include "paddle/fluid/platform/enforce.h"

REGISTER_FILE_SYMBOLS(aligned_allocator);

namespace paddle {
namespace memory {
namespace allocation {
Expand All @@ -39,8 +40,9 @@ class AlignedAllocation : public Allocation {
};

AlignedAllocator::AlignedAllocator(
const std::shared_ptr<Allocator>& underlying_allocator, size_t alignment)
: underlying_allocator_(underlying_allocator), alignment_(alignment) {
std::shared_ptr<Allocator> underlying_allocator, size_t alignment)
: underlying_allocator_(std::move(underlying_allocator)),
alignment_(alignment) {
PADDLE_ENFORCE_GT(
alignment_,
0,
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/memory/allocation/aligned_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace allocation {

class AlignedAllocator : public Allocator {
public:
AlignedAllocator(const std::shared_ptr<Allocator>& underlying_allocator,
AlignedAllocator(std::shared_ptr<Allocator> underlying_allocator,
size_t alignment);

bool IsAllocThreadSafe() const override;
Expand Down
5 changes: 3 additions & 2 deletions paddle/fluid/memory/allocation/allocator_facade.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
#include <shared_mutex>
#include <utility>

#include "paddle/fluid/memory/allocation/cuda_allocator.h"
#include "paddle/fluid/memory/allocation/cuda_managed_allocator.h"
Expand Down Expand Up @@ -141,8 +142,8 @@ class CUDAGraphAllocator
DecoratedAllocationPtr underlying_allocation_;
};

explicit CUDAGraphAllocator(const std::shared_ptr<Allocator>& allocator)
: underlying_allocator_(allocator) {}
explicit CUDAGraphAllocator(std::shared_ptr<Allocator> allocator)
: underlying_allocator_(std::move(allocator)) {}

public:
~CUDAGraphAllocator() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <algorithm>
#include <mutex> // NOLINT
#include <utility>

#include "paddle/fluid/memory/allocation/aligned_allocator.h"
#include "paddle/fluid/platform/flags.h"
Expand Down Expand Up @@ -46,12 +47,12 @@ namespace memory {
namespace allocation {

AutoGrowthBestFitAllocator::AutoGrowthBestFitAllocator(
const std::shared_ptr<Allocator> &underlying_allocator,
std::shared_ptr<Allocator> underlying_allocator,
size_t alignment,
size_t chunk_size,
bool allow_free_idle_chunk,
int extra_padding_size)
: underlying_allocator_(underlying_allocator),
: underlying_allocator_(std::move(underlying_allocator)),
alignment_(alignment),
chunk_size_(std::max(AlignedSize(chunk_size, alignment), alignment)),
allow_free_idle_chunk_(allow_free_idle_chunk),
Expand Down
11 changes: 5 additions & 6 deletions paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ namespace allocation {

class AutoGrowthBestFitAllocator : public Allocator {
public:
AutoGrowthBestFitAllocator(
const std::shared_ptr<Allocator> &underlying_allocator,
size_t alignment,
size_t chunk_size = 0,
bool allow_free_idle_chunk = true,
int extra_padding_size = 0);
AutoGrowthBestFitAllocator(std::shared_ptr<Allocator> underlying_allocator,
size_t alignment,
size_t chunk_size = 0,
bool allow_free_idle_chunk = true,
int extra_padding_size = 0);

bool IsAllocThreadSafe() const override { return true; }

Expand Down
10 changes: 8 additions & 2 deletions paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@
// limitations under the License.

#include "paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.h"

#include <utility>
#include "paddle/common/enforce.h"

namespace paddle {
namespace dialect {
IrSelectedRows::IrSelectedRows(phi::DataType dtype,
const phi::DDim& dims,
phi::DataLayout layout,
const LoD& lod,
LoD lod,
size_t offset)
: dims_(dims), dtype_(dtype), layout_(layout), lod_(lod), offset_(offset) {}
: dims_(dims),
dtype_(dtype),
layout_(layout),
lod_(std::move(lod)),
offset_(offset) {}

IrSelectedRows::IrSelectedRows(const IrSelectedRows& other) {
dims_ = other.dims();
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class IrSelectedRows
IrSelectedRows(phi::DataType dtype,
const phi::DDim& dims,
phi::DataLayout layout,
const LoD& lod,
LoD lod,
size_t offset = 0);

IrSelectedRows(IrSelectedRows&& other) = default;
Expand Down
10 changes: 8 additions & 2 deletions paddle/fluid/pir/dialect/operator/ir/ir_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@

#include "paddle/fluid/pir/dialect/operator/ir/ir_tensor.h"

#include <utility>

#include "paddle/common/enforce.h"

namespace paddle {
namespace dialect {
IrTensor::IrTensor(phi::DataType dtype,
const phi::DDim& dims,
phi::DataLayout layout,
const LoD& lod,
LoD lod,
size_t offset)
: dims_(dims), dtype_(dtype), layout_(layout), lod_(lod), offset_(offset) {}
: dims_(dims),
dtype_(dtype),
layout_(layout),
lod_(std::move(lod)),
offset_(offset) {}

IrTensor::IrTensor(const IrTensor& other) {
dims_ = other.dims();
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/pir/dialect/operator/ir/ir_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class IrTensor : public phi::TensorBase,
IrTensor(phi::DataType dtype,
const phi::DDim& dims,
phi::DataLayout layout,
const LoD& lod,
LoD lod,
size_t offset = 0);

IrTensor(IrTensor&& other) = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
// limitations under the License.

#include "paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h"

#include <utility>
#include "paddle/phi/core/enforce.h"

namespace paddle {
namespace dialect {

OpYamlInfoParser::OpYamlInfoParser(const OpInfoTuple& op_info_tuple,
bool is_legacy_op)
: op_info_tuple_(op_info_tuple), is_legacy_op_(is_legacy_op) {
OpYamlInfoParser::OpYamlInfoParser(OpInfoTuple op_info_tuple, bool is_legacy_op)
: op_info_tuple_(std::move(op_info_tuple)), is_legacy_op_(is_legacy_op) {
parse();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OpYamlInfoParser {
public:
OpYamlInfoParser() = delete;

TEST_API explicit OpYamlInfoParser(const OpInfoTuple& op_info_tuple,
TEST_API explicit OpYamlInfoParser(OpInfoTuple op_info_tuple,
bool is_legacy_op = false);

TEST_API bool IsTensorAttribute(size_t index) const;
Expand Down
11 changes: 5 additions & 6 deletions paddle/fluid/pir/drr/include/drr_rewrite_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ class ResultPatternGraph;

class DrrRewritePattern : public pir::RewritePattern {
public:
DrrRewritePattern(
const std::string& pattern_name,
const DrrPatternContext& drr_context,
pir::IrContext* context,
pir::PatternBenefit benefit,
const std::shared_ptr<const DrrPatternBase>& drr_pattern_owner);
DrrRewritePattern(const std::string& pattern_name,
const DrrPatternContext& drr_context,
pir::IrContext* context,
pir::PatternBenefit benefit,
std::shared_ptr<const DrrPatternBase> drr_pattern_owner);

bool MatchAndRewrite(
pir::Operation* op,
Expand Down
3 changes: 2 additions & 1 deletion paddle/fluid/pir/drr/src/match_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

#include <cstdint>
#include <utility>

#include "paddle/fluid/pir/drr/include/drr_match_context.h"
#include "paddle/fluid/pir/drr/src/match_context_impl.h"
Expand All @@ -22,7 +23,7 @@ namespace paddle {
namespace drr {

MatchContext::MatchContext(std::shared_ptr<const MatchContextImpl> impl)
: impl_(impl) {}
: impl_(std::move(impl)) {}

const pir::Value& MatchContext::Tensor(const std::string& tensor_name) const {
return impl_->Tensor(tensor_name);
Expand Down
5 changes: 3 additions & 2 deletions paddle/fluid/pir/drr/src/rewrite_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <glog/logging.h>
#include <queue>
#include <utility>

#include "glog/vlog_is_on.h"
#include "paddle/fluid/pir/drr/include/drr_pattern_base.h"
Expand All @@ -33,7 +34,7 @@ DrrRewritePattern::DrrRewritePattern(
const DrrPatternContext& drr_context,
pir::IrContext* context,
pir::PatternBenefit benefit,
const std::shared_ptr<const DrrPatternBase>& drr_pattern_owner)
std::shared_ptr<const DrrPatternBase> drr_pattern_owner)
: pir::RewritePattern(
(*drr_context.source_pattern_graph()->OutputNodes().begin())->name(),
benefit,
Expand All @@ -44,7 +45,7 @@ DrrRewritePattern::DrrRewritePattern(
constraints_(drr_context.constraints()),
post_processes_(drr_context.post_processes()),
result_pattern_graph_(drr_context.result_pattern_graph()),
drr_pattern_owner_(drr_pattern_owner) {
drr_pattern_owner_(std::move(drr_pattern_owner)) {
PADDLE_ENFORCE_NE(source_pattern_graph_->owned_op_call().empty(),
true,
phi::errors::InvalidArgument(
Expand Down
12 changes: 8 additions & 4 deletions paddle/fluid/pir/transforms/gpu/fused_weight_only_linear_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "paddle/fluid/pir/transforms/gpu/fused_weight_only_linear_pass.h"

#include <utility>

#include "paddle/fluid/pir/dialect/operator/ir/pd_op.h"
#include "paddle/fluid/pir/drr/include/drr_pattern_base.h"
#include "paddle/fluid/pir/utils/general_functions.h"
Expand Down Expand Up @@ -46,9 +48,11 @@ class FusedWeightOnlyLinearWithBiasPattern

public:
FusedWeightOnlyLinearWithBiasPattern(bool reverse_add,
const std::string &algo,
std::string algo,
int sm_version)
: reverse_add_(reverse_add), algo_(algo), sm_version_(sm_version) {}
: reverse_add_(reverse_add),
algo_(std::move(algo)),
sm_version_(sm_version) {}

std::string name() const override {
return "FusedWeightOnlyLinearWithBiasPattern";
Expand Down Expand Up @@ -165,8 +169,8 @@ class FusedWeightOnlyLinearNoBiasPattern : public paddle::drr::DrrPatternBase {
int sm_version_;

public:
FusedWeightOnlyLinearNoBiasPattern(const std::string &algo, int sm_version)
: algo_(algo), sm_version_(sm_version) {}
FusedWeightOnlyLinearNoBiasPattern(std::string algo, int sm_version)
: algo_(std::move(algo)), sm_version_(sm_version) {}

public:
std::string name() const override {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "paddle/fluid/pir/transforms/onednn/conv_activation_onednn_fuse_pass.h"

#include <utility>

#include "paddle/fluid/pir/dialect/operator/ir/onednn_op.h"
#include "paddle/fluid/pir/dialect/operator/ir/pd_op.h"
#include "paddle/fluid/pir/drr/include/drr_pattern_base.h"
Expand All @@ -38,10 +40,10 @@ class ConvActivationFusePattern : public paddle::drr::DrrPatternBase {

public:
ConvActivationFusePattern(size_t activation_count,
const std::string &activation_name,
std::string activation_name,
int fused_level)
: activation_count_(activation_count),
activation_name_(activation_name),
activation_name_(std::move(activation_name)),
fused_level_(fused_level) {}

std::string name() const override {
Expand Down Expand Up @@ -224,8 +226,9 @@ class ConvGeluFusePattern : public paddle::drr::DrrPatternBase {
const int fused_level_;

public:
ConvGeluFusePattern(const std::string &activation_name, int fused_level)
: activation_name_(activation_name), fused_level_(fused_level) {}
ConvGeluFusePattern(std::string activation_name, int fused_level)
: activation_name_(std::move(activation_name)),
fused_level_(fused_level) {}

std::string name() const override { return "ConvGeluFusePattern"; }

Expand Down Expand Up @@ -367,8 +370,9 @@ class ConvClipFusePattern : public paddle::drr::DrrPatternBase {
const int fused_level_;

public:
ConvClipFusePattern(const std::string &activation_name, int fused_level)
: activation_name_(activation_name), fused_level_(fused_level) {}
ConvClipFusePattern(std::string activation_name, int fused_level)
: activation_name_(std::move(activation_name)),
fused_level_(fused_level) {}

std::string name() const override { return "ConvClipFusePattern"; }

Expand Down
8 changes: 5 additions & 3 deletions paddle/fluid/pir/transforms/onednn/conv_bias_fuse_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "paddle/fluid/pir/transforms/onednn/conv_bias_fuse_pass.h"

#include <utility>

#include "paddle/fluid/pir/dialect/operator/ir/onednn_op.h"
#include "paddle/fluid/pir/dialect/operator/ir/pd_op.h"
#include "paddle/fluid/pir/drr/include/drr_pattern_base.h"
Expand All @@ -30,9 +32,9 @@ class ConvBiasFusePattern : public paddle::drr::DrrPatternBase {
std::string fused_conv_name_;

public:
ConvBiasFusePattern(const std::string &conv_name,
const std::string &fused_conv_name)
: conv_name_(conv_name), fused_conv_name_(fused_conv_name) {}
ConvBiasFusePattern(std::string conv_name, std::string fused_conv_name)
: conv_name_(std::move(conv_name)),
fused_conv_name_(std::move(fused_conv_name)) {}

std::string name() const override { return "ConvBiasFusePattern"; }

Expand Down
Loading