提交 e6778337 编写于 作者: Q Qiao Longfei

code clean

上级 5c65eff6
...@@ -73,18 +73,6 @@ static inline void parse_line( ...@@ -73,18 +73,6 @@ static inline void parse_line(
} }
} }
static void print_map(
std::unordered_map<std::string, std::vector<int64_t>>* map) {
for (auto it = map->begin(); it != map->end(); ++it) {
std::cout << it->first << " -> ";
std::cout << "[";
for (auto& i : it->second) {
std::cout << i << " ";
}
std::cout << "]\n";
}
}
class Reader { class Reader {
public: public:
virtual ~Reader() {} virtual ~Reader() {}
...@@ -162,10 +150,6 @@ void ReadThread(const std::vector<std::string>& file_list, ...@@ -162,10 +150,6 @@ void ReadThread(const std::vector<std::string>& file_list,
VLOG(3) << "reader inited"; VLOG(3) << "reader inited";
uint64_t t0 = GetTimeInSec();
int i = 0;
while (reader.HasNext()) { while (reader.HasNext()) {
batch_data.clear(); batch_data.clear();
batch_data.reserve(batch_size); batch_data.reserve(batch_size);
...@@ -186,7 +170,6 @@ void ReadThread(const std::vector<std::string>& file_list, ...@@ -186,7 +170,6 @@ void ReadThread(const std::vector<std::string>& file_list,
break; break;
} }
} }
// print_map(&batch_data[0]);
std::vector<framework::LoDTensor> lod_datas; std::vector<framework::LoDTensor> lod_datas;
...@@ -224,19 +207,10 @@ void ReadThread(const std::vector<std::string>& file_list, ...@@ -224,19 +207,10 @@ void ReadThread(const std::vector<std::string>& file_list,
queue->Push(lod_datas); queue->Push(lod_datas);
VLOG(4) << "push one data, queue_size=" << queue->Size(); VLOG(4) << "push one data, queue_size=" << queue->Size();
if (i != 0 && i % 100 == 0) {
uint64_t t1 = GetTimeInSec();
float line_per_s = 100 * batch_size * 1000000 / (t1 - t0);
VLOG(3) << "[" << thread_id << "]"
<< " line_per_second = " << line_per_s;
t0 = t1;
}
i++;
} }
(*thread_status)[thread_id] = Stopped; (*thread_status)[thread_id] = Stopped;
VLOG(3) << "thread " << thread_id << " exited"; VLOG(3) << "set status to stopped, thread " << thread_id << " exited";
} }
} // namespace reader } // namespace reader
......
...@@ -39,15 +39,6 @@ void ReadThread(const std::vector<std::string>& file_list, ...@@ -39,15 +39,6 @@ void ReadThread(const std::vector<std::string>& file_list,
int thread_id, std::vector<ReaderThreadStatus>* thread_status, int thread_id, std::vector<ReaderThreadStatus>* thread_status,
std::shared_ptr<LoDTensorBlockingQueue> queue); std::shared_ptr<LoDTensorBlockingQueue> queue);
inline uint64_t GetTimeInSec() {
using clock = std::conditional<std::chrono::high_resolution_clock::is_steady,
std::chrono::high_resolution_clock,
std::chrono::steady_clock>::type;
return std::chrono::duration_cast<std::chrono::microseconds>(
clock::now().time_since_epoch())
.count();
}
class CTRReader : public framework::FileReader { class CTRReader : public framework::FileReader {
public: public:
explicit CTRReader(const std::shared_ptr<LoDTensorBlockingQueue>& queue, explicit CTRReader(const std::shared_ptr<LoDTensorBlockingQueue>& queue,
......
...@@ -33,6 +33,7 @@ using paddle::operators::reader::LoDTensorBlockingQueueHolder; ...@@ -33,6 +33,7 @@ using paddle::operators::reader::LoDTensorBlockingQueueHolder;
using paddle::operators::reader::CTRReader; using paddle::operators::reader::CTRReader;
using paddle::framework::LoDTensor; using paddle::framework::LoDTensor;
using paddle::framework::LoD; using paddle::framework::LoD;
using paddle::framework::DDim;
using paddle::platform::CPUPlace; using paddle::platform::CPUPlace;
static void generatedata(const std::vector<std::string>& data, static void generatedata(const std::vector<std::string>& data,
...@@ -73,17 +74,17 @@ TEST(CTR_READER, read_data) { ...@@ -73,17 +74,17 @@ TEST(CTR_READER, read_data) {
std::vector<int64_t> label_value = {0, 0, 1, 0, 1, 1, 0, 1, 1, 1}; std::vector<int64_t> label_value = {0, 0, 1, 0, 1, 1, 0, 1, 1, 1};
std::vector<std::tuple<LoD, std::vector<int64_t>>> data_slot_6002{ std::vector<std::tuple<LoD, std::vector<int64_t>>> data_slot_6002{
{{{0, 1, 2}}, {0, 0}}, {{{0, 1, 2, 7}}, {0, 0, 10, 11, 12, 13, 14}},
{{{0, 5, 6}}, {10, 11, 12, 13, 14, 0}}, {{{0, 1, 2, 3}}, {0, 0, 0}},
{{{0, 1, 2}}, {0, 0}}, {{{0, 1, 2, 3}}, {30, 0, 40}},
{{{0, 1, 2}}, {30, 0}}, {{{0, 1}}, {0}}};
{{{0, 1, 2}}, {40, 0}}};
std::vector<std::tuple<LoD, std::vector<int64_t>>> data_slot_6003{ std::vector<std::tuple<LoD, std::vector<int64_t>>> data_slot_6003{
{{{0, 1, 4}}, {1, 5, 6, 7}}, {{{0, 1, 4, 5}}, {1, 5, 6, 7, 0}},
{{{0, 1, 5}}, {0, 15, 16, 17, 18}}, {{{0, 4, 5, 6}}, {15, 16, 17, 18, 0, 0}},
{{{0, 1, 2}}, {0, 0}}, {{{0, 1, 3, 4}}, {31, 35, 36, 41}},
{{{0, 1, 3}}, {31, 35, 36}}, {{{0, 3}}, {47, 48, 49}}};
{{{0, 1, 4}}, {41, 47, 48, 49}}};
std::vector<DDim> label_dims = {{1, 3}, {1, 3}, {1, 3}, {1, 1}};
LoDTensorBlockingQueueHolder queue_holder; LoDTensorBlockingQueueHolder queue_holder;
int capacity = 64; int capacity = 64;
...@@ -91,7 +92,7 @@ TEST(CTR_READER, read_data) { ...@@ -91,7 +92,7 @@ TEST(CTR_READER, read_data) {
std::shared_ptr<LoDTensorBlockingQueue> queue = queue_holder.GetQueue(); std::shared_ptr<LoDTensorBlockingQueue> queue = queue_holder.GetQueue();
int batch_size = 2; int batch_size = 3;
int thread_num = 1; int thread_num = 1;
std::vector<std::string> slots = {"6002", "6003"}; std::vector<std::string> slots = {"6002", "6003"};
std::vector<std::string> file_list; std::vector<std::string> file_list;
...@@ -103,15 +104,15 @@ TEST(CTR_READER, read_data) { ...@@ -103,15 +104,15 @@ TEST(CTR_READER, read_data) {
reader.Start(); reader.Start();
size_t batch_num = std::ceil(ctr_data.size() / batch_size) * thread_num; size_t batch_num =
std::ceil(static_cast<float>(ctr_data.size()) / batch_size) * thread_num;
for (size_t i = 0; i < batch_num; ++i) { for (size_t i = 0; i < batch_num; ++i) {
std::vector<LoDTensor> out; std::vector<LoDTensor> out;
reader.ReadNext(&out); reader.ReadNext(&out);
ASSERT_EQ(out.size(), slots.size() + 1); ASSERT_EQ(out.size(), slots.size() + 1);
auto& label_tensor = out.back(); auto& label_tensor = out.back();
ASSERT_EQ(label_tensor.dims(), ASSERT_EQ(label_tensor.dims(), label_dims[i]);
paddle::framework::make_ddim({1, batch_size}));
for (size_t j = 0; j < batch_size && i * batch_num + j < ctr_data.size(); for (size_t j = 0; j < batch_size && i * batch_num + j < ctr_data.size();
++j) { ++j) {
auto& label = label_tensor.data<int64_t>()[j]; auto& label = label_tensor.data<int64_t>()[j];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册