Skip to content

Commit eeb4f9d

Browse files
pytorchbotSS-JIA
authored andcommitted
[ET-VK][ez][buck] Simplify test buck file (#7593)
* [ET-VK] Parse required extensions of shaders and check capabilities during dispatch ## Context Now that we are using GLSL/SPIR-V extensions more heavily in our shaders, there is a risk that a particular shader uses an extension that is not supported by the physical device. It is tedious to manually check that all the extensions required by a shader is supported by the device; it would be much more convenient for developers if there was an automated way to perform this check. This diff provides a solution for this. Materially, this has manifested into an issue with our internal CI tests that run on Android emulator (which uses swiftshader under the hood). If the emulator tries to compile a shader that requires the `shaderInt16` feature, then the emulator will crash. ## Solution 1. Update `ShaderInfo` to have fields indicating whether certain extensions that require device support is required. 2. Update the `gen_vulkan_spv.py` shader compilation script to parse the GLSL code and log whether aforemention extensions are needed in the generated `ShaderInfo`. 3. Introduce a new exception class, `ShaderNotSupportedError`. 4. Before dispatching, check that all extensions required by the shader is supported by the device. If not, throw the new exception class. 4. In the generated operator correctness tests, skip the test if `ShaderNotSupportedError` is thrown. Differential Revision: [D67992067](https://our.internmc.facebook.com/intern/diff/D67992067/) ghstack-source-id: 260809479 Pull Request resolved: #7576 * [ET-VK][ez][buck] Simplify test buck file ## Context The targets file for the op tests define a binary and test rule for each c++ file; instead of manually defining these rules each time, create a helper function to condense the code. Differential Revision: [D67992066](https://our.internmc.facebook.com/intern/diff/D67992066/) ghstack-source-id: 260809480 Pull Request resolved: #7577 --------- Co-authored-by: Stephen Jia <[email protected]>
1 parent c4880e5 commit eeb4f9d

File tree

1 file changed

+47
-140
lines changed

1 file changed

+47
-140
lines changed

backends/vulkan/test/op_tests/targets.bzl

Lines changed: 47 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,44 @@ load("@fbsource//xplat/caffe2:pt_defs.bzl", "get_pt_ops_deps")
33
load("@fbsource//xplat/caffe2:pt_ops.bzl", "pt_operator_library")
44
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
55

6+
def define_test_targets(test_name, extra_deps = [], src_file = None, is_fbcode = False):
7+
deps_list = [
8+
"//third-party/googletest:gtest_main",
9+
"//executorch/backends/vulkan:vulkan_graph_runtime",
10+
runtime.external_dep_location("libtorch"),
11+
] + extra_deps
12+
13+
src_file_str = src_file if src_file else "{}.cpp".format(test_name)
14+
15+
runtime.cxx_binary(
16+
name = "{}_bin".format(test_name),
17+
srcs = [
18+
src_file_str,
19+
],
20+
compiler_flags = [
21+
"-Wno-unused-variable",
22+
],
23+
define_static_target = False,
24+
deps = deps_list,
25+
)
26+
27+
runtime.cxx_test(
28+
name = test_name,
29+
srcs = [
30+
src_file_str,
31+
],
32+
contacts = ["[email protected]"],
33+
fbandroid_additional_loaded_sonames = [
34+
"torch-code-gen",
35+
"vulkan_graph_runtime",
36+
"vulkan_graph_runtime_shaderlib",
37+
],
38+
platforms = [ANDROID],
39+
use_instrumentation_test = True,
40+
deps = deps_list,
41+
)
42+
43+
644
def define_common_targets(is_fbcode = False):
745
if is_fbcode:
846
return
@@ -82,19 +120,6 @@ def define_common_targets(is_fbcode = False):
82120
default_outs = ["."],
83121
)
84122

85-
runtime.cxx_binary(
86-
name = "compute_graph_op_tests_bin",
87-
srcs = [
88-
":generated_op_correctness_tests_cpp[op_tests.cpp]",
89-
],
90-
define_static_target = False,
91-
deps = [
92-
"//third-party/googletest:gtest_main",
93-
"//executorch/backends/vulkan:vulkan_graph_runtime",
94-
runtime.external_dep_location("libtorch"),
95-
],
96-
)
97-
98123
runtime.cxx_binary(
99124
name = "compute_graph_op_benchmarks_bin",
100125
srcs = [
@@ -111,135 +136,17 @@ def define_common_targets(is_fbcode = False):
111136
],
112137
)
113138

114-
runtime.cxx_test(
115-
name = "compute_graph_op_tests",
116-
srcs = [
117-
":generated_op_correctness_tests_cpp[op_tests.cpp]",
118-
],
119-
contacts = ["[email protected]"],
120-
fbandroid_additional_loaded_sonames = [
121-
"torch-code-gen",
122-
"vulkan_graph_runtime",
123-
"vulkan_graph_runtime_shaderlib",
124-
],
125-
platforms = [ANDROID],
126-
use_instrumentation_test = True,
127-
deps = [
128-
"//third-party/googletest:gtest_main",
129-
"//executorch/backends/vulkan:vulkan_graph_runtime",
130-
runtime.external_dep_location("libtorch"),
131-
],
139+
define_test_targets(
140+
"compute_graph_op_tests",
141+
src_file=":generated_op_correctness_tests_cpp[op_tests.cpp]"
132142
)
133143

134-
runtime.cxx_binary(
135-
name = "sdpa_test_bin",
136-
srcs = [
137-
"sdpa_test.cpp",
138-
],
139-
compiler_flags = [
140-
"-Wno-unused-variable",
141-
],
142-
define_static_target = False,
143-
deps = [
144-
"//third-party/googletest:gtest_main",
145-
"//executorch/backends/vulkan:vulkan_graph_runtime",
146-
"//executorch/extension/llm/custom_ops:custom_ops_aot_lib",
147-
],
148-
)
149-
150-
runtime.cxx_test(
151-
name = "sdpa_test",
152-
srcs = [
153-
"sdpa_test.cpp",
154-
],
155-
contacts = ["[email protected]"],
156-
fbandroid_additional_loaded_sonames = [
157-
"torch-code-gen",
158-
"vulkan_graph_runtime",
159-
"vulkan_graph_runtime_shaderlib",
160-
],
161-
platforms = [ANDROID],
162-
use_instrumentation_test = True,
163-
deps = [
164-
"//third-party/googletest:gtest_main",
165-
"//executorch/backends/vulkan:vulkan_graph_runtime",
166-
"//executorch/extension/llm/custom_ops:custom_ops_aot_lib",
167-
"//executorch/extension/tensor:tensor",
168-
runtime.external_dep_location("libtorch"),
169-
],
170-
)
171-
172-
runtime.cxx_binary(
173-
name = "linear_weight_int4_test_bin",
174-
srcs = [
175-
"linear_weight_int4_test.cpp",
176-
],
177-
compiler_flags = [
178-
"-Wno-unused-variable",
179-
],
180-
define_static_target = False,
181-
deps = [
182-
"//third-party/googletest:gtest_main",
183-
"//executorch/backends/vulkan:vulkan_graph_runtime",
184-
runtime.external_dep_location("libtorch"),
185-
],
186-
)
187-
188-
runtime.cxx_test(
189-
name = "linear_weight_int4_test",
190-
srcs = [
191-
"linear_weight_int4_test.cpp",
192-
],
193-
contacts = ["[email protected]"],
194-
fbandroid_additional_loaded_sonames = [
195-
"torch-code-gen",
196-
"vulkan_graph_runtime",
197-
"vulkan_graph_runtime_shaderlib",
198-
],
199-
platforms = [ANDROID],
200-
use_instrumentation_test = True,
201-
deps = [
202-
"//third-party/googletest:gtest_main",
203-
"//executorch/backends/vulkan:vulkan_graph_runtime",
144+
define_test_targets(
145+
"sdpa_test",
146+
extra_deps = [
204147
"//executorch/extension/llm/custom_ops:custom_ops_aot_lib",
205148
"//executorch/extension/tensor:tensor",
206-
runtime.external_dep_location("libtorch"),
207-
],
208-
)
209-
210-
runtime.cxx_binary(
211-
name = "rotary_embedding_test_bin",
212-
srcs = [
213-
"rotary_embedding_test.cpp",
214-
],
215-
compiler_flags = [
216-
"-Wno-unused-variable",
217-
],
218-
define_static_target = False,
219-
deps = [
220-
"//third-party/googletest:gtest_main",
221-
"//executorch/backends/vulkan:vulkan_graph_runtime",
222-
runtime.external_dep_location("libtorch"),
223-
],
224-
)
225-
226-
runtime.cxx_test(
227-
name = "rotary_embedding_test",
228-
srcs = [
229-
"rotary_embedding_test.cpp",
230-
],
231-
contacts = ["[email protected]"],
232-
fbandroid_additional_loaded_sonames = [
233-
"torch-code-gen",
234-
"vulkan_graph_runtime",
235-
"vulkan_graph_runtime_shaderlib",
236-
],
237-
platforms = [ANDROID],
238-
use_instrumentation_test = True,
239-
deps = [
240-
"//third-party/googletest:gtest_main",
241-
"//executorch/backends/vulkan:vulkan_graph_runtime",
242-
"//executorch/extension/tensor:tensor",
243-
runtime.external_dep_location("libtorch"),
244-
],
149+
]
245150
)
151+
define_test_targets("linear_weight_int4_test")
152+
define_test_targets("rotary_embedding_test")

0 commit comments

Comments
 (0)