Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check errors for the CUDA kernel calls. #5436

Merged
merged 1 commit into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions paddle/framework/operator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ void OperatorWithKernel::Run(const Scope& scope,
}

kernel_iter->second->Compute(ctx);

// throws errors if have.
dev_ctx.Finish();
}

} // namespace framework
Expand Down
5 changes: 0 additions & 5 deletions paddle/operators/math/detail/lstm_gpu_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,6 @@ void gpu_lstm_backward(const platform::DeviceContext& context, Op op,
op, value, grad, frameSize, batchSize, active_node, active_gate,
active_state);
}

cudaStreamSynchronize(stream);
// TODO(qingqing): Add cuda error check for each kernel.
cudaError_t err = cudaGetLastError();
PADDLE_ENFORCE(err, cudaGetErrorString(err));
}

} // namespace detail
Expand Down
5 changes: 5 additions & 0 deletions paddle/platform/device_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ void CUDADeviceContext::Wait() const {
PADDLE_ENFORCE(cudaStreamSynchronize(stream_));
}

void CUDADeviceContext::Finish() const {
Wait();
PADDLE_ENFORCE(cudaGetLastError());
}

Eigen::GpuDevice* CUDADeviceContext::eigen_device() const {
return eigen_device_.get();
}
Expand Down
5 changes: 5 additions & 0 deletions paddle/platform/device_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class DeviceContext {
DeviceType* GetEigenDevice() const;

virtual void Wait() const {}

virtual void Finish() const {}
};

class CPUDeviceContext : public DeviceContext {
Expand Down Expand Up @@ -77,6 +79,9 @@ class CUDADeviceContext : public DeviceContext {
/*! \brief Wait for all operations completion in the stream. */
void Wait() const override;

/*! \brief Check potential errors for the cuda kernel calls. */
void Finish() const override;

/*! \brief Return place in the device context. */
Place GetPlace() const override;

Expand Down