提交 220db4f3 编写于 作者: Y Yancey1989

clean code

上级 cb8a24be
......@@ -118,7 +118,6 @@ std::unique_ptr<ir::Graph> BuildStrategy::Apply(
std::unique_ptr<ir::Graph> graph(new ir::Graph(main_program));
for (std::shared_ptr<ir::Pass> &pass : pass_builder_->AllPasses()) {
VLOG(5) << "run pass: " << pass->Type();
if (pass->Type() == "multi_devices_pass") {
pass->Erase("places");
pass->SetNotOwned<const std::vector<platform::Place>>("places", &places);
......
......@@ -329,7 +329,6 @@ std::unique_ptr<ir::Graph> MultiDevSSAGraphBuilder::ApplyImpl(
std::unordered_map<std::string, int> sharded_var_device;
for (ir::Node *node : sorted_ops) {
VLOG(5) << "op name: " << node->Op()->Type();
if (boost::get<int>(
node->Op()->GetAttr(OpProtoAndCheckerMaker::OpRoleAttrName())) ==
static_cast<int>(OpRole::kRPC)) {
......@@ -366,11 +365,9 @@ std::unique_ptr<ir::Graph> MultiDevSSAGraphBuilder::ApplyImpl(
// is true only for the op that scale the final scalar loss.
// It also assumes backward op will always follow the forward op in
// the block.
VLOG(5) << "this is loss scale op!";
is_forwarding = false;
} else {
int op_dev_id = GetOpDeviceID(result, node, sharded_var_device);
VLOG(5) << "on device id: " << op_dev_id;
if (op_dev_id != -1) { // This op only runs on one specific device.
CreateComputationalOp(&result, node, op_dev_id);
for (ir::Node *n : node->outputs) {
......
......@@ -20,8 +20,6 @@ limitations under the License. */
#include <unordered_set>
#include <vector>
#include "ThreadPool.h"
#include "paddle/fluid/framework/details/build_strategy.h"
#include "paddle/fluid/framework/details/execution_strategy.h"
#include "paddle/fluid/framework/executor.h"
......
......@@ -58,10 +58,7 @@ int64_t GetEagerDeletionThreshold() {
(static_cast<int64_t>(1) << 30));
}
Scope::~Scope() {
VLOG(5) << "~Scope()";
DropKids();
}
Scope::~Scope() { DropKids(); }
Scope& Scope::NewScope() const {
SCOPE_LOCK_GUARD
......
......@@ -48,18 +48,9 @@ void ThreadPool::Init() {
ThreadPool::ThreadPool(int num_threads) : running_(true) {
threads_.resize(num_threads);
for (int i = 0; i < num_threads; ++i) {
// for (auto& thread : threads_) {
for (auto& thread : threads_) {
// TODO(Yancey1989): binding the thread on the specify CPU number
threads_[i].reset(
new std::thread(std::bind(&ThreadPool::TaskLoop, this, i)));
/**
sched_param sch;
int policy;
pthread_getschedparam(threads_[i]->native_handle(), &policy, &sch);
if (pthread_setschedparam(threads_[i]->native_handle(), SCHED_FIFO, &sch)) {
VLOG(1) << "Failed to setschedparam: " << errno;
}**/
thread.reset(new std::thread(std::bind(&ThreadPool::TaskLoop, this)));
}
}
......@@ -77,7 +68,7 @@ ThreadPool::~ThreadPool() {
}
}
void ThreadPool::TaskLoop(int i) {
void ThreadPool::TaskLoop() {
while (true) {
Task task;
......
......@@ -99,7 +99,7 @@ class ThreadPool {
// The constructor starts threads to run TaskLoop, which retrieves
// and runs tasks from the queue.
void TaskLoop(int i);
void TaskLoop();
// Init is called by GetInstance.
static void Init();
......
......@@ -59,47 +59,3 @@ TEST(ThreadPool, ConcurrentRun) {
}
EXPECT_EQ(sum, ((n + 1) * n) / 2);
}
static int64_t GetTS() {
struct timeval tp;
gettimeofday(&tp, NULL);
return tp.tv_sec * 1000000 + tp.tv_usec;
}
void multi_call(std::function<void()> call) {
for (int i = 0; i < 500; ++i) {
call();
}
}
TEST(ThreadPool, PERFORMANCE) {
auto sum = [] {
int a = 0;
for (int i = 0; i < 1000; ++i) {
a += i;
}
};
// framework::ThreadPool *pool = new framework::ThreadPool(2);
int64_t start = GetTS();
for (int i = 0; i < 1000; ++i) {
// int64_t s = GetTS();
framework::Async(std::move(sum));
// pool->Run(std::move(sum));
// VLOG(5) << "push to pool spent : " << GetTS() - s << " (us).";
}
VLOG(5) << "pool spent: " << GetTS() - start << " (us).";
start = GetTS();
for (int i = 0; i < 1000; ++i) {
sum();
}
VLOG(5) << "sequence call spent: " << GetTS() - start << " (us).";
std::vector<std::thread> threads;
start = GetTS();
for (int i = 0; i < 2; ++i) {
std::thread t(multi_call, std::ref(sum));
threads.push_back(std::move(t));
}
for (auto& thread : threads) {
thread.join();
}
VLOG(5) << "two threads spent: " << GetTS() - start << " (us).";
}
......@@ -67,12 +67,9 @@ class BlockingQueue {
}
bool Receive(T* elem) {
VLOG(1) << "blocking queue::Receive ...";
std::unique_lock<std::mutex> lock(mutex_);
receive_cv_.wait(lock, [&] { return !queue_.empty() || closed_; });
VLOG(1) << "queue_.empty()=" << queue_.empty();
if (!queue_.empty()) {
if (elem == nullptr) VLOG(1) << "elem is nullptr";
PADDLE_ENFORCE_NOT_NULL(elem);
*elem = queue_.front();
if (LIKELY(!speed_test_mode_)) {
......
......@@ -82,13 +82,11 @@ void BufferedReader::StartImpl() {
}
void BufferedReader::ReadNextImpl(std::vector<framework::LoDTensor> *out) {
VLOG(1) << "ReadNextImpl start on place: " << place_;
if (position_.empty()) {
out->clear();
return;
}
size_t i = position_.front().get();
VLOG(1) << "position front: " << i;
position_.pop();
if (i == -1UL) {
......@@ -105,7 +103,6 @@ void BufferedReader::ReadNextImpl(std::vector<framework::LoDTensor> *out) {
ReadAsync(prev_pos_);
}
prev_pos_ = i;
VLOG(1) << "success ReadNextImpl";
}
} // namespace reader
......
......@@ -25,15 +25,9 @@ class CreateDoubleBufferReaderOp : public framework::OperatorBase {
private:
void RunImpl(const framework::Scope& scope,
const platform::Place& dev_place) const override {
VLOG(1) << "find var in scope: " << &scope;
auto* out_var = scope.FindVar(Output("Out"));
VLOG(1) << "var " << Output("Out") << " -> " << out_var;
auto* out = out_var->GetMutable<framework::ReaderHolder>();
// auto* out = scope.Var(Output("Out"))
// ->template GetMutable<framework::ReaderHolder>();
auto* out = scope.Var(Output("Out"))
->template GetMutable<framework::ReaderHolder>();
if (out->Get() != nullptr) {
VLOG(1) << Output("Out") << " is not nullptr.";
return;
}
const auto& underlying_reader = scope.FindVar(Input("UnderlyingReader"))
......@@ -52,11 +46,8 @@ class CreateDoubleBufferReaderOp : public framework::OperatorBase {
sin >> num;
place = platform::CUDAPlace(static_cast<int>(num));
}
VLOG(1) << "create buffered reader on " << place;
out->Reset(framework::MakeDecoratedReader<BufferedReader>(underlying_reader,
place, 2));
VLOG(1) << "Reset Buffered Reader in var: "
<< scope.FindVar(Input("UnderlyingReader"));
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册