From 5afa9db0dffafbfc5e5523ef5f738d741a2fc97a Mon Sep 17 00:00:00 2001 From: Stephen Jia Date: Tue, 12 Nov 2024 10:36:01 -0800 Subject: [PATCH] [ET-VK] Introduce no_volk buck targets TSIA. Introduce variants of the vulkan backend buck targets that do not use volk. Differential Revision: [D65827152](https://our.internmc.facebook.com/intern/diff/D65827152/) [ghstack-poisoned] --- backends/vulkan/targets.bzl | 240 +++++++++++++++++++----------------- 1 file changed, 127 insertions(+), 113 deletions(-) diff --git a/backends/vulkan/targets.bzl b/backends/vulkan/targets.bzl index c2b46774aa1..c73cb29893b 100644 --- a/backends/vulkan/targets.bzl +++ b/backends/vulkan/targets.bzl @@ -4,7 +4,7 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") def get_vulkan_compiler_flags(): return ["-Wno-missing-prototypes", "-Wno-global-constructors"] -def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False): +def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False, no_volk = False): gen_vulkan_spv_target = "//xplat/executorch/backends/vulkan:gen_vulkan_spv_bin" glslc_path = "//xplat/caffe2/fb/vulkan/dotslash:glslc" @@ -42,6 +42,7 @@ def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False): labels = ["uses_dotslash"], ) + suffix = "_no_volk" if no_volk else "" runtime.cxx_library( name = name, srcs = [ @@ -56,7 +57,7 @@ def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False): # Define a soname that can be used for dynamic loading in Java, Python, etc. soname = "lib{}.$(ext)".format(name), exported_deps = [ - "//executorch/backends/vulkan:vulkan_compute_api", + "//executorch/backends/vulkan:vulkan_compute_api{}".format(suffix), ], ) @@ -89,126 +90,139 @@ def define_common_targets(is_fbcode = False): ]), ) - vulkan_spv_shader_lib( - name = "vulkan_graph_runtime_shaderlib", - spv_filegroups = { - ":vulkan_graph_runtime_shaders": "runtime/graph/ops/glsl", - }, - is_fbcode = is_fbcode, - ) + for no_volk in [True, False]: + suffix = "_no_volk" if no_volk else "" - VK_API_PREPROCESSOR_FLAGS = [] - VK_API_DEPS = [ - "fbsource//third-party/VulkanMemoryAllocator/3.0.1:VulkanMemoryAllocator_xplat", - ] + VK_API_PREPROCESSOR_FLAGS = [] + VK_API_DEPS = [ + "fbsource//third-party/VulkanMemoryAllocator/3.0.1:VulkanMemoryAllocator_xplat", + ] - if is_fbcode: - VK_API_DEPS += [ - "fbsource//third-party/swiftshader:swiftshader_vk_headers", - "fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_fbcode", - "fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_so", + default_deps = [] + android_deps = [ + "fbsource//third-party/toolchains:android", ] - else: - VK_API_DEPS += select({ - "DEFAULT": [ - "fbsource//third-party/volk:volk", - ], - "ovr_config//os:android": [ - "fbsource//third-party/volk:volk", - "fbsource//third-party/toolchains:android" - ], - "ovr_config//os:macos-arm64": [ - "//third-party/khronos:moltenVK_static" + default_flags = [ + "-DUSE_VULKAN_WRAPPER", + ] + android_flags = [ + "-DUSE_VULKAN_WRAPPER", + "-DVK_ANDROID_external_memory_android_hardware_buffer", + ] + + if not no_volk: + for deps in [default_deps, android_deps]: + deps.append("fbsource//third-party/volk:volk") + for flags in [default_flags, android_flags]: + flags.append("-DUSE_VULKAN_VOLK") + else: + android_deps.append("fbsource//third-party/toolchains:vulkan") + + if is_fbcode: + VK_API_DEPS += [ + "fbsource//third-party/swiftshader:swiftshader_vk_headers", + "fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_fbcode", + "fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_so", + ] + else: + VK_API_DEPS += select({ + "DEFAULT": default_deps, + "ovr_config//os:android": android_deps, + "ovr_config//os:macos-arm64": [ + "//third-party/khronos:moltenVK_static" + ], + }) + VK_API_PREPROCESSOR_FLAGS += select({ + "DEFAULT": default_flags, + "ovr_config//os:android": android_flags, + "ovr_config//os:macos-arm64": [] + }) + + runtime.cxx_library( + name = "vulkan_compute_api{}".format(suffix), + compiler_flags = get_vulkan_compiler_flags(), + srcs = native.glob([ + "runtime/api/**/*.cpp", + "runtime/utils/**/*.cpp", + "runtime/vk_api/**/*.cpp", + ]), + exported_headers = native.glob([ + "runtime/api/**/*.h", + "runtime/utils/**/*.h", + "runtime/vk_api/**/*.h", + ]), + visibility = [ + "//executorch/backends/vulkan/...", + "@EXECUTORCH_CLIENTS", ], - }) - VK_API_PREPROCESSOR_FLAGS += select({ - "DEFAULT": [ - "-DUSE_VULKAN_WRAPPER", - "-DUSE_VULKAN_VOLK", + exported_preprocessor_flags = VK_API_PREPROCESSOR_FLAGS, + exported_deps = VK_API_DEPS, + ) + + runtime.cxx_library( + name = "vulkan_graph_runtime{}".format(suffix), + srcs = native.glob([ + "runtime/graph/**/*.cpp", + ]), + compiler_flags = get_vulkan_compiler_flags(), + exported_headers = native.glob([ + "runtime/graph/**/*.h", + ]), + visibility = [ + "//executorch/backends/...", + "//executorch/extension/pybindings/...", + "//executorch/test/...", + "@EXECUTORCH_CLIENTS", ], - "ovr_config//os:android": [ - "-DUSE_VULKAN_WRAPPER", - "-DUSE_VULKAN_VOLK", - "-DVK_ANDROID_external_memory_android_hardware_buffer" + exported_deps = [ + ":vulkan_graph_runtime_shaderlib", ], - "ovr_config//os:macos-arm64": [] - }) + define_static_target = False, + # Static initialization is used to register operators to the global operator registry, + # therefore link_whole must be True to make sure unused symbols are not discarded. + # @lint-ignore BUCKLINT: Avoid `link_whole=True` + link_whole = True, + # Define an soname that can be used for dynamic loading in Java, Python, etc. + soname = "libvulkan_graph_runtime.$(ext)", + ) - runtime.cxx_library( - name = "vulkan_compute_api", - compiler_flags = get_vulkan_compiler_flags(), - srcs = native.glob([ - "runtime/api/**/*.cpp", - "runtime/utils/**/*.cpp", - "runtime/vk_api/**/*.cpp", - ]), - exported_headers = native.glob([ - "runtime/api/**/*.h", - "runtime/utils/**/*.h", - "runtime/vk_api/**/*.h", - ]), - visibility = [ - "//executorch/backends/vulkan/...", - "@EXECUTORCH_CLIENTS", - ], - exported_preprocessor_flags = VK_API_PREPROCESSOR_FLAGS, - exported_deps = VK_API_DEPS, - ) + vulkan_spv_shader_lib( + name = "vulkan_graph_runtime_shaderlib{}".format(suffix), + spv_filegroups = { + ":vulkan_graph_runtime_shaders": "runtime/graph/ops/glsl", + }, + is_fbcode = is_fbcode, + no_volk = no_volk, + ) - runtime.cxx_library( - name = "vulkan_graph_runtime", - srcs = native.glob([ - "runtime/graph/**/*.cpp", - ]), - compiler_flags = get_vulkan_compiler_flags(), - exported_headers = native.glob([ - "runtime/graph/**/*.h", - ]), - visibility = [ - "//executorch/backends/...", - "//executorch/extension/pybindings/...", - "//executorch/test/...", - "@EXECUTORCH_CLIENTS", - ], - exported_deps = [ - ":vulkan_graph_runtime_shaderlib", - ], - define_static_target = False, - # Static initialization is used to register operators to the global operator registry, - # therefore link_whole must be True to make sure unused symbols are not discarded. - # @lint-ignore BUCKLINT: Avoid `link_whole=True` - link_whole = True, - # Define an soname that can be used for dynamic loading in Java, Python, etc. - soname = "libvulkan_graph_runtime.$(ext)", - ) - runtime.cxx_library( - name = "vulkan_backend_lib", - srcs = native.glob([ - "runtime/*.cpp", - ]), - compiler_flags = get_vulkan_compiler_flags(), - headers = native.glob([ - "runtime/*.h", - ]), - visibility = [ - "//executorch/backends/...", - "//executorch/extension/pybindings/...", - "//executorch/test/...", - "@EXECUTORCH_CLIENTS", - ], - deps = [ - ":vulkan_graph_runtime", - "//executorch/backends/vulkan/serialization:vk_delegate_schema", - "//executorch/runtime/core:event_tracer", - "//executorch/runtime/backend:interface", - "//executorch/runtime/core/exec_aten/util:tensor_util", - ], - define_static_target = False, - # VulkanBackend.cpp needs to compile with executor as whole - # @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole) - link_whole = True, - ) + runtime.cxx_library( + name = "vulkan_backend_lib{}".format(suffix), + srcs = native.glob([ + "runtime/*.cpp", + ]), + compiler_flags = get_vulkan_compiler_flags(), + headers = native.glob([ + "runtime/*.h", + ]), + visibility = [ + "//executorch/backends/...", + "//executorch/extension/pybindings/...", + "//executorch/test/...", + "@EXECUTORCH_CLIENTS", + ], + deps = [ + ":vulkan_graph_runtime{}".format(suffix), + "//executorch/backends/vulkan/serialization:vk_delegate_schema", + "//executorch/runtime/core:event_tracer", + "//executorch/runtime/backend:interface", + "//executorch/runtime/core/exec_aten/util:tensor_util", + ], + define_static_target = False, + # VulkanBackend.cpp needs to compile with executor as whole + # @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole) + link_whole = True, + ) ## ## AOT targets