Skip to content

Commit 482f3d6

Browse files
Update
[ghstack-poisoned]
2 parents cbfe8bb + 0e76a97 commit 482f3d6

File tree

14 files changed

+108
-22
lines changed

14 files changed

+108
-22
lines changed

.ci/scripts/setup-vulkan-linux-deps.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ install_swiftshader() {
2323

2424
export VK_ICD_FILENAMES="${_swiftshader_dir}/swiftshader/build/Linux/vk_swiftshader_icd.json"
2525
export LD_LIBRARY_PATH="${_swiftshader_dir}/swiftshader/build/Linux/"
26+
export ETVK_USING_SWIFTSHADER=1
2627
}
2728

2829
install_vulkan_sdk() {

.github/workflows/pull.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,43 @@ jobs:
864864
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh
865865
866866
867+
test-vulkan-models-linux:
868+
name: test-vulkan-models-linux
869+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
870+
permissions:
871+
id-token: write
872+
contents: read
873+
with:
874+
runner: linux.2xlarge
875+
docker-image: ci-image:executorch-ubuntu-22.04-clang12
876+
submodules: 'recursive'
877+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
878+
timeout: 90
879+
script: |
880+
set -eux
881+
882+
# The generic Linux job chooses to use base env, not the one setup by the image
883+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
884+
conda activate "${CONDA_ENV}"
885+
886+
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
887+
source .ci/scripts/setup-vulkan-linux-deps.sh
888+
889+
# Setup python
890+
PYTHON_EXECUTABLE=python \
891+
CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" \
892+
.ci/scripts/setup-linux.sh --build-tool "cmake"
893+
894+
PYTHON_EXECUTABLE=python bash backends/vulkan/test/scripts/test_model.sh --build
895+
896+
# Test models serially
897+
models="mv2 mv3 edsr resnet18 resnet50 dl3"
898+
for model in $models; do
899+
python -m examples.vulkan.export --model_name=$model --test
900+
done
901+
902+
903+
867904
nxp-build-test:
868905
name: nxp-build-test
869906
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pip-out/
2424
# Any exported models and profiling outputs
2525
*.bin
2626
*.model
27+
*.etdump
2728
tokenizer.json
2829
*.pte
2930
*.ptd
@@ -58,6 +59,7 @@ xcuserdata/
5859
/include/
5960
/share/
6061
/version.py
62+
*.csv
6163

6264
# Android
6365
*.aar

backends/test/harness/TARGETS

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ oncall("executorch")
44

55
runtime.python_library(
66
name = "tester",
7-
srcs = [
8-
"__init__.py",
9-
"tester.py",
10-
] + native.glob(["stages/*.py"]),
7+
srcs = native.glob(["*.py", "stages/*.py"]),
118
visibility = [
129
"//executorch/...",
1310
"@EXECUTORCH_CLIENTS",

backends/test/harness/stages/to_edge_transform_and_lower.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414
class ToEdgeTransformAndLower(Stage):
1515
def __init__(
1616
self,
17-
default_partitioner_cls: Type,
17+
default_partitioner_cls: Type | None = None,
1818
partitioners: Optional[List[Partitioner]] = None,
1919
edge_compile_config: Optional[EdgeCompileConfig] = None,
2020
):
21-
self.partitioners = partitioners or [default_partitioner_cls()]
21+
self.partitioners = (
22+
partitioners or [default_partitioner_cls()]
23+
if default_partitioner_cls is not None
24+
else []
25+
)
2226
self.edge_compile_conf = edge_compile_config or EdgeCompileConfig()
2327
self.edge_dialect_program = None
2428

backends/test/harness/tester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def __init__(
3434
self,
3535
module: torch.nn.Module,
3636
example_inputs: Tuple[torch.Tensor],
37-
stage_classes: Dict[StageType, Callable],
37+
stage_classes: Dict[StageType, Callable] | None = None,
3838
dynamic_shapes: Optional[Tuple[Any]] = None,
3939
):
4040
module.eval()
4141

42-
self.stage_classes = stage_classes
42+
self.stage_classes = stage_classes or Tester.default_stage_classes()
4343
self.original_module = module
4444
self.example_inputs = example_inputs
4545
self.dynamic_shapes = dynamic_shapes

backends/test/suite/flow.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from dataclasses import dataclass, field
3+
from dataclasses import dataclass
44
from typing import Callable
55

66
from executorch.backends.test.harness import Tester
@@ -26,16 +26,25 @@ class TestFlow:
2626
tester_factory: Callable[..., Tester]
2727
""" A factory function that returns a Tester instance for this lowering flow. """
2828

29-
quantize: bool = field(default=False)
29+
quantize: bool = False
3030
""" Whether to tester should run the quantize stage on the model. """
3131

3232
quantize_stage_factory: Callable[..., Quantize] | None = None
3333
""" A factory function which instantiates a Quantize stage. Can be None to use the tester's default. """
3434

35+
is_delegated: bool = True
36+
""" Indicates whether the flow is expected to generate CALL_DELEGATE nodes. """
37+
3538

3639
def all_flows() -> dict[str, TestFlow]:
3740
flows = []
3841

42+
from executorch.backends.test.suite.flows.portable import PORTABLE_TEST_FLOW
43+
44+
flows += [
45+
PORTABLE_TEST_FLOW,
46+
]
47+
3948
try:
4049
from executorch.backends.test.suite.flows.xnnpack import (
4150
XNNPACK_STATIC_INT8_PER_CHANNEL_TEST_FLOW,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import logging
2+
3+
from executorch.backends.test.harness import Tester
4+
from executorch.backends.test.suite.flow import TestFlow
5+
6+
logger = logging.getLogger(__name__)
7+
logger.setLevel(logging.INFO)
8+
9+
10+
def _create_portable_flow() -> TestFlow:
11+
return TestFlow(
12+
"portable",
13+
backend="portable",
14+
tester_factory=Tester,
15+
is_delegated=False,
16+
)
17+
18+
19+
PORTABLE_TEST_FLOW = _create_portable_flow()

backends/test/suite/runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def build_result(
125125
if n.op == "call_function"
126126
)
127127

128-
# Only run the runtime portion if something was delegated.
129-
if is_delegated:
128+
# Only run the runtime portion if something was delegated (or the flow doesn't delegate).
129+
if is_delegated or not flow.is_delegated:
130130
try:
131131
tester.to_executorch().serialize()
132132
extra_stats["pte_size_bytes"] = len(tester.get_artifact())

backends/vulkan/cmake/ShaderLibrary.cmake

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ function(gen_vulkan_shader_lib_cpp shaders_path)
4949
set(VULKAN_SHADERGEN_ENV "")
5050
set(VULKAN_SHADERGEN_OUT_PATH ${CMAKE_BINARY_DIR}/vulkan_compute_shaders)
5151

52+
set(GEN_SPV_ARGS "--optimize")
53+
if(DEFINED ENV{ETVK_USING_SWIFTSHADER})
54+
if("$ENV{ETVK_USING_SWIFTSHADER}" STREQUAL "1"
55+
OR "$ENV{ETVK_USING_SWIFTSHADER}" STREQUAL "True"
56+
)
57+
list(APPEND GEN_SPV_ARGS "--replace-u16vecn")
58+
endif()
59+
endif()
60+
5261
add_custom_command(
5362
COMMENT "Generating Vulkan Compute Shaders"
5463
OUTPUT ${VULKAN_SHADERGEN_OUT_PATH}/spv.cpp
@@ -58,7 +67,7 @@ function(gen_vulkan_shader_lib_cpp shaders_path)
5867
${shaders_path} --output-path ${VULKAN_SHADERGEN_OUT_PATH}
5968
--glslc-path=${GLSLC_PATH}
6069
--tmp-dir-path=${VULKAN_SHADERGEN_OUT_PATH}/shader_cache/ --env
61-
${VULKAN_GEN_ARG_ENV} --optimize
70+
${VULKAN_GEN_ARG_ENV} ${GEN_SPV_ARGS}
6271
DEPENDS ${shaders_path}/*
6372
${EXECUTORCH_ROOT}/backends/vulkan/runtime/gen_vulkan_spv.py
6473
)

0 commit comments

Comments
 (0)