summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Stellard <thomas.stellard@amd.com>2014-10-14 19:30:37 -0400
committerTom Stellard <thomas.stellard@amd.com>2014-11-06 08:32:18 -0500
commit471b509f9c1b2333f06e55245380d424950e3abb (patch)
tree01a16178db02f91d37d5bb8adb857b90e0ea5b4b
parentecf0faa4d71c0e117569c6e0edfe57b2f8bbabf7 (diff)
cl: Add test for clCreateProgramWithBinary() v3
v2: - Fix filename in doxygen comments - Remove redundant binary status check. v3: - Add test cases for passing binary programs to clBuildProgram() and clCompileProgram(). Reviewed-by: Francisco Jerez <currojerez@riseup.net>
-rw-r--r--tests/cl.py1
-rw-r--r--tests/cl/api/CMakeLists.cl.txt1
-rw-r--r--tests/cl/api/create-program-with-binary.c224
3 files changed, 226 insertions, 0 deletions
diff --git a/tests/cl.py b/tests/cl.py
index 83257289b..3154b4b6a 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 460c8acec..a51b45ee3 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 000000000..4873b76fc
--- /dev/null
+++ b/tests/cl/api/create-program-with-binary.c
@@ -0,0 +1,224 @@
+/*
+ * Copyright © 2012 Blaž Tomažič <blaz.tomazic@gmail.com>
+ * 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;
+}