Skip to content
Draft
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
39 changes: 39 additions & 0 deletions backends/arm/common/arm_compile_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DebugMode(Enum):
compiler_flags: list[str] = field(default_factory=list)
path_for_intermediates: str | None = None
tosa_debug_mode: DebugMode | None = None
tosa_dev_mode: bool | None = None

_TOSA_SPEC_KEY = "tosa_spec"
_COMPILE_FLAGS_KEY = "compile_flags"
Expand All @@ -44,6 +45,7 @@ class DebugMode(Enum):
_DEBUG_MODE_KEY = "dump_debug_info"
_OUTPUT_REORDER_KEY = "ouput_reorder_workaround"
_TRANSFORM_PIPELINE_CONFIG_KEY = "transform_pipeline_config"
_TOSA_DEV_MODE = "tosa_sw_dev_mode"
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant naming is inconsistent with the other compile-spec keys (_TOSA_SPEC_KEY, _COMPILE_FLAGS_KEY, ...). Consider renaming _TOSA_DEV_MODE to _TOSA_DEV_MODE_KEY (and updating references) to match the established pattern.

Suggested change
_TOSA_DEV_MODE = "tosa_sw_dev_mode"
_TOSA_DEV_MODE_KEY = "tosa_sw_dev_mode"

Copilot uses AI. Check for mistakes.

def _set_compile_specs(
self,
Expand All @@ -53,6 +55,7 @@ def _set_compile_specs(
tosa_debug_mode: DebugMode | None = None,
output_order_workaround: bool = False,
pipeline_config: ArmPassPipelineConfig | None = None,
tosa_dev_mode: bool | None = None,
):
"""Set all values of dataclass directly."""
self.tosa_spec = tosa_spec
Expand All @@ -61,6 +64,7 @@ def _set_compile_specs(
self.tosa_debug_mode = tosa_debug_mode
self._pipeline_config = pipeline_config
self.output_order_workaround = output_order_workaround
self.tosa_dev_mode = tosa_dev_mode
if output_order_workaround:
warnings.warn(
"ArmCompileSpec(output_order_workaround=True) is deprecated and will be "
Expand All @@ -78,6 +82,7 @@ def _from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
tosa_debug_mode: ArmCompileSpec.DebugMode | None = None
output_order_workaround: bool = False
pipeline_config: ArmPassPipelineConfig | None = None
tosa_dev_mode: bool | None = None
unknown_specs: dict[str, str] = {}
for spec in compile_specs:
key = spec.key
Expand Down Expand Up @@ -128,6 +133,20 @@ def _from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
"More than one transform pipeline entry in compile spec."
)
pipeline_config = ArmPassPipelineConfig.from_dict(json.loads(val))
elif key == ArmCompileSpec._TOSA_DEV_MODE:
if tosa_dev_mode is not None:
raise ValueError(
"More than one tosa_sw_dev_mode entry in compile spec."
)
raw = bytes(spec.value)
if raw == b"\x01":
tosa_dev_mode = True
elif raw == b"\x00":
tosa_dev_mode = False
else:
raise ValueError(
f"Invalid tosa_sw_dev_mode byte value: {raw!r}, expected b'\\x00' or b'\\x01'."
)
else:
unknown_specs[key] = val

Expand All @@ -151,6 +170,7 @@ def _from_list(cls, compile_specs: list[CompileSpec]): # noqa: C901
tosa_debug_mode=tosa_debug_mode,
output_order_workaround=output_order_workaround,
pipeline_config=pipeline_config,
tosa_dev_mode=tosa_dev_mode,
)
cls._from_list_hook(compile_spec, unknown_specs)
compile_spec._validate()
Expand Down Expand Up @@ -227,6 +247,15 @@ def _to_list(self):
self._pipeline_config.serialize(),
)
)

if self.tosa_dev_mode is not None:
compile_spec.append(
CompileSpec(
ArmCompileSpec._TOSA_DEV_MODE,
b"\x01" if self.tosa_dev_mode else b"\x00",
)
)

return compile_spec

def _get_pass_pipeline_config(self) -> ArmPassPipelineConfig:
Expand Down Expand Up @@ -290,6 +319,16 @@ def dump_debug_info(self, debug_mode: DebugMode | None):
self.tosa_debug_mode = debug_mode
return self

def _set_tosa_dev_mode(self, tosa_dev_mode: bool):
"""Sets whether to enable TOSA software development mode.

Args:
tosa_dev_mode: Boolean indicating whether to enable TOSA software development mode.

"""
self.tosa_dev_mode = tosa_dev_mode
return self
Comment on lines +322 to +330
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tosa_dev_mode is declared as bool | None, but _set_tosa_dev_mode only accepts bool. Since call sites may pass through an unset value, consider changing the parameter type to bool | None (and documenting what None means), or enforce non-None at all call sites.

Copilot uses AI. Check for mistakes.

@deprecated(
"set_output_order_workaround() is deprecated and will be removed in v1.5; please remove this call."
)
Expand Down
4 changes: 4 additions & 0 deletions backends/arm/tosa/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def _preprocess( # noqa: C901
targetDraft=True if version.minor > 0 else False,
)

if compile_spec.tosa_dev_mode:
tosa_graph.setExperimentalDevVersion()

if not (
tosa_spec.version.major == ts.TOSA_VERSION_MAJOR
and tosa_spec.version.minor <= ts.TOSA_VERSION_MINOR
Expand Down Expand Up @@ -440,4 +443,5 @@ def filter_tosa_compile_specs(
)
.dump_debug_info(compile_spec.tosa_debug_mode)
.set_output_order_workaround(compile_spec.output_order_workaround)
._set_tosa_dev_mode(compile_spec.tosa_dev_mode)
)
Comment on lines 443 to 447
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter_tosa_compile_specs() calls ._set_tosa_dev_mode(compile_spec.tosa_dev_mode) where tosa_dev_mode can be None. This currently conflicts with _set_tosa_dev_mode(self, tosa_dev_mode: bool) and can trip static type checks; also it’s clearer to only set the flag when it’s explicitly provided. Consider guarding the call (only call when not None) or updating _set_tosa_dev_mode to accept bool | None.

Copilot uses AI. Check for mistakes.
Loading
Loading