Skip to content

Commit d200b51

Browse files
committed
Vulkan2 Runtime API
1 parent d9bbdbc commit d200b51

File tree

15 files changed

+1782
-1534
lines changed

15 files changed

+1782
-1534
lines changed

apps/android_rpc/app/src/main/jni/tvm_runtime.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@
6262
#endif
6363

6464
#ifdef TVM_VULKAN_RUNTIME
65-
#include "../src/runtime/vulkan/vulkan_device_api.cc"
66-
#include "../src/runtime/vulkan/vulkan_module.cc"
65+
#include "../src/runtime/vulkan/vulkan2.cc"
6766
#endif
6867

6968
#ifdef USE_SORT

cmake/modules/Vulkan.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if(USE_VULKAN)
2929
message(FATAL_ERROR "Cannot find Vulkan, USE_VULKAN=" ${USE_VULKAN})
3030
endif()
3131
message(STATUS "Build with VULKAN support")
32-
file(GLOB RUNTIME_VULKAN_SRCS src/runtime/vulkan/*.cc)
32+
file(GLOB RUNTIME_VULKAN_SRCS src/runtime/vulkan/vulkan2.cc)
3333
file(GLOB COMPILER_VULKAN_SRCS src/codegen/spirv/*.cc)
3434
list(APPEND RUNTIME_SRCS ${RUNTIME_VULKAN_SRCS})
3535
list(APPEND COMPILER_SRCS ${COMPILER_VULKAN_SRCS})

src/codegen/spirv/build_vulkan.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
#include "codegen_spirv.h"
3131
#include "../build_common.h"
32-
#include "../../runtime/vulkan/vulkan_module.h"
32+
33+
#include "../../runtime/vulkan/vulkan2_shader.h"
34+
#include "../../runtime/vulkan/vulkan2_module.h"
3335

3436
namespace tvm {
3537
namespace codegen {

src/codegen/spirv/ir_builder.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ namespace spirv {
3333
void IRBuilder::InitHeader() {
3434
CHECK_EQ(header_.size(), 0U);
3535
header_.push_back(spv::MagicNumber);
36-
header_.push_back(spv::Version);
36+
// Use SPIR-V v1.0. This needs to be kept in sync (or at least behind)
37+
// `VkApplicationInfo.apiVersion` in `vulkan2.cc` to ensure Vulkan API
38+
// validation passes.
39+
header_.push_back(0x10000);
3740
// generator: set to 0, unknown
3841
header_.push_back(0U);
3942
// Bound: set during Finalize

src/runtime/vulkan/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!--- Licensed to the Apache Software Foundation (ASF) under one -->
2+
<!--- or more contributor license agreements. See the NOTICE file -->
3+
<!--- distributed with this work for additional information -->
4+
<!--- regarding copyright ownership. The ASF licenses this file -->
5+
<!--- to you under the Apache License, Version 2.0 (the -->
6+
<!--- "License"); you may not use this file except in compliance -->
7+
<!--- with the License. You may obtain a copy of the License at -->
8+
9+
<!--- http://www.apache.org/licenses/LICENSE-2.0 -->
10+
11+
<!--- Unless required by applicable law or agreed to in writing, -->
12+
<!--- software distributed under the License is distributed on an -->
13+
<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
14+
<!--- KIND, either express or implied. See the License for the -->
15+
<!--- specific language governing permissions and limitations -->
16+
<!--- under the License. -->
17+
18+
19+
## Components
20+
21+
### Vulkan2DeviceAPI
22+
23+
Implements the TVM DeviceAPI interface. Owns the core Vulkan datastructures. Is responsible for initializing the Vulkan instance and devices, querying for possible extensions.
24+
25+
### Vulkan2ThreadEntry
26+
27+
Thread-local state for the Vulkan runtime. Maintains a staging buffer (for copies), and a Vulkan2Stream per device.
28+
29+
### Vulkan2WrappedFunc
30+
31+
Responsible for launching computation kernels. Responsible for obtaining a
32+
Vulkan2Pipeline instance (from the Vulkan2ModuleNode), and launches the kernel
33+
(via immediate or deferred mode) on the active Vulkan2Stream instance.
34+
35+
## Stream execution in the Vulkan programming model.
36+
37+
THe natural model for TVM DeviceAPI implementation and runtime follows the CUDA
38+
API model. That is, we launch "kernels" onto a (implicit or explicit) "stream"
39+
(which execute asynchronously with respect to the host, but ordered with respect
40+
to the stream), and explicitly synchronize the stream with respect to the host.
41+
We simulate this behaviour in the Vulkan model by maintaining a thread-local
42+
`vkCommandBuffer` instance, and queueing up (or eagerly executing, depending on
43+
the availability of the `VK_KHR_push_descriptor` extension). When we synchronize
44+
the stream, we end the command buffer recording, submit it to the device queue,
45+
and wait on the corresponding fence.

0 commit comments

Comments
 (0)