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
22 changes: 20 additions & 2 deletions backends/arm/test/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,17 @@ runtime.python_library(
)

runtime.python_library(
name = "arm_tester",
srcs = glob(["tester/*.py"]),
name = "arm_tester_serialize",
srcs = ["tester/serialize.py"],
deps = [
"//executorch/backends/xnnpack/test/tester:tester",
"//executorch/devtools/backend_debug:delegation_info",
]
)

runtime.python_library(
name = "arm_tester_lib",
srcs = glob(["tester/*.py"], exclude = ["tester/serialize.py"]),
deps = [
":common",
"//executorch/backends/xnnpack/test/tester:tester",
Expand All @@ -55,4 +64,13 @@ runtime.python_library(
]
)


runtime.python_library(
name = "arm_tester",
deps = [
"//executorch/backends/arm/test:arm_tester_lib",
"//executorch/backends/arm/test:arm_tester_serialize",
]
)

define_arm_tests()
6 changes: 4 additions & 2 deletions backends/arm/test/ops/test_tanh.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,27 @@ def test_tanh_tosa_INT(test_data: Tuple):


@common.parametrize("test_data", test_data_suite)
@common.XfailIfNoCorstone300
def test_tanh_u55_INT(test_data: Tuple):
pipeline = EthosU55PipelineINT[input_t1](
Tanh(),
(test_data(),),
aten_op,
exir_ops=[],
run_on_fvp=False,
run_on_fvp=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

was there a reason it was disabled in OSS in the first place? If CI is clean I am ok with this PR enabling this.

Copy link
Contributor

Choose a reason for hiding this comment

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

also add @common.XfailIfNoCorstone300 as a decorator?

)
pipeline.run()


@common.parametrize("test_data", test_data_suite)
@common.XfailIfNoCorstone320
def test_tanh_u85_INT(test_data: Tuple):
pipeline = EthosU85PipelineINT[input_t1](
Tanh(),
(test_data(),),
aten_op,
exir_ops=[],
run_on_fvp=False,
run_on_fvp=True,
)
pipeline.run()

Expand Down
3 changes: 2 additions & 1 deletion backends/arm/test/targets.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# load("//caffe2/test/fb:defs.bzl", "define_tests")
load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_fbcode")
load("@fbcode_macros//build_defs:python_pytest.bzl", "python_pytest")
load("@bazel_skylib//lib:paths.bzl", "paths")

Expand Down Expand Up @@ -59,7 +60,7 @@ def define_arm_tests():
"//executorch/kernels/quantized:custom_ops_generated_lib",
],
deps = [
"//executorch/backends/arm/test:arm_tester",
"//executorch/backends/arm/test/tester/fb:arm_tester_fb" if is_fbcode else "//executorch/backends/arm/test:arm_tester",
"//executorch/backends/arm/test:conftest",
"//executorch/backends/arm:ethosu",
"//executorch/backends/arm/tosa:compile_spec",
Expand Down
49 changes: 6 additions & 43 deletions backends/arm/test/tester/arm_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import logging

import os
from collections import Counter
from pprint import pformat
from typing import (
Expand Down Expand Up @@ -42,17 +41,15 @@
)
from executorch.backends.arm.test.runner_utils import (
dbg_tosa_fb_to_json,
get_elf_path,
get_output_quantization_params,
get_target_board,
run_target,
TosaReferenceModelDispatch,
)

from executorch.backends.arm.test.tester.analyze_output_utils import (
dump_error_output,
print_error_diffs,
)
from executorch.backends.arm.test.tester.serialize import Serialize
from executorch.backends.arm.tosa import TosaSpecification
from executorch.backends.arm.tosa.compile_spec import TosaCompileSpec
from executorch.backends.arm.tosa.mapping import extract_tensor_meta
Expand Down Expand Up @@ -90,7 +87,6 @@

from torch.export.graph_signature import ExportGraphSignature, InputSpec, OutputSpec
from torch.fx import Graph
from torch.utils._pytree import tree_flatten


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -179,43 +175,6 @@ def run(
)


class Serialize(tester.Serialize):
def __init__(self, compile_spec: ArmCompileSpec, timeout):
super().__init__()
self.timeout = timeout
self.executorch_program_manager: ExecutorchProgramManager | None
self.compile_spec = compile_spec

def run(self, artifact: ExecutorchProgramManager, inputs=None) -> None:
super().run(artifact, inputs)
# Keep the entire ExecutorchProgramManager for execution.
self.executorch_program_manager = artifact

def run_artifact(self, inputs):
if self.executorch_program_manager is None:
raise RuntimeError(
"Tried running artifact from Serialize stage without running the stage."
)
inputs_flattened, _ = tree_flatten(inputs)
intermediate_path = self.compile_spec.get_intermediate_path()
target_board = get_target_board(self.compile_spec)
elf_path = get_elf_path(target_board)

if not os.path.exists(elf_path):
raise FileNotFoundError(
f"Did not find build arm_executor_runner in path {elf_path}, run setup_testing.sh?"
)

return run_target(
self.executorch_program_manager,
inputs_flattened,
intermediate_path,
target_board,
elf_path,
self.timeout,
)


class ToExecutorch(tester.ToExecutorch):
def run_artifact(self, inputs):
with TosaReferenceModelDispatch():
Expand Down Expand Up @@ -419,7 +378,11 @@ def serialize(
self, serialize_stage: Optional[Serialize] = None, timeout: int = 480
):
if serialize_stage is None:
serialize_stage = Serialize(self.compile_spec, timeout)
serialize_stage = Serialize(
compile_spec=self.compile_spec,
module=self.original_module,
timeout=timeout,
)
assert (
self.compile_spec.get_intermediate_path() is not None
), "Can't dump serialized file when compile specs do not contain an artifact path."
Expand Down
75 changes: 75 additions & 0 deletions backends/arm/test/tester/serialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2024-2025 Arm Limited and/or its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

import logging
import os
from typing import Optional

import executorch.backends.xnnpack.test.tester.tester as tester

import torch.fx

from executorch.backends.arm.common.arm_compile_spec import ArmCompileSpec

from executorch.backends.arm.test.runner_utils import (
get_elf_path,
get_target_board,
run_target,
)

from executorch.exir import ExecutorchProgramManager
from torch.utils._pytree import tree_flatten


logger = logging.getLogger(__name__)


class Serialize(tester.Serialize):
def __init__(
self,
compile_spec: ArmCompileSpec,
module: Optional[torch.nn.Module],
timeout: int = 120,
):
"""
Args:
compile_spec: CompileSpecs to be used for serialization.
module: Original Module to be used for serialization. Optional - can be used for reference output generation.
timeout: Timeout for fvp. Default is 120 seconds.
"""
super().__init__()
self.module = module
self.timeout = timeout
self.executorch_program_manager: ExecutorchProgramManager | None
self.compile_spec = compile_spec

def run(self, artifact: ExecutorchProgramManager, inputs=None) -> None:
super().run(artifact, inputs)
# Keep the entire ExecutorchProgramManager for execution.
self.executorch_program_manager = artifact

def run_artifact(self, inputs):
if self.executorch_program_manager is None:
raise RuntimeError(
"Tried running artifact from Serialize stage without running the stage."
)
inputs_flattened, _ = tree_flatten(inputs)
intermediate_path = self.compile_spec.get_intermediate_path()
target_board = get_target_board(self.compile_spec)
elf_path = get_elf_path(target_board)

if not os.path.exists(elf_path):
raise FileNotFoundError(
f"Did not find build arm_executor_runner in path {elf_path}, run setup_testing.sh?"
)

return run_target(
self.executorch_program_manager,
inputs_flattened,
intermediate_path,
target_board,
elf_path,
self.timeout,
)
Loading