Skip to content

Commit 927af46

Browse files
committed
Vulkan: Select device with env variable, and do not initialize unused devices
1 parent 10c6501 commit 927af46

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

stable-diffusion.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,17 @@ class StableDiffusionGGML {
172172
#endif
173173
#ifdef SD_USE_VULKAN
174174
LOG_DEBUG("Using Vulkan backend");
175-
for (int device = 0; device < ggml_backend_vk_get_device_count(); ++device) {
175+
size_t device = 0;
176+
const int device_count = ggml_backend_vk_get_device_count();
177+
if (device_count) {
178+
const char* SD_VK_DEVICE = getenv("SD_VK_DEVICE");
179+
if (SD_VK_DEVICE != nullptr) {
180+
device = (size_t)std::stoull(SD_VK_DEVICE);
181+
if (device >= device_count) {
182+
LOG_WARN("Cannot find targeted vulkan device (%lld), falling back to device 0...", device);
183+
device = 0;
184+
}
185+
}
176186
backend = ggml_backend_vk_init(device);
177187
}
178188
if (!backend) {

0 commit comments

Comments
 (0)