[Piglit] [PATCH] cl: Add a test for clEnqueueCopyBuffer
Tom Stellard
tom at stellard.net
Fri Nov 15 16:34:40 PST 2013
On Fri, Nov 15, 2013 at 04:38:33PM -0600, Aaron Watry wrote:
> On Fri, Nov 15, 2013 at 1:46 PM, Tom Stellard <tom at stellard.net> wrote:
> > From: Tom Stellard <thomas.stellard at amd.com>
> >
> > ---
> > tests/all_cl.tests | 1 +
> > tests/cl/api/CMakeLists.cl.txt | 1 +
> > tests/cl/api/enqueue-copy-buffer.c | 87 ++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 89 insertions(+)
> > create mode 100644 tests/cl/api/enqueue-copy-buffer.c
> >
> > diff --git a/tests/all_cl.tests b/tests/all_cl.tests
> > index 877119e..a648e1a 100644
> > --- a/tests/all_cl.tests
> > +++ b/tests/all_cl.tests
> > @@ -59,6 +59,7 @@ add_plain_test(api, 'clRetainComandQueue and clReleaseCommandQueue', ['cl-api-re
> > add_plain_test(api, 'clGetCommandQueueInfo', ['cl-api-get-command-queue-info'])
> > # Memory objects
> > add_plain_test(api, 'clCreateBuffer', ['cl-api-create-buffer'])
> > +add_plain_test(api, 'clEnqueueCopyBuffer', ['cl-api-enqueue-copy-buffer'])
> > add_plain_test(api, 'clEnqueueReadBuffer and clEnqueueWriteBuffer', ['cl-api-enqueue-read_write-buffer'])
> > add_plain_test(api, 'clGetMemObjectInfo', ['cl-api-get-mem-object-info'])
> > add_plain_test(api, 'clGetImageInfo', ['cl-api-get-image-info'])
> > diff --git a/tests/cl/api/CMakeLists.cl.txt b/tests/cl/api/CMakeLists.cl.txt
> > index ae7e3bf..7374b64 100644
> > --- a/tests/cl/api/CMakeLists.cl.txt
> > +++ b/tests/cl/api/CMakeLists.cl.txt
> > @@ -15,6 +15,7 @@ piglit_cl_add_api_test (retain_release-command-queue retain_release-command-queu
> >
> > # Memory objects
> > piglit_cl_add_api_test (create-buffer create-buffer.c)
> > +piglit_cl_add_api_test (enqueue-copy-buffer enqueue-copy-buffer.c)
> > piglit_cl_add_api_test (enqueue-read_write-buffer enqueue-read_write-buffer.c)
> > piglit_cl_add_api_test (retain_release-mem-object retain_release-mem-object.c)
> > piglit_cl_add_api_test (get-mem-object-info get-mem-object-info.c)
> > diff --git a/tests/cl/api/enqueue-copy-buffer.c b/tests/cl/api/enqueue-copy-buffer.c
> > new file mode 100644
> > index 0000000..34118d6
> > --- /dev/null
> > +++ b/tests/cl/api/enqueue-copy-buffer.c
> > @@ -0,0 +1,87 @@
> > +/*
> > + * Copyright 2013 Advanced Micro Devices, Inc.
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice (including the next
> > + * paragraph) shall be included in all copies or substantial portions of the
> > + * Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> > + * DEALINGS IN THE SOFTWARE.
> > + *
> > + * Authors: Tom Stellard <thomas.stellard at amd.com>
> > + *
> > + */
> > +
> > +#include "piglit-framework-cl-api.h"
> > +#include "piglit-util-cl.h"
> > +
> > +
> > +PIGLIT_CL_API_TEST_CONFIG_BEGIN
> > +
> > + config.name = "clEnqueueCopyBuffer";
> > + config.version_min = 10;
> > +
> > + config.run_per_platform = true;
> > + config.create_context = true;
> > +
> > +PIGLIT_CL_API_TEST_CONFIG_END
> > +
> > +enum piglit_result
> > +piglit_cl_test(const int argc,
> > + const char **argv,
> > + const struct piglit_cl_api_test_config* config,
> > + const struct piglit_cl_api_test_env* env)
> > +{
> > + int host_src_buffer[4] = {1, 2, 3, 4};
> > + int host_dst_buffer[4] = {0, 0, 0, 0};
> > + cl_mem device_src_buffer, device_dst_buffer;
> > + cl_command_queue queue = env->context->command_queues[0];
> > + cl_int err;
> > + int i;
> > +
> > + memset(host_dst_buffer, 0, sizeof(host_dst_buffer));
>
> Is this necessary given that host_dst_buffer is initialized as {0, 0, 0, 0}?
>
> > +
> > + device_src_buffer = piglit_cl_create_buffer(
> > + env->context, 0, sizeof(host_src_buffer));
> > + device_dst_buffer = piglit_cl_create_buffer(
> > + env->context, 0, sizeof(host_dst_buffer));
>
> For both of these buffers, would you mind explicitly passing the
> cl_mem_flags as CL_MEM_READ_WRITE
> which is the default anyway? Without that, I had to make a round trip
> through the piglit util functions and the
> spec to figure out what was happening. Since we're not actually
> running a kernel at any point, the flags
> themselves shouldn't matter here.
>
> I don't feel too strongly about either change, so either way:
> Reviewed-by: Aaron Watry <awatry at gmail.com>
>
Thanks for the review. I have made these changes and pushed this patch.
-Tom
>
> > + if (!piglit_cl_write_whole_buffer(queue,
> > + device_src_buffer, host_src_buffer) ||
> > + !piglit_cl_write_whole_buffer(queue,
> > + device_dst_buffer, host_dst_buffer)) {
> > + return PIGLIT_FAIL;
> > + }
> > +
> > + err = clEnqueueCopyBuffer(queue, device_src_buffer, device_dst_buffer,
> > + 0, 0, sizeof(host_src_buffer), 0, NULL, NULL);
> > + if (!piglit_cl_check_error(err, CL_SUCCESS)) {
> > + return PIGLIT_FAIL;
> > + }
> > +
> > + if (!piglit_cl_read_whole_buffer(queue, device_dst_buffer,
> > + host_dst_buffer)) {
> > + return PIGLIT_FAIL;
> > + }
> > +
> > + for (i = 0; i < sizeof(host_src_buffer) / sizeof(host_src_buffer[0]);
> > + i++) {
> > + if (!piglit_cl_probe_integer(host_dst_buffer[i],
> > + host_src_buffer[i], 0)) {
> > + fprintf(stderr, "Error at %d\n", i);
> > + return PIGLIT_FAIL;
> > + }
> > + }
> > + return PIGLIT_PASS;
> > +}
> > --
> > 1.8.1.4
> >
> > _______________________________________________
> > Piglit mailing list
> > Piglit at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/piglit
More information about the Piglit
mailing list