Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Verify, optimize, and explore cycle-approximate simulation with uScope!

```bash
pip install --upgrade pip setuptools wheel
git git@github.com:ProteusLab/uScope.git
git clone git@github.com:ProteusLab/uScope.git
cd uScope
pip install -e .
```
Expand Down
Binary file modified examples/reference/reference.json.gz
Binary file not shown.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ classifiers = [
"License :: OSI Approved :: Apache 2.0 License",
]
requires-python = ">=3.8"
dependencies = ["tqdm>=4.62"]

[project.scripts]
uScope = "uScope.main:main"
Expand Down
6 changes: 6 additions & 0 deletions src/uScope/O3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PipelineStage(Enum):
ISSUE = "issue"
COMPLETE = "complete"
RETIRE = "retire"
STORE_COMPLETE = "store_complete"

@staticmethod
def order():
Expand All @@ -34,13 +35,18 @@ class Instruction:
opclass: str
stages: Dict[PipelineStage, int]
stage_order: List[PipelineStage]
store_tick: int = 0

@property
def mnemonic(self):
if not self.disasm:
return Instruction.UNKNOWN
return self.disasm.split()[0].upper()

@property
def is_squashed(self) -> bool:
return self.stages.get(PipelineStage.RETIRE, 0) == 0

# NOTE: https://github.com/gem5/gem5/blob/stable/src/cpu/FuncUnit.py
class OpClass(Enum):
IntAlu = "IntAlu"
Expand Down
57 changes: 44 additions & 13 deletions src/uScope/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import json
import logging
from pathlib import Path
from typing import Any, Optional
from abc import ABC, abstractmethod

from .O3 import PipelineStage, OpClass, Instruction
from .utils import stable_hash

logger = logging.getLogger(__name__)


class IConfig(ABC):
@abstractmethod
def get_func_unit(self, opclass: OpClass) -> str:
Expand All @@ -16,9 +20,17 @@ def get_stage_name(self, stage : PipelineStage) -> str:
assert False, f"Pipeline stage name mapping method wasn't defined in {type(self).__name__}"

@abstractmethod
def get_color_for_instr(self, instr : Instruction) -> str:
def get_color_for_instr(self, instr: Instruction) -> str:
assert False, f"Color mapping method wasn't defined in {type(self).__name__}"

@abstractmethod
def get_squashed_cname(self) -> str:
assert False, f"Squashed color method wasn't defined in {type(self).__name__}"

@abstractmethod
def store_completions_pid(self) -> int:
assert False, f"Store Completions Process ID wasn't defined in {type(self).__name__}"

@abstractmethod
def pipeline_pid(self) -> int:
assert False, f"Pipeline Process ID wasn't defined in {type(self).__name__}"
Expand All @@ -35,14 +47,21 @@ def pipeline_width(self) -> int:
def func_units_width(self) -> int:
assert False, f"Functional Units width wasn't defined in {type(self).__name__}"


class Config(IConfig):
def __init__(self, data: dict):
self._data = data
for key, value in data.items():

def __getattr__(self, name: str):
key = name.lstrip("_")
if key in self._data:
value = self._data[key]
if isinstance(value, dict):
setattr(self, f"_{key}", Config(value))
else:
setattr(self, f"_{key}", value)
return Config(value)
return value
raise AttributeError(
f"'{type(self).__name__}' object has no attribute '{name}'"
)

@property
def settings(self):
Expand All @@ -64,21 +83,28 @@ def pipeline_width(self) -> int:
def func_units_width(self) -> int:
return self.settings._MAX_FUNC_UNITS_WIDTH

@property
def store_completions_pid(self) -> int:
return self.settings._PID_STORE_COMPLETIONS_BASE

def get_func_unit(self, opclass: Any) -> str:
return self._func_units.get(str(opclass), "No_OpClass")

def get_stage_name(self, stage : PipelineStage) -> str:
def get_stage_name(self, stage: PipelineStage) -> str:
return self._stage_names[stage.value]

def get_color_for_func_unit(self, unit) -> str:
return self._colors.get(unit, self._colors._default)

def get_color_for_instr(self, instr : Instruction) -> str:
def get_color_for_instr(self, instr: Instruction) -> str:
unit = self.get_func_unit(instr.opclass)
family = self._colors.get(unit, self._colors._default)
idx = stable_hash(instr.mnemonic, len(family))
return family[idx]

def get_squashed_cname(self) -> str:
return self._colors._squashed

def __getitem__(self, key: str) -> Any:
return self._data[key]

Expand All @@ -100,13 +126,18 @@ def load_config(config_path: Optional[Path] = None) -> Config:
if builtin_dir.is_dir():
for json_file in builtin_dir.glob("*.json"):
key = json_file.stem
with open(json_file, 'r', encoding='utf-8') as f:
with open(json_file, "r", encoding="utf-8") as f:
config_data[key] = json.load(f)

if config_path is not None and config_path.is_dir():
for json_file in config_path.glob("*.json"):
key = json_file.stem
with open(json_file, 'r', encoding='utf-8') as f:
config_data[key] = json.load(f)
if config_path is not None:
if config_path.is_dir():
for json_file in config_path.glob("*.json"):
key = json_file.stem
with open(json_file, "r", encoding="utf-8") as f:
config_data[key] = json.load(f)
else:
logger.warning(
"Config path '%s' is not a directory — ignoring", config_path
)

return Config(config_data)
3 changes: 2 additions & 1 deletion src/uScope/configs/colors.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@
"good",
"rail_idle",
"yellow"
]
],
"squashed": "grey"
}
1 change: 1 addition & 0 deletions src/uScope/configs/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"PID_PIPELINE_STAGES_BASE": 100,
"PID_FUNC_UNITS_BASE": 200,
"PID_STORE_COMPLETIONS_BASE": 300,
"MAX_PIPE_WIDTH": 256,
"MAX_FUNC_UNITS_WIDTH": 8
}
3 changes: 2 additions & 1 deletion src/uScope/configs/stage_names.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"dispatch": "Dispatch",
"issue": "Issue",
"complete": "Complete",
"retire": "Retire"
"retire": "Retire",
"store_complete": "Store Complete"
}
Loading
Loading