[Piglit] [PATCH v2] cl: Add a test for the predefined macros
Serge Martin
edb+piglit at sigluy.net
Thu Sep 29 10:55:26 UTC 2016
On 2016-09-18 16:47, Niels Ole Salscheider wrote:
> Signed-off-by: Niels Ole Salscheider <niels_ole at salscheider-online.de>
> ---
> tests/cl/program/CMakeLists.cl.txt | 1 +
> tests/cl/program/predefined-macros.c | 408
> +++++++++++++++++++++++++++++++++++
> 2 files changed, 409 insertions(+)
> create mode 100644 tests/cl/program/predefined-macros.c
>
> diff --git a/tests/cl/program/CMakeLists.cl.txt
> b/tests/cl/program/CMakeLists.cl.txt
> index 82dc675..c8d7307 100644
> --- a/tests/cl/program/CMakeLists.cl.txt
> +++ b/tests/cl/program/CMakeLists.cl.txt
> @@ -1,3 +1,4 @@
> piglit_cl_add_program_test (tester program-tester.c)
> piglit_cl_add_program_test (max-work-item-sizes max-work-item-sizes.c)
> piglit_cl_add_program_test (bitcoin-phatk bitcoin-phatk.c)
> +piglit_cl_add_program_test (predefined-macros predefined-macros.c)
> diff --git a/tests/cl/program/predefined-macros.c
> b/tests/cl/program/predefined-macros.c
> new file mode 100644
> index 0000000..ff2b75f
> --- /dev/null
> +++ b/tests/cl/program/predefined-macros.c
> @@ -0,0 +1,408 @@
> +/*
> + * Copyright © 2016 Niels Ole Salscheider
> <niels_ole at salscheider-online.de>
> + *
> + * 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.
> + */
> +
Hello
Tanks for the v2.
There is a mix of alignement made with tab and space in the whole file
Pleas use one tab ident per level and align with the same number
of tab + spaces if the instruction need multiples lines.
Others comment below.
> +#include "piglit-framework-cl-program.h"
> +
> +char *program_source =
> +"kernel void test(global int* file_defined, global int* line_defined,
> \n"
> +" global int* opencl_version_defined, global int* opencl_version,
> \n"
> +" global int* opencl_c_version_defined, global int*
> opencl_c_version, \n"
> +" global int* cl_version_defined, global int* cl_version, \n"
> +" global int* endian_little_defined, global int* endian_little, \n"
> +" global int* image_support_defined, global int* image_support) \n"
> +"{ \n"
> +"#ifdef __FILE__ \n"
> +" *file_defined = 1; \n"
> +"#else \n"
> +" *file_defined = 0; \n"
> +"#endif \n"
> +"\n"
> +"#ifdef __LINE__ \n"
> +" *line_defined = 1; \n"
> +"#else \n"
> +" *line_defined = 0; \n"
> +"#endif \n"
> +"\n"
> +"#ifdef __OPENCL_VERSION__ \n"
> +" *opencl_version_defined = 1; \n"
> +" *opencl_version = __OPENCL_VERSION__; \n"
> +"#else \n"
> +" *opencl_version_defined = 0; \n"
> +"#endif \n"
> +"\n"
> +"#ifdef __OPENCL_C_VERSION__ \n"
> +" *opencl_c_version_defined = 1; \n"
> +" *opencl_c_version = __OPENCL_C_VERSION__; \n"
> +"#else \n"
> +" *opencl_c_version_defined = 0; \n"
> +"#endif \n"
> +"\n"
> +"#ifdef CL_VERSION_1_0 \n"
> +" cl_version_defined[0] = 1; \n"
> +" cl_version[0] = CL_VERSION_1_0; \n"
> +"#else \n"
> +" cl_version_defined[0] = 0; \n"
> +"#endif \n"
> +"\n"
> +"#ifdef CL_VERSION_1_1 \n"
> +" cl_version_defined[1] = 1; \n"
> +" cl_version[1] = CL_VERSION_1_1; \n"
> +"#else \n"
> +" cl_version_defined[1] = 0; \n"
> +"#endif \n"
> +"\n"
> +"#ifdef CL_VERSION_1_2 \n"
> +" cl_version_defined[2] = 1; \n"
> +" cl_version[2] = CL_VERSION_1_2; \n"
> +"#else \n"
> +" cl_version_defined[2] = 0; \n"
> +"#endif \n"
> +"\n"
> +"#ifdef CL_VERSION_2_0 \n"
> +" cl_version_defined[3] = 1; \n"
> +" cl_version[3] = CL_VERSION_2_0; \n"
> +"#else \n"
> +" cl_version_defined[3] = 0; \n"
> +"#endif \n"
> +"\n"
> +"#ifdef __ENDIAN_LITTLE__ \n"
> +" *endian_little_defined = 1; \n"
> +" *endian_little = __ENDIAN_LITTLE__; \n"
> +"#else \n"
> +" *endian_little_defined = 0; \n"
> +"#endif \n"
> +"#ifdef __IMAGE_SUPPORT__ \n"
> +" *image_support_defined = 1; \n"
> +" *image_support = __IMAGE_SUPPORT_; \n"
__IMAGE_SUPPORT__
> +"#else \n"
> +" *image_support_defined = 0; \n"
> +"#endif \n"
> +"}";
> +
> +PIGLIT_CL_PROGRAM_TEST_CONFIG_BEGIN
> +
> + config.name = "Check if all required macros are defined";
I would have call it "Preprocessor Macros." but i's up to you.
> + config.clc_version_min = 10;
> + config.run_per_device = true;
> +
> + config.program_source = program_source;
> + config.kernel_name = "test";
> +
> +PIGLIT_CL_PROGRAM_TEST_CONFIG_END
> +
> +int
> +version_from_string(char* string, int *version)
> +{
> + int major, minor;
> + char *token;
> + char delim = ' ';
> + strtok(string, &delim);
> + delim = '.';
> + token = strtok(NULL, &delim);
> + if (!token) {
> + return 0;
> + }
> + major = atoi(token);
> + delim = ' ';
> + token = strtok(NULL, &delim);
> + if (!token) {
> + return 0;
> + }
> + minor = atoi(token);
> + *version = 100 * major + 10 * minor;
> +
> + return 1;
> +}
> +
> +#define NUM_CL_VERSION 4
> +
> +enum piglit_result
> +piglit_cl_test(const int argc,
> + const char** argv,
> + const struct piglit_cl_program_test_config* config,
> + const struct piglit_cl_program_test_env* env)
> +{
> + enum piglit_result result = PIGLIT_PASS;
> +
> + size_t work_size = 1;
> +
> + cl_int file_defined;
> + cl_mem file_defined_mem = NULL;
> + cl_int line_defined;
> + cl_mem line_defined_mem = NULL;
> + cl_int opencl_version_defined;
> + cl_mem opencl_version_defined_mem = NULL;
> + cl_int opencl_version;
> + cl_mem opencl_version_mem = NULL;
> + cl_int opencl_c_version;
> + cl_mem opencl_c_version_mem = NULL;
> + cl_int opencl_c_version_defined;
> + cl_mem opencl_c_version_defined_mem = NULL;
> + cl_int cl_version_defined[NUM_CL_VERSION];
> + cl_mem cl_version_defined_mem = NULL;
> + cl_int cl_version[NUM_CL_VERSION];
> + cl_mem cl_version_mem = NULL;
> + cl_int endian_little_defined;
> + cl_mem endian_little_defined_mem = NULL;
> + cl_int endian_little;
> + cl_mem endian_little_mem = NULL;
> + cl_int image_support_defined;
> + cl_mem image_support_defined_mem = NULL;
> + cl_int image_support;
> + cl_mem image_support_mem = NULL;
> +
> + char* opencl_version_str_host = NULL;
> + char* opencl_c_version_str_host = NULL;
> + cl_bool* endian_little_host = NULL;
> + cl_bool* image_support_host = NULL;
> +
> + opencl_version_str_host = piglit_cl_get_device_info(env->device_id,
> +
> CL_DEVICE_VERSION);
> +#ifdef CL_VERSION_1_2
> + opencl_c_version_str_host = piglit_cl_get_device_info(env->device_id,
> + CL_DEVICE_OPENCL_C_VERSION);
> +#endif
> + endian_little_host = piglit_cl_get_device_info(env->device_id,
> +
> CL_DEVICE_ENDIAN_LITTLE);
> + image_support_host = piglit_cl_get_device_info(env->device_id,
> +
> CL_DEVICE_IMAGE_SUPPORT);
> +
> + // create buffers for the results
> + file_defined_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + line_defined_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + opencl_version_defined_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + opencl_version_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + opencl_c_version_defined_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + opencl_c_version_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + cl_version_defined_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + NUM_CL_VERSION * sizeof(cl_int));
> + cl_version_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + NUM_CL_VERSION * sizeof(cl_int));
> + endian_little_defined_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + endian_little_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + image_support_defined_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> + image_support_mem = piglit_cl_create_buffer(env->context,
> + CL_MEM_WRITE_ONLY,
> + sizeof(cl_int));
> +
> + // set kernel args and run the kernel
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 0, &file_defined_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 1, &line_defined_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 2,
> + &opencl_version_defined_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 3, &opencl_version_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 4,
> + &opencl_c_version_defined_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 5,
> &opencl_c_version_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 6,
> + &cl_version_defined_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 7, &cl_version_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 8,
> + &endian_little_defined_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 9, &endian_little_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 10,
> + &image_support_defined_mem);
> + piglit_cl_set_kernel_buffer_arg(env->kernel, 11, &image_support_mem);
> + piglit_cl_execute_ND_range_kernel(env->context->command_queues[0],
> + env->kernel,
> + 1,
> + NULL,
> + &work_size,
> + &work_size);
> +
> + // read the buffers and check their values
> + piglit_cl_read_buffer(env->context->command_queues[0],
> file_defined_mem,
> + 0, sizeof(cl_int), &file_defined);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> line_defined_mem,
> + 0, sizeof(cl_int), &line_defined);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + opencl_version_defined_mem, 0, sizeof(cl_int),
> + &opencl_version_defined);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + opencl_version_mem, 0, sizeof(cl_int),
> + &opencl_version);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + opencl_c_version_defined_mem, 0, sizeof(cl_int),
> + &opencl_c_version_defined);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + opencl_c_version_mem, 0, sizeof(cl_int),
> + &opencl_c_version);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + cl_version_defined_mem, 0,
> + NUM_CL_VERSION * sizeof(cl_int),
> + cl_version_defined);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + cl_version_mem, 0,
> + NUM_CL_VERSION * sizeof(cl_int),
> + cl_version);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + endian_little_defined_mem, 0, sizeof(cl_int),
> + &endian_little_defined);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + endian_little_mem, 0, sizeof(cl_int),
> + &endian_little);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + image_support_defined_mem, 0, sizeof(cl_int),
> + &image_support_defined);
> + piglit_cl_read_buffer(env->context->command_queues[0],
> + image_support_mem, 0, sizeof(cl_int),
> + &image_support);
> +
> + if (file_defined != 1) {
> + printf("__FILE__ is not defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
I think it will be nice to use subtests.
Like in cl/api/set-kernel_args for exemple.
> + }
> + if (line_defined != 1) {
> + printf("__LINE__ is not defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + if (opencl_version_defined != 1) {
> + printf("__OPENCL_VERSION__ is not defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + } else {
> + int opencl_version_host;
> + if (!version_from_string(opencl_version_str_host,
> + &opencl_version_host)) {
> + printf("Could not determine host OpenCL version.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + } else {
> + if (opencl_version != opencl_version_host) {
> + printf("__OPENCL_VERSION__ has unexpected value"
> + " (%d (device) vs. %d (host)).\n",
> + opencl_version, opencl_version_host);
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + }
> +
> + if (opencl_version >= 110 && !cl_version_defined[0]) {
> + printf("CL_VERSION_1_0 must be defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
I'm not sure that all CL_VERSION_X_0 must be defined,
may be only the relevant one is strictly needed.
AMD ocl on cpu doesn't but it could be a bug.
If someone have access to another ocl lib, I would be nice to compare.
Serge
> + if (opencl_version >= 110 && !cl_version_defined[1]) {
> + printf("CL_VERSION_1_1 must be defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + if (opencl_version >= 120 && !cl_version_defined[2]) {
> + printf("CL_VERSION_1_2 must be defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + if (opencl_version >= 200 && !cl_version_defined[3]) {
> + printf("CL_VERSION_2_0 must be defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + if (opencl_version >= 120) {
> + int opencl_c_version_host;
> + if (!version_from_string(opencl_c_version_str_host,
> + &opencl_c_version_host)) {
> + printf("Could not determine host OpenCL C version.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + } else {
> + if (!opencl_c_version_defined ||
> + opencl_c_version != opencl_c_version_host) {
> + printf("__OPENCL_C_VERSION__ has unexpected value"
> + "(%d (device) vs. %d (host)).\n",
> + opencl_c_version, opencl_c_version_host);
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + }
> + }
> + }
> +
> + if (cl_version_defined[0] && cl_version[0] != 100) {
> + printf("CL_VERSION_1_0 must be 100 if defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + if (cl_version_defined[1] && cl_version[1] != 110) {
> + printf("CL_VERSION_1_1 must be 110 if defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + if (cl_version_defined[2] && cl_version[2] != 120) {
> + printf("CL_VERSION_1_2 must be 120 if defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + if (cl_version_defined[3] && cl_version[3] != 200) {
> + printf("CL_VERSION_2_0 must be 200 if defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + if (*endian_little_host != endian_little_defined) {
> + printf("Definition of __ENDIAN_LITTLE__ inconsistent.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + if (endian_little_defined && endian_little != 1) {
> + printf("__ENDIAN_LITTLE__ must be 1 if defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + if (*image_support_host != image_support_defined) {
> + printf("Definition of __IMAGE_SUPPORT__ inconsistent.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> + if (image_support_defined && image_support != 1) {
> + printf("__IMAGE_SUPPORT__ must be 1 if defined.\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + // free cl resources
> + clReleaseMemObject(file_defined_mem);
> + clReleaseMemObject(line_defined_mem);
> + clReleaseMemObject(opencl_version_defined_mem);
> + clReleaseMemObject(opencl_version_mem);
> + clReleaseMemObject(opencl_c_version_defined_mem);
> + clReleaseMemObject(opencl_c_version_mem);
> + clReleaseMemObject(cl_version_defined_mem);
> + clReleaseMemObject(cl_version_mem);
> + clReleaseMemObject(endian_little_defined_mem);
> + clReleaseMemObject(endian_little_mem);
> + clReleaseMemObject(image_support_defined_mem);
> + clReleaseMemObject(image_support_mem);
> +
> + // free host resources
> + free(opencl_version_str_host);
> + free(opencl_c_version_str_host);
> + free(endian_little_host);
> + free(image_support_host);
> +
> + return result;
> +}
More information about the Piglit
mailing list