Skip to content

Commit 27df617

Browse files
committed
vulkan: add environment variable GGML_VK_PREFER_HOST_MEMORY to avoid VRAM allocation
1 parent bfcce4d commit 27df617

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
@@ -166,6 +166,7 @@ struct vk_device_struct {
166166
uint32_t subgroup_size;
167167
uint32_t shader_core_count;
168168
bool uma;
169+
bool prefer_host_memory;
169170
bool float_controls_rte_fp16;
170171

171172
bool subgroup_size_control;
@@ -1293,7 +1294,9 @@ static vk_buffer ggml_vk_create_buffer_check(vk_device& device, size_t size, vk:
12931294
static vk_buffer ggml_vk_create_buffer_device(vk_device& device, size_t size) {
12941295
vk_buffer buf;
12951296
try {
1296-
if (device->uma) {
1297+
if (device->prefer_host_memory) {
1298+
buf = ggml_vk_create_buffer(device, size, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent, vk::MemoryPropertyFlagBits::eDeviceLocal);
1299+
} else if (device->uma) {
12971300
// Fall back to host memory type
12981301
buf = ggml_vk_create_buffer(device, size, vk::MemoryPropertyFlagBits::eDeviceLocal, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
12991302
} else {
@@ -2188,6 +2191,9 @@ static vk_device ggml_vk_get_device(size_t idx) {
21882191
device->physical_device = physical_devices[dev_num];
21892192
const std::vector<vk::ExtensionProperties> ext_props = device->physical_device.enumerateDeviceExtensionProperties();
21902193

2194+
const char* GGML_VK_PREFER_HOST_MEMORY = getenv("GGML_VK_PREFER_HOST_MEMORY");
2195+
device->prefer_host_memory = GGML_VK_PREFER_HOST_MEMORY != nullptr;
2196+
21912197
bool fp16_storage = false;
21922198
bool fp16_compute = false;
21932199
bool maintenance4_support = false;

0 commit comments

Comments
 (0)