From 29f66c240877228fca30a799bbf9f532647034aa Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Sun, 30 Sep 2018 15:49:04 +0800 Subject: [PATCH] Polish code --- paddle/fluid/platform/device_context.cc | 10 +++++++++- paddle/fluid/pybind/tensor_py.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/platform/device_context.cc b/paddle/fluid/platform/device_context.cc index 7d6c3412ce3..80ffc680c2a 100644 --- a/paddle/fluid/platform/device_context.cc +++ b/paddle/fluid/platform/device_context.cc @@ -167,7 +167,7 @@ class CudnnHolder { if (required_workspace_len > WorkspaceSize()) { ReallocateWorkspace(required_workspace_len); } - cudnn_func(workspace_->ptr()); + cudnn_func(WorkspacePtr()); } ~CudnnHolder() { PADDLE_ENFORCE(dynload::cudnnDestroy(cudnn_handle_)); } @@ -181,6 +181,14 @@ class CudnnHolder { } } + void* WorkspacePtr() const { + if (workspace_ == nullptr) { + return nullptr; + } else { + return workspace_->ptr(); + } + } + void ReallocateWorkspace(size_t required_workspace_len) { if (required_workspace_len <= WorkspaceSize()) { return; diff --git a/paddle/fluid/pybind/tensor_py.h b/paddle/fluid/pybind/tensor_py.h index 0e5fd97951a..1b95ec66bd5 100644 --- a/paddle/fluid/pybind/tensor_py.h +++ b/paddle/fluid/pybind/tensor_py.h @@ -99,7 +99,7 @@ struct CastToPyBufferImpl { py_buffer->shape = reinterpret_cast( malloc(sizeof(Py_ssize_t) * tensor.dims().size())); - for (size_t i = 0; i < tensor.dims().size(); ++i) { + for (int i = 0; i < tensor.dims().size(); ++i) { py_buffer->shape[i] = tensor.dims()[i]; } -- GitLab