示例#1
0
def json_verify_intercepted(args, kernels, json_to_kernel_map, success_cache):
  if args.verify_intercepted >= len(json_to_kernel_map):
    raise JSONError("No kernel " + str(args.verify_intercepted) + " in JSON file")

  k = kernels[json_to_kernel_map[args.verify_intercepted]]
  return_code, out_data = json_verify_kernel(args, os.path.dirname(args.kernel.name), k, success_cache)

  result_format = "Verification of {} ({}) {} with: local size = [{}] global size = [{}]"
  print(result_format.format(k.entry_point,
                             k.kernel_file,
                             "succeeded" if return_code == ErrorCodes.SUCCESS else "failed",
                             ",".join(map(str, k.local_size)),
                             ",".join(map(str, k.global_size))
                            ))

  if return_code != ErrorCodes.SUCCESS:
    print("The error message is:")
    print(out_data)
示例#2
0
def json_verify_kernel(args, base_path, kernel, success_cache):
    if kernel in success_cache:
        return ErrorCodes.SUCCESS, "Verified: Found result in success cache"

    kernel_args = copy.deepcopy(args)
    kernel_name = os.path.join(base_path, kernel.kernel_file)
    try:
        kernel_args.kernel = open(kernel_name, "r")
    except IOError as e:
        raise JSONError(str(e))
    kernel_args.kernel_name, kernel_args.kernel_ext = \
      os.path.splitext(kernel_name)
    kernel_args.source_language = SourceLanguage.OpenCL
    kernel_args.group_size = kernel.local_size
    kernel_args.global_size = kernel.global_size
    kernel_args.num_groups = kernel.num_groups
    if "compiler_flags" in kernel:
        kernel_args.defines += kernel.compiler_flags.defines
        kernel_args.includes += kernel.compiler_flags.includes
    if "kernel_arguments" in kernel:
        scalar_args = [arg for arg in kernel.kernel_arguments \
                         if arg.type == "scalar" or arg.type == "sampler"]
        scalar_vals = [arg.value if "value" in arg else "*" \
                         for arg in scalar_args]
        kernel_args.kernel_args = [[kernel.entry_point] + scalar_vals]
        array_args = [arg for arg in kernel.kernel_arguments \
                        if arg.type == "array" or arg.type == "image"]
        array_sizes = [arg.size if "size" in arg else "*" \
                         for arg in array_args]
        kernel_args.kernel_arrays = [[kernel.entry_point] + array_sizes]
    outFile = tempfile.SpooledTemporaryFile()
    return_code = main(kernel_args, outFile, subprocess.STDOUT)
    outFile.seek(0)
    out_data = outFile.read()[:-1]
    outFile.close()

    if return_code == ErrorCodes.SUCCESS:
        success_cache.append(kernel)

    return return_code, out_data