From 50e77d59e04432fa33c98c56ef3f858f795c49f6 Mon Sep 17 00:00:00 2001 From: papertager <2567587994@qq.com> Date: Tue, 9 Jun 2026 11:09:42 +0800 Subject: [PATCH 1/2] Add JSON operator listing to mcoplib benchmark --- benchmark/mcoplib_mxbenchmark_ops.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/benchmark/mcoplib_mxbenchmark_ops.py b/benchmark/mcoplib_mxbenchmark_ops.py index 93b6932..75f78ce 100644 --- a/benchmark/mcoplib_mxbenchmark_ops.py +++ b/benchmark/mcoplib_mxbenchmark_ops.py @@ -12,8 +12,7 @@ try: import cuda.bench._nvbench as bench except ImportError: - print("[ERROR] Runtime environment missing 'nvbench'. Please check configuration.") - sys.exit(1) + bench = None # Import base class for type checking from mcoplib_mxbenchmark_op_wrapper import OpBenchmarkBase @@ -115,12 +114,17 @@ def get_base_dir(): return os.path.dirname(os.path.abspath(__file__)) -def list_supported_operators(): +def list_supported_operators(json_output=False): + operators = sorted(SUPPORTED_OPERATORS) + if json_output: + print(json.dumps({"operators": operators, "count": len(operators)}, sort_keys=True)) + return + print("\n" + "="*40 + f"\n{' Supported Operators ':=^40}\n" + "="*40) - if not SUPPORTED_OPERATORS: + if not operators: print(" (No operators defined in SUPPORTED_OPERATORS list)") else: - for op in sorted(SUPPORTED_OPERATORS): + for op in operators: print(f" * {op}") print("="*40 + "\n") @@ -576,6 +580,7 @@ def perform_comparison(cur_raw, hist_raw): parser = argparse.ArgumentParser(description="MCOPLIB Operator Performance Benchmark") parser.add_argument("--op", type=str, default=None, help="Operator name (Required, unless --list is used)") parser.add_argument("--list", action="store_true", help="List all supported operators and exit") + parser.add_argument("--list-json", action="store_true", help="Print supported operators as JSON and exit") parser.add_argument("--csv", type=str, default=None, help="Path to result CSV") group = parser.add_mutually_exclusive_group() @@ -587,8 +592,8 @@ def perform_comparison(cur_raw, hist_raw): args, unknown = parser.parse_known_args() # 1. Handle --list - if args.list: - list_supported_operators() + if args.list or args.list_json: + list_supported_operators(json_output=args.list_json) sys.exit(0) # 2. Validate Core Argument --op @@ -601,6 +606,10 @@ def perform_comparison(cur_raw, hist_raw): print("-"*80 + "\n") sys.exit(1) + if bench is None: + print("[ERROR] Runtime environment missing 'nvbench'. Please check configuration.") + sys.exit(1) + # 3. Load Operator op_name = args.op op_instance = load_operator_runner(op_name) From 685897090745b3bce9937a4961028fca29d6b7e3 Mon Sep 17 00:00:00 2001 From: papertager <2567587994@qq.com> Date: Thu, 11 Jun 2026 00:37:32 +0800 Subject: [PATCH 2/2] Keep benchmark JSON output machine-friendly --- benchmark/mcoplib_mxbenchmark_ops.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/benchmark/mcoplib_mxbenchmark_ops.py b/benchmark/mcoplib_mxbenchmark_ops.py index 75f78ce..5169e83 100644 --- a/benchmark/mcoplib_mxbenchmark_ops.py +++ b/benchmark/mcoplib_mxbenchmark_ops.py @@ -578,7 +578,12 @@ def perform_comparison(cur_raw, hist_raw): # ============================================================================= if __name__ == "__main__": parser = argparse.ArgumentParser(description="MCOPLIB Operator Performance Benchmark") - parser.add_argument("--op", type=str, default=None, help="Operator name (Required, unless --list is used)") + parser.add_argument( + "--op", + type=str, + default=None, + help="Operator name (Required, unless --list or --list-json is used)", + ) parser.add_argument("--list", action="store_true", help="List all supported operators and exit") parser.add_argument("--list-json", action="store_true", help="Print supported operators as JSON and exit") parser.add_argument("--csv", type=str, default=None, help="Path to result CSV") @@ -607,7 +612,7 @@ def perform_comparison(cur_raw, hist_raw): sys.exit(1) if bench is None: - print("[ERROR] Runtime environment missing 'nvbench'. Please check configuration.") + print("[ERROR] Runtime environment missing 'nvbench'. Please check configuration.", file=sys.stderr) sys.exit(1) # 3. Load Operator