Skip to content

Commit 0861136

Browse files
committed
remove const_cast
1 parent 2e982b3 commit 0861136

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

paddle/fluid/distributed/table/memory_sparse_table.cc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ namespace paddle {
2727
namespace distributed {
2828

2929
// TODO(zhaocaibei123): configure
30-
bool FLAGS_pslib_create_value_when_push = false;
31-
int FLAGS_pslib_table_save_max_retry = 3;
32-
bool FLAGS_pslib_enable_create_feasign_randomly = false;
30+
bool FLAGS_pserver_create_value_when_push = false;
31+
int FLAGS_pserver_table_save_max_retry = 3;
32+
bool FLAGS_pserver_enable_create_feasign_randomly = false;
3333

3434
int32_t MemorySparseTable::initialize() {
3535
_shards_task_pool.resize(_task_pool_size);
@@ -142,7 +142,7 @@ int32_t MemorySparseTable::load(const std::string& path,
142142
LOG(ERROR) << "MemorySparseTable load failed, retry it! path:"
143143
<< channel_config.path << " , retry_num=" << retry_num;
144144
}
145-
if (retry_num > paddle::distributed::FLAGS_pslib_table_save_max_retry) {
145+
if (retry_num > paddle::distributed::FLAGS_pserver_table_save_max_retry) {
146146
LOG(ERROR) << "MemorySparseTable load failed reach max limit!";
147147
exit(-1);
148148
}
@@ -213,7 +213,7 @@ int32_t MemorySparseTable::load_local_fs(const std::string& path,
213213
<< file_list[file_start_idx + i]
214214
<< " , retry_num=" << retry_num;
215215
}
216-
if (retry_num > paddle::distributed::FLAGS_pslib_table_save_max_retry) {
216+
if (retry_num > paddle::distributed::FLAGS_pserver_table_save_max_retry) {
217217
LOG(ERROR) << "MemorySparseTable load failed reach max limit!";
218218
exit(-1);
219219
}
@@ -293,7 +293,7 @@ int32_t MemorySparseTable::save(const std::string& dirname,
293293
if (is_write_failed) {
294294
_afs_client.remove(channel_config.path);
295295
}
296-
if (retry_num > paddle::distributed::FLAGS_pslib_table_save_max_retry) {
296+
if (retry_num > paddle::distributed::FLAGS_pserver_table_save_max_retry) {
297297
LOG(ERROR) << "MemorySparseTable save prefix failed reach max limit!";
298298
exit(-1);
299299
}
@@ -424,13 +424,11 @@ int32_t MemorySparseTable::pull_sparse(float* pull_values,
424424
size_t data_size = value_size - mf_value_size;
425425
if (itr == local_shard.end()) {
426426
// ++missed_keys;
427-
if (FLAGS_pslib_create_value_when_push) {
427+
if (FLAGS_pserver_create_value_when_push) {
428428
memset(data_buffer, 0, sizeof(float) * data_size);
429429
} else {
430430
auto& feature_value = local_shard[key];
431431
feature_value.resize(data_size);
432-
// float* data_ptr =
433-
// const_cast<float*>(feature_value.data());
434432
float* data_ptr = feature_value.data();
435433
_value_accesor->create(&data_buffer_ptr, 1);
436434
memcpy(data_ptr, data_buffer_ptr,
@@ -497,7 +495,7 @@ int32_t MemorySparseTable::push_sparse(const uint64_t* keys,
497495
auto itr = local_shard.find(key);
498496
if (itr == local_shard.end()) {
499497
VLOG(0) << "sparse table push_sparse: " << key << "not found!";
500-
if (FLAGS_pslib_enable_create_feasign_randomly &&
498+
if (FLAGS_pserver_enable_create_feasign_randomly &&
501499
!_value_accesor->create_value(1, update_data)) {
502500
continue;
503501
}
@@ -511,7 +509,6 @@ int32_t MemorySparseTable::push_sparse(const uint64_t* keys,
511509
}
512510

513511
auto& feature_value = itr.value();
514-
// float* value_data = const_cast<float*>(feature_value.data());
515512
float* value_data = feature_value.data();
516513
size_t value_size = feature_value.size();
517514

@@ -574,7 +571,7 @@ int32_t MemorySparseTable::_push_sparse(const uint64_t* keys,
574571
const float* update_data = values[push_data_idx];
575572
auto itr = local_shard.find(key);
576573
if (itr == local_shard.end()) {
577-
if (FLAGS_pslib_enable_create_feasign_randomly &&
574+
if (FLAGS_pserver_enable_create_feasign_randomly &&
578575
!_value_accesor->create_value(1, update_data)) {
579576
continue;
580577
}
@@ -587,7 +584,6 @@ int32_t MemorySparseTable::_push_sparse(const uint64_t* keys,
587584
itr = local_shard.find(key);
588585
}
589586
auto& feature_value = itr.value();
590-
// float* value_data = const_cast<float*>(feature_value.data());
591587
float* value_data = feature_value.data();
592588
size_t value_size = feature_value.size();
593589
if (value_size == value_col) { // 已拓展到最大size, 则就地update
@@ -598,7 +594,6 @@ int32_t MemorySparseTable::_push_sparse(const uint64_t* keys,
598594
_value_accesor->update(&data_buffer_ptr, &update_data, 1);
599595
if (_value_accesor->need_extend_mf(data_buffer)) {
600596
feature_value.resize(value_col);
601-
// value_data = const_cast<float*>(feature_value.data());
602597
value_data = feature_value.data();
603598
_value_accesor->create(&value_data, 1);
604599
}

0 commit comments

Comments
 (0)