Skip to content

Commit cfd6788

Browse files
committed
[ET-VK] Move files using the Vulkan API to vk_api/
Pull Request resolved: #4125 and move from namespace `api` to `vkapi`. This gave me a major headache in the number of places to update. This stack orgnaizes ET-VK neatly into three abstraction levels, both by folder and by namespace: 1. `namespace vkcompute` and `graph/`: for operator computation implementation and scheduling. 2. `namespace vkcompute::api` and `graph/api/`: for tensor objects (and other objects wrapping our VulkanBuffer/VulkanImage). 3. `namespace vkcompute::vkapi` and `graph/api/vk_api/`: for direct users of Vulkan API Additionally, we have - `namespace vkcompute::utils` and `graph/api/utils/`: for utils used by both namespace `api` and `vkapi` ghstack-source-id: 232399401 @exported-using-ghexport Differential Revision: [D59281539](https://our.internmc.facebook.com/intern/diff/D59281539/)
1 parent c839b9e commit cfd6788

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1063
-1022
lines changed

backends/vulkan/runtime/VulkanBackend.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,47 +59,47 @@ const uint8_t* get_constant_data_ptr(
5959
return constant_data + constant_bytes->offset();
6060
}
6161

62-
api::ScalarType get_scalar_type(const vkgraph::VkDataType& vk_datatype) {
62+
vkapi::ScalarType get_scalar_type(const vkgraph::VkDataType& vk_datatype) {
6363
switch (vk_datatype) {
6464
case vkgraph::VkDataType::BOOL:
65-
return api::kBool;
65+
return vkapi::kBool;
6666
case vkgraph::VkDataType::UINT8:
67-
return api::kByte;
67+
return vkapi::kByte;
6868
case vkgraph::VkDataType::INT8:
69-
return api::kChar;
69+
return vkapi::kChar;
7070
case vkgraph::VkDataType::INT32:
71-
return api::kInt;
71+
return vkapi::kInt;
7272
case vkgraph::VkDataType::FLOAT16:
73-
return api::kHalf;
73+
return vkapi::kHalf;
7474
case vkgraph::VkDataType::FLOAT32:
75-
return api::kFloat;
75+
return vkapi::kFloat;
7676
}
7777
}
7878

79-
api::StorageType get_storage_type(
79+
vkapi::StorageType get_storage_type(
8080
const vkgraph::VkStorageType& vk_storage_type) {
8181
switch (vk_storage_type) {
8282
case vkgraph::VkStorageType::BUFFER:
83-
return api::kBuffer;
83+
return vkapi::kBuffer;
8484
case vkgraph::VkStorageType::TEXTURE_3D:
85-
return api::kTexture3D;
85+
return vkapi::kTexture3D;
8686
case vkgraph::VkStorageType::TEXTURE_2D:
87-
return api::kTexture2D;
87+
return vkapi::kTexture2D;
8888
default:
8989
break;
9090
}
9191
VK_THROW("Invalid storage type encountered!");
9292
}
9393

94-
api::GPUMemoryLayout get_memory_layout(
94+
vkapi::GPUMemoryLayout get_memory_layout(
9595
const vkgraph::VkMemoryLayout& vk_memory_layout) {
9696
switch (vk_memory_layout) {
9797
case vkgraph::VkMemoryLayout::TENSOR_WIDTH_PACKED:
98-
return api::kWidthPacked;
98+
return vkapi::kWidthPacked;
9999
case vkgraph::VkMemoryLayout::TENSOR_HEIGHT_PACKED:
100-
return api::kHeightPacked;
100+
return vkapi::kHeightPacked;
101101
case vkgraph::VkMemoryLayout::TENSOR_CHANNELS_PACKED:
102-
return api::kChannelsPacked;
102+
return vkapi::kChannelsPacked;
103103
default:
104104
break;
105105
}
@@ -115,16 +115,16 @@ GraphConfig get_graph_config(ArrayRef<CompileSpec>& compile_specs) {
115115
if (strcmp(spec.key, "storage_type_override") == 0) {
116116
ET_CHECK_MSG(value_size == sizeof(int32_t), "Unexpected value size!");
117117
int value_as_int = static_cast<int>(getUInt32LE(value_data));
118-
api::StorageType storage_type =
119-
static_cast<api::StorageType>(value_as_int);
118+
vkapi::StorageType storage_type =
119+
static_cast<vkapi::StorageType>(value_as_int);
120120

121121
config.set_storage_type_override(storage_type);
122122
}
123123
if (strcmp(spec.key, "memory_layout_override") == 0) {
124124
ET_CHECK_MSG(value_size == sizeof(uint32_t), "Unexpected value size!");
125125
uint32_t value_as_int = getUInt32LE(value_data);
126-
api::GPUMemoryLayout memory_layout =
127-
static_cast<api::GPUMemoryLayout>(value_as_int);
126+
vkapi::GPUMemoryLayout memory_layout =
127+
static_cast<vkapi::GPUMemoryLayout>(value_as_int);
128128

129129
config.set_memory_layout_override(memory_layout);
130130
}
@@ -171,16 +171,16 @@ class GraphBuilder {
171171
}
172172

173173
void add_tensor_to_graph(const uint32_t fb_id, VkTensorPtr tensor_fb) {
174-
const api::ScalarType& dtype = get_scalar_type(tensor_fb->datatype());
175-
api::StorageType storage_type =
174+
const vkapi::ScalarType& dtype = get_scalar_type(tensor_fb->datatype());
175+
vkapi::StorageType storage_type =
176176
tensor_fb->storage_type() == vkgraph::VkStorageType::DEFAULT_STORAGE
177177
? compute_graph_->suggested_storage_type()
178178
: get_storage_type(tensor_fb->storage_type());
179179

180180
UIntVector dims_fb = tensor_fb->dims();
181181
const std::vector<int64_t> dims_vector(dims_fb->cbegin(), dims_fb->cend());
182182

183-
api::GPUMemoryLayout memory_layout =
183+
vkapi::GPUMemoryLayout memory_layout =
184184
tensor_fb->memory_layout() == vkgraph::VkMemoryLayout::DEFAULT_LAYOUT
185185
? compute_graph_->suggested_memory_layout(dims_vector)
186186
: get_memory_layout(tensor_fb->memory_layout());

backends/vulkan/runtime/api/Context.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*/
88

99
#include <executorch/backends/vulkan/runtime/api/Context.h>
10-
#include <executorch/backends/vulkan/runtime/api/VkUtils.h>
10+
11+
#include <executorch/backends/vulkan/runtime/api/vk_api/VkUtils.h>
1112

1213
#ifndef VULKAN_DESCRIPTOR_POOL_SIZE
1314
#define VULKAN_DESCRIPTOR_POOL_SIZE 1024u
@@ -23,7 +24,7 @@ namespace api {
2324
Context::Context(size_t adapter_i, const ContextConfig& config)
2425
: config_(config),
2526
// Important handles
26-
adapter_p_(runtime()->get_adapter_p(adapter_i)),
27+
adapter_p_(vkapi::runtime()->get_adapter_p(adapter_i)),
2728
device_(adapter_p_->device_handle()),
2829
queue_(adapter_p_->request_queue()),
2930
// Resource pools
@@ -72,8 +73,8 @@ void Context::report_shader_dispatch_start(
7273
cmd_,
7374
dispatch_id,
7475
shader_name,
75-
create_extent3d(global_wg_size),
76-
create_extent3d(local_wg_size));
76+
vkapi::create_extent3d(global_wg_size),
77+
vkapi::create_extent3d(local_wg_size));
7778
}
7879
}
7980

@@ -83,17 +84,17 @@ void Context::report_shader_dispatch_end() {
8384
}
8485
}
8586

86-
DescriptorSet Context::get_descriptor_set(
87-
const ShaderInfo& shader_descriptor,
87+
vkapi::DescriptorSet Context::get_descriptor_set(
88+
const vkapi::ShaderInfo& shader_descriptor,
8889
const utils::uvec3& local_workgroup_size,
89-
const SpecVarList& additional_constants) {
90+
const vkapi::SpecVarList& additional_constants) {
9091
VkDescriptorSetLayout shader_layout =
9192
shader_layout_cache().retrieve(shader_descriptor.kernel_layout);
9293

9394
VkPipelineLayout pipeline_layout =
9495
pipeline_layout_cache().retrieve(shader_layout);
9596

96-
SpecVarList spec_constants = {
97+
vkapi::SpecVarList spec_constants = {
9798
SV(local_workgroup_size.data[0u]),
9899
SV(local_workgroup_size.data[1u]),
99100
SV(local_workgroup_size.data[2u])};
@@ -112,9 +113,9 @@ DescriptorSet Context::get_descriptor_set(
112113
}
113114

114115
void Context::register_shader_dispatch(
115-
const DescriptorSet& descriptors,
116-
PipelineBarrier& pipeline_barrier,
117-
const ShaderInfo& shader_descriptor,
116+
const vkapi::DescriptorSet& descriptors,
117+
vkapi::PipelineBarrier& pipeline_barrier,
118+
const vkapi::ShaderInfo& shader_descriptor,
118119
const utils::uvec3& global_workgroup_size) {
119120
// Adjust the global workgroup size based on the output tile size
120121
uint32_t global_wg_w = utils::div_up(
@@ -180,12 +181,12 @@ Context* context() {
180181
try {
181182
const uint32_t cmd_submit_frequency = 16u;
182183

183-
const CommandPoolConfig cmd_config{
184+
const vkapi::CommandPoolConfig cmd_config{
184185
32u, // cmdPoolInitialSize
185186
8u, // cmdPoolBatchSize
186187
};
187188

188-
const DescriptorPoolConfig descriptor_pool_config{
189+
const vkapi::DescriptorPoolConfig descriptor_pool_config{
189190
VULKAN_DESCRIPTOR_POOL_SIZE, // descriptorPoolMaxSets
190191
VULKAN_DESCRIPTOR_POOL_SIZE, // descriptorUniformBufferCount
191192
VULKAN_DESCRIPTOR_POOL_SIZE, // descriptorStorageBufferCount
@@ -194,7 +195,7 @@ Context* context() {
194195
32u, // descriptorPileSizes
195196
};
196197

197-
const QueryPoolConfig query_pool_config{
198+
const vkapi::QueryPoolConfig query_pool_config{
198199
VULKAN_QUERY_POOL_SIZE, // maxQueryCount
199200
256u, // initialReserveSize
200201
};
@@ -206,7 +207,7 @@ Context* context() {
206207
query_pool_config,
207208
};
208209

209-
return new Context(runtime()->default_adapter_i(), config);
210+
return new Context(vkapi::runtime()->default_adapter_i(), config);
210211
} catch (...) {
211212
}
212213

0 commit comments

Comments
 (0)