I'm not really sure if I like this approach. Couldn't this be tested with the attached test case instead? Note that I can't actually execute that test case currently, since I'm getting an error from the R600 back-end on the machines that I have available to me, and my Nvidia machine is not with me at the moment.
If we do have to go with this approach, I have the following comments: On Thu, May 30, 2013 at 3:06 AM, Yi Sun <[email protected]> wrote: > Invoked function get_work_dim in OpenCL, and read back the return value, > then validate it with the value which passed to the function > clEnqueueNDRangeKernel. > > Signed-off-by: Yi Sun <[email protected]> > --- > tests/all_cl.tests | 3 +- > tests/cl/custom/CMakeLists.cl.txt | 1 + > tests/cl/custom/get_work_dim.c | 88 > +++++++++++++++++++++++++++++++++++++ > 3 files changed, 91 insertions(+), 1 deletions(-) > create mode 100644 tests/cl/custom/get_work_dim.c > > diff --git a/tests/all_cl.tests b/tests/all_cl.tests > index 8cefa43..b0b950f 100644 > --- a/tests/all_cl.tests > +++ b/tests/all_cl.tests > @@ -38,6 +38,7 @@ profile.tests['Program'] = program > > # Custom > add_plain_test(custom, 'Run simple kernel', ['cl-custom-run-simple-kernel']) > +add_plain_test(custom, 'Buildin function get_work_dim', > ['cl-custom-get_work_dim']) Buildin should be changed to Builtin (here and everywhere else that uses this spelling). > > # API > # Platform > diff --git a/tests/cl/custom/CMakeLists.cl.txt > b/tests/cl/custom/CMakeLists.cl.txt > index 4f93e2a..9f8d5cb 100644 > --- a/tests/cl/custom/CMakeLists.cl.txt > +++ b/tests/cl/custom/CMakeLists.cl.txt > @@ -1 +1,2 @@ > piglit_cl_add_custom_test (run-simple-kernel run-simple-kernel.c) > +piglit_cl_add_custom_test (get_work_dim get_work_dim.c) > diff --git a/tests/cl/custom/get_work_dim.c b/tests/cl/custom/get_work_dim.c > new file mode 100644 > index 0000000..583b5a4 > --- /dev/null > +++ b/tests/cl/custom/get_work_dim.c > @@ -0,0 +1,88 @@ > +/* > + * Copyright © 2013 Yi Sun <[email protected]> > + * > + * 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. > + */ > + > +#include "piglit-framework-cl-custom.h" > + > +PIGLIT_CL_CUSTOM_TEST_CONFIG_BEGIN > + > + config.name = "Buildin Function get_work_dim"; > + config.run_per_device = true; > + > +PIGLIT_CL_CUSTOM_TEST_CONFIG_END > + > +//char* source = "kernel void test(global int* out){ *out = -1; }"; Remove this commented out source line > +char* source =" \n"\ > +"kernel void buildin_work_dim( __global int *ret ) { \n"\ > +" *ret = get_work_dim(); \n"\ > +"} \n"\ > +"\n"; > + > +enum piglit_result > +piglit_cl_test(const int argc, > + const char** argv, > + const struct piglit_cl_custom_test_config* config, > + const struct piglit_cl_custom_test_env* env) > +{ > + enum piglit_result result = PIGLIT_PASS; > + > + size_t global_size[] = {256, 256}; > + size_t local_size[] = {16,16}; This won't work on all valid OpenCL implementations. local_size should be changed to {1,1}, or you should use the clGetKernelWorkGroupInfo API function to get the maximum local size and then make sure that 16x16 fits within those bounds. I think that one example where this won't work would be the Apple MacOS 10.6/10.7 CPU-based CL implementation... I think that this implementation defined the max local size to be either 1 or the number of CPU cores available. > + int i; > + cl_int data = 0; > + > + piglit_cl_context context = NULL; > + cl_mem buffer = NULL; > + cl_program program = NULL; > + cl_kernel kernel = NULL; > + > + /* Create objects up to the kernel */ > + context = piglit_cl_create_context(env->platform_id, &env->device_id, > 1); > + buffer = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE, > sizeof(cl_int)); > + program = piglit_cl_build_program_with_source(context, 1, &source, > ""); > + kernel = piglit_cl_create_kernel(program, "buildin_work_dim"); > + > + /* Set kernel arguments and run the kernel */ > + piglit_cl_set_kernel_buffer_arg(kernel, 0, &buffer); > + > + for( i=1; i <= 2; i++ ) > + { Why are we only testing up to two dimensions? Why not test all 3? --Aaron > + // Run the kernel > + piglit_cl_execute_ND_range_kernel(context->command_queues[0], > kernel, i, global_size, local_size); > + > + /* Read the buffer and check the result */ > + piglit_cl_read_buffer(context->command_queues[0], buffer, 0, > sizeof(cl_int), &data); > + > + if(data != i) { > + fprintf(stderr, "get_work_dim return wrong value(%d), > should be %d!.\n", data, i); > + result = PIGLIT_FAIL; > + } > + } > + > + /* Release resources */ > + clReleaseKernel(kernel); > + clReleaseProgram(program); > + clReleaseMemObject(buffer); > + piglit_cl_release_context(context); > + > + return result; > +} > -- > 1.7.6.4 > > _______________________________________________ > Piglit mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/piglit
get_work_dim.cl
Description: Binary data
_______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
