@@ -4,7 +4,7 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
44def get_vulkan_compiler_flags ():
55 return ["-Wno-missing-prototypes" , "-Wno-global-constructors" ]
66
7- def vulkan_spv_shader_lib (name , spv_filegroups , is_fbcode = False ):
7+ def vulkan_spv_shader_lib (name , spv_filegroups , is_fbcode = False , no_volk = False ):
88 gen_vulkan_spv_target = "//xplat/executorch/backends/vulkan:gen_vulkan_spv_bin"
99 glslc_path = "//xplat/caffe2/fb/vulkan/dotslash:glslc"
1010
@@ -42,6 +42,7 @@ def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False):
4242 labels = ["uses_dotslash" ],
4343 )
4444
45+ suffix = "_no_volk" if no_volk else ""
4546 runtime .cxx_library (
4647 name = name ,
4748 srcs = [
@@ -56,7 +57,7 @@ def vulkan_spv_shader_lib(name, spv_filegroups, is_fbcode = False):
5657 # Define a soname that can be used for dynamic loading in Java, Python, etc.
5758 soname = "lib{}.$(ext)" .format (name ),
5859 exported_deps = [
59- "//executorch/backends/vulkan:vulkan_compute_api" ,
60+ "//executorch/backends/vulkan:vulkan_compute_api{}" . format ( suffix ) ,
6061 ],
6162 )
6263
@@ -89,126 +90,139 @@ def define_common_targets(is_fbcode = False):
8990 ]),
9091 )
9192
92- vulkan_spv_shader_lib (
93- name = "vulkan_graph_runtime_shaderlib" ,
94- spv_filegroups = {
95- ":vulkan_graph_runtime_shaders" : "runtime/graph/ops/glsl" ,
96- },
97- is_fbcode = is_fbcode ,
98- )
93+ for no_volk in [True , False ]:
94+ suffix = "_no_volk" if no_volk else ""
9995
100- VK_API_PREPROCESSOR_FLAGS = []
101- VK_API_DEPS = [
102- "fbsource//third-party/VulkanMemoryAllocator/3.0.1:VulkanMemoryAllocator_xplat" ,
103- ]
96+ VK_API_PREPROCESSOR_FLAGS = []
97+ VK_API_DEPS = [
98+ "fbsource//third-party/VulkanMemoryAllocator/3.0.1:VulkanMemoryAllocator_xplat" ,
99+ ]
104100
105- if is_fbcode :
106- VK_API_DEPS += [
107- "fbsource//third-party/swiftshader:swiftshader_vk_headers" ,
108- "fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_fbcode" ,
109- "fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_so" ,
101+ default_deps = []
102+ android_deps = [
103+ "fbsource//third-party/toolchains:android" ,
110104 ]
111- else :
112- VK_API_DEPS += select ({
113- "DEFAULT" : [
114- "fbsource//third-party/volk:volk" ,
115- ],
116- "ovr_config//os:android" : [
117- "fbsource//third-party/volk:volk" ,
118- "fbsource//third-party/toolchains:android"
119- ],
120- "ovr_config//os:macos-arm64" : [
121- "//third-party/khronos:moltenVK_static"
105+ default_flags = [
106+ "-DUSE_VULKAN_WRAPPER" ,
107+ ]
108+ android_flags = [
109+ "-DUSE_VULKAN_WRAPPER" ,
110+ "-DVK_ANDROID_external_memory_android_hardware_buffer" ,
111+ ]
112+
113+ if not no_volk :
114+ for deps in [default_deps , android_deps ]:
115+ deps .append ("fbsource//third-party/volk:volk" )
116+ for flags in [default_flags , android_flags ]:
117+ flags .append ("-DUSE_VULKAN_VOLK" )
118+ else :
119+ android_deps .append ("fbsource//third-party/toolchains:vulkan" )
120+
121+ if is_fbcode :
122+ VK_API_DEPS += [
123+ "fbsource//third-party/swiftshader:swiftshader_vk_headers" ,
124+ "fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_fbcode" ,
125+ "fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_so" ,
126+ ]
127+ else :
128+ VK_API_DEPS += select ({
129+ "DEFAULT" : default_deps ,
130+ "ovr_config//os:android" : android_deps ,
131+ "ovr_config//os:macos-arm64" : [
132+ "//third-party/khronos:moltenVK_static"
133+ ],
134+ })
135+ VK_API_PREPROCESSOR_FLAGS += select ({
136+ "DEFAULT" : default_flags ,
137+ "ovr_config//os:android" : android_flags ,
138+ "ovr_config//os:macos-arm64" : []
139+ })
140+
141+ runtime .cxx_library (
142+ name = "vulkan_compute_api{}" .format (suffix ),
143+ compiler_flags = get_vulkan_compiler_flags (),
144+ srcs = native .glob ([
145+ "runtime/api/**/*.cpp" ,
146+ "runtime/utils/**/*.cpp" ,
147+ "runtime/vk_api/**/*.cpp" ,
148+ ]),
149+ exported_headers = native .glob ([
150+ "runtime/api/**/*.h" ,
151+ "runtime/utils/**/*.h" ,
152+ "runtime/vk_api/**/*.h" ,
153+ ]),
154+ visibility = [
155+ "//executorch/backends/vulkan/..." ,
156+ "@EXECUTORCH_CLIENTS" ,
122157 ],
123- })
124- VK_API_PREPROCESSOR_FLAGS += select ({
125- "DEFAULT" : [
126- "-DUSE_VULKAN_WRAPPER" ,
127- "-DUSE_VULKAN_VOLK" ,
158+ exported_preprocessor_flags = VK_API_PREPROCESSOR_FLAGS ,
159+ exported_deps = VK_API_DEPS ,
160+ )
161+
162+ runtime .cxx_library (
163+ name = "vulkan_graph_runtime{}" .format (suffix ),
164+ srcs = native .glob ([
165+ "runtime/graph/**/*.cpp" ,
166+ ]),
167+ compiler_flags = get_vulkan_compiler_flags (),
168+ exported_headers = native .glob ([
169+ "runtime/graph/**/*.h" ,
170+ ]),
171+ visibility = [
172+ "//executorch/backends/..." ,
173+ "//executorch/extension/pybindings/..." ,
174+ "//executorch/test/..." ,
175+ "@EXECUTORCH_CLIENTS" ,
128176 ],
129- "ovr_config//os:android" : [
130- "-DUSE_VULKAN_WRAPPER" ,
131- "-DUSE_VULKAN_VOLK" ,
132- "-DVK_ANDROID_external_memory_android_hardware_buffer"
177+ exported_deps = [
178+ ":vulkan_graph_runtime_shaderlib" ,
133179 ],
134- "ovr_config//os:macos-arm64" : []
135- })
180+ define_static_target = False ,
181+ # Static initialization is used to register operators to the global operator registry,
182+ # therefore link_whole must be True to make sure unused symbols are not discarded.
183+ # @lint-ignore BUCKLINT: Avoid `link_whole=True`
184+ link_whole = True ,
185+ # Define an soname that can be used for dynamic loading in Java, Python, etc.
186+ soname = "libvulkan_graph_runtime.$(ext)" ,
187+ )
136188
137- runtime .cxx_library (
138- name = "vulkan_compute_api" ,
139- compiler_flags = get_vulkan_compiler_flags (),
140- srcs = native .glob ([
141- "runtime/api/**/*.cpp" ,
142- "runtime/utils/**/*.cpp" ,
143- "runtime/vk_api/**/*.cpp" ,
144- ]),
145- exported_headers = native .glob ([
146- "runtime/api/**/*.h" ,
147- "runtime/utils/**/*.h" ,
148- "runtime/vk_api/**/*.h" ,
149- ]),
150- visibility = [
151- "//executorch/backends/vulkan/..." ,
152- "@EXECUTORCH_CLIENTS" ,
153- ],
154- exported_preprocessor_flags = VK_API_PREPROCESSOR_FLAGS ,
155- exported_deps = VK_API_DEPS ,
156- )
189+ vulkan_spv_shader_lib (
190+ name = "vulkan_graph_runtime_shaderlib{}" .format (suffix ),
191+ spv_filegroups = {
192+ ":vulkan_graph_runtime_shaders" : "runtime/graph/ops/glsl" ,
193+ },
194+ is_fbcode = is_fbcode ,
195+ no_volk = no_volk ,
196+ )
157197
158- runtime .cxx_library (
159- name = "vulkan_graph_runtime" ,
160- srcs = native .glob ([
161- "runtime/graph/**/*.cpp" ,
162- ]),
163- compiler_flags = get_vulkan_compiler_flags (),
164- exported_headers = native .glob ([
165- "runtime/graph/**/*.h" ,
166- ]),
167- visibility = [
168- "//executorch/backends/..." ,
169- "//executorch/extension/pybindings/..." ,
170- "//executorch/test/..." ,
171- "@EXECUTORCH_CLIENTS" ,
172- ],
173- exported_deps = [
174- ":vulkan_graph_runtime_shaderlib" ,
175- ],
176- define_static_target = False ,
177- # Static initialization is used to register operators to the global operator registry,
178- # therefore link_whole must be True to make sure unused symbols are not discarded.
179- # @lint-ignore BUCKLINT: Avoid `link_whole=True`
180- link_whole = True ,
181- # Define an soname that can be used for dynamic loading in Java, Python, etc.
182- soname = "libvulkan_graph_runtime.$(ext)" ,
183- )
184198
185- runtime .cxx_library (
186- name = "vulkan_backend_lib" ,
187- srcs = native .glob ([
188- "runtime/*.cpp" ,
189- ]),
190- compiler_flags = get_vulkan_compiler_flags (),
191- headers = native .glob ([
192- "runtime/*.h" ,
193- ]),
194- visibility = [
195- "//executorch/backends/..." ,
196- "//executorch/extension/pybindings/..." ,
197- "//executorch/test/..." ,
198- "@EXECUTORCH_CLIENTS" ,
199- ],
200- deps = [
201- ":vulkan_graph_runtime" ,
202- "//executorch/backends/vulkan/serialization:vk_delegate_schema" ,
203- "//executorch/runtime/core:event_tracer" ,
204- "//executorch/runtime/backend:interface" ,
205- "//executorch/runtime/core/exec_aten/util:tensor_util" ,
206- ],
207- define_static_target = False ,
208- # VulkanBackend.cpp needs to compile with executor as whole
209- # @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
210- link_whole = True ,
211- )
199+ runtime .cxx_library (
200+ name = "vulkan_backend_lib{}" . format ( suffix ) ,
201+ srcs = native .glob ([
202+ "runtime/*.cpp" ,
203+ ]),
204+ compiler_flags = get_vulkan_compiler_flags (),
205+ headers = native .glob ([
206+ "runtime/*.h" ,
207+ ]),
208+ visibility = [
209+ "//executorch/backends/..." ,
210+ "//executorch/extension/pybindings/..." ,
211+ "//executorch/test/..." ,
212+ "@EXECUTORCH_CLIENTS" ,
213+ ],
214+ deps = [
215+ ":vulkan_graph_runtime{}" . format ( suffix ) ,
216+ "//executorch/backends/vulkan/serialization:vk_delegate_schema" ,
217+ "//executorch/runtime/core:event_tracer" ,
218+ "//executorch/runtime/backend:interface" ,
219+ "//executorch/runtime/core/exec_aten/util:tensor_util" ,
220+ ],
221+ define_static_target = False ,
222+ # VulkanBackend.cpp needs to compile with executor as whole
223+ # @lint-ignore BUCKLINT: Avoid `link_whole=True` (https://fburl.com/avoid-link-whole)
224+ link_whole = True ,
225+ )
212226
213227 ##
214228 ## AOT targets
0 commit comments