|
| 1 | +################################################################################ |
| 2 | +# Copyright 2024 Intel Corporation |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +################################################################################ |
| 16 | + |
| 17 | + |
| 18 | +import json |
| 19 | +import sys |
| 20 | +import argparse |
| 21 | +import gcext.ir |
| 22 | +import gcext.dialects.onednn_graph |
| 23 | +from . import graph, runner, gapi, util |
| 24 | + |
| 25 | +try: |
| 26 | + parser = argparse.ArgumentParser(prog="benchmark tool for graph compiler") |
| 27 | + parser.add_argument("--mlir", required=True, help="a mlir case file", type=str) |
| 28 | + parser.add_argument("--entry", required=True, help="main entry function", type=str) |
| 29 | + parser.add_argument( |
| 30 | + "--json", |
| 31 | + default=None, |
| 32 | + help="dump graph api json file into the specified file name", |
| 33 | + type=str, |
| 34 | + ) |
| 35 | + parser.add_argument( |
| 36 | + "--seed", |
| 37 | + required=False, |
| 38 | + default=0, |
| 39 | + type=int, |
| 40 | + help="a seed value to generate data filling", |
| 41 | + ) |
| 42 | + parser.add_argument( |
| 43 | + "--verbose", |
| 44 | + type=int, |
| 45 | + default=util.NO_VERBOSE, |
| 46 | + help="verbose level", |
| 47 | + choices=[ |
| 48 | + util.NO_VERBOSE, |
| 49 | + util.COMPARE_VERBOSE, |
| 50 | + util.ERROR_OUTPUT_VERBOSE, |
| 51 | + util.OUTPUT_VERBOSE, |
| 52 | + util.INPUT_VERBOSE, |
| 53 | + ], |
| 54 | + ) |
| 55 | + |
| 56 | + args = parser.parse_args() |
| 57 | + util.set_seed(args.seed) |
| 58 | +except argparse.ArgumentError: |
| 59 | + sys.stderr.write("Argument parse failed\n") |
| 60 | + sys.exit(1) |
| 61 | + |
| 62 | +with open(args.mlir, "r") as mlir_file: |
| 63 | + with gcext.ir.Context() as ctx: |
| 64 | + gcext.dialects.onednn_graph.register_dialect() |
| 65 | + module = gcext.ir.Module.parse(mlir_file.read()) |
| 66 | + g = gapi.MLIRGraph(module) |
| 67 | + graph_object = g.convert_to_json('"' + args.entry + '"') |
| 68 | + if args.json is not None: |
| 69 | + with open(args.json, "w") as json_file: |
| 70 | + json.dump(graph_object, json_file) |
0 commit comments