1 /*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9 #include <executorch/backends/vulkan/runtime/graph/GraphConfig.h>
10
11 namespace vkcompute {
12
GraphConfig()13 GraphConfig::GraphConfig() {
14 // No automatic submissions
15 const uint32_t cmd_submit_frequency = UINT32_MAX;
16
17 // Only one command buffer will be encoded at a time
18 const vkapi::CommandPoolConfig cmd_config{
19 1u, // cmd_pool_initial_size
20 1u, // cmd_pool_batch_size
21 };
22
23 // Use lazy descriptor pool initialization by default; the graph runtime will
24 // tally up the number of descriptor sets needed while building the graph and
25 // trigger descriptor pool initialization with exact sizes before encoding the
26 // command buffer.
27 const vkapi::DescriptorPoolConfig descriptor_pool_config{
28 0u, // descriptor_pool_max_sets
29 0u, // descriptor_uniform_buffer_count
30 0u, // descriptor_storage_buffer_count
31 0u, // descriptor_combined_sampler_count
32 0u, // descriptor_storage_image_count
33 0u, // descriptor_pile_sizes
34 };
35
36 const vkapi::QueryPoolConfig query_pool_config{};
37
38 context_config = {
39 cmd_submit_frequency,
40 cmd_config,
41 descriptor_pool_config,
42 query_pool_config,
43 };
44
45 // Empirically selected safety factor. If descriptor pools start running out
46 // of memory, increase this safety factor.
47 descriptor_pool_safety_factor = 1.25;
48
49 // For now, force kTexture3D storage as we are still developing shader support
50 // for buffer storage type.
51 enable_storage_type_override = true;
52 storage_type_override = utils::kTexture3D;
53
54 // For now, force kWidthPacked memory layout by default as we are still
55 // developing support for other memory layouts. In the future memory layout
56 // settings will be serialized as part of the graph.
57 enable_memory_layout_override = true;
58 memory_layout_override = utils::kWidthPacked;
59
60 // QueryPool objects are used to measure execution times of individual shader
61 // dispatches. By default, this functionality is disabled.
62 enable_querypool = false;
63
64 enable_local_wg_size_override = false;
65 local_wg_size_override = {};
66 }
67
set_storage_type_override(utils::StorageType storage_type)68 void GraphConfig::set_storage_type_override(utils::StorageType storage_type) {
69 enable_storage_type_override = true;
70 storage_type_override = storage_type;
71 }
72
set_memory_layout_override(utils::GPUMemoryLayout memory_layout)73 void GraphConfig::set_memory_layout_override(
74 utils::GPUMemoryLayout memory_layout) {
75 enable_memory_layout_override = true;
76 memory_layout_override = memory_layout;
77 }
78
set_local_wg_size_override(const utils::uvec3 & local_wg_size)79 void GraphConfig::set_local_wg_size_override(
80 const utils::uvec3& local_wg_size) {
81 enable_local_wg_size_override = true;
82 local_wg_size_override = local_wg_size;
83 }
84
85 } // namespace vkcompute
86