Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gongweibao committed Mar 21, 2018
1 parent 735a5c0 commit e25a270
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 68 deletions.
4 changes: 0 additions & 4 deletions benchmark/cluster/vgg16/vgg16_fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,6 @@ def train_loop(exe, trainer_prog):
len(data) / (time.time() - ts))
) # The accuracy is the accumulation of batches, but not the current batch.

if batch_id >= 20:
print("test complete after batch_id >=20")
break

pass_elapsed = time.time() - start_time
pass_train_acc = train_pass_acc.eval()
pass_test_acc = test(exe)
Expand Down
16 changes: 9 additions & 7 deletions paddle/fluid/operators/detail/grpc_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ void ProcGetResponse(const VarHandle& var_h, const grpc::ByteBuffer& msg);

class BaseProcessor {
public:
explicit BaseProcessor(std::shared_ptr<grpc::Channel> ch) {
stub_ = sendrecv::SendRecvService::NewStub(ch);
context_ = NULL;
}
explicit BaseProcessor(std::shared_ptr<grpc::Channel> ch) { context_ = NULL; }

virtual ~BaseProcessor() {}

Expand All @@ -86,7 +83,6 @@ class BaseProcessor {

virtual void Process() = 0;

std::unique_ptr<sendrecv::SendRecvService::Stub> stub_;
std::unique_ptr<grpc::ClientContext> context_;
grpc::Status status_;
VarHandle var_h_;
Expand Down Expand Up @@ -137,23 +133,29 @@ class GetProcessor : public BaseProcessor {
class BatchBarrierProcessor : public BaseProcessor {
public:
explicit BatchBarrierProcessor(std::shared_ptr<grpc::Channel> ch)
: BaseProcessor(ch) {}
: BaseProcessor(ch) {
stub_ = sendrecv::SendRecvService::NewStub(ch);
}

virtual ~BatchBarrierProcessor() {}

virtual void Process() {}
sendrecv::VoidMessage reply_;
std::unique_ptr<sendrecv::SendRecvService::Stub> stub_;
};

class FetchBarrierProcessor : public BaseProcessor {
public:
explicit FetchBarrierProcessor(std::shared_ptr<grpc::Channel> ch)
: BaseProcessor(ch) {}
: BaseProcessor(ch) {
stub_ = sendrecv::SendRecvService::NewStub(ch);
}

virtual ~FetchBarrierProcessor() {}

virtual void Process() {}
sendrecv::VariableMessage reply_;
std::unique_ptr<sendrecv::SendRecvService::Stub> stub_;
};

class RPCClient {
Expand Down
40 changes: 0 additions & 40 deletions paddle/fluid/operators/detail/sendrecvop_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,13 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
}
if (platform::is_gpu_place(ctx.GetPlace())) {
#ifdef PADDLE_WITH_CUDA
/*
struct timeval t0_wait, t1_wait;
gettimeofday(&t0_wait, 0);
std::thread::id this_id = std::this_thread::get_id();
*/

PADDLE_ENFORCE(platform::is_gpu_place(tensor.place()));
platform::CPUPlace cpu;
auto& gpu_dev_ctx =
static_cast<const platform::CUDADeviceContext&>(ctx);
auto copy_size = tensor.memory_size();
payload = memory::Alloc(cpu, copy_size);

/*
gettimeofday(&t1_wait, 0);
double t_wait = double((t1_wait.tv_sec - t0_wait.tv_sec) * 1000.0 +
(t1_wait.tv_usec - t0_wait.tv_usec) / 1000.0);
std::stringstream ss;
ss << "se malloc var_name:" << name << ", dims: " << tensor.dims()
<< ", time:" << t_wait << "ms, thread_id:" << this_id;
std::cout << ss.str() << '\n';
*/

memory::Copy(cpu, payload,
boost::get<platform::CUDAPlace>(tensor.place()),
reinterpret_cast<const void*>(tensor.data<void>()),
Expand All @@ -108,30 +92,6 @@ void SerializeToByteBuffer(const std::string& name, framework::Variable* var,
memory::Free(cpu, backing);
};

{
PrintDetail(name, tensor, ctx, "memcopy gpu");
/*
std::stringstream ss;
ss << "se memcpy gpu var_name:" << name
<< ", dims: " << tensor.dims();
std::cout << ss.str() << ", data:";
float* data = reinterpret_cast<float*>(payload);
for (int i = 0; i < 10; i++) {
printf("%.f ", data[i]);
}
printf("\n");
*/
}
/*
gettimeofday(&t1_wait, 0);
t_wait = double((t1_wait.tv_sec - t0_wait.tv_sec) * 1000.0 +
(t1_wait.tv_usec - t0_wait.tv_usec) / 1000.0);
std::stringstream ss2;
ss2 << "se memcpy gpu var_name:" << name << ", dims: " << tensor.dims()
<< ", time:" << t_wait << "ms, thread_id:" << this_id;
std::cout << ss2.str() << '\n';
*/
#endif
} else {
payload = tensor.data<void>();
Expand Down
17 changes: 0 additions & 17 deletions paddle/fluid/operators/detail/sendrecvop_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,6 @@ inline std::type_index ToTypeIndex(sendrecv::VariableMessage::Type type) {
}
}

inline void PrintDetail(std::string name, const framework::Tensor& src,
const platform::DeviceContext& ctx,
std::string post_fix = "") {
if (name != "batch_norm_11.w_1@GRAD.trainer_0") {
return;
}

std::vector<float> vec;
framework::TensorToVector<float>(src, ctx, &vec);

printf("%s name:%s, data:", post_fix.c_str(), name.c_str());
for (uint32_t i = 0; i < vec.size(); i++) {
printf("%.f ", vec[i]);
}
printf("\n");
}

} // namespace detail
} // namespace operators
} // namespace paddle

0 comments on commit e25a270

Please sign in to comment.