diff --git a/hpvm/docs/getting-started.rst b/hpvm/docs/getting-started.rst index 2054c46d0a1eeaa3eb65afed8ab11696418e21d4..a3cd05da837d730e06ff74aca6f8846697919448 100644 --- a/hpvm/docs/getting-started.rst +++ b/hpvm/docs/getting-started.rst @@ -15,7 +15,7 @@ The result will be a figure showing the accuracy-performance tradeoff of VGG16 o * Please check ``test/dnn_benchmarks/model_params/`` exists and contains ``vgg16_cifar10/`` and ``pytorch/vgg16_cifar10.pth.tar``, which may not be the case if you opted out of model parameter download in the installer. - In that case, you may run the installer again to download the parameter. + In that case, you may run the installer again to download the model parameters. It will not rebuild everything from scratch. Generating and Compiling a DNN Model diff --git a/hpvm/projects/keras/keras_frontend/approxhpvm_translator.py b/hpvm/projects/keras/keras_frontend/approxhpvm_translator.py index 8f39d77987fe0a4b595f48276480b80187047ea2..304391fea0d74b66635ef0875d94469e22f7cd46 100644 --- a/hpvm/projects/keras/keras_frontend/approxhpvm_translator.py +++ b/hpvm/projects/keras/keras_frontend/approxhpvm_translator.py @@ -950,22 +950,15 @@ class TensorRtTranslator: op_cost_str = " \"op_cost\" : { \n" op_cost_str += self.json_str[:-3] - #f.write(self.json_str) op_cost_str += "\n }, \n\n" f.write(op_cost_str) - - knobs_speedup_str = "\n \"knob_speedup\" : { \n" - for key in knobs_speedups: - knobs_speedup_str += "\"" + str(key) + "\" : " + str(knobs_speedups[key]) + ", \n" - - f.write(knobs_speedup_str[:-3] + "\n}, \n\n") - + + f.write(knobs_str + " \n") layer_knobs_str = " \"op_knobs\" : { \n" layer_knobs_str += self.knobs_str[:-3] layer_knobs_str += " \n\n }, \n\n" - layer_knobs_str += "\"baseline_knob\" : " + baseline_knobs + ", \n" labels_path = weights_dir + "/tune_labels.bin" layer_knobs_str += "\"tune_labels_path\" : \"" + labels_path + "\", \n" layer_knobs_str += "\"conf_path\" : \"tuner_confs.txt\", \n" diff --git a/hpvm/projects/keras/keras_frontend/knobs.py b/hpvm/projects/keras/keras_frontend/knobs.py index 942df9021cacdffd21950db9ce98bce80957571a..4d225f4ed1d1fa3066e0c993b166e5269675f2df 100644 --- a/hpvm/projects/keras/keras_frontend/knobs.py +++ b/hpvm/projects/keras/keras_frontend/knobs.py @@ -1,38 +1,373 @@ -knobs_speedups = {} -knobs_speedups[11] = 1 -knobs_speedups[12] = 1.5 -knobs_speedups[151] = 3 -knobs_speedups[152] = 3 -knobs_speedups[153] = 3 -knobs_speedups[154] = 3 -knobs_speedups[155] = 2.25 -knobs_speedups[156] = 2.25 -knobs_speedups[157] = 2.25 -knobs_speedups[158] = 2.25 -knobs_speedups[159] = 2.25 -knobs_speedups[160] = 2.25 -knobs_speedups[161] = 2 -knobs_speedups[162] = 2 -knobs_speedups[163] = 2 -knobs_speedups[164] = 2 -knobs_speedups[165] = 2 -knobs_speedups[166] = 2 -knobs_speedups[167] = 2 -knobs_speedups[168] = 2 -knobs_speedups[261] = 3 -knobs_speedups[262] = 3 -knobs_speedups[263] = 2.25 -knobs_speedups[264] = 2.25 -knobs_speedups[265] = 2.25 -knobs_speedups[266] = 2 -knobs_speedups[267] = 2 -knobs_speedups[268] = 2 -knobs_speedups[269] = 2 - - -conv_knobs = "\"12\", \"151\", \"152\", \"153\", \"154\", \"155\", \"156\", \"157\", \"158\", \"159\", \"160\", \"161\", \"162\", \"163\", \"164\", \"165\", \"166\", \"167\", \"168\", \"261\", \"262\", \"263\", \"264\", \"265\", \"266\", \"267\", \"268\", \"269\"" - -baseline_knobs = "\"12\"" + + +knobs_str = """ + +"knobs": { + "11": { + "speedup": 1.0, + "baseline_priority": 1, + "devices": [ + "cpu" + ] + }, + "12": { + "speedup": 1.5, + "baseline_priority": 0, + "devices": [ + "gpu" + ] + }, + "121": { + "speedup": 2, + "devices": [ + "cpu" + ] + }, + "122": { + "speedup": 2, + "devices": [ + "cpu" + ] + }, + "123": { + "speedup": 2, + "devices": [ + "cpu" + ] + }, + "124": { + "speedup": 2, + "devices": [ + "cpu" + ] + }, + "125": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "126": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "127": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "128": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "129": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "130": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "131": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "132": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "133": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "134": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "135": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "136": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "137": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "138": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "231": { + "speedup": 2, + "devices": [ + "cpu" + ] + }, + "232": { + "speedup": 2, + "devices": [ + "cpu" + ] + }, + "233": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "234": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "235": { + "speedup": 1.5, + "devices": [ + "cpu" + ] + }, + "236": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "237": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "238": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "239": { + "speedup": 1.33, + "devices": [ + "cpu" + ] + }, + "151": { + "speedup": 3.0, + "devices": [ + "gpu" + ] + }, + "152": { + "speedup": 3.0, + "devices": [ + "gpu" + ] + }, + "153": { + "speedup": 3.0, + "devices": [ + "gpu" + ] + }, + "154": { + "speedup": 3.0, + "devices": [ + "gpu" + ] + }, + "155": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "156": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "157": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "158": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "159": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "160": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "161": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "162": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "163": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "164": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "165": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "166": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "167": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "168": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "261": { + "speedup": 3.0, + "devices": [ + "gpu" + ] + }, + "262": { + "speedup": 3.0, + "devices": [ + "gpu" + ] + }, + "263": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "264": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "265": { + "speedup": 2.25, + "devices": [ + "gpu" + ] + }, + "266": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "267": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "268": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + }, + "269": { + "speedup": 2.0, + "devices": [ + "gpu" + ] + } + }, + + +""" + + +conv_knobs = "\"11\", \"12\"," + +for i in range(121, 139): + conv_knobs += "\"" + str(i) + "\"" + conv_knobs += ", " + +for i in range(151, 169): + conv_knobs += "\"" + str(i) + "\"" + conv_knobs += ", " + +for i in range(231, 240): + conv_knobs += "\"" + str(i) + "\"" + conv_knobs += ", " + +for i in range(261, 270): + conv_knobs += "\"" + str(i) + "\"" + if i != 269: + conv_knobs += ", " + + +baseline_knobs = "\"11\", \"12\"" diff --git a/hpvm/projects/predtuner b/hpvm/projects/predtuner index 83e5ca83c83a69b6220ec4344ae31cac16fa8c46..7159825f27ee7b3c5731ee1b9418c6eafda6622a 160000 --- a/hpvm/projects/predtuner +++ b/hpvm/projects/predtuner @@ -1 +1 @@ -Subproject commit 83e5ca83c83a69b6220ec4344ae31cac16fa8c46 +Subproject commit 7159825f27ee7b3c5731ee1b9418c6eafda6622a diff --git a/hpvm/projects/torch2hpvm/torch2hpvm/approxknobs.json b/hpvm/projects/torch2hpvm/torch2hpvm/approxknobs.json index 64f4e8816b07208d03ccab98624c6c0e477f8e98..4d254610d29969b3766b1f9db9a1f105fb8fda1d 100644 --- a/hpvm/projects/torch2hpvm/torch2hpvm/approxknobs.json +++ b/hpvm/projects/torch2hpvm/torch2hpvm/approxknobs.json @@ -1,450 +1,504 @@ -[ - { - "name": "11", +{ + "11": { "speedup": 1.0, "applies_to": null, - "is_baseline": true, - "devices": null + "baseline_priority": 1, + "devices": [ + "cpu" + ] }, - { - "name": "12", + "12": { "speedup": 1.5, - "applies_to": [ - "convolution", - "linear" - ], - "devices": ["gpu"] + "applies_to": null, + "baseline_priority": 0, + "devices": [ + "gpu" + ] }, - { - "name": "121", + "121": { "speedup": 2, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "122", + "122": { "speedup": 2, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "123", + "123": { "speedup": 2, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "124", + "124": { "speedup": 2, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "125", + "125": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "126", + "126": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "127", + "127": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "128", + "128": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "129", + "129": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "130", + "130": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "131", + "131": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "132", + "132": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "133", + "133": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "134", + "134": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "135", + "135": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "136", + "136": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "137", + "137": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "138", + "138": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "231", + "231": { "speedup": 2, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "232", + "232": { "speedup": 2, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "233", + "233": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "234", + "234": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "235", + "235": { "speedup": 1.5, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "236", + "236": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "237", + "237": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "238", + "238": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "239", + "239": { "speedup": 1.33, "applies_to": [ "convolution" - ], - "devices": ["cpu"] + ], + "devices": [ + "cpu" + ] }, - { - "name": "151", + "151": { "speedup": 3.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "152", + "152": { "speedup": 3.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "153", + "153": { "speedup": 3.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "154", + "154": { "speedup": 3.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "155", + "155": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "156", + "156": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "157", + "157": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "158", + "158": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "159", + "159": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "160", + "160": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "161", + "161": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "162", + "162": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "163", + "163": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "164", + "164": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "165", + "165": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "166", + "166": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "167", + "167": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "168", + "168": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "261", + "261": { "speedup": 3.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "262", + "262": { "speedup": 3.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "263", + "263": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "264", + "264": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "265", + "265": { "speedup": 2.25, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "266", + "266": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "267", + "267": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "268", + "268": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] }, - { - "name": "269", + "269": { "speedup": 2.0, "applies_to": [ "convolution" - ], - "devices": ["gpu"] + ], + "devices": [ + "gpu" + ] } -] +} \ No newline at end of file diff --git a/hpvm/projects/torch2hpvm/torch2hpvm/compile.py b/hpvm/projects/torch2hpvm/torch2hpvm/compile.py index 044eaa10f8632a889dc7183e79b60f409fc21d2d..a3865a007c86605ba044f91f6fa3d6202bd2110c 100644 --- a/hpvm/projects/torch2hpvm/torch2hpvm/compile.py +++ b/hpvm/projects/torch2hpvm/torch2hpvm/compile.py @@ -120,31 +120,22 @@ class ModelExporter: from collections import defaultdict with Path(approx_knobs_file).open() as f: - knobs = json.load(f) + knobs = json.load(f) # knob name to knob attrs dict # 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: - name = k["name"] - if "is_baseline" in k: - if baseline_knob: - raise ValueError("Multiple baseline knobs") - baseline_knob = name - applies_to = k["applies_to"] + for name, attrs in knobs.items(): + applies_to = attrs.pop("applies_to") if applies_to is None: default_knobs.append(name) continue for ty in applies_to: 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]] = {} - used_knobs = set() for node in self.dfg.traverse_order: if not node.hpvm_op_type: continue @@ -160,9 +151,7 @@ class ModelExporter: { "op_cost": op_cost, "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, + "knobs": knobs, **self.path_params, }, f,