From 25a06bc503c7d07ffc5480ac107e3c8681937971 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Thu, 9 Jan 2020 04:11:39 -0800 Subject: [PATCH] Add Vulkan memory objects to TfLite GPU API. PiperOrigin-RevId: 288871910 Change-Id: I0e2598db746bc2b57724cacc8840684e44fb1730 --- tensorflow/lite/delegates/gpu/BUILD | 1 + tensorflow/lite/delegates/gpu/api.h | 8 ++++ tensorflow/workspace.bzl | 2 + third_party/vulkan_headers/BUILD | 0 third_party/vulkan_headers/BUILD.bazel | 56 ++++++++++++++++++++++++ third_party/vulkan_headers/workspace.bzl | 15 +++++++ 6 files changed, 82 insertions(+) create mode 100644 third_party/vulkan_headers/BUILD create mode 100644 third_party/vulkan_headers/BUILD.bazel create mode 100644 third_party/vulkan_headers/workspace.bzl diff --git a/tensorflow/lite/delegates/gpu/BUILD b/tensorflow/lite/delegates/gpu/BUILD index 9b787e7d196..dd85e419c4c 100644 --- a/tensorflow/lite/delegates/gpu/BUILD +++ b/tensorflow/lite/delegates/gpu/BUILD @@ -204,6 +204,7 @@ cc_library( "@com_google_absl//absl/types:span", "@com_google_absl//absl/types:variant", "@opencl_headers", + "@vulkan_headers//:vulkan_headers_no_prototypes", ], ) diff --git a/tensorflow/lite/delegates/gpu/api.h b/tensorflow/lite/delegates/gpu/api.h index a2a2d872b6d..803983214e2 100644 --- a/tensorflow/lite/delegates/gpu/api.h +++ b/tensorflow/lite/delegates/gpu/api.h @@ -44,6 +44,7 @@ limitations under the License. #include "tensorflow/lite/delegates/gpu/common/status.h" #include "tensorflow/lite/delegates/gpu/common/util.h" #include "tensorflow/lite/delegates/gpu/gl/portable_gl31.h" +#include namespace tflite { namespace gpu { @@ -103,6 +104,13 @@ struct OpenClTexture { // TODO(akulik): should it specify texture format? }; +struct VulkanMemory { + VulkanMemory() = default; + explicit VulkanMemory(VkDeviceMemory new_memory) : memory(new_memory) {} + + VkDeviceMemory memory; +}; + struct CpuMemory { CpuMemory() = default; CpuMemory(void* new_data, size_t new_size_bytes) diff --git a/tensorflow/workspace.bzl b/tensorflow/workspace.bzl index 4a045fe386f..19ce3c7be31 100755 --- a/tensorflow/workspace.bzl +++ b/tensorflow/workspace.bzl @@ -38,6 +38,7 @@ load("//third_party/pasta:workspace.bzl", pasta = "repo") load("//third_party/psimd:workspace.bzl", psimd = "repo") load("//third_party/pthreadpool:workspace.bzl", pthreadpool = "repo") load("//third_party/sobol_data:workspace.bzl", sobol_data = "repo") +load("//third_party/vulkan_headers:workspace.bzl", vulkan_headers = "repo") def initialize_third_party(): """ Load third party repositories. See above load() statements. """ @@ -59,6 +60,7 @@ def initialize_third_party(): psimd() pthreadpool() sobol_data() + vulkan_headers() # Sanitize a dependency so that it works correctly from code that includes # TensorFlow as a submodule. diff --git a/third_party/vulkan_headers/BUILD b/third_party/vulkan_headers/BUILD new file mode 100644 index 00000000000..e69de29bb2d diff --git a/third_party/vulkan_headers/BUILD.bazel b/third_party/vulkan_headers/BUILD.bazel new file mode 100644 index 00000000000..5d4162519a7 --- /dev/null +++ b/third_party/vulkan_headers/BUILD.bazel @@ -0,0 +1,56 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +exports_files(["LICENSE"]) + +VULKAN_HDRS = [ + "include/vulkan/vk_platform.h", + "include/vulkan/vk_sdk_platform.h", + "include/vulkan/vulkan.h", + "include/vulkan/vulkan_core.h", +] + +VULKAN_TEXTUAL_HDRS = [ + "include/vulkan/vulkan_android.h", + "include/vulkan/vulkan_fuchsia.h", + "include/vulkan/vulkan_ggp.h", + "include/vulkan/vulkan_ios.h", + "include/vulkan/vulkan_macos.h", + "include/vulkan/vulkan_metal.h", + "include/vulkan/vulkan_vi.h", + "include/vulkan/vulkan_wayland.h", + "include/vulkan/vulkan_win32.h", + "include/vulkan/vulkan_xcb.h", + "include/vulkan/vulkan_xlib.h", + "include/vulkan/vulkan_xlib_xrandr.h", +] + +# The main vulkan public headers for applications. This excludes headers +# designed for ICDs and layers. +cc_library( + name = "vulkan_headers", + hdrs = VULKAN_HDRS, + includes = ["include"], + textual_hdrs = VULKAN_TEXTUAL_HDRS, +) + +# Like :vulkan_headers but defining VK_NO_PROTOTYPES to disable the +# inclusion of C function prototypes. Useful if dynamically loading +# all symbols via dlopen/etc. +cc_library( + name = "vulkan_headers_no_prototypes", + hdrs = VULKAN_HDRS, + defines = ["VK_NO_PROTOTYPES"], + includes = ["include"], + textual_hdrs = VULKAN_TEXTUAL_HDRS, +) + +# Provides a C++-ish interface to Vulkan. +cc_library( + name = "vulkan_hpp", + hdrs = ["include/vulkan/vulkan.hpp"], + defines = ["VULKAN_HPP_NO_EXCEPTIONS"], + includes = ["include"], + deps = [":vulkan_headers"], +) diff --git a/third_party/vulkan_headers/workspace.bzl b/third_party/vulkan_headers/workspace.bzl new file mode 100644 index 00000000000..aaa3401bd2a --- /dev/null +++ b/third_party/vulkan_headers/workspace.bzl @@ -0,0 +1,15 @@ +"""Loads Vulkan-Headers, used by TF Lite.""" + +load("//third_party:repo.bzl", "third_party_http_archive") + +def repo(): + third_party_http_archive( + name = "vulkan_headers", + strip_prefix = "Vulkan-Headers-0e57fc1cfa56a203efe43e4dfb9b3c9e9b105593", + sha256 = "096c4bff0957e9d6777b47d01c63e99ad9cf9d57e52be688a661b2473f8e52cb", + urls = [ + "https://mirror.bazel.build/github.com/KhronosGroup/Vulkan-Headers/archive/0e57fc1cfa56a203efe43e4dfb9b3c9e9b105593.tar.gz", + "https://github.com/KhronosGroup/Vulkan-Headers/archive/0e57fc1cfa56a203efe43e4dfb9b3c9e9b105593.tar.gz", + ], + build_file = "//third_party/vulkan_headers:BUILD.bazel", + )