Skip to content
Snippets Groups Projects
Commit 60c4cea8 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Allocators: allow zero size, return None

parent bdf0a13d
No related branches found
No related tags found
1 merge request!113Better empty handling
...@@ -54,6 +54,11 @@ not complicated:: ...@@ -54,6 +54,11 @@ not complicated::
Allocate a :class:`pyopencl.Buffer` of the given *size*. Allocate a :class:`pyopencl.Buffer` of the given *size*.
.. versionchanged :: 2020.2
The allocator will succeed even for allocations of size zero,
returning *None*.
.. class:: ImmediateAllocator(queue, mem_flags=pyopencl.mem_flags.READ_WRITE) .. class:: ImmediateAllocator(queue, mem_flags=pyopencl.mem_flags.READ_WRITE)
*mem_flags* takes its values from :class:`pyopencl.mem_flags` and corresponds *mem_flags* takes its values from :class:`pyopencl.mem_flags` and corresponds
...@@ -68,6 +73,11 @@ not complicated:: ...@@ -68,6 +73,11 @@ not complicated::
Allocate a :class:`pyopencl.Buffer` of the given *size*. Allocate a :class:`pyopencl.Buffer` of the given *size*.
.. versionchanged :: 2020.2
The allocator will succeed even for allocations of size zero,
returning *None*.
.. class:: MemoryPool(allocator[, leading_bits_in_bin_id]) .. class:: MemoryPool(allocator[, leading_bits_in_bin_id])
A memory pool for OpenCL device memory. *allocator* must be an instance of A memory pool for OpenCL device memory. *allocator* must be an instance of
......
...@@ -104,6 +104,9 @@ namespace ...@@ -104,6 +104,9 @@ namespace
pointer_type allocate(size_type s) pointer_type allocate(size_type s)
{ {
if (s == 0)
return nullptr;
return pyopencl::create_buffer(m_context->data(), m_flags, s, 0); return pyopencl::create_buffer(m_context->data(), m_flags, s, 0);
} }
}; };
...@@ -137,6 +140,9 @@ namespace ...@@ -137,6 +140,9 @@ namespace
pointer_type allocate(size_type s) pointer_type allocate(size_type s)
{ {
if (s == 0)
return nullptr;
pointer_type ptr = pyopencl::create_buffer( pointer_type ptr = pyopencl::create_buffer(
m_context->data(), m_flags, s, 0); m_context->data(), m_flags, s, 0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment