Skip to content

Commit

Permalink
deal with PADDLE_ENFORCE_CUDA_SUCCESS macro in pr PaddlePaddle#23816
Browse files Browse the repository at this point in the history
  • Loading branch information
Shixiaowei02 committed Apr 22, 2020
1 parent 2b0e12b commit bb6690a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 31 deletions.
13 changes: 3 additions & 10 deletions paddle/fluid/platform/device_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,17 @@ class CUDAContext {
<< "Please recompile or reinstall Paddle with compatible CUDNN "
"version.";
}
PADDLE_ENFORCE_CUDA_SUCCESS(dynload::cudnnCreate(&cudnn_handle_));
PADDLE_ENFORCE_CUDA_SUCCESS(
dynload::cudnnCreate(&cudnn_handle_),
platform::errors::Fatal(
"Failed to create Cudnn handle in DeviceContext"));
PADDLE_ENFORCE_CUDA_SUCCESS(
dynload::cudnnSetStream(cudnn_handle_, RawStream()),
platform::errors::Fatal(
"Failed to set stream for Cudnn handle in DeviceContext"));
dynload::cudnnSetStream(cudnn_handle_, RawStream()));
} else {
cudnn_handle_ = nullptr;
}
}

void DestoryCuDNNContext() {
if (cudnn_handle_) {
PADDLE_ENFORCE_CUDA_SUCCESS(
dynload::cudnnDestroy(cudnn_handle_),
platform::errors::Fatal("Failed to destory Cudnn handle"));
PADDLE_ENFORCE_CUDA_SUCCESS(dynload::cudnnDestroy(cudnn_handle_));
}
cudnn_handle_ = nullptr;
}
Expand Down
16 changes: 4 additions & 12 deletions paddle/fluid/platform/stream/cuda_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@ bool CUDAStream::Init(const Place& place, const Priority& priority) {
CUDADeviceGuard guard(boost::get<CUDAPlace>(place_).device);
if (priority == Priority::kHigh) {
PADDLE_ENFORCE_CUDA_SUCCESS(
cudaStreamCreateWithPriority(&stream_, kDefaultFlag, -1),
platform::errors::Fatal("High priority cuda stream creation failed."));
cudaStreamCreateWithPriority(&stream_, kDefaultFlag, -1));
} else if (priority == Priority::kNormal) {
PADDLE_ENFORCE_CUDA_SUCCESS(
cudaStreamCreateWithPriority(&stream_, kDefaultFlag, 0),
platform::errors::Fatal(
"Normal priority cuda stream creation failed."));
cudaStreamCreateWithPriority(&stream_, kDefaultFlag, 0));
}
callback_manager_.reset(new StreamCallbackManager(stream_));
VLOG(3) << "CUDAStream Init stream: " << stream_
Expand All @@ -49,9 +46,7 @@ void CUDAStream::Destroy() {
Wait();
WaitCallback();
if (stream_) {
PADDLE_ENFORCE_CUDA_SUCCESS(
cudaStreamDestroy(stream_),
platform::errors::Fatal("Cuda stream destruction failed."));
PADDLE_ENFORCE_CUDA_SUCCESS(cudaStreamDestroy(stream_));
}
stream_ = nullptr;
}
Expand All @@ -67,10 +62,7 @@ void CUDAStream::Wait() const {
}
#endif

PADDLE_ENFORCE_CUDA_SUCCESS(
e_sync, platform::errors::Fatal(
"cudaStreamSynchronize raises error: %s, errono: %d",
cudaGetErrorString(e_sync), static_cast<int>(e_sync)));
PADDLE_ENFORCE_CUDA_SUCCESS(e_sync);
}

} // namespace stream
Expand Down
12 changes: 3 additions & 9 deletions paddle/fluid/platform/stream/cuda_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,15 @@ class CUDAStream final {
template <typename Callback>
void RecordEvent(cudaEvent_t ev, Callback callback) const {
callback();
PADDLE_ENFORCE_CUDA_SUCCESS(
cudaEventRecord(ev, stream_),
platform::errors::Fatal("CUDA event recording failed."));
PADDLE_ENFORCE_CUDA_SUCCESS(cudaEventRecord(ev, stream_));
}

void RecordEvent(cudaEvent_t ev) const {
PADDLE_ENFORCE_CUDA_SUCCESS(
cudaEventRecord(ev, stream_),
platform::errors::Fatal("CUDA event recording failed."));
PADDLE_ENFORCE_CUDA_SUCCESS(cudaEventRecord(ev, stream_));
}

void WaitEvent(cudaEvent_t ev) const {
PADDLE_ENFORCE_CUDA_SUCCESS(
cudaStreamWaitEvent(stream_, ev, 0),
platform::errors::Fatal("Failed to wait event."));
PADDLE_ENFORCE_CUDA_SUCCESS(cudaStreamWaitEvent(stream_, ev, 0));
}

void Wait() const;
Expand Down

0 comments on commit bb6690a

Please sign in to comment.