v2:
  - Fix filename in doxygen comments
  - Remove redundant binary status check.

v3:
  - Add test cases for passing binary programs to clBuildProgram() and
    clCompileProgram().
---
 tests/cl.py                               |   1 +
 tests/cl/api/CMakeLists.cl.txt            |   1 +
 tests/cl/api/create-program-with-binary.c | 224 ++++++++++++++++++++++++++++++
 3 files changed, 226 insertions(+)
 create mode 100644 tests/cl/api/create-program-with-binary.c

diff --git a/tests/cl.py b/tests/cl.py
index 8325728..3154b4b 100644
--- a/tests/cl.py
+++ b/tests/cl.py
@@ -71,6 +71,7 @@ add_plain_test(api, 'clGetMemObjectInfo', 
['cl-api-get-mem-object-info'])
 add_plain_test(api, 'clGetImageInfo', ['cl-api-get-image-info'])
 add_plain_test(api, 'clRetainMemObject and clReleaseMemObject', 
['cl-api-retain_release-mem-object'])
 #  Program
+add_plain_test(api, 'clCreateProgramWithBinary', 
['cl-api-create-program-with-binary'])
 add_plain_test(api, 'clCreateProgramWithSource', 
['cl-api-create-program-with-source'])
 add_plain_test(api, 'clBuildProgram', ['cl-api-build-program'])
 add_plain_test(api, 'clCreateKernelsInProgram', 
['cl-api-create-kernels-in-program'])
diff --git a/tests/cl/api/CMakeLists.cl.txt b/tests/cl/api/CMakeLists.cl.txt
index 460c8ac..a51b45e 100644
--- a/tests/cl/api/CMakeLists.cl.txt
+++ b/tests/cl/api/CMakeLists.cl.txt
@@ -26,6 +26,7 @@ piglit_cl_add_api_test (get-mem-object-info 
get-mem-object-info.c)
 piglit_cl_add_api_test (get-image-info get-image-info.c)
 
 # Programs
+piglit_cl_add_api_test (create-program-with-binary 
create-program-with-binary.c)
 piglit_cl_add_api_test (create-program-with-source 
create-program-with-source.c)
 piglit_cl_add_api_test (retain_release-program retain_release-program.c)
 piglit_cl_add_api_test (build-program build-program.c)
diff --git a/tests/cl/api/create-program-with-binary.c 
b/tests/cl/api/create-program-with-binary.c
new file mode 100644
index 0000000..4873b76
--- /dev/null
+++ b/tests/cl/api/create-program-with-binary.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright © 2012 Blaž Tomažič <[email protected]>
+ * Copyright 2014 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.
+ */
+
+/**
+ * @file create-program-with-binary.c
+ *
+ * Test API function:
+ *
+ *  cl_program clCreateProgramWithBinary (cl_context context,
+ *                                        cl_uint num_devices,
+ *                                        const cl_device_id *device_list,
+ *                                        const size_t *lengths,
+ *                                        const unsigned char **binaries,
+ *                                        cl_int *binary_status,
+ *                                        cl_int *errcode_ret)
+ */
+
+#include "piglit-framework-cl-api.h"
+
+
+PIGLIT_CL_API_TEST_CONFIG_BEGIN
+
+       config.name = "clCreateProgramWithBinary";
+       config.version_min = 10;
+
+       config.run_per_platform = true;
+       config.create_context = true;
+
+PIGLIT_CL_API_TEST_CONFIG_END
+
+
+const char* dummy_kernel = "kernel void dummy_kernel() { }";
+
+static cl_program create_binary_program(const piglit_cl_context ctx)
+{
+       cl_program program = NULL;
+       cl_program binary_program = NULL;
+       cl_int errNo;
+       unsigned i;
+
+       size_t kernel_length = strlen(dummy_kernel);
+       cl_context cl_ctx = ctx->cl_ctx;
+       size_t *sizes;
+       unsigned char **binaries;
+
+       program = clCreateProgramWithSource(cl_ctx,
+                                           1,
+                                           &dummy_kernel,
+                                           &kernel_length,
+                                           &errNo);
+
+       if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+               fprintf(stderr, "clCreateProgramWithSource failed "
+                               "(error code: %s)\n",
+                       piglit_cl_get_error_name(errNo));
+               goto fail;
+       }
+
+
+       errNo = clBuildProgram(program, ctx->num_devices,
+                               ctx->device_ids, NULL, NULL, NULL);
+
+       if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+               fprintf(stderr, "clBuildProgram failed "
+                               "(error code: %s)\n",
+                       piglit_cl_get_error_name(errNo));
+               goto free_program;
+       }
+
+
+       sizes = calloc(sizeof(size_t), ctx->num_devices);
+       errNo = clGetProgramInfo(program, CL_PROGRAM_BINARY_SIZES,
+                                sizeof(size_t) * ctx->num_devices,
+                                sizes, NULL);
+
+       if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+               fprintf(stderr, "clCreateProgramInfo failed "
+                               "(error code: %s)\n",
+                       piglit_cl_get_error_name(errNo));
+               goto free_sizes;
+       }
+
+       binaries = calloc(sizeof(char*),  ctx->num_devices);
+       for (i = 0; i < ctx->num_devices; i++) {
+               binaries[i] = malloc(sizes[i]);
+       }
+
+       errNo = clGetProgramInfo(program, CL_PROGRAM_BINARIES,
+                                sizeof(char*) * ctx->num_devices,
+                                binaries, NULL);
+
+       if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+               fprintf(stderr, "clCreateProgramInfo failed "
+                               "(error code: %s)\n",
+                       piglit_cl_get_error_name(errNo));
+               goto free_binaries;
+       }
+
+       binary_program = clCreateProgramWithBinary (cl_ctx, ctx->num_devices,
+                                                     ctx->device_ids,
+                                                     sizes, binaries,
+                                                     NULL,
+                                                     &errNo);
+
+       if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+               fprintf(stderr, "clCreateProgramWithBinary failed "
+                               "(error code: %s)\n",
+                       piglit_cl_get_error_name(errNo));
+               goto free_binaries;
+       }
+
+free_binaries:
+       for (i = 0; i < ctx->num_devices; i++) {
+               free(binaries[i]);
+       }
+       free(binaries);
+
+free_sizes:
+       free(sizes);
+
+free_program:
+       clReleaseProgram(program);
+
+fail:
+       return binary_program;
+
+}
+
+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 i;
+       cl_program binary_program;
+       cl_kernel kernel;
+       cl_int errNo;
+
+       piglit_cl_context ctx = env->context;
+       enum piglit_result result = PIGLIT_PASS;
+
+       binary_program = create_binary_program(ctx);
+       if (!binary_program) {
+               piglit_merge_result(&result, PIGLIT_FAIL);
+               goto fail;
+       }
+
+
+       /* test0: Execute a binary program */
+       kernel = clCreateKernel(binary_program, "dummy_kernel", &errNo);
+
+       if (!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+               fprintf(stderr, "clCreateKernel failed "
+                               "(error code: %s)\n",
+                       piglit_cl_get_error_name(errNo));
+               piglit_merge_result(&result, PIGLIT_FAIL);
+               goto done_test0;
+       }
+
+       for (i = 0; i < ctx->num_devices; i++) {
+               size_t global_work_size = 1;
+               size_t local_work_size = 1;
+               cl_command_queue queue = ctx->command_queues[i];
+               if (!piglit_cl_enqueue_ND_range_kernel(queue, kernel, 1,
+                                       &global_work_size, &local_work_size)) {
+                       fprintf(stderr, "Failed to execute binary kernel.");
+                       piglit_merge_result(&result, PIGLIT_FAIL);
+               }
+       }
+
+       clReleaseKernel(kernel);
+done_test0:
+
+       /* test1: Pass binary program to clBuildProgram() */
+       errNo = clBuildProgram(binary_program, ctx->num_devices,
+                               ctx->device_ids, NULL, NULL, NULL);
+       if (!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+               fprintf(stderr, "Failed to compile binary program.");
+               piglit_merge_result(&result, PIGLIT_FAIL);
+       }
+
+       /* test2 Pass binary program to clCompileProgram() */
+
+#ifdef CL_VERSION_1_2
+
+       if (piglit_cl_get_platform_version(ctx->platform_id) >= 12) {
+               errNo = clCompileProgram(binary_program, ctx->num_devices,
+                                       ctx->device_ids, NULL, 0, NULL, NULL,
+                                       NULL, NULL);
+               if (!piglit_cl_check_error(errNo, CL_INVALID_OPERATION)) {
+                       fprintf(stderr, "Passing a binary program to "
+                               "clCompileProgram() should return "
+                               "CL_INVALID_OPERATION");
+                       piglit_merge_result(&result, PIGLIT_FAIL);
+               }
+       }
+#endif
+
+       clReleaseProgram(binary_program);
+fail:
+       return result;
+}
-- 
1.8.5.5

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to