Vulkan Runtime
导航
Vulkan Runtime#
TVM supports using Vulkan compute shaders to execute queries. Each computational kernel is compiled into a SPIR-V shader, which can then be called using the TVM interface.
Vulkan Features, Limits#
Since different Vulkan implementations may enable different optional features or have different physical limits, the code generation must know which features are available to use. These correspond to specific Vulkan capabilities/limits as in Vulkan Capabilities Table. If unspecified, TVM assumes that a capability is not available, or that a limit is the minimum guaranteed by the Vulkan spec in the Required Limits section.
These parameters can be either explicitly specific when defining a
Target, or can be queried from a
device. To query from a device, the special parameter
-from_device=N
can be used to query all vulkan device parameters
from device id N
. Any additional parameters explicitly specified
will override the parameters queried from the device.
Target Parameter |
Required Vulkan Version/Extension |
Parameter Queried |
Default Value |
---|---|---|---|
|
Vulkan 1.1+ |
|
0 (interpreted as VkSubgroupFeatureFlagBits) |
|
|
128 bytes |
|
|
|
16384 bytes |
|
|
|
227bytes |
|
|
|
4 |
|
|
VK_KHR_storage_buffer_storage_class |
false |
|
|
VK_KHR_8bit_storage |
|
false |
|
VK_KHR_16bit_storage |
|
false |
|
VK_KHR_shader_float16_int8 |
|
false |
|
|
false |
|
|
VK_KHR_shader_float16_int8 |
|
false |
|
|
false |
|
|
|
false |
As of May 2021, not all Vulkan implementations are supported. For example, support for 64-bit integers is required. If a Vulkan target is not supported, an error message should be issued during SPIR-V code generation. Efforts are also underway to remove these requirements and support additional Vulkan implementations.
SPIR-V Capabilities#
Some of the device-specific capabilities also correspond to SPIR-V capabilities or extensions that must be declared in the shader, or a minimum SPIR-V version required in order to use a feature. The TVM-generated shaders will declare the minimum set of extensions/capabilities and the minimum allowed version of SPIR-V that are needed to execute the compiled graph.
If the shader generation requires a capability or extension that is
not enabled in the Target
, an exception will be raised.
Target Parameter |
Required SPIR-V Version/Extension |
Declared Capability |
---|---|---|
|
SPIR-V 1.3+ |
Varies, see VkSubgroupFeatureFlagBits |
|
SPV_KHR_storage_buffer_storage_class |
|
|
SPV_KHR_8bit_storage |
StorageBuffer8BitAccess |
|
SPV_KHR_16bit_storage |
StorageBuffer16BitAccess |
|
Float16 |
|
|
Float64 |
|
|
Int8 |
|
|
Int16 |
|
|
Int64 |
Vulkan-Specific Environment Variables#
Both the SPIR-V code generation and the Vulkan runtime have environment variables that can modify some of the runtime behavior. These are intended for debugging purposes, both to more easily test specific code paths, and to output more information as needed. All boolean flags are true if the environment variable is set to a non-zero integer. An unset variable, the integer zero, or an empty string are all false boolean flags.
TVM_VULKAN_DISABLE_PUSH_DESCRIPTOR
- A boolean flag. If true, TVM will explicitly allocate descriptors, and will not use the VK_KHR_push_descriptor or VK_KHR_descriptor_update_template extensions. If false, TVM will decide whether to use these extensions based on their availability.TVM_VULKAN_DISABLE_DEDICATED_ALLOCATION
- A boolean flag. If true, TVM will not mark memory allocations as being dedicated allocations, and will not use the VK_KHR_dedicated_allocation extension. If false, TVM will decide whether memory allocations should be marked as dedicated based on the VkMemoryDedicatedRequirements for that buffer.TVM_VULKAN_ENABLE_VALIDATION_LAYERS
- A boolean flag. If true, TVM will enable Vulkan validation layers that the device supports. If false, no validation layers are enabled.TVM_VULKAN_DISABLE_SHADER_VALIDATION
- A boolean flag. If true, the SPIR-V shader validation done with spvValidate is skipped. If false (default), all SPIR-V shaders generated by TVM are validated with spvValidate.TVM_VULKAN_DEBUG_SHADER_SAVEPATH
- A path to a directory. If set to a non-empty string, the Vulkan codegen will save tir, binary SPIR-V, and disassembled SPIR-V shaders to this directory, to be used for debugging purposes.