[Piglit] [PATCH v2] cl: add clGetKernelArgInfo
Jan Vesely
jan.vesely at rutgers.edu
Sun Aug 9 15:17:49 PDT 2015
On Sun, 2015-08-02 at 00:54 +0200, EdB wrote:
> ---
> tests/cl.py | 1 +
> tests/cl/api/CMakeLists.cl.txt | 1 +
> tests/cl/api/get-kernel-arg-info.c | 281
> +++++++++++++++++++++++++++++++++++++
> tests/util/piglit-util-cl-enum.c | 11 ++
> tests/util/piglit-util-cl-enum.h | 1 +
> 5 files changed, 295 insertions(+)
> create mode 100644 tests/cl/api/get-kernel-arg-info.c
>
> diff --git a/tests/cl.py b/tests/cl.py
> index c55d3dd..53153e8 100644
> --- a/tests/cl.py
> +++ b/tests/cl.py
> @@ -76,6 +76,7 @@ with profile.group_manager(PiglitCLTest, 'api') as
> g:
> # Kernel
> g(['cl-api-create-kernel'], 'clCreateKernel')
> g(['cl-api-create-kernels-in-program'],
> 'clCreateKernelsInProgram')
> + g(['cl-api-get-kernel-arg-info'], 'clGetKernelArgInfo')
> g(['cl-api-get-kernel-info'], 'clGetKernelInfo')
> g(['cl-api-get-kernel-work-group-info'],
> 'clGetKernelWorkGroupInfo')
> g(['cl-api-retain_release-kernel'], 'clRetainKernel and
> clReleaseKernel')
> diff --git a/tests/cl/api/CMakeLists.cl.txt
> b/tests/cl/api/CMakeLists.cl.txt
> index 7e78491..3082411 100644
> --- a/tests/cl/api/CMakeLists.cl.txt
> +++ b/tests/cl/api/CMakeLists.cl.txt
> @@ -41,6 +41,7 @@ piglit_cl_add_api_test (create-kernels-in-program
> create-kernels-in-program.c)
> piglit_cl_add_api_test (set-kernel-arg set-kernel-arg.c)
> piglit_cl_add_api_test (retain_release-kernel retain_release
> -kernel.c)
> piglit_cl_add_api_test (get-kernel-info get-kernel-info.c)
> +piglit_cl_add_api_test (get-kernel-arg-info get-kernel-arg-info.c)
> piglit_cl_add_api_test (get-kernel-work-group-info get-kernel-work
> -group-info.c)
>
> # Events
> diff --git a/tests/cl/api/get-kernel-arg-info.c b/tests/cl/api/get
> -kernel-arg-info.c
> new file mode 100644
> index 0000000..147e7d8
> --- /dev/null
> +++ b/tests/cl/api/get-kernel-arg-info.c
> @@ -0,0 +1,280 @@
> +/*
> + * Copyright © 2014 EdB <edb+piglit at sigluy.net>
> + *
> + * 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.
> + *
> + * copied from get-kernel-info.c
> + * Copyright © 2012 Blaž Tomažič <blaz.tomazic at gmail.com>
> + */
> +
> +/**
> + * @file get-kernel-arg-info.c
> + *
> + * Test API function:
> + *
> + * cl_int clGetKernelArgInfo (cl_kernel kernel,
> + * cl_uint arg_indx,
> + * cl_kernel_arg_info param_name,
> + * size_t param_value_size,
> + * void *param_value,
> + * size_t *param_value_size_ret)
> + */
> +
> +#include "piglit-framework-cl-api.h"
> +
> +
> +PIGLIT_CL_API_TEST_CONFIG_BEGIN
> +
> + config.name = "clGetKernelArgInfo";
> + config.version_min = 12;
> +
> + config.run_per_platform = true;
> + config.create_context = true;
> +
> + config.program_source = "kernel void dummy_kernel(int
> param_1) {}";
> + config.build_options = "-cl-kernel-arg-info";
> +
> +PIGLIT_CL_API_TEST_CONFIG_END
> +
> +
> +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)
> +{
> +#if defined(CL_VERSION_1_2)
> + enum piglit_result result = PIGLIT_PASS;
> +
> + int i;
> + cl_int errNo;
> + cl_kernel kernel;
> +
> + size_t param_value_size;
> + size_t ret_value_size;
> + size_t expected_size;
> +#define BUFFER_SIZE 8
> + char param_value[BUFFER_SIZE];
> +
> + int num_kernel_arg_infos =
> PIGLIT_CL_ENUM_NUM(cl_kernel_arg_info, env->version);
> + const cl_kernel_arg_info* kernel_arg_infos =
> PIGLIT_CL_ENUM_ARRAY(cl_kernel_arg_info);
> +
> + kernel = clCreateKernel(env->program,
> + "dummy_kernel",
> + &errNo);
> + if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
> + fprintf(stderr,
> + "Failed (error code: %s): Create kernel.\n",
> + piglit_cl_get_error_name(errNo));
> + return PIGLIT_FAIL;
> + }
> +
> + /*** Normal usage ***/
> + for(i = 0; i < num_kernel_arg_infos; ++i) {
> + printf("%s\n",
> piglit_cl_get_enum_name(kernel_arg_infos[i]));
> +
> + param_value_size = 0;
> + ret_value_size = 0;
> +
> + errNo = clGetKernelArgInfo(kernel,
> + 0,
> + kernel_arg_infos[i],
> + 0,
> + NULL,
> + ¶m_value_size);
> + if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
> + fprintf(stderr,
> + "Failed (error code: %s): Get size
> of %s.\n",
> + piglit_cl_get_error_name(errNo),
> +
> piglit_cl_get_enum_name(kernel_arg_infos[i]));
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + continue;
> + }
> +
> + if (param_value_size > BUFFER_SIZE) {
> + fprintf(stderr,
> + "Failed: BUFFER_SIZE is too low\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + continue;
> + }
> +
> + errNo = clGetKernelArgInfo(kernel,
> + 0,
> + kernel_arg_infos[i],
> + BUFFER_SIZE,
> + ¶m_value,
> + &ret_value_size);
> + if(!piglit_cl_check_error(errNo, CL_SUCCESS)) {
> + fprintf(stderr,
> + "Failed (error code: %s): Get value
> of %s.\n",
> + piglit_cl_get_error_name(errNo),
> +
> piglit_cl_get_enum_name(kernel_arg_infos[i]));
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + continue;
> + }
> +
> + if (param_value_size != ret_value_size) {
> + fprintf(stderr,
> + "Failed: the returned size doesn't
> matches the queried one\n");
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + continue;
> + }
> +
> +#define CASE(_enum_, _type_, _n_) \
> + case _enum_: \
> + expected_size = sizeof(_type_) * ( _n_ ); \
> + break;
> +
> + expected_size = 0;
> + switch (kernel_arg_infos[i]) {
> + CASE(CL_KERNEL_ARG_ADDRESS_QUALIFIER,
> + cl_kernel_arg_address_qualifier, 1)
> + CASE(CL_KERNEL_ARG_ACCESS_QUALIFIER,
> + cl_kernel_arg_access_qualifier, 1)
> + CASE(CL_KERNEL_ARG_TYPE_NAME, char, 3 + 1)
> + CASE(CL_KERNEL_ARG_TYPE_QUALIFIER,
> + cl_kernel_arg_type_qualifier, 1)
> + CASE(CL_KERNEL_ARG_NAME, char, 7 + 1)
> + }
> +
> +#undef CASE
> +
> + if (ret_value_size != expected_size) {
> + fprintf(stderr,
> + "Failed: the returned size doesn't
> matches. Expected %lu, got %lu\n",
> + expected_size, ret_value_size);
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + //TODO: test returned values
> + }
> +
> + /*** Errors ***/
> +
> + /*
> + * CL_INVALID_ARG_INDEX if arg_indx is not a valid argument
> index.
> + */
> + errNo = clGetKernelArgInfo(kernel,
> + 99,
> + CL_KERNEL_ARG_NAME,
> + 0,
> + NULL,
> + ¶m_value_size);
> + if(!piglit_cl_check_error(errNo, CL_INVALID_ARG_INDEX)) {
> + fprintf(stderr,
> + "Failed (error code: %s): Trigger
> CL_INVALID_ARG_INDEX if arg_indx is not a valid argument index.\n",
> + piglit_cl_get_error_name(errNo));
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + /*
> + * CL_INVALID_VALUE if param_name is not one of the
> supported
> + * values or if size in bytes specified by param_value_size
> is
> + * less than size of return type and param_value is not a
> NULL
> + * value.
> + */
> + errNo = clGetKernelArgInfo(kernel,
> + 0,
> + CL_DEVICE_NAME,
> + 0,
> + NULL,
> + ¶m_value_size);
> + if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
> + fprintf(stderr,
> + "Failed (error code: %s): Trigger
> CL_INVALID_VALUE if param_name is not one of the supported
> values.\n",
> + piglit_cl_get_error_name(errNo));
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + errNo = clGetKernelArgInfo(kernel,
> + 0,
> + CL_KERNEL_ARG_NAME,
> + 1,
> + ¶m_value,
> + NULL);
> + if(!piglit_cl_check_error(errNo, CL_INVALID_VALUE)) {
> + fprintf(stderr,
> + "Failed (error code: %s): Trigger
> CL_INVALID_VALUE if size in bytes specified by param_value is less
> than size of return type and param_value is not a NULL value.\n",
> + piglit_cl_get_error_name(errNo));
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + /*
> + * CL_KERNEL_ARG_INFO_NOT_AVAILABLE
> + * if the argument information is not available for kernel.
> + */
> +
> +/*
> + * PoCL and AMD Accelerated Parallel Processing always return arg
> info.
> + * It doesn't seem valuable to fail in that case.
> + * If your really want it, just define
> CL_KERNEL_ARG_INFO_NOT_AVAILABLE_STRIC
> + * at compilation time
> + */
> +#ifdef CL_KERNEL_ARG_INFO_NOT_AVAILABLE_STRIC
I don't think omitting the last 'T' saves much here, or was it just a
typo?
Do they include -cl-kernel-arg-info by default? Maybe we can filter it
based on whether the flag is present in
clGetProgramBuildInfo(CL_PROGRAM_BUILD_OPTIONS).
I'd enable the subtest by default anyway, it's not the first time an
implementation breaks specs to make life easier for lazy ppl.
> +{
> + char* strings[] = { "kernel void dummy_kernel(int param_a)
> {}" };
> +
> + cl_program prog = piglit_cl_build_program_with_source(env
> ->context,
> + 1,
> +
> strings,
> + "");
> + cl_kernel kern = piglit_cl_create_kernel(prog,
> "dummy_kernel");
> +
> + errNo = clGetKernelArgInfo(kern,
> + 0,
> + CL_KERNEL_ARG_NAME,
> + 0,
> + NULL,
> + ¶m_value_size);
> + if(!piglit_cl_check_error(errNo,
> CL_KERNEL_ARG_INFO_NOT_AVAILABLE)) {
> + fprintf(stderr,
> + "Failed (error code: %s): Trigger
> CL_KERNEL_ARG_INFO_NOT_AVAILABLE if the argument information is not
> available for kernel.\n",
> + piglit_cl_get_error_name(errNo));
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + clReleaseKernel(kern);
> + clReleaseProgram(prog);
> +}
> +#endif
> +
> + /*
> + * CL_INVALID_KERNEL if kernel is not a valid kernel object.
> + */
> + errNo = clGetKernelArgInfo(NULL,
> + 0,
> + CL_KERNEL_ARG_NAME,
> + 0,
> + NULL,
> + ¶m_value_size);
> + if(!piglit_cl_check_error(errNo, CL_INVALID_KERNEL)) {
> + fprintf(stderr,
> + "Failed (error code: %s): Trigger
> CL_INVALID_KERNEL if kernel is not a valid kernel object.\n",
> + piglit_cl_get_error_name(errNo));
> + piglit_merge_result(&result, PIGLIT_FAIL);
> + }
> +
> + clReleaseKernel(kernel);
> +
> + return result;
> +#else
> + return PIGLIT_SKIP;
> +#endif
> +}
> diff --git a/tests/util/piglit-util-cl-enum.c b/tests/util/piglit
> -util-cl-enum.c
> index 5a38e01..3156ce2 100644
> --- a/tests/util/piglit-util-cl-enum.c
> +++ b/tests/util/piglit-util-cl-enum.c
> @@ -750,6 +750,17 @@ PIGLIT_CL_DEFINE_ENUM_2(cl_kernel_info, 5, 5, 6)
> = {
> };
> PIGLIT_CL_DEFINE_ENUM_PTR_2(cl_kernel_info);
>
> +PIGLIT_CL_DEFINE_ENUM_2(cl_kernel_arg_info, 0, 0, 5) = {
> +#ifdef CL_VERSION_1_2
> + CL_KERNEL_ARG_ADDRESS_QUALIFIER,
> + CL_KERNEL_ARG_ACCESS_QUALIFIER,
> + CL_KERNEL_ARG_TYPE_NAME,
> + CL_KERNEL_ARG_TYPE_QUALIFIER,
> + CL_KERNEL_ARG_NAME, //5
> +#endif //CL_VERSION_1_2
> +};
> +PIGLIT_CL_DEFINE_ENUM_PTR_2(cl_kernel_arg_info);
> +
This fails to compile without 1.2 headers, the enum type is not
defined. You'll need to wrap all of cl_kernel_arg_info in the ifdef
block, or provide stub enum. The former sounds cleaner to me.
> PIGLIT_CL_DEFINE_ENUM_2(cl_kernel_work_group_info, 3, 5, 6) = {
> CL_KERNEL_WORK_GROUP_SIZE,
> CL_KERNEL_COMPILE_WORK_GROUP_SIZE,
> diff --git a/tests/util/piglit-util-cl-enum.h b/tests/util/piglit
> -util-cl-enum.h
> index 16c8d3e..f956c8b 100644
> --- a/tests/util/piglit-util-cl-enum.h
> +++ b/tests/util/piglit-util-cl-enum.h
> @@ -81,6 +81,7 @@ PIGLIT_CL_DEFINE_ENUM_PROTOTYPE_2(cl_program_info);
> PIGLIT_CL_DEFINE_ENUM_PROTOTYPE_2(cl_program_build_info);
> PIGLIT_CL_DEFINE_ENUM_PROTOTYPE_2(cl_mem_info);
> PIGLIT_CL_DEFINE_ENUM_PROTOTYPE_2(cl_kernel_info);
> +PIGLIT_CL_DEFINE_ENUM_PROTOTYPE_2(cl_kernel_arg_info);
Same here, build fails with undefined type on opencl 1.1.
> PIGLIT_CL_DEFINE_ENUM_PROTOTYPE_2(cl_kernel_work_group_info);
> PIGLIT_CL_DEFINE_ENUM_PROTOTYPE_2(cl_event_info);
> PIGLIT_CL_DEFINE_ENUM_PROTOTYPE_2(cl_image_info);
FYI: intel CPU OCL returns INVALID_VALUE instead of INVALID_ARG_INDEX,
otherwise passes.
sorry for the delay,
--
Jan Vesely <jan.vesely at rutgers.edu>
More information about the Piglit
mailing list