---
 tests/cl.py                               |   1 +
 tests/cl/api/CMakeLists.cl.txt            |   1 +
 tests/cl/api/create-program-with-binary.c | 189 ++++++++++++++++++++++++++++++
 3 files changed, 191 insertions(+)
 create mode 100644 tests/cl/api/create-program-with-binary.c

diff --git a/tests/cl.py b/tests/cl.py
index 67ed542..1812e11 100644
--- a/tests/cl.py
+++ b/tests/cl.py
@@ -73,6 +73,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..f2b3791
--- /dev/null
+++ b/tests/cl/api/create-program-with-binary.c
@@ -0,0 +1,189 @@
+/*
+ * 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-source.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() { }";
+
+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)
+{
+       enum piglit_result result = PIGLIT_PASS;
+       int i;
+
+       cl_int errNo;
+       cl_program program;
+       cl_program binary_program;
+       piglit_cl_context ctx = env->context;
+       cl_context cl_ctx = ctx->cl_ctx;
+       cl_kernel kernel;
+
+       size_t kernel_length = strlen(dummy_kernel);
+       size_t *sizes = calloc(sizeof(size_t), ctx->num_devices);
+       unsigned char **binaries = calloc(sizeof(char*),  ctx->num_devices);
+       cl_int *binary_status = calloc(sizeof(cl_int), ctx->num_devices);
+
+
+       /*** Normal usage ***/
+
+       /* with errNo */
+       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));
+               piglit_merge_result(&result, PIGLIT_FAIL);
+               goto done;
+       }
+
+
+       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));
+               piglit_merge_result(&result, PIGLIT_FAIL);
+               goto done;
+       }
+
+
+       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));
+               piglit_merge_result(&result, PIGLIT_FAIL);
+               goto done;
+       }
+
+       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));
+               piglit_merge_result(&result, PIGLIT_FAIL);
+               goto done;
+       }
+
+       binary_program = clCreateProgramWithBinary (cl_ctx, ctx->num_devices,
+                                                     ctx->device_ids,
+                                                     sizes, binaries,
+                                                     binary_status,
+                                                     &errNo);
+
+       if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+               fprintf(stderr, "clCreateProgramWithBinary failed "
+                               "(error code: %s)\n",
+                       piglit_cl_get_error_name(errNo));
+               piglit_merge_result(&result, PIGLIT_FAIL);
+               goto done;
+       }
+
+       for (i = 0; i < ctx->num_devices; i++) {
+               if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
+                       fprintf(stderr, "failed to load binary for device %d"
+                                       "(error code: %s)\n", i,
+                               piglit_cl_get_error_name(errNo));
+                       piglit_merge_result(&result, PIGLIT_FAIL);
+                       goto done;
+               }
+       }
+
+       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;
+       }
+
+
+       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)) {
+                       piglit_merge_result(&result, PIGLIT_FAIL);
+                       goto done;
+               }
+       }
+done:
+       for (i = 0; i < ctx->num_devices; i++) {
+               free(binaries[i]);
+       }
+       free(sizes);
+       free(binaries);
+       free(binary_status);
+
+       return result;
+}
-- 
1.8.5.5

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

Reply via email to