diff --git a/hpvm/projects/predtuner b/hpvm/projects/predtuner index 108de0205d1f84082f9722d2e0e7b51dd5f8d997..83e5ca83c83a69b6220ec4344ae31cac16fa8c46 160000 --- a/hpvm/projects/predtuner +++ b/hpvm/projects/predtuner @@ -1 +1 @@ -Subproject commit 108de0205d1f84082f9722d2e0e7b51dd5f8d997 +Subproject commit 83e5ca83c83a69b6220ec4344ae31cac16fa8c46 diff --git a/hpvm/projects/torch2hpvm/torch2hpvm/approxknobs.json b/hpvm/projects/torch2hpvm/torch2hpvm/approxknobs.json index 9d7cb28a8b3fcc2301735c21e99119beb5a89907..64f4e8816b07208d03ccab98624c6c0e477f8e98 100644 --- a/hpvm/projects/torch2hpvm/torch2hpvm/approxknobs.json +++ b/hpvm/projects/torch2hpvm/torch2hpvm/approxknobs.json @@ -3,7 +3,8 @@ "name": "11", "speedup": 1.0, "applies_to": null, - "is_baseline": true + "is_baseline": true, + "devices": null }, { "name": "12", @@ -11,195 +12,439 @@ "applies_to": [ "convolution", "linear" - ] + ], + "devices": ["gpu"] + }, + { + "name": "121", + "speedup": 2, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "122", + "speedup": 2, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "123", + "speedup": 2, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "124", + "speedup": 2, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "125", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "126", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "127", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "128", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "129", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "130", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "131", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "132", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "133", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "134", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "135", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "136", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "137", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "138", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "231", + "speedup": 2, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "232", + "speedup": 2, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "233", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "234", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "235", + "speedup": 1.5, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "236", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "237", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "238", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] + }, + { + "name": "239", + "speedup": 1.33, + "applies_to": [ + "convolution" + ], + "devices": ["cpu"] }, { "name": "151", "speedup": 3.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "152", "speedup": 3.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "153", "speedup": 3.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "154", "speedup": 3.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "155", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "156", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "157", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "158", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "159", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "160", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "161", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "162", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "163", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "164", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "165", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "166", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "167", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "168", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "261", "speedup": 3.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "262", "speedup": 3.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "263", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "264", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "265", "speedup": 2.25, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "266", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "267", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "268", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] }, { "name": "269", "speedup": 2.0, "applies_to": [ "convolution" - ] + ], + "devices": ["gpu"] } ] diff --git a/hpvm/projects/torch2hpvm/torch2hpvm/compile.py b/hpvm/projects/torch2hpvm/torch2hpvm/compile.py index d53776b363595dd10b8f46f792474b941f444f2b..044eaa10f8632a889dc7183e79b60f409fc21d2d 100644 --- a/hpvm/projects/torch2hpvm/torch2hpvm/compile.py +++ b/hpvm/projects/torch2hpvm/torch2hpvm/compile.py @@ -121,45 +121,47 @@ class ModelExporter: with Path(approx_knobs_file).open() as f: knobs = json.load(f) - KnobInfoT = Tuple[str, float] - ty_knobs: Dict[str, List[KnobInfoT]] = defaultdict(list) - default_knobs: List[KnobInfoT] = [] + # Organize knobs into defaults and the ones for certain types + ty_knobs: Dict[str, str] = defaultdict(list) + default_knobs: List[str] = [] baseline_knob = None for k in knobs: - kp = k["name"], k["speedup"] + name = k["name"] if "is_baseline" in k: if baseline_knob: raise ValueError("Multiple baseline knobs") - baseline_knob = k["name"] + baseline_knob = name applies_to = k["applies_to"] if applies_to is None: - default_knobs.append(kp) + default_knobs.append(name) continue for ty in applies_to: - ty_knobs[ty].append(kp) + ty_knobs[ty].append(name) if not baseline_knob: raise ValueError("No baseline knob given") + + # Enumerate operators and find knobs for each idx = 0 op_cost: Dict[str, int] = {} op_knobs: Dict[str, List[str]] = {} - knob_speedup: Dict[str, float] = {} + used_knobs = set() for node in self.dfg.traverse_order: if not node.hpvm_op_type: continue hpvm_op_name = f"{node.hpvm_op_type}_{idx}" type_knobs = ty_knobs.get(node.hpvm_op_type, []) - this_op_knobs = type_knobs + default_knobs - knobs_speedup = dict(this_op_knobs) + op_knobs[hpvm_op_name] = type_knobs + default_knobs op_cost[hpvm_op_name] = int(node.get_flops()) # May get np.int64 - op_knobs[hpvm_op_name] = list(knobs_speedup.keys()) - knob_speedup.update(knobs_speedup) idx += 1 + + # Write out with Path(output).open("w") as f: json.dump( { "op_cost": op_cost, - "knob_speedup": knob_speedup, "op_knobs": op_knobs, + "knob_speedup": {k["name"]: k["speedup"] for k in knobs}, + "knob_devices": {k["name"]: k["devices"] for k in knobs}, "baseline_knob": baseline_knob, **self.path_params, }, diff --git a/hpvm/test/dnn_benchmarks/pytorch/test_tuning/test_tuning.py b/hpvm/test/dnn_benchmarks/pytorch/test_tuning/test_tuning.py index c589b108d73277977820407f1874cf33053fcc34..9f969a42616804e4b26eb90b3d379a2b5dd08436 100755 --- a/hpvm/test/dnn_benchmarks/pytorch/test_tuning/test_tuning.py +++ b/hpvm/test/dnn_benchmarks/pytorch/test_tuning/test_tuning.py @@ -24,7 +24,7 @@ def main(): binary_file, exporter = dnn.export_example_dnn(netname, codegen_dir, True) metadata_file = codegen_dir / exporter.metadata_file_name # Tuning - app = PipedBinaryApp("test", binary_file, metadata_file) + app = PipedBinaryApp("test", binary_file, metadata_file, tuning_device="cpu") tuner = app.get_tuner() tuner.tune( 5,