2 * Copyright 2013 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 * Authors: Tom Stellard <thomas.stellard@amd.com>
27 /* The r600g driver stores all global buffers in a single memory pool and
28 * has a simple memory manager to allocate and deallocate buffers in the pool.
29 * This test was inspired by a bug in the allocator where assigning a new
30 * buffer the lowest offset in the pool, would delete the buffer which
31 * previously had the lowest offset.
34 #include "piglit-framework-cl-custom.h"
36 PIGLIT_CL_CUSTOM_TEST_CONFIG_BEGIN
38 config
.name
= "clFlush() after clEnqueueNDRangeKernel()";
39 config
.run_per_device
= true;
41 PIGLIT_CL_CUSTOM_TEST_CONFIG_END
43 #define BUFFER_SIZE 1024 * 1024
46 "kernel void test(global int *out) { *out = 1; }\n";
49 piglit_cl_test(const int argc
,
51 const struct piglit_cl_custom_test_config
*config
,
52 const struct piglit_cl_custom_test_env
*env
)
54 size_t global_size
= 1, local_size
= 1;
55 piglit_cl_context context
= NULL
;
56 cl_command_queue queue
= NULL
;
57 cl_mem buffer0
= NULL
, buffer1
= NULL
, buffer2
= NULL
, buffer3
= NULL
;
58 cl_program program
= NULL
;
59 cl_kernel kernel
= NULL
;
60 int data
[BUFFER_SIZE
/ sizeof(int)];
63 context
= piglit_cl_create_context(env
->platform_id
, &env
->device_id
, 1);
64 queue
= context
->command_queues
[0];
66 buffer0
= piglit_cl_create_buffer(context
, CL_MEM_WRITE_ONLY
, BUFFER_SIZE
);
67 buffer1
= piglit_cl_create_buffer(context
, CL_MEM_WRITE_ONLY
, BUFFER_SIZE
);
69 program
= piglit_cl_build_program_with_source(context
, 1, &source
, "");
70 kernel
= piglit_cl_create_kernel(program
, "test");
72 /* Use the first buffer */
73 if (!piglit_cl_set_kernel_arg(kernel
, 0, sizeof(cl_mem
), &buffer0
)) {
77 if (!piglit_cl_enqueue_ND_range_kernel(queue
, kernel
, 1, NULL
,
78 &global_size
, &local_size
,
83 /* Use the second buffer */
84 if (!piglit_cl_set_kernel_arg(kernel
, 0, sizeof(cl_mem
), &buffer1
)) {
88 if (!piglit_cl_enqueue_ND_range_kernel(queue
, kernel
, 1, NULL
,
89 &global_size
, &local_size
,
94 /* Delete the first buffer */
95 clReleaseMemObject(buffer0
);
97 /* Create and use the third buffer */
98 buffer2
= piglit_cl_create_buffer(context
, CL_MEM_WRITE_ONLY
, BUFFER_SIZE
);
99 if (!piglit_cl_set_kernel_arg(kernel
, 0, sizeof(cl_mem
), &buffer2
)) {
103 if (!piglit_cl_enqueue_ND_range_kernel(queue
, kernel
, 1, NULL
,
104 &global_size
, &local_size
,
109 /* Create the fourth buffer. */
110 buffer3
= piglit_cl_create_buffer(context
, CL_MEM_WRITE_ONLY
, BUFFER_SIZE
);
112 /* At this point, the bug in r600g will cause buffer3 and buffer1 to
113 * have the same offset, so if we write to buffer3, then the data
114 * will appear in buffer1.
117 /* Clear both buffers */
118 memset(data
, 0, sizeof(data
));
119 piglit_cl_write_whole_buffer(queue
, buffer1
, data
);
120 piglit_cl_write_whole_buffer(queue
, buffer3
, data
);
122 /* Write data to buffer1 */
123 memset(data
, 0xff, sizeof(data
));
124 piglit_cl_write_whole_buffer(queue
, buffer3
, data
);
126 /* Check that the data wasn't also written to buffer1 */
127 memset(data
, 0, sizeof(data
));
128 if (!piglit_cl_read_whole_buffer(queue
, buffer1
, data
)) {
132 for (i
= 0; i
< BUFFER_SIZE
/ sizeof(int); i
++) {
134 fprintf(stderr
, "Error at data[%u], unexpected value 0x%02x\n", i
, data
[i
]);