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

fix build warning: [Wsign-compare] on linux #46644

Merged
merged 13 commits into from
Oct 19, 2022

Conversation

Li-fAngyU
Copy link
Contributor

@Li-fAngyU Li-fAngyU commented Sep 29, 2022

PR types

Others

PR changes

Others

Describe

fix build warning: [Wsign-compare] on linux

@paddle-bot
Copy link

paddle-bot bot commented Sep 29, 2022

你的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 Sep 29, 2022
@luotao1 luotao1 self-assigned this Sep 30, 2022
@Li-fAngyU
Copy link
Contributor Author

@luotao1 针对 reinterpret_cast<uint64_t *>(...) 无法将 type "const char *" 转化成 type "uint64_t *" 这个问题(CI-GpuPS Error),我去查了一些资料,可以利用 const_cast 去除 const 限制,然后就可以利用 reinterpret_cast 进行类型转换了。

请问有更好的方式吗?

注:原本是直接使用 (uint64_t *)(...) 强制转换。

@luotao1
Copy link
Contributor

luotao1 commented Sep 30, 2022

可以利用 const_cast 去除 const 限制,然后就可以利用 reinterpret_cast 进行类型转换了。

const_cast 也是慎用。CI-GpuPS Error 不进行reinterpret_cast<uint64_t *>(...)会报错么?我看目前还有-Wunused-variable的错误。

@@ -78,7 +78,7 @@ paddle::framework::GpuPsCommGraphFea GraphTable::make_gpu_ps_graph_fea(
paddle::framework::GpuPsFeaInfo x;
std::vector<uint64_t> feature_ids;
for (size_t j = 0; j < bags[i].size(); j++) {
// TODO use FEATURE_TABLE instead
// TODO(danleifeng): Stuff. use FEATURE_TABLE instead
Copy link
Contributor

Choose a reason for hiding this comment

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

Stuff. 可以去掉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到

@@ -996,31 +996,31 @@ int32_t MemorySparseTable::PushSparse(const uint64_t* keys,
update_value_col,
values,
&task_keys]() -> int {
auto& keys = task_keys[shard_id];
auto& local_shard = _local_shards[shard_id];
auto &keys = task_keys[shard_id];
Copy link
Contributor

Choose a reason for hiding this comment

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

这些 & 和 * 的修改是格式化工具自动修改的么?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的

@@ -254,7 +255,8 @@ char *GraphTable::random_sample_neighbor_from_ssd(
ch,
sizeof(int) * 2 + sizeof(uint64_t),
str) == 0) {
uint64_t *data = ((uint64_t *)str.c_str());
uint64_t *data =
reinterpret_cast<uint64_t *>(const_cast<char *>(str.c_str()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Wsign-compare,会对这段报warning么?是不是precommit的时候报的warning?因为distributed目录下很多没有做代码格式化,如果碰到,可以加 // NOLINT 先豁免本行。这个PR主要修Wsign-compare,其他内容可以不修。

@Li-fAngyU
Copy link
Contributor Author

可以利用 const_cast 去除 const 限制,然后就可以利用 reinterpret_cast 进行类型转换了。

const_cast 也是慎用。CI-GpuPS Error 不进行reinterpret_cast<uint64_t *>(...)会报错么?我看目前还有-Wunused-variable的错误。

对的还有 Wunused-variable 的Warning。

@luotao1 luotao1 requested a review from zhiqiu October 13, 2022 11:59
bool zero_init) {
for (int i = 0; i < _embedding_dim; ++i) {
for (int i = 0; i < static_cast<int>(_embedding_dim); ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (int i = 0; i < static_cast<int>(_embedding_dim); ++i) {
for (size_t i = 0; i < _embedding_dim; ++i) {

Same for others.

@@ -177,7 +177,7 @@ paddle::framework::GpuPsCommGraph GraphTable::make_gpu_ps_graph(
}));
}
}
for (int i = 0; i < (int)tasks.size(); i++) tasks[i].get();
for (int i = 0; i < static_cast<int>(tasks.size()); i++) tasks[i].get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (int i = 0; i < static_cast<int>(tasks.size()); i++) tasks[i].get();
for (size_t i = 0; i < tasks.size(); i++) tasks[i].get();

@@ -120,7 +120,7 @@ paddle::framework::GpuPsCommGraphFea GraphTable::make_gpu_ps_graph_fea(
res.init_on_cpu(tot_len, (unsigned int)node_ids.size(), slot_num);
unsigned int offset = 0, ind = 0;
for (int i = 0; i < task_pool_size_; i++) {
for (int j = 0; j < (int)node_id_array[i].size(); j++) {
for (int j = 0; j < static_cast<int>(node_id_array[i].size()); j++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (int j = 0; j < static_cast<int>(node_id_array[i].size()); j++) {
for (size_t j = 0; j < node_id_array[i].size(); j++) {

zhiqiu
zhiqiu previously approved these changes Oct 18, 2022
Copy link
Contributor

@zhiqiu zhiqiu left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1
Copy link
Contributor

luotao1 commented Oct 18, 2022

请根据 代码风格检查指南 修复下CodeStyle流水线

@Li-fAngyU Li-fAngyU requested review from zhiqiu and removed request for zhiqiu October 19, 2022 01:49
@Li-fAngyU Li-fAngyU requested review from luotao1 and zhiqiu and removed request for luotao1 October 19, 2022 01:49
@luotao1 luotao1 merged commit be273ea into PaddlePaddle:develop Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants