Skip to content

Commit

Permalink
[ET-VK][ez][buck] Simplify test buck file (#7593)
Browse files Browse the repository at this point in the history
* [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 <ssjia@meta.com>
  • Loading branch information
pytorchbot and SS-JIA authored Jan 13, 2025
1 parent a1c5678 commit 8967d1e
Showing 1 changed file with 47 additions and 140 deletions.
187 changes: 47 additions & 140 deletions backends/vulkan/test/op_tests/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,44 @@ load("@fbsource//xplat/caffe2:pt_defs.bzl", "get_pt_ops_deps")
load("@fbsource//xplat/caffe2:pt_ops.bzl", "pt_operator_library")
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")

def define_test_targets(test_name, extra_deps = [], src_file = None, is_fbcode = False):
deps_list = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
runtime.external_dep_location("libtorch"),
] + extra_deps

src_file_str = src_file if src_file else "{}.cpp".format(test_name)

runtime.cxx_binary(
name = "{}_bin".format(test_name),
srcs = [
src_file_str,
],
compiler_flags = [
"-Wno-unused-variable",
],
define_static_target = False,
deps = deps_list,
)

runtime.cxx_test(
name = test_name,
srcs = [
src_file_str,
],
contacts = ["oncall+ai_infra_mobile_platform@xmail.facebook.com"],
fbandroid_additional_loaded_sonames = [
"torch-code-gen",
"vulkan_graph_runtime",
"vulkan_graph_runtime_shaderlib",
],
platforms = [ANDROID],
use_instrumentation_test = True,
deps = deps_list,
)


def define_common_targets(is_fbcode = False):
if is_fbcode:
return
Expand Down Expand Up @@ -82,19 +120,6 @@ def define_common_targets(is_fbcode = False):
default_outs = ["."],
)

runtime.cxx_binary(
name = "compute_graph_op_tests_bin",
srcs = [
":generated_op_correctness_tests_cpp[op_tests.cpp]",
],
define_static_target = False,
deps = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
runtime.external_dep_location("libtorch"),
],
)

runtime.cxx_binary(
name = "compute_graph_op_benchmarks_bin",
srcs = [
Expand All @@ -111,135 +136,17 @@ def define_common_targets(is_fbcode = False):
],
)

runtime.cxx_test(
name = "compute_graph_op_tests",
srcs = [
":generated_op_correctness_tests_cpp[op_tests.cpp]",
],
contacts = ["oncall+ai_infra_mobile_platform@xmail.facebook.com"],
fbandroid_additional_loaded_sonames = [
"torch-code-gen",
"vulkan_graph_runtime",
"vulkan_graph_runtime_shaderlib",
],
platforms = [ANDROID],
use_instrumentation_test = True,
deps = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
runtime.external_dep_location("libtorch"),
],
define_test_targets(
"compute_graph_op_tests",
src_file=":generated_op_correctness_tests_cpp[op_tests.cpp]"
)

runtime.cxx_binary(
name = "sdpa_test_bin",
srcs = [
"sdpa_test.cpp",
],
compiler_flags = [
"-Wno-unused-variable",
],
define_static_target = False,
deps = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
"//executorch/extension/llm/custom_ops:custom_ops_aot_lib",
],
)

runtime.cxx_test(
name = "sdpa_test",
srcs = [
"sdpa_test.cpp",
],
contacts = ["oncall+ai_infra_mobile_platform@xmail.facebook.com"],
fbandroid_additional_loaded_sonames = [
"torch-code-gen",
"vulkan_graph_runtime",
"vulkan_graph_runtime_shaderlib",
],
platforms = [ANDROID],
use_instrumentation_test = True,
deps = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
"//executorch/extension/llm/custom_ops:custom_ops_aot_lib",
"//executorch/extension/tensor:tensor",
runtime.external_dep_location("libtorch"),
],
)

runtime.cxx_binary(
name = "linear_weight_int4_test_bin",
srcs = [
"linear_weight_int4_test.cpp",
],
compiler_flags = [
"-Wno-unused-variable",
],
define_static_target = False,
deps = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
runtime.external_dep_location("libtorch"),
],
)

runtime.cxx_test(
name = "linear_weight_int4_test",
srcs = [
"linear_weight_int4_test.cpp",
],
contacts = ["oncall+ai_infra_mobile_platform@xmail.facebook.com"],
fbandroid_additional_loaded_sonames = [
"torch-code-gen",
"vulkan_graph_runtime",
"vulkan_graph_runtime_shaderlib",
],
platforms = [ANDROID],
use_instrumentation_test = True,
deps = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
define_test_targets(
"sdpa_test",
extra_deps = [
"//executorch/extension/llm/custom_ops:custom_ops_aot_lib",
"//executorch/extension/tensor:tensor",
runtime.external_dep_location("libtorch"),
],
)

runtime.cxx_binary(
name = "rotary_embedding_test_bin",
srcs = [
"rotary_embedding_test.cpp",
],
compiler_flags = [
"-Wno-unused-variable",
],
define_static_target = False,
deps = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
runtime.external_dep_location("libtorch"),
],
)

runtime.cxx_test(
name = "rotary_embedding_test",
srcs = [
"rotary_embedding_test.cpp",
],
contacts = ["oncall+ai_infra_mobile_platform@xmail.facebook.com"],
fbandroid_additional_loaded_sonames = [
"torch-code-gen",
"vulkan_graph_runtime",
"vulkan_graph_runtime_shaderlib",
],
platforms = [ANDROID],
use_instrumentation_test = True,
deps = [
"//third-party/googletest:gtest_main",
"//executorch/backends/vulkan:vulkan_graph_runtime",
"//executorch/extension/tensor:tensor",
runtime.external_dep_location("libtorch"),
],
]
)
define_test_targets("linear_weight_int4_test")
define_test_targets("rotary_embedding_test")

0 comments on commit 8967d1e

Please sign in to comment.