opencl backend: separate copying of memory to device from buffer allocation
commit033b129feec94d9bf4482b318bf7e02c359a5119
authorSven Verdoolaege <skimo@kotnet.org>
Wed, 10 Sep 2014 12:08:22 +0000 (10 14:08 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 16 Sep 2014 07:36:18 +0000 (16 09:36 +0200)
treeb4d52ff680cf9469cddde9cb0e80871193325e4f
parent4ab97338c222207d4300fc6b90738f246f958660
opencl backend: separate copying of memory to device from buffer allocation

There does not appear to be any particular reason why this copying
was combined together with the buffer allocation in 2b8a598 (Add OpenCL
backend, Fri Jun 21 11:57:05 2013 +0200).
However, ever since fd0e714 (opencl backend: avoid uninitialized
cl_mem objects, Wed May 7 12:56:20 2014 +0100), we allocate a buffer
that contains at least one element, even if the original host array
contains no elements.  In principle, C99 does not allow arrays with
zero elements, but most compilers do and so do we.  In this cases
we would therefore be copying data from memory beyond the host array.
This copying does not seem to have caused any problems in practice so far,
but we should still fix it.

An added advantage of separating the copying from the allocation
is that the cuda backend does the same, such that the difference
between the two backends is reduced by this commit.

Tested-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
opencl.c