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.52】Fix readability-redundant-smartptr-get-final #64582

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions paddle/fluid/eager/custom_operator/custom_operator_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,7 @@ phi::distributed::SpmdInfo RunInferSpmdFn(
auto& t = ctx.InputAt(j);
phi::distributed::DistMetaTensor meta_tensor;
if (t.impl().get()) {
meta_tensor =
paddle::experimental::MakeDistMetaTensor(*(t.impl().get()));
meta_tensor = paddle::experimental::MakeDistMetaTensor(*(t.impl()));
}
meta_tensors.emplace_back(std::move(meta_tensor));
}
Expand All @@ -504,8 +503,7 @@ phi::distributed::SpmdInfo RunInferSpmdFn(
auto& t = ctx.InputAt(range.first);
phi::distributed::DistMetaTensor meta_tensor;
if (t.impl().get()) {
meta_tensor =
paddle::experimental::MakeDistMetaTensor(*(t.impl().get()));
meta_tensor = paddle::experimental::MakeDistMetaTensor(*(t.impl()));
}
tensor_inputs.emplace_back(std::move(meta_tensor));
}
Expand Down
72 changes: 28 additions & 44 deletions paddle/fluid/framework/io/crypto/aes_cipher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ std::string AESCipher::EncryptInternal(const std::string& plaintext,
BuildCipher(true, &need_iv, &m_cipher, &m_filter);
if (need_iv) {
iv_ = CipherUtils::GenKey(iv_size_);
m_cipher.get()->SetKeyWithIV(
key_char,
key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0))),
iv_.size());
m_cipher->SetKeyWithIV(key_char,
key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0))),
iv_.size());
} else {
m_cipher.get()->SetKey(key_char, key.size());
m_cipher->SetKey(key_char, key.size());
}

std::string ciphertext;
Expand All @@ -85,13 +84,12 @@ std::string AESCipher::DecryptInternal(const std::string& ciphertext,
if (need_iv) {
iv_ = ciphertext.substr(0, iv_size_ / 8);
ciphertext_beg = iv_size_ / 8;
m_cipher.get()->SetKeyWithIV(
key_char,
key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0))),
iv_.size());
m_cipher->SetKeyWithIV(key_char,
key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0))),
iv_.size());
} else {
m_cipher.get()->SetKey(key_char, key.size());
m_cipher->SetKey(key_char, key.size());
}
std::string plaintext;
m_filter->Attach(new CryptoPP::StringSink(plaintext));
Expand All @@ -112,13 +110,12 @@ std::string AESCipher::AuthenticatedEncryptInternal(
BuildAuthEncCipher(&need_iv, &m_cipher, &m_filter);
if (need_iv) {
iv_ = CipherUtils::GenKey(iv_size_);
m_cipher.get()->SetKeyWithIV(
key_char,
key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0))),
iv_.size());
m_cipher->SetKeyWithIV(key_char,
key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0))),
iv_.size());
} else {
m_cipher.get()->SetKey(key_char, key.size());
m_cipher->SetKey(key_char, key.size());
}

std::string ciphertext;
Expand All @@ -144,13 +141,12 @@ std::string AESCipher::AuthenticatedDecryptInternal(
if (need_iv) {
iv_ = ciphertext.substr(0, iv_size_ / 8);
ciphertext_beg = iv_size_ / 8;
m_cipher.get()->SetKeyWithIV(
key_char,
key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0))),
iv_.size());
m_cipher->SetKeyWithIV(key_char,
key.size(),
reinterpret_cast<const unsigned char*>(&(iv_.at(0))),
iv_.size());
} else {
m_cipher.get()->SetKey(key_char, key.size());
m_cipher->SetKey(key_char, key.size());
}
std::string plaintext;
m_filter->Attach(new CryptoPP::StringSink(plaintext));
Expand All @@ -173,43 +169,31 @@ void AESCipher::BuildCipher(
if (aes_cipher_name_ == "AES_ECB_PKCSPadding" && for_encrypt) {
m_cipher->reset(new CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption);
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
nullptr,
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
**m_cipher, nullptr, CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
} else if (aes_cipher_name_ == "AES_ECB_PKCSPadding" && !for_encrypt) {
m_cipher->reset(new CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption);
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
nullptr,
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
**m_cipher, nullptr, CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
} else if (aes_cipher_name_ == "AES_CBC_PKCSPadding" && for_encrypt) {
m_cipher->reset(new CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption);
*need_iv = true;
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
nullptr,
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
**m_cipher, nullptr, CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
} else if (aes_cipher_name_ == "AES_CBC_PKCSPadding" && !for_encrypt) {
m_cipher->reset(new CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption);
*need_iv = true;
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
nullptr,
CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
**m_cipher, nullptr, CryptoPP::BlockPaddingSchemeDef::PKCS_PADDING));
} else if (aes_cipher_name_ == "AES_CTR_NoPadding" && for_encrypt) {
m_cipher->reset(new CryptoPP::CTR_Mode<CryptoPP::AES>::Encryption);
*need_iv = true;
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
nullptr,
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
**m_cipher, nullptr, CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
} else if (aes_cipher_name_ == "AES_CTR_NoPadding" && !for_encrypt) {
m_cipher->reset(new CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption);
*need_iv = true;
m_filter->reset(new CryptoPP::StreamTransformationFilter(
*(*m_cipher).get(),
nullptr,
CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
**m_cipher, nullptr, CryptoPP::BlockPaddingSchemeDef::NO_PADDING));
} else {
PADDLE_THROW(paddle::platform::errors::Unimplemented(
"Create cipher error. "
Expand All @@ -226,7 +210,7 @@ void AESCipher::BuildAuthEncCipher(
m_cipher->reset(new CryptoPP::GCM<CryptoPP::AES>::Encryption);
*need_iv = true;
m_filter->reset(new CryptoPP::AuthenticatedEncryptionFilter(
*(*m_cipher).get(),
**m_cipher,
nullptr,
false,
tag_size_ / 8,
Expand All @@ -248,7 +232,7 @@ void AESCipher::BuildAuthDecCipher(
m_cipher->reset(new CryptoPP::GCM<CryptoPP::AES>::Decryption);
*need_iv = true;
m_filter->reset(new CryptoPP::AuthenticatedDecryptionFilter(
*(*m_cipher).get(),
**m_cipher,
nullptr,
CryptoPP::AuthenticatedDecryptionFilter::DEFAULT_FLAGS,
tag_size_ / 8,
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/new_executor/workqueue/workqueue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class WorkQueueImpl : public WorkQueue {
if (options_.track_task && options.events_waiter != nullptr) {
empty_notifier_ = options.events_waiter->RegisterEvent(kQueueEmptyEvent);
void* storage = AlignedMalloc(sizeof(TaskTracker), alignof(TaskTracker));
tracker_ = new (storage) TaskTracker(*empty_notifier_.get());
tracker_ = new (storage) TaskTracker(*empty_notifier_);
}
if (options_.detached == false && options.events_waiter != nullptr) {
destruct_notifier_ =
Expand Down Expand Up @@ -132,7 +132,7 @@ WorkQueueGroupImpl::WorkQueueGroupImpl(
options.events_waiter != nullptr) {
empty_notifier_ = options.events_waiter->RegisterEvent(kQueueEmptyEvent);
void* storage = AlignedMalloc(sizeof(TaskTracker), alignof(TaskTracker));
tracker_ = new (storage) TaskTracker(*empty_notifier_.get());
tracker_ = new (storage) TaskTracker(*empty_notifier_);
}
if (options.detached == false && options.events_waiter != nullptr &&
!destruct_notifier_) {
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/inference/api/analysis_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ AnalysisConfig::AnalysisConfig() {
}

PassStrategy *AnalysisConfig::pass_builder() const {
if (!pass_builder_.get()) {
if (!pass_builder_) {
if (use_gpu_) {
LOG(INFO) << "Create GPU IR passes";
pass_builder_ = std::make_unique<GpuPassStrategy>();
Expand Down
2 changes: 1 addition & 1 deletion paddle/fluid/jit/function_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ FunctionInfo::FunctionInfo(const std::string& func_name,
const std::string& FunctionInfo::FunctionName() const { return func_name_; }

const framework::ProgramDesc& FunctionInfo::ProgramDesc() const {
return *program_desc_.get();
return *program_desc_.get(); // NOLINT
}

const std::vector<std::string>& FunctionInfo::ParamNames() const {
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/pir/drr/src/pattern_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ void GraphTopo::WalkGraphNodesTopoOrder(

// init opcall_dependent
for (const std::shared_ptr<OpCall> &opcall_sptr : owned_opcall) {
if (opcall_sptr.get()->inputs().empty()) { // opcall inputs is empty
if (opcall_sptr->inputs().empty()) { // opcall inputs is empty
opcall_queue.push(opcall_sptr.get());
} else {
for (const auto &pre_depd_tensor : opcall_sptr.get()->inputs()) {
for (const auto &pre_depd_tensor : opcall_sptr->inputs()) {
opcall_dependent[opcall_sptr.get()].insert(pre_depd_tensor->name());
}
}
Expand Down
5 changes: 2 additions & 3 deletions paddle/fluid/pir/drr/src/rewrite_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ bool DrrRewritePattern::PatternGraphMatch(
VLOG(6) << "PatternGraphMatch Start: op(" << op->name() << ")";
const OpCall* anchor = *source_pattern_graph_->OutputNodes().begin();
std::unordered_map<const OpCall*, std::unordered_set<pir::Operation*>>
bind_map =
FindCandidateIrOutputOp(op, anchor, *(source_pattern_graph_.get()));
bind_map = FindCandidateIrOutputOp(op, anchor, *source_pattern_graph_);
if (bind_map.empty()) {
return false;
}
Expand Down Expand Up @@ -116,7 +115,7 @@ bool DrrRewritePattern::PatternGraphMatch(
return std::make_pair(drr_op, ir_op);
});
if (MatchFromOutputToInput(
output_op_map, *(source_pattern_graph_.get()), match_ctx)) {
output_op_map, *source_pattern_graph_, match_ctx)) {
*source_pattern_match_ctx = *match_ctx;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/api/lib/tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bool Tensor::is_dense_tensor() const {
return phi::DenseTensor::classof(impl_.get());
}
bool Tensor::is_dist_tensor() const {
if (impl_.get() == nullptr) {
if (impl_ == nullptr) {
return false;
}
return phi::distributed::DistTensor::classof(impl_.get());
Expand Down
4 changes: 2 additions & 2 deletions paddle/phi/core/distributed/gloo_comm_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void GlooCommContext::Send(const phi::DenseTensor& in_tensor,
SendRecvOptions opts(gloo_context_);
const auto& dtype = in_tensor.dtype();
GENERATE_FUNC(dtype, SetInput, &opts, in_tensor);
opts.setSrc(gloo_context_.get()->rank);
opts.setSrc(gloo_context_->rank);
opts.setDst(dst);
opts.setTag(tag);
send_recv(&opts);
Expand All @@ -160,7 +160,7 @@ void GlooCommContext::Recv(phi::DenseTensor* out_tensor,
const auto& dtype = out_tensor->dtype();
GENERATE_FUNC(dtype, SetOutput, &opts, out_tensor);
opts.setSrc(src);
opts.setDst(gloo_context_.get()->rank);
opts.setDst(gloo_context_->rank);
opts.setTag(tag);
send_recv(&opts);
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/core/selected_rows_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void SelectedRowsImpl::Get(const phi::DenseTensor& ids,
phi::VisitDataType(value_->dtype(),
TensorCopyVisitor(value,
i * value_width,
*value_.get(),
*value_,
index * value_width,
value_width));
}
Expand Down
4 changes: 2 additions & 2 deletions paddle/phi/core/threadpool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ThreadPool* ThreadPool::GetInstance() {
}

void ThreadPool::Init() {
if (threadpool_.get() == nullptr) {
if (threadpool_ == nullptr) {
// TODO(Yancey1989): specify the max threads number
int num_threads = static_cast<int>(std::thread::hardware_concurrency());
if (FLAGS_dist_threadpool_size > 0) {
Expand Down Expand Up @@ -109,7 +109,7 @@ ThreadPool* ThreadPoolIO::GetInstanceIO() {
}

void ThreadPoolIO::InitIO() {
if (io_threadpool_.get() == nullptr) {
if (io_threadpool_ == nullptr) {
// TODO(typhoonzero1986): make this configurable
io_threadpool_ = std::make_unique<ThreadPool>(FLAGS_io_threadpool_size);
}
Expand Down