diff --git a/mlir/utils/spirv/gen_spirv_dialect.py b/mlir/utils/spirv/gen_spirv_dialect.py --- a/mlir/utils/spirv/gen_spirv_dialect.py +++ b/mlir/utils/spirv/gen_spirv_dialect.py @@ -445,8 +445,8 @@ Arguments: - instructions: a list containing a subset of SPIR-V instructions' grammar Returns: - - A map with keys representing capabilities and values of lists of instructions - enabled by the corresponding key + - A map with keys representing capabilities and values of lists of + instructions enabled by the corresponding key """ cap_to_inst = {} @@ -473,13 +473,15 @@ existing_opcodes = [k[11:] for k in re.findall('def SPV_OC_\w+', content[1])] existing_instructions = list( - filter(lambda inst: (inst['opname'] in existing_opcodes), instructions)) + filter(lambda inst: (inst['opname'] in existing_opcodes), + instructions)) instructions_opnames = [inst['opname'] for inst in instructions] remaining_opcodes = list(set(instructions_opnames) - set(existing_opcodes)) remaining_instructions = list( - filter(lambda inst: (inst['opname'] in remaining_opcodes), instructions)) + filter(lambda inst: (inst['opname'] in remaining_opcodes), + instructions)) rem_cap_to_instr = map_cap_to_opnames(remaining_instructions) ex_cap_to_instr = map_cap_to_opnames(existing_instructions) @@ -492,14 +494,16 @@ rem_cap_to_cov[cap] = 0.0 else: rem_cap_to_cov[cap] = \ - (len(ex_cap_to_instr[cap]) / (len(ex_cap_to_instr[cap]) + len(rem_cap_to_instr[cap]))) + (len(ex_cap_to_instr[cap]) / (len(ex_cap_to_instr[cap]) \ + + len(rem_cap_to_instr[cap]))) report = {} # Merge the 3 maps into one report for cap in rem_cap_to_instr: report[cap] = {} - report[cap]['Supported Instructions'] = ex_cap_to_instr[cap] if cap in ex_cap_to_instr else [] + report[cap]['Supported Instructions'] = \ + ex_cap_to_instr[cap] if cap in ex_cap_to_instr else [] report[cap]['Unsupported Instructions'] = rem_cap_to_instr[cap] report[cap]['Coverage'] = '{}%'.format(int(rem_cap_to_cov[cap] * 100)) diff --git a/mlir/utils/spirv/report_coverage.sh b/mlir/utils/spirv/report_coverage.sh new file mode 100755 --- /dev/null +++ b/mlir/utils/spirv/report_coverage.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Script for reporting current level of SPIR-V spec instruction coverage in spv +# Dialect. It dumps to standard output a YAML string of current coverage. +# +# Run as: +# ./report_coverage.sh + +set -e + +current_file="$(readlink -f "$0")" +current_dir="$(dirname "$current_file")" + +python3 ${current_dir}/gen_spirv_dialect.py \ + --base-td-path ${current_dir}/../../include/mlir/Dialect/SPIRV/SPIRVBase.td \ + --gen-inst-coverage