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

[clang-tidy] NO.6 enable modernize-avoid-c-arrays check #55774

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented Jul 28, 2023

PR types

Others

PR changes

Others

Description

@GreatV 帮忙看看是否需要引入。

(这个也不能自动修复)

相关链接:

@paddle-bot
Copy link

paddle-bot bot commented Jul 28, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added contributor External developers status: proposed labels Jul 28, 2023
@GreatV
Copy link
Contributor

GreatV commented Jul 28, 2023

这个pytorch中是启用的,tensorflow中没有启用,跟pytorch对齐吧。

@gouzil gouzil changed the title [clang-tidy] NO.6 enable modernize-avoid-c-arrays check [clang-tidy] NO.6 enable modernize-avoid-c-arrays check Jul 28, 2023
@gouzil
Copy link
Member Author

gouzil commented Jul 28, 2023

这个pytorch中是启用的,tensorflow中没有启用,跟pytorch对齐吧。

我其实是担心会有一些性能上的损失

测试代码:

#include <iostream>
#include <array>

class demo1 {
    public:
        static constexpr uint32_t attributes_num = 1;
        static const char *attributes_name[attributes_num];
};

class demo2 {
    public:
        static constexpr uint32_t attributes_num = 1;
        const std::array<char*, attributes_num> attributes_name  = {"program"};
};

const char *demo1::attributes_name[demo1::attributes_num] = {"program"};

static void charbenchmark(benchmark::State& state) {
  for (auto _ : state) {
    demo1 d;
    benchmark::DoNotOptimize(d.attributes_name[0]);
  }
}
BENCHMARK(charbenchmark);

static void arraybenchmark(benchmark::State& state) {
  for (auto _ : state) {
    demo2 d2;
    benchmark::DoNotOptimize(d2.attributes_name[0]);
  }
}
BENCHMARK(arraybenchmark);

测试网站: https://quick-bench.com/

使用gcc8.1, -std=c++11

不开启 -O 优化
_6oLYEGUMHvxFjsUWXRs9abopJM

开启 -Os 优化
r7iUVpqD1JzEnatF-WlRRz4_fyU

@GreatV
Copy link
Contributor

GreatV commented Jul 28, 2023

release版一般会开启-O优化的吧

@@ -50,7 +50,7 @@ class IR_API GetParameterOp : public ir::Op<GetParameterOp> {
using Op::Op;
static const char *name() { return "builtin.get_parameter"; }
static constexpr uint32_t attributes_num = 1;
static const char *attributes_name[attributes_num];
const std::array<char *, attributes_num> attributes_name = {"parameter_name"};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我们是必须要设定为 static,不建议修改

@gouzil
Copy link
Member Author

gouzil commented Jul 29, 2023

存量过多拆分成几个pr来做,当前进度5%(可能还没到)

@SigureMo
Copy link
Member

SigureMo commented Jul 29, 2023

@gouzil 我看了下任务 7 cppcoreguidelines-avoid-c-arrays,文档里说它只是任务 6 modernize-avoid-c-arrays 的一个 alias,所以表单里任务 6、7 都记上你的名字了哈,最后完成时候同时启用这俩就行

@GreatV 另外,任务 1、2 和 8、9 好像也只是 alias 的关系,我在表单里做了一下标记以免认领冲突~

@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Jul 31, 2023
@luotao1
Copy link
Contributor

luotao1 commented Jul 31, 2023

需要解决下流水线的编译问题

@gouzil
Copy link
Member Author

gouzil commented Aug 1, 2023

需要解决下流水线的编译问题

Done

@luotao1
Copy link
Contributor

luotao1 commented Aug 1, 2023

存量过多拆分成几个pr来做,当前进度5%(可能还没到)

当前commit还是进度5%不到么?

@@ -33,11 +33,11 @@ limitations under the License. */
#include "paddle/phi/backends/dynload/nvtx.h"
#endif

PHI_DEFINE_bool(enable_host_event_recorder_hook,
PHI_DEFINE_bool(enable_host_event_recorder_hook, // NOLINT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

话说这些宏的话,是不是可以从宏定义处直接加 NOLINT 捏?不然可能要加很多 NOLINT

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有一部分是因为第三方库引起的

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我有在paddle/phi/core/flags.hPHI_DEFINE_bool宏加上了,但是还是会扫到

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我之前试的是,好像必须在相关语句的第一行才行,第二行好像就不太行

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,修复了

@gouzil
Copy link
Member Author

gouzil commented Aug 1, 2023

存量过多拆分成几个pr来做,当前进度5%(可能还没到)

当前commit还是进度5%不到么?

是的,由于时间有点久了,先合入一部分然后我再扫一次,这个pr主要是验证可行性以及一些解决方案

zhangbo9674
zhangbo9674 previously approved these changes Aug 1, 2023
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow

@luotao1 luotao1 merged commit c000091 into PaddlePaddle:develop Aug 2, 2023
@gouzil gouzil deleted the clang_tidy_enable_check_modernize-avoid-c-arrays branch August 2, 2023 11:54
@luotao1 luotao1 added HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 and removed HappyOpenSource 快乐开源活动issue与PR labels Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants