Skip to content

Commit b044a0f

Browse files
authored
vulkan: add environment variable GGML_VK_PREFER_HOST_MEMORY to avoid VRAM allocation (#11592)
1 parent 19d3c82 commit b044a0f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ struct vk_device_struct {
167167
uint32_t subgroup_size;
168168
uint32_t shader_core_count;
169169
bool uma;
170+
bool prefer_host_memory;
170171
bool float_controls_rte_fp16;
171172

172173
bool subgroup_size_control;
@@ -1294,7 +1295,9 @@ static vk_buffer ggml_vk_create_buffer_check(vk_device& device, size_t size, vk:
12941295
static vk_buffer ggml_vk_create_buffer_device(vk_device& device, size_t size) {
12951296
vk_buffer buf;
12961297
try {
1297-
if (device->uma) {
1298+
if (device->prefer_host_memory) {
1299+
buf = ggml_vk_create_buffer(device, size, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent, vk::MemoryPropertyFlagBits::eDeviceLocal);
1300+
} else if (device->uma) {
12981301
// Fall back to host memory type
12991302
buf = ggml_vk_create_buffer(device, size, vk::MemoryPropertyFlagBits::eDeviceLocal, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
13001303
} else {
@@ -2199,6 +2202,9 @@ static vk_device ggml_vk_get_device(size_t idx) {
21992202
device->physical_device = physical_devices[dev_num];
22002203
const std::vector<vk::ExtensionProperties> ext_props = device->physical_device.enumerateDeviceExtensionProperties();
22012204

2205+
const char* GGML_VK_PREFER_HOST_MEMORY = getenv("GGML_VK_PREFER_HOST_MEMORY");
2206+
device->prefer_host_memory = GGML_VK_PREFER_HOST_MEMORY != nullptr;
2207+
22022208
bool fp16_storage = false;
22032209
bool fp16_compute = false;
22042210
bool maintenance4_support = false;

0 commit comments

Comments
 (0)