Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
225d331
refine profiler && add runtime tracer
cjld Jan 12, 2019
fc6dc7d
test=develop
cjld Jan 12, 2019
41c82ca
test=develop
cjld Jan 12, 2019
e9a625f
test=develop
cjld Jan 12, 2019
98a7543
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
cjld Jan 12, 2019
a84497c
test=develop
cjld Jan 12, 2019
c431b6a
test=develop
cjld Jan 13, 2019
e069fab
test=develop
cjld Jan 13, 2019
31be7bf
test=develop
cjld Jan 14, 2019
d17f79e
test=develop
cjld Jan 15, 2019
bb49a5b
fix bug && test=develop
cjld Jan 18, 2019
c2cb082
add thread id map && test=develop
cjld Jan 20, 2019
18f9158
test=develop
cjld Jan 20, 2019
eeb2aa7
testing
cjld Feb 3, 2019
5510f31
bug fix
cjld Feb 3, 2019
b59cd77
Merge branch 'profiler_refine_tmp' into profiler_refine
cjld Feb 3, 2019
fbd3122
remove cuda event && refine code && test=develop
cjld Feb 3, 2019
29c461f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
cjld Feb 3, 2019
dda480c
test=develop
cjld Feb 3, 2019
fa15b9f
test=develop
cjld Feb 3, 2019
6188131
test=develop
cjld Feb 3, 2019
02158db
fix windows temp file && test=develop
cjld Feb 15, 2019
a1ca223
test=develop
cjld Feb 17, 2019
58dea48
fix windows bug && test=develop
cjld Feb 17, 2019
e46c6b9
fix start up issue && test=develop
cjld Feb 17, 2019
b00bee2
code polish && test=develop
cjld Feb 18, 2019
058bcd8
remove unused code && test=develop
cjld Feb 18, 2019
f0c9f10
add some cupti cbid && test=develop
cjld Feb 18, 2019
f878edf
add FLAGS_multiple_of_cupti_buffer_size && test=develop
cjld Feb 19, 2019
3f29bb8
fix compile error && test=develop
cjld Feb 20, 2019
12ecf7d
add keyword && test=develop
cjld Feb 20, 2019
03a7de2
fix && test=develop
cjld Feb 20, 2019
4f39900
code polish && test=develop
cjld Feb 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion paddle/fluid/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ cc_library(timer SRCS timer.cc)
cc_test(timer_test SRCS timer_test.cc DEPS timer)

cc_library(device_tracer SRCS device_tracer.cc DEPS boost profiler_proto framework_proto ${GPU_CTX_DEPS})
cc_library(profiler SRCS profiler.cc DEPS device_context device_tracer)
if(WITH_GPU)
nv_library(profiler SRCS profiler.cc profiler.cu DEPS device_context device_tracer)
else()
cc_library(profiler SRCS profiler.cc DEPS device_context device_tracer)
endif()
cc_test(profiler_test SRCS profiler_test.cc DEPS profiler)

nv_test(float16_gpu_test SRCS float16_test.cu DEPS lod_tensor)
Expand Down
34 changes: 13 additions & 21 deletions paddle/fluid/platform/profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,6 @@ double Event::CudaElapsedMs(const Event& e) const {
#endif
}

#ifdef PADDLE_WITH_CUDA
static void ForEachDevice(std::function<void(int)> func) {
auto original_device = GetCurrentDeviceId();
int count = GetCUDADeviceCount();
for (int i = 0; i < count; i++) {
SetDeviceId(i);
func(i);
}
SetDeviceId(original_device);
}
#endif

inline EventList& GetEventList() {
if (!g_event_list) {
std::lock_guard<std::mutex> guard(g_all_event_lists_mutex);
Expand Down Expand Up @@ -210,6 +198,15 @@ RecordBlock::~RecordBlock() {
ClearCurBlock();
}

static void BuildVar(const std::string& param_name,
std::initializer_list<const char*> arguments,
paddle::framework::proto::OpDesc::Var* var) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that BuildVar is not used in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mistake, removed.

var->set_parameter(param_name);
for (auto& arg_name : arguments) {
*var->mutable_arguments()->Add() = arg_name;
}
}

void EnableProfiler(ProfilerState state) {
PADDLE_ENFORCE(state != ProfilerState::kDisabled,
"Can't enable profiling, since the input state is ",
Expand All @@ -223,16 +220,11 @@ void EnableProfiler(ProfilerState state) {
should_send_profile_state = true;
GetDeviceTracer()->Enable();
#ifdef PADDLE_WITH_CUDA
if (g_state == ProfilerState::kCUDA || g_state == ProfilerState::kAll) {
if (g_state == ProfilerState::kCUDA || g_state == ProfilerState::kAll ||
g_state == ProfilerState::kCPU) {
// Generate some dummy events first to reduce the startup overhead.
for (int i = 0; i < 5; i++) {
ForEachDevice([](int d) {
DeviceContext* dev_ctx = new CUDADeviceContext(CUDAPlace(d));
Mark("_cuda_startup_");
dev_ctx->Wait();
delete dev_ctx;
});
}
DummyKernelAndEvent();
GetDeviceTracer()->Reset();
}
#endif
// Mark the profiling start.
Expand Down
50 changes: 50 additions & 0 deletions paddle/fluid/platform/profiler.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.

licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#include "paddle/fluid/platform/profiler.h"

#include <cuda.h>

namespace paddle {
namespace platform {

__global__ void DummyKernel(int *a) { a[0] = 0; }

static void ForEachDevice(std::function<void(int)> func) {
auto original_device = GetCurrentDeviceId();
int count = GetCUDADeviceCount();
for (int i = 0; i < count; i++) {
SetDeviceId(i);
func(i);
}
SetDeviceId(original_device);
}

void DummyKernelAndEvent() {
for (int i = 0; i < 5; i++) {
ForEachDevice([](int d) {
CUDADeviceContext *dev_ctx = new CUDADeviceContext(CUDAPlace(d));
Mark("_cuda_startup_");
int *ptr;
PADDLE_ENFORCE(cudaMalloc(&ptr, sizeof(int)));
DummyKernel<<<1, 1, 0, dev_ctx->stream()>>>(ptr);
dev_ctx->Wait();
PADDLE_ENFORCE(cudaFree(ptr));
delete dev_ctx;
Copy link
Contributor

Choose a reason for hiding this comment

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

ptr should be freed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

freed by cudaFree.

});
}
}

} // namespace platform
} // namespace paddle
4 changes: 4 additions & 0 deletions paddle/fluid/platform/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,9 @@ bool ShouldSendProfileState();
void SetProfileListener();
int64_t ListenerId();

#ifdef PADDLE_WITH_CUDA
void DummyKernelAndEvent();
#endif

} // namespace platform
} // namespace paddle