Skip to content

Commit 88d1dd3

Browse files
committed
Update
[ghstack-poisoned]
2 parents c19a8ea + 4b43363 commit 88d1dd3

File tree

14 files changed

+1245
-9
lines changed

14 files changed

+1245
-9
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

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,16 +757,16 @@ if(EXECUTORCH_BUILD_PYBIND)
757757
list(APPEND _dep_libs openvino_backend)
758758
endif()
759759

760-
if(EXECUTORCH_BUILD_VULKAN)
761-
list(APPEND _dep_libs vulkan_backend)
762-
endif()
763-
764760
if(EXECUTORCH_BUILD_XNNPACK)
765761
# need to explicitly specify XNNPACK and xnnpack-microkernels-prod here
766762
# otherwise uses XNNPACK and microkernel-prod symbols from libtorch_cpu
767763
list(APPEND _dep_libs xnnpack_backend XNNPACK xnnpack-microkernels-prod)
768764
endif()
769765

766+
if(EXECUTORCH_BUILD_VULKAN)
767+
list(APPEND _dep_libs vulkan_backend)
768+
endif()
769+
770770
# compile options for pybind
771771
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
772772
-fexceptions

backends/vulkan/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ set_target_properties(vulkan_schema PROPERTIES LINKER_LANGUAGE CXX)
101101
target_include_directories(
102102
vulkan_schema
103103
INTERFACE
104-
${SCHEMA_INCLUDE_DIR}
104+
$<BUILD_INTERFACE:${SCHEMA_INCLUDE_DIR}>
105105
$<BUILD_INTERFACE:${EXECUTORCH_ROOT}/third-party/flatbuffers/include>
106106
)
107107

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
)

backends/vulkan/partitioner/vulkan_partitioner.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# pyre-strict
88

99
import logging
10-
from typing import Any, Callable, Dict, final, List, Mapping, Optional, Tuple
10+
from typing import Any, Callable, Dict, final, List, Mapping, Optional, Set, Tuple
1111

1212
import executorch.backends.vulkan.utils as utils
1313

@@ -17,6 +17,7 @@
1717
get_op_features,
1818
has_impl,
1919
OpFeatures,
20+
OpKey,
2021
vulkan_supported_ops,
2122
)
2223

@@ -55,11 +56,17 @@ def __init__(
5556
texture_limits: utils.ImageExtents,
5657
buffer_limit: int,
5758
require_dynamic_shape: bool = False,
59+
operator_blocklist: Optional[Set[OpKey]] = None,
60+
operator_allowlist: Optional[Set[OpKey]] = None,
5861
) -> None:
5962
super().__init__()
6063
self.texture_limits: utils.ImageExtents = texture_limits
6164
self.buffer_limit = buffer_limit
6265
self.require_dynamic_shapes = require_dynamic_shape
66+
self.operator_blocklist: Set[OpKey] = (
67+
operator_blocklist if operator_blocklist is not None else set()
68+
)
69+
self.operator_allowlist = operator_allowlist
6370

6471
def op_node_is_compatible( # noqa: C901: Function is too complex
6572
self, node: torch.fx.Node, features: Optional[OpFeatures] = None
@@ -77,6 +84,17 @@ def op_node_is_compatible( # noqa: C901: Function is too complex
7784
assert isinstance(first_arg, torch._ops.OpOverload)
7885
target = first_arg.name()
7986

87+
# Operator allow list is only used for torch ops
88+
if (
89+
utils.is_torch_op_node(node)
90+
and (self.operator_allowlist is not None)
91+
and (target not in self.operator_allowlist)
92+
):
93+
return False, "op is not in allowlist"
94+
95+
if target in self.operator_blocklist:
96+
return False, "op is in blocklist"
97+
8098
# Extract the features for the node's operator, if no override was provided
8199
if features is None:
82100
if not has_impl(target):
@@ -93,7 +111,7 @@ def op_node_is_compatible( # noqa: C901: Function is too complex
93111
if op_repsets.any_is_empty():
94112
return (
95113
False,
96-
"No valid representations for a tensor in the operation",
114+
f"no valid representations for op {utils.node_io_str(node)}",
97115
)
98116

99117
return True, "Op is compatible"
@@ -277,6 +295,8 @@ class VulkanPartitioner(Partitioner):
277295
def __init__(
278296
self,
279297
compile_options: Optional[Dict[str, Any]] = None,
298+
operator_blocklist: Optional[List[OpKey]] = None,
299+
operator_allowlist: Optional[List[OpKey]] = None,
280300
) -> None:
281301
self.options: Dict[str, Any] = {}
282302
if compile_options is not None:
@@ -285,6 +305,18 @@ def __init__(
285305
compile_spec = parse_compile_options(self.options)
286306
self.delegation_spec = DelegationSpec(VulkanBackend.__name__, compile_spec)
287307

308+
self.operator_blocklist: Set[OpKey] = set()
309+
if operator_blocklist is not None:
310+
for entry in operator_blocklist or []:
311+
self.operator_blocklist.add(entry)
312+
313+
self.operator_allowlist: Optional[Set[OpKey]] = None
314+
if operator_allowlist is not None:
315+
self.operator_allowlist = set()
316+
for entry in operator_allowlist:
317+
assert self.operator_allowlist is not None
318+
self.operator_allowlist.add(entry)
319+
288320
def ops_to_not_decompose(
289321
self, ep: ExportedProgram
290322
) -> Tuple[List[torch._ops.OpOverload], Optional[Callable[[torch.fx.Node], bool]]]:
@@ -308,6 +340,8 @@ def partition(self, exported_program: ExportedProgram) -> PartitionResult:
308340
texture_limits,
309341
buffer_limit,
310342
require_dynamic_shape=self.options.get("require_dynamic_shapes", False),
343+
operator_blocklist=self.operator_blocklist,
344+
operator_allowlist=self.operator_allowlist,
311345
),
312346
allows_single_node_partition=True,
313347
)

backends/vulkan/runtime/gen_vulkan_spv.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ def compile_spirv(shader_paths_pair) -> Tuple[str, str]:
10831083
for spv_out_path, glsl_out_path in pool.map(
10841084
compile_spirv, self.output_file_map.items()
10851085
):
1086-
print(spv_to_glsl_map)
10871086
spv_to_glsl_map[spv_out_path] = glsl_out_path
10881087

10891088
return spv_to_glsl_map

0 commit comments

Comments
 (0)