OpenCL 1.2 allows that buffers that aren't used by kernels to remain mapped while said kernel is executed. --- tests/cl.py | 1 + tests/cl/custom/CMakeLists.cl.txt | 1 + tests/cl/custom/behavior_of_unused_maps.c | 162 ++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) create mode 100644 tests/cl/custom/behavior_of_unused_maps.c
diff --git a/tests/cl.py b/tests/cl.py index 7360e6d..9de77cc 100644 --- a/tests/cl.py +++ b/tests/cl.py @@ -47,6 +47,7 @@ add_plain_test(custom, 'r600 create release buffer bug', ['cl-custom-r600-create add_plain_test(custom, 'Alignment checker', ['cl-custom-alignment-checker']) add_plain_test(custom, 'r600 mapping bug', ['cl-custom-r600-mapping-bug']) add_plain_test(custom, 'behavior of read maps', ['cl-custom-behavior-of-read-maps']) +add_plain_test(custom, 'behavior of unused maps', ['cl-custom-behavior-of-unused-maps']) add_plain_test(custom, 'Buffer flags', ['cl-custom-buffer-flags']) # API diff --git a/tests/cl/custom/CMakeLists.cl.txt b/tests/cl/custom/CMakeLists.cl.txt index 9d3c4ab..e8c0fdc 100644 --- a/tests/cl/custom/CMakeLists.cl.txt +++ b/tests/cl/custom/CMakeLists.cl.txt @@ -6,3 +6,4 @@ piglit_cl_add_custom_test (use-sub-buffer-in-kernel use-sub-buffer-in-kernel.c) piglit_cl_add_custom_test (alignment-checker alignment-checker.c) piglit_cl_add_custom_test (r600-mapping-bug r600-mapping-bug.c) piglit_cl_add_custom_test (behavior-of-read-maps behavior_of_read_maps.c) +piglit_cl_add_custom_test (behavior-of-unused-maps behavior_of_unused_maps.c) diff --git a/tests/cl/custom/behavior_of_unused_maps.c b/tests/cl/custom/behavior_of_unused_maps.c new file mode 100644 index 0000000..931a3b1 --- /dev/null +++ b/tests/cl/custom/behavior_of_unused_maps.c @@ -0,0 +1,162 @@ +/* + * Copyright 2014 Bruno Jiménez + * + * 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: Bruno Jiménez <[email protected]> + * + */ + +#include "piglit-framework-cl-custom.h" + +PIGLIT_CL_CUSTOM_TEST_CONFIG_BEGIN + + config.name = "Check for undefined behavior of unused maps"; + config.run_per_device = true; + +PIGLIT_CL_CUSTOM_TEST_CONFIG_END + +char *source = + "kernel void test(global uint *in, global uint *out) { \n" + " int gid = get_global_id(0); \n" + " out[gid] = in[gid]; \n" + "}"; + +#define BUFFER_SIZE 9 * 1024 + +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) +{ + unsigned int i; + cl_int err; + cl_mem buffer0, buffer1, buffer2, buffer3; + + uint32_t *map0; + uint32_t *map1; + uint32_t local_data2[BUFFER_SIZE]; + uint32_t local_data3[BUFFER_SIZE]; + + piglit_cl_context context = NULL; + cl_command_queue queue; + + cl_program program = NULL; + cl_kernel kernel = NULL; + + size_t global_size = BUFFER_SIZE; + size_t local_size = 1; + + context = piglit_cl_create_context(env->platform_id, &env->device_id, 1); + queue = context->command_queues[0]; + + /* Buffers 0 and 1 will be used to check for undefined behaviour in mapped + * buffers when launching kernels. + * Buffers 3 and 4 will be used to launch que kernel and force the relocation + * of the pool */ + buffer0 = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE, 1024); + buffer1 = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE, 1024); + buffer2 = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE, + sizeof(local_data2)); + buffer3 = piglit_cl_create_buffer(context, CL_MEM_READ_WRITE, + sizeof(local_data3)); + + /* First, we copy some known data to buffer0, which will be the + * buffer mapped for read */ + map0 = clEnqueueMapBuffer(queue, buffer0, CL_TRUE, CL_MAP_WRITE, + 0, 1024, 0, NULL, NULL, &err); + if (err != CL_SUCCESS) + return PIGLIT_FAIL; + + memset(map0, 0x55, 1024); + + err = clEnqueueUnmapMemObject(queue, buffer0, map0, 0, NULL, NULL); + if (err != CL_SUCCESS) + return PIGLIT_FAIL; + + map0 = clEnqueueMapBuffer(queue, buffer0, CL_TRUE, CL_MAP_READ, + 0, 1024, 0, NULL, NULL, &err); + + + /* Now, we map buffer1 for writing */ + map1 = clEnqueueMapBuffer(queue, buffer1, CL_TRUE, CL_MAP_WRITE, + 0, 1024, 0, NULL, NULL, &err); + if (err != CL_SUCCESS) + return PIGLIT_FAIL; + + + /* Now we just launch a kernel */ + memset(local_data2, 0x22, sizeof(local_data2)); + piglit_cl_write_whole_buffer(queue, buffer2, local_data2); + memset(local_data3, 0x00, sizeof(local_data3)); + piglit_cl_write_whole_buffer(queue, buffer3, local_data3); + + program = piglit_cl_build_program_with_source(context, 1, &source, ""); + kernel = piglit_cl_create_kernel(program, "test"); + + piglit_cl_set_kernel_buffer_arg(kernel, 0, &buffer2); + piglit_cl_set_kernel_buffer_arg(kernel, 1, &buffer3); + + piglit_cl_execute_ND_range_kernel(queue, kernel, 1, + &global_size, &local_size); + + /* We check what have happened to the mapped buffers. Supposedly, + * they should still be perfectly valid */ + + /* map0 should have all 0x55 */ + for (i = 0; i < 256; i++) { + if(map0[i] != 0x55555555) { + return PIGLIT_FAIL; + } + } + + /* Just to be sure, we unmap the buffer, map it and check it again */ + err = clEnqueueUnmapMemObject(queue, buffer0, map0, 0, NULL, NULL); + if (err != CL_SUCCESS) + return PIGLIT_FAIL; + + map0 = clEnqueueMapBuffer(queue, buffer0, CL_TRUE, CL_MAP_READ, + 0, 1024, 0, NULL, NULL, &err); + + for (i = 0; i < 256; i++) { + if(map0[i] != 0x55555555) { + return PIGLIT_FAIL; + } + } + + /* map1 should be a valid place for writing */ + memset(map1, 0x44, 1024); + + err = clEnqueueUnmapMemObject(queue, buffer1, map1, 0, NULL, NULL); + if (err != CL_SUCCESS) + return PIGLIT_FAIL; + + map0 = clEnqueueMapBuffer(queue, buffer1, CL_TRUE, CL_MAP_READ, + 0, 1024, 0, NULL, NULL, &err); + + for (i = 0; i < 256; i++) { + if(map1[i] != 0x44444444) { + return PIGLIT_FAIL; + } + } + + return PIGLIT_PASS; +} -- 2.0.0 _______________________________________________ Piglit mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/piglit
