|
1 | 1 | import os |
2 | 2 | import sys |
3 | | -import tempfile |
4 | 3 | import importlib |
| 4 | +import json |
| 5 | + |
| 6 | +CONFIG_TORCHSIM_DIR = os.environ.get('TORCHSIM_DIR', default='/workspace/PyTorchSim') |
| 7 | +CONFIG_GEM5_PATH = os.environ.get('GEM5_PATH', default="/workspace/gem5/build/RISCV/gem5.opt") |
| 8 | +CONFIG_TORCHSIM_LLVM_PATH = os.environ.get('TORCHSIM_LLVM_PATH', default="/usr/bin") |
| 9 | + |
| 10 | +CONFIG_TORCHSIM_DUMP_MLIR_IR = int(os.environ.get("TORCHSIM_DUMP_MLIR_IR", default=False)) |
| 11 | +CONFIG_TORCHSIM_DUMP_LLVM_IR = int(os.environ.get("TORCHSIM_DUMP_LLVM_IR", default=False)) |
5 | 12 |
|
6 | 13 | def __getattr__(name): |
| 14 | + # TOGSim config |
| 15 | + config_path = os.environ.get('TOGSIM_CONFIG', |
| 16 | + default=f"{CONFIG_TORCHSIM_DIR}/configs/systolic_ws_128x128_c1_simple_noc_tpuv3.json") |
| 17 | + if name == "CONFIG_TOGSIM_CONFIG": |
| 18 | + return config_path |
| 19 | + config_json = json.load(open(config_path, 'r')) |
7 | 20 |
|
8 | 21 | # Hardware info config |
9 | | - if name == "CONFIG_VECTOR_LANE": |
10 | | - return int(os.environ.get("TORCHSIM_VECTOR_LANE", default=128)) |
11 | | - if name == "CONFIG_VECTOR_LANE_STRIDE": |
12 | | - return int(os.environ.get("TORCHSIM_VECTOR_LANE_STRIDE", default=2)) |
| 22 | + if name == "vpu_num_lanes": |
| 23 | + return config_json["vpu_num_lanes"] |
13 | 24 | if name == "CONFIG_SPAD_INFO": |
14 | 25 | return { |
15 | 26 | "spad_vaddr" : 0xD0000000, |
16 | 27 | "spad_paddr" : 0x2000000000, |
17 | | - "spad_size" : int(os.environ.get("TORCHSIM_SPAD_SIZE", default=128)) << 10 # Note: spad size per lane |
| 28 | + "spad_size" : config_json["vpu_spad_size_kb_per_lane"] << 10 # Note: spad size per lane |
18 | 29 | } |
| 30 | + |
19 | 31 | if name == "CONFIG_PRECISION": |
20 | | - return 4 # 32bit |
| 32 | + return 4 # 32bit |
21 | 33 | if name == "CONFIG_NUM_CORES": |
22 | | - return 1 |
23 | | - if name == "CONFIG_VLEN": |
24 | | - return 256 # 256bits / 32bits = 8 [elements] |
25 | | - |
26 | | - # Tile size config |
27 | | - if name == "CONFIG_TORCHSIM_DIR": |
28 | | - return os.environ.get('TORCHSIM_DIR', default='/workspace/PyTorchSim') |
29 | | - |
30 | | - if name == "CONFIG_TORCHSIM_DUMP_PATH": |
31 | | - return os.environ.get('TORCHSIM_DUMP_PATH', default = f"{tempfile.gettempdir()}/torchinductor") |
32 | | - if name == "CONFIG_TORCHSIM_DUMP_FILE": |
33 | | - return int(os.environ.get('TORCHSIM_DUMP_FILE', default=True)) |
34 | | - if name == "CONFIG_TORCHSIM_FUNCTIONAL_MODE": |
35 | | - return int(os.environ.get('TORCHSIM_FUNCTIONAL_MODE', default=True)) |
36 | | - if name == "CONFIG_TORCHSIM_TIMING_MODE": |
37 | | - return int(os.environ.get("TORCHSIM_TIMING_MODE", True)) |
38 | | - if name == "CONFIG_CLEANUP_DUMP_ARGS": |
39 | | - return int(os.environ.get('CLEANUP_DUMP_ARGS', default=False)) |
40 | | - |
41 | | - # LLVM PATH |
42 | | - if name == "CONFIG_TORCHSIM_LLVM_PATH": |
43 | | - return os.environ.get('TORCHSIM_LLVM_PATH', default="/usr/bin") |
44 | | - if name == "CONFIG_TORCHSIM_CUSTOM_PASS_PATH": |
45 | | - return os.environ.get('TORCHSIM_CUSTOM_PASS_PATH', |
46 | | - default=f"{__getattr__('CONFIG_TORCHSIM_DIR')}/GemminiLowerPass/build") |
47 | | - if name == "CONFIG_TORCHSIM_DUMP_MLIR_IR": |
48 | | - return int(os.environ.get("TORCHSIM_DUMP_MLIR_IR", default=False)) |
49 | | - if name == "CONFIG_TORCHSIM_DUMP_LLVM_IR": |
50 | | - return int(os.environ.get("TORCHSIM_DUMP_LLVM_IR", default=False)) |
51 | | - |
52 | | - # TOGSim config |
53 | | - if name == "CONFIG_TOGSIM_CONFIG": |
54 | | - return os.environ.get('TORCHSIM_CONFIG', |
55 | | - default=f"{__getattr__('CONFIG_TORCHSIM_DIR')}/TOGSim/configs/systolic_ws_128x128_c1_simple_noc_tpuv3.json") |
56 | | - if name == "CONFIG_TOGSIM_EAGER_MODE": |
57 | | - return int(os.environ.get("TOGSIM_EAGER_MODE", default=False)) |
58 | | - if name == "CONFIG_TOGSIM_DRYRUN": |
59 | | - return int(os.environ.get('TOGSIM_DRYRUN', default=False)) |
60 | | - if name == "CONFIG_TOGSIM_DEBUG_LEVEL": |
61 | | - return os.environ.get("TOGSIM_DEBUG_LEVEL", "") |
| 34 | + return config_json["num_cores"] |
| 35 | + if name == "vpu_vector_length_bits": |
| 36 | + return config_json["vpu_vector_length_bits"] |
| 37 | + |
| 38 | + if name == "pytorchsim_functional_mode": |
| 39 | + return config_json['pytorchsim_functional_mode'] |
| 40 | + if name == "pytorchsim_timing_mode": |
| 41 | + return config_json['pytorchsim_timing_mode'] |
| 42 | + |
| 43 | + # Mapping strategy |
| 44 | + if name == "codegen_mapping_strategy": |
| 45 | + codegen_mapping_strategy = config_json["codegen_mapping_strategy"] |
| 46 | + assert(codegen_mapping_strategy in ["heuristic", "autotune", "external-then-heuristic", "external-then-autotune"]), "Invalid mapping strategy!" |
| 47 | + return codegen_mapping_strategy |
| 48 | + |
| 49 | + if name == "codegen_external_mapping_file": |
| 50 | + return config_json["codegen_external_mapping_file"] |
| 51 | + |
| 52 | + # Autotune config |
| 53 | + if name == "codegen_autotune_max_retry": |
| 54 | + return config_json["codegen_autotune_max_retry"] |
| 55 | + if name == "codegen_autotune_template_topk": |
| 56 | + return config_json["codegen_autotune_template_topk"] |
62 | 57 |
|
63 | | - # GEM5 config |
64 | | - if name == "CONFIG_GEM5_PATH": |
65 | | - return os.environ.get('GEM5_PATH', default="/workspace/gem5/build/RISCV/gem5.opt") |
66 | | - if name == "CONFIG_GEM5_SCRIPT_PATH": |
67 | | - return os.environ.get('GEM5_SCRIPT_PATH', |
68 | | - default=f"{__getattr__('CONFIG_TORCHSIM_DIR')}/gem5_script/script_systolic.py") |
69 | | - |
70 | | - # AUTOTUNE config |
71 | | - if name == "CONFIG_AUTOTUNE": |
72 | | - return int(os.environ.get('AUTOTUNE', default=False)) |
73 | | - if name == "CONFIG_AUTOTUNE_TEMPLATE": |
74 | | - return int(os.environ.get('AUTOTUNE_TEMPLATE', default=False)) |
75 | | - if name == "CONFIG_MAX_AUTOTUNE_TRY": |
76 | | - return int(os.environ.get('MAX_AUTOTUNE_TRY', default=10)) |
77 | | - if name == "CONFIG_AUTOTUNE_TEMPLATE_TOPK": |
78 | | - return int(os.environ.get('AUTOTUNE_TEMPLATE_TOPK', default=4)) |
79 | | - |
80 | | - # For block sparse |
81 | | - if name == "CONFIG_BLOCK_SPARSE": |
82 | | - return int(os.environ.get('BLOCK_SPARSE', default=0)) |
83 | | - |
84 | | - # For GEMM tile size |
85 | | - if name == "CONFIG_MANUAL_TILE_SIZE": |
86 | | - return int(os.environ.get('TORCHSIM_MANUAL_TILE_SIZE', default=False)) |
87 | | - if name == "CONFIG_TILE_M": |
88 | | - return int(os.getenv("TORCHSIM_TILE_M", __getattr__("CONFIG_VECTOR_LANE"))) |
89 | | - if name == "CONFIG_TILE_N": |
90 | | - return int(os.getenv("TORCHSIM_TILE_N", __getattr__("CONFIG_VECTOR_LANE"))) |
91 | | - if name == "CONFIG_TILE_K": |
92 | | - return int(os.getenv("TORCHSIM_TILE_K", __getattr__("CONFIG_VECTOR_LANE"))) |
93 | | - |
94 | | - if name == "CONFIG_SUBTILE": |
95 | | - return int(os.environ.get('TORCHSIM_SUBTILE', default=True)) |
96 | | - if name == "CONFIG_MANUAL_SUBTILE_SIZE": |
97 | | - return int(os.environ.get('TORCHSIM_MANUAL_SUBTILE_SIZE', default=False)) |
98 | | - if name == "CONFIG_SUBTILE_M": |
99 | | - return int(os.environ.get('TORCHSIM_SUBTILE_M', default=__getattr__("CONFIG_VECTOR_LANE"))) |
100 | | - if name == "CONFIG_SUBTILE_N": |
101 | | - return int(os.environ.get('TORCHSIM_SUBTILE_N', default=__getattr__("CONFIG_VECTOR_LANE"))) |
102 | | - if name == "CONFIG_SUBTILE_K": |
103 | | - return int(os.environ.get('TORCHSIM_SUBTILE_K', default=__getattr__("CONFIG_VECTOR_LANE"))) |
104 | | - |
105 | | - if name == "CONFIG_GEMM_CHEATSHEET_PATH": |
106 | | - return os.environ.get('TORCHSIM_GEMM_CHEATSHEET_PATH', |
107 | | - default=f"{__getattr__('CONFIG_TORCHSIM_DIR')}/validation/gemm_tpuv3_cheatsheet.json") |
108 | 58 | # Compiler Optimization |
109 | | - if name == "CONFIG_COMPILER_OPTIMIZATION": |
110 | | - return os.environ.get('TORCHSIM_COMPILER_OPTIMIZATION', default="all") # options: all, none, custom |
| 59 | + if name == "codegen_compiler_optimization": |
| 60 | + return config_json["codegen_compiler_optimization"] |
| 61 | + |
111 | 62 | # Advanced fusion options |
112 | 63 | if name == "CONFIG_FUSION": |
113 | | - return True if (__getattr__("CONFIG_COMPILER_OPTIMIZATION") == "all" or "fusion" in __getattr__("CONFIG_COMPILER_OPTIMIZATION")) else False |
| 64 | + return True if (__getattr__("codegen_compiler_optimization") == "all" or "fusion" in __getattr__("codegen_compiler_optimization")) else False |
114 | 65 | if name == "CONFIG_FUSION_REDUCTION_EPILOGUE": |
115 | | - return True if (__getattr__("CONFIG_COMPILER_OPTIMIZATION") == "all" or "reduction_epliogue" in __getattr__("CONFIG_COMPILER_OPTIMIZATION")) else False |
| 66 | + return True if (__getattr__("codegen_compiler_optimization") == "all" or "reduction_epliogue" in __getattr__("codegen_compiler_optimization")) else False |
116 | 67 | if name == "CONFIG_FUSION_REDUCTION_REDUCTION": |
117 | | - return True if (__getattr__("CONFIG_COMPILER_OPTIMIZATION") == "all" or "reduction_reduction" in __getattr__("CONFIG_COMPILER_OPTIMIZATION")) else False |
| 68 | + return True if (__getattr__("codegen_compiler_optimization") == "all" or "reduction_reduction" in __getattr__("codegen_compiler_optimization")) else False |
118 | 69 | if name == "CONFIG_FUSION_PROLOGUE": |
119 | | - return True if ((__getattr__("CONFIG_COMPILER_OPTIMIZATION") == "all") or ("prologue" in __getattr__("CONFIG_COMPILER_OPTIMIZATION"))) else False |
| 70 | + return True if ((__getattr__("codegen_compiler_optimization") == "all") or ("prologue" in __getattr__("codegen_compiler_optimization"))) else False |
120 | 71 | if name == "CONFIG_SINGLE_BATCH_CONV": |
121 | | - return True if (__getattr__("CONFIG_COMPILER_OPTIMIZATION") == "all" or "single_batch_conv" in __getattr__("CONFIG_COMPILER_OPTIMIZATION")) else False |
| 72 | + return True if (__getattr__("codegen_compiler_optimization") == "all" or "single_batch_conv" in __getattr__("codegen_compiler_optimization")) else False |
122 | 73 | if name == "CONFIG_MULTI_TILE_CONV": |
123 | | - return True if (__getattr__("CONFIG_COMPILER_OPTIMIZATION") == "all" or "multi_tile_conv" in __getattr__("CONFIG_COMPILER_OPTIMIZATION")) else False |
| 74 | + return True if (__getattr__("codegen_compiler_optimization") == "all" or "multi_tile_conv" in __getattr__("codegen_compiler_optimization")) else False |
| 75 | + if name == "CONFIG_SUBTILE": |
| 76 | + return True if (__getattr__("codegen_compiler_optimization") == "all" or "subtile" in __getattr__("codegen_compiler_optimization")) else False |
| 77 | + |
| 78 | + if name == "CONFIG_TOGSIM_DEBUG_LEVEL": |
| 79 | + return os.environ.get("TOGSIM_DEBUG_LEVEL", "") |
| 80 | + if name == "CONFIG_TORCHSIM_DUMP_PATH": |
| 81 | + return os.environ.get('TORCHSIM_DUMP_PATH', default = CONFIG_TORCHSIM_DIR) |
| 82 | + if name == "CONFIG_TORCHSIM_LOG_PATH": |
| 83 | + return os.environ.get('TORCHSIM_DUMP_LOG_PATH', default = os.path.join(CONFIG_TORCHSIM_DIR, "togsim_results")) |
| 84 | + |
| 85 | + if name == "CONFIG_TOGSIM_EAGER_MODE": |
| 86 | + return int(os.environ.get("TOGSIM_EAGER_MODE", default=False)) |
124 | 87 |
|
125 | 88 | # SRAM Buffer allocation plan |
126 | 89 | def load_plan_from_module(module_path): |
|
0 commit comments