Skip to content

Commit

Permalink
[Vulkan] Add device capabilities to Target, use in codegen (#8127)
Browse files Browse the repository at this point in the history
* [Vulkan] Enable instance/device extensions

- Vulkan requires that extensions be explicitly enabled if used.
  Explicitly list out which extensions are required (currently none)
  and which are optional.

* [Vulkan] Extract device information from vulkan API.

- Based on vkGetPhysicalDeviceProperties and
  vkGetPhysicalDeviceFeatures, determine which Vulkan capabilities are
  supported, pack into a Target.

* [Vulkan] Query instance-supported apiVersion before creating instance

- Previously, vkCreateInstance was called to initialize Vulkan 1.0.

* [Vulkan] Moved options for dedicated allocation and push descriptors to environment variables

- Query support for dedicated allocation and push descriptors along
  with the rest of the device support.  Move the options to disable
  their use from compile-time variables to environment variables
  `TVM_VULKAN_DISABLE_PUSH_DESCRIPTOR` and
  `TVM_VULKAN_DISABLE_DEDICATED_ALLOCATION`.

* [Vulkan] Move option for vulkan validation layers to environment variable

- Moved to enable faster use as a debug tool.  If
  `TVM_VULKAN_ENABLE_VALIDATION_LAYERS` is a non-empty string,
  validation layers will be enabled.

* [Vulkan] Explicitly enable vulkan features in device creation

- Vulkan requires that features be explicitly enabled before use.  For
  each feature that the device supports and a shader might use,
  declare it in the call to `vkCreateDevice`.

* [Vulkan] Avoid repeated queries for device attributes.

- Implement `VulkanDeviceAPI::GetAttr` based on the per-device values
  stored in the Target.  This pulls all logic for querying device
  parameters is in a single location.

* [Vulkan] Implement "from_device" flag for the vulkan target.

- With the number of device capabilities that may or may not be
  supported by a vulkan driver, it can be tedious to input them.
  Specifying "-from_device=0" now indicate that any unspecified values
  should be read from the device.

* [Vulkan][Codegen] Read vulkan device capabilities/limits from Target

- Previously, the codegen assumed that all device features were
  present.  Now, the codegen reads device capabilities from the
  Target, and throws an error if codegen would require use of an
  unsupported feature.

Co-authored-by: Eric Lunderberg <[email protected]>
  • Loading branch information
Lunderberg and Lunderberg authored May 26, 2021
1 parent 69e56c6 commit c02cafb
Show file tree
Hide file tree
Showing 6 changed files with 527 additions and 179 deletions.
21 changes: 0 additions & 21 deletions cmake/modules/Vulkan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
# Be compatible with older version of CMake
find_vulkan(${USE_VULKAN})

# Extra Vulkan runtime options, exposed for advanced users.
tvm_option(USE_VULKAN_IMMEDIATE_MODE "Use Vulkan Immediate mode
(KHR_push_descriptor extension)" ON IF USE_VULKAN)
tvm_option(USE_VULKAN_DEDICATED_ALLOCATION "Use Vulkan dedicated allocations" ON
IF USE_VULKAN)
tvm_option(USE_VULKAN_VALIDATION "Enable Vulkan API validation layers" OFF
IF USE_VULKAN)

if(USE_VULKAN)
if(NOT Vulkan_FOUND)
message(FATAL_ERROR "Cannot find Vulkan, USE_VULKAN=" ${USE_VULKAN})
Expand All @@ -38,17 +30,4 @@ if(USE_VULKAN)
list(APPEND COMPILER_SRCS ${COMPILER_VULKAN_SRCS})
list(APPEND TVM_LINKER_LIBS ${Vulkan_SPIRV_TOOLS_LIBRARY})
list(APPEND TVM_RUNTIME_LINKER_LIBS ${Vulkan_LIBRARY})

if(USE_VULKAN_IMMEDIATE_MODE)
message(STATUS "Build with Vulkan immediate mode")
add_definitions(-DUSE_VULKAN_IMMEDIATE_MODE=1)
endif()
if(USE_VULKAN_DEDICATED_ALLOCATION)
message(STATUS "Build with Vulkan dedicated allocation")
add_definitions(-DUSE_VULKAN_DEDICATED_ALLOCATION=1)
endif()
if(USE_VULKAN_VALIDATION)
message(STATUS "Build with Vulkan API validation")
add_definitions(-DUSE_VULKAN_VALIDATION=1)
endif()
endif(USE_VULKAN)
2 changes: 1 addition & 1 deletion python/tvm/_ffi/runtime_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def api_version(self):
The version of the SDK
"""
return self._GetDeviceAttr(self.device_type, self.device_id, 12)
return self._GetDeviceAttr(self.device_type, self.device_id, 11)

@property
def driver_version(self):
Expand Down
Loading

0 comments on commit c02cafb

Please sign in to comment.