[Beignet] [PATCH] Fix based on piglit OpenCL failed case (cl-program-tester).

Zhigang Gong zhigang.gong at linux.intel.com
Tue Dec 2 16:50:25 PST 2014


This is not a valid fix for beignet. Please check the OpenCL spec:

-cl-std=
  Determine the OpenCL C language version to use. A value for this option must be
  provided. Valid values are:
  CL1.1 – Support all OpenCL C programs that use the OpenCL C language features
          defined in section 6 of the OpenCL 1.1 specification.
  CL1.2 – Support all OpenCL C programs that use the OpenCL C language features
          defined in section 6 of the OpenCL 1.2 specification.

So -cl-std=CL1.0 is not a valid value, and the backend reports:
  Invalid build option: -cl-std=CL1.0
is comply with the spec. Don't try to filter this type of options in runtime library.

This should be a bug in the piglit test case.

On Tue, Dec 02, 2014 at 04:07:06PM +0800, Yan Wang wrote:
> Fix tests/cl/program/build/optimization-options-cl10.cl
> After calling check_cl_version_option, -cl-std=CLX.X should be
> removed. This options couldn't be accepted by the subsequent
> process.
> 
> Signed-off-by: Yan Wang <yan.wang at linux.intel.com>
> ---
>  src/cl_program.c | 50 ++++++++++++++++++++++++++++++++++++++------------
>  1 file changed, 38 insertions(+), 12 deletions(-)
> 
> diff --git a/src/cl_program.c b/src/cl_program.c
> index c30f85e..07de15b 100644
> --- a/src/cl_program.c
> +++ b/src/cl_program.c
> @@ -438,7 +438,7 @@ error:
>  
>  /* Before we do the real work, we need to check whether our platform
>     cl version can meet -cl-std= */
> -static int check_cl_version_option(cl_program p, const char* options) {
> +static int check_cl_version_option(cl_program p, const char* options, char** fopt) {
>    const char* s = NULL;
>    int ver1 = 0;
>    int ver2 = 0;
> @@ -467,16 +467,25 @@ static int check_cl_version_option(cl_program p, const char* options) {
>      if (ver2 < ver1)
>        return 0;
>  
> +    TRY_ALLOC_NO_ERR (*fopt, cl_calloc(strlen(options) + 1, sizeof(char)));
> +    memcpy(*fopt, options, s - options);
> +    if (s + strlen("-cl-std=CLX.X") < options + strlen(options))
> +      memcpy((*fopt) + (s - options), s + strlen("-cl-std=CLX.X"),
> +        options + strlen(options) - s - strlen("-cl-std=CLX.X"));
> +
>      return 1;
>    }
>  
>    return 1;
> +error:
> +  return 0;
>  }
>  
>  LOCAL cl_int
>  cl_program_build(cl_program p, const char *options)
>  {
>    cl_int err = CL_SUCCESS;
> +  char* filter_options = NULL;
>    int i = 0;
>    int copyed = 0;
>  
> @@ -485,7 +494,7 @@ cl_program_build(cl_program p, const char *options)
>      goto error;
>    }
>  
> -  if (!check_cl_version_option(p, options)) {
> +  if (!check_cl_version_option(p, options, &filter_options)) {
>      err = CL_BUILD_PROGRAM_FAILURE;
>      goto error;
>    }
> @@ -495,8 +504,12 @@ cl_program_build(cl_program p, const char *options)
>          cl_free(p->build_opts);
>          p->build_opts = NULL;
>        }
> -      TRY_ALLOC (p->build_opts, cl_calloc(strlen(options) + 1, sizeof(char)));
> -      memcpy(p->build_opts, options, strlen(options));
> +      if (filter_options) {
> +        p->build_opts = filter_options; 
> +      } else {
> +        TRY_ALLOC (p->build_opts, cl_calloc(strlen(options) + 1, sizeof(char)));
> +        memcpy(p->build_opts, options, strlen(options));
> +      }
>  
>        p->source_type = p->source ? FROM_SOURCE : p->binary ? FROM_BINARY : FROM_LLVM;
>      }
> @@ -515,7 +528,8 @@ cl_program_build(cl_program p, const char *options)
>        goto error;
>      }
>  
> -    p->opaque = compiler_program_new_from_source(p->ctx->device->vendor_id, p->source, p->build_log_max_sz, options, p->build_log, &p->build_log_sz);
> +    p->opaque = compiler_program_new_from_source(p->ctx->device->vendor_id, p->source, p->build_log_max_sz,
> +      filter_options ? filter_options : options, p->build_log, &p->build_log_sz);
>      if (UNLIKELY(p->opaque == NULL)) {
>        if (p->build_log_sz > 0 && strstr(p->build_log, "error: error reading 'options'"))
>          err = CL_INVALID_BUILD_OPTIONS;
> @@ -532,7 +546,8 @@ cl_program_build(cl_program p, const char *options)
>        goto error;
>      }
>  
> -    compiler_program_build_from_llvm(p->opaque, p->build_log_max_sz, p->build_log, &p->build_log_sz, options);
> +    compiler_program_build_from_llvm(p->opaque, p->build_log_max_sz, p->build_log, &p->build_log_sz,
> +      filter_options ? filter_options : options);
>      if (UNLIKELY(p->opaque == NULL)) {
>        if (p->build_log_sz > 0 && strstr(p->build_log, "error: error reading 'options'"))
>          err = CL_INVALID_BUILD_OPTIONS;
> @@ -587,9 +602,10 @@ cl_program_link(cl_context            context,
>    cl_int err = CL_SUCCESS;
>    cl_int i = 0;
>    int copyed = 0;
> +  char* filter_options = NULL;
>    p = cl_program_new(context);
>  
> -  if (!check_cl_version_option(p, options)) {
> +  if (!check_cl_version_option(p, options, &filter_options)) {
>      err = CL_BUILD_PROGRAM_FAILURE;
>      goto error;
>    }
> @@ -614,7 +630,8 @@ cl_program_link(cl_context            context,
>      p->binary_type = CL_PROGRAM_BINARY_TYPE_EXECUTABLE;
>    }
>  
> -  compiler_program_build_from_llvm(p->opaque, p->build_log_max_sz, p->build_log, &p->build_log_sz, options);
> +  compiler_program_build_from_llvm(p->opaque, p->build_log_max_sz, p->build_log, &p->build_log_sz,
> +    filter_options ? filter_options : options);
>  
>    /* Create all the kernels */
>    TRY (cl_program_load_gen_program, p);
> @@ -633,6 +650,8 @@ cl_program_link(cl_context            context,
>      copyed += sz;
>    }
>  done:
> +  if (filter_options)
> +    cl_free(filter_options);
>    p->is_built = 1;
>    p->build_status = CL_BUILD_SUCCESS;
>    if (errcode_ret)
> @@ -640,6 +659,8 @@ done:
>    return p;
>  
>  error:
> +  if (filter_options)
> +    cl_free(filter_options);
>    p->build_status = CL_BUILD_ERROR;
>    if (errcode_ret)
>      *errcode_ret = err;
> @@ -655,13 +676,14 @@ cl_program_compile(cl_program            p,
>  {
>    cl_int err = CL_SUCCESS;
>    int i = 0;
> +  char* filter_options = NULL;
>  
>    if (p->ref_n > 1) {
>      err = CL_INVALID_OPERATION;
>      goto error;
>    }
>  
> -  if (!check_cl_version_option(p, options)) {
> +  if (!check_cl_version_option(p, options, &filter_options)) {
>      err = CL_BUILD_PROGRAM_FAILURE;
>      goto error;
>    }
> @@ -672,8 +694,12 @@ cl_program_compile(cl_program            p,
>          cl_free(p->build_opts);
>          p->build_opts = NULL;
>        }
> -      TRY_ALLOC (p->build_opts, cl_calloc(strlen(options) + 1, sizeof(char)));
> -      memcpy(p->build_opts, options, strlen(options));
> +      if (filter_options) {
> +        p->build_opts = filter_options; 
> +      } else {
> +        TRY_ALLOC (p->build_opts, cl_calloc(strlen(options) + 1, sizeof(char)));
> +        memcpy(p->build_opts, options, strlen(options));
> +      }
>  
>        p->source_type = p->source ? FROM_SOURCE : p->binary ? FROM_BINARY : FROM_LLVM;
>      }
> @@ -725,7 +751,7 @@ cl_program_compile(cl_program            p,
>      }
>  
>      p->opaque = compiler_program_compile_from_source(p->ctx->device->vendor_id, p->source, temp_header_path,
> -        p->build_log_max_sz, options, p->build_log, &p->build_log_sz);
> +        p->build_log_max_sz, filter_options ? filter_options : options, p->build_log, &p->build_log_sz);
>  
>      char rm_path[255]="rm ";
>      strncat(rm_path, temp_header_path, strlen(temp_header_path));
> -- 
> 1.9.3
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list