summaryrefslogtreecommitdiff
path: root/src/clpp11.hpp
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2018-01-06 16:08:27 +0100
committerGitHub <noreply@github.com>2018-01-06 16:08:27 +0100
commita7ccce196915db7a3b7ea7fe8ea9048f5b1204c6 (patch)
tree27dd8771ee6f913b5a2dabfae115bbe7fbc9d979 /src/clpp11.hpp
parent8040a4e355bdf6531eb9c4c5ae1fe4f792899d24 (diff)
parentad197da08da7ef414db90dbb97e92c575363c280 (diff)
Merge pull request #238 from CNugteren/gemm_api_with_temp_buffer
GEMM API with optional temp buffer
Diffstat (limited to 'src/clpp11.hpp')
-rw-r--r--src/clpp11.hpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/clpp11.hpp b/src/clpp11.hpp
index 6ebf1322..2119f26b 100644
--- a/src/clpp11.hpp
+++ b/src/clpp11.hpp
@@ -614,10 +614,11 @@ class Buffer {
}
// Regular constructor with memory management. If this class does not own the buffer object, then
- // the memory will not be freed automatically afterwards.
+ // the memory will not be freed automatically afterwards. If the size is set to 0, this will
+ // become a stub containing a nullptr
explicit Buffer(const Context &context, const BufferAccess access, const size_t size):
- buffer_(new cl_mem, [access](cl_mem* m) {
- if (access != BufferAccess::kNotOwned) { CheckError(clReleaseMemObject(*m)); }
+ buffer_(new cl_mem, [access, size](cl_mem* m) {
+ if (access != BufferAccess::kNotOwned && size > 0) { CheckError(clReleaseMemObject(*m)); }
delete m;
}),
access_(access) {
@@ -625,7 +626,7 @@ class Buffer {
if (access_ == BufferAccess::kReadOnly) { flags = CL_MEM_READ_ONLY; }
if (access_ == BufferAccess::kWriteOnly) { flags = CL_MEM_WRITE_ONLY; }
auto status = CL_SUCCESS;
- *buffer_ = clCreateBuffer(context(), flags, size*sizeof(T), nullptr, &status);
+ *buffer_ = (size > 0) ? clCreateBuffer(context(), flags, size*sizeof(T), nullptr, &status) : nullptr;
CLCudaAPIError::Check(status, "clCreateBuffer");
}