From 7798c46dd4e9caa7d02c8426cc14e98140579516 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Sun, 7 Oct 2012 12:40:54 -0500 Subject: [PATCH] Fix allocation of arrays in CompiledKernel. --- loopy/compiled.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/loopy/compiled.py b/loopy/compiled.py index 41f401426..a7bade92e 100644 --- a/loopy/compiled.py +++ b/loopy/compiled.py @@ -191,12 +191,17 @@ class CompiledKernel: from pytools import all assert all(s > 0 for s in numpy_strides) - alloc_size = sum(astrd*(alen-1) - for alen, astrd in zip(shape, numpy_strides)) + 1 + alloc_size = (sum(astrd*(alen-1) + for alen, astrd in zip(shape, numpy_strides)) + + arg.dtype.itemsize) + + if allocator is None: + storage = cl.Buffer(queue.context, cl.mem_flags.READ_WRITE, alloc_size) + else: + storage = allocator(alloc_size) - storage = cl_array.empty(queue, alloc_size, arg.dtype, - allocator=allocator) - val = cl_array.as_strided(storage, shape, numpy_strides) + val = cl_array.Array(queue, shape, arg.dtype, + strides=numpy_strides, data=storage, allocator=allocator) else: assert _arg_matches_spec(arg, val, kwargs) -- GitLab