Compare commits

...

2 Commits

Author SHA1 Message Date
Jared Van Bortel 8dbe93db22 kompute: fix device name leaks
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2 weeks ago
Jared Van Bortel 0cbca27c8b settings: prefix vk devices with "Vulkan: ", update old names
Signed-off-by: Jared Van Bortel <jared@nomic.ai>
2 weeks ago

@ -1 +1 @@
Subproject commit e21d0b32e9324b1df40107d9004cc6b67cdd1567
Subproject commit 40bac11e427f2307305b86c322cb366bb95fcb8a

@ -405,7 +405,7 @@ bool LLamaModel::loadModel(const std::string &modelPath, int n_ctx, int ngl)
if (usingGPUDevice()) {
#ifdef GGML_USE_KOMPUTE
if (llama_verbose()) {
std::cerr << "llama.cpp: using Vulkan on " << ggml_vk_current_device().name << std::endl;
std::cerr << "llama.cpp: using Vulkan on " << d_ptr->deviceName << std::endl;
}
d_ptr->backend_name = "kompute";
#elif defined(GGML_USE_VULKAN)
@ -652,6 +652,8 @@ bool LLamaModel::initializeGPUDevice(size_t memoryRequired, const std::string &n
bool ok = ggml_vk_get_device(&device, memoryRequired, name.c_str());
if (ok) {
d_ptr->device = device.index;
d_ptr->deviceName = device.name;
ggml_vk_device_destroy(&device);
return true;
}
#else
@ -665,17 +667,15 @@ bool LLamaModel::initializeGPUDevice(int device, std::string *unavail_reason) co
{
#if defined(GGML_USE_KOMPUTE) || defined(GGML_USE_VULKAN) || defined(GGML_USE_CUDA)
(void)unavail_reason;
d_ptr->device = device;
#ifndef GGML_USE_KOMPUTE
auto devices = availableGPUDevices();
auto it = std::find_if(devices.begin(), devices.end(), [device](auto &dev) { return dev.index == device; });
d_ptr->device = device;
d_ptr->deviceName = it < devices.end() ? it->name : "(unknown)";
#endif
return true;
#else
(void)device;
if (unavail_reason) {
*unavail_reason = "built without Kompute";
*unavail_reason = "built without a GPU backend";
}
return false;
#endif
@ -714,9 +714,7 @@ const char *LLamaModel::backendName() const {
const char *LLamaModel::gpuDeviceName() const {
if (usingGPUDevice()) {
#ifdef GGML_USE_KOMPUTE
return ggml_vk_current_device().name;
#elif defined(GGML_USE_VULKAN) || defined(GGML_USE_CUDA)
#if defined(GGML_USE_KOMPUTE) || defined(GGML_USE_VULKAN) || defined(GGML_USE_CUDA)
return d_ptr->deviceName.c_str();
#endif
}

@ -1,6 +1,7 @@
#ifndef LLMODEL_H
#define LLMODEL_H
#include <algorithm>
#include <cstdint>
#include <fstream>
#include <functional>
@ -8,6 +9,7 @@
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
using namespace std::string_literals;
@ -54,8 +56,24 @@ public:
backend(backend), index(index), type(type), heapSize(heapSize), name(std::move(name)),
vendor(std::move(vendor)) {}
std::string selectionName() const { return backend == "cuda"s ? "CUDA: " + name : name; }
std::string reportedName() const { return backend == "cuda"s ? name + " (CUDA)" : name; }
std::string selectionName() const { return m_backendNames.at(backend) + ": " + name; }
std::string reportedName() const { return name + " (" + m_backendNames.at(backend) + ")"; }
static std::string updateSelectionName(const std::string &name) {
if (name == "Auto" || name == "CPU" || name == "Metal")
return name;
auto it = std::find_if(m_backendNames.begin(), m_backendNames.end(), [&name](const auto &entry) {
return name.starts_with(entry.second + ": ");
});
if (it != m_backendNames.end())
return name;
return "Vulkan: " + name; // previously, there were only Vulkan devices
}
private:
static inline const std::unordered_map<std::string, std::string> m_backendNames {
{"cuda", "CUDA"}, {"kompute", "Vulkan"},
};
};
class Implementation {

@ -790,7 +790,23 @@ QString MySettings::device() const
{
QSettings setting;
setting.sync();
return setting.value("device", default_device).toString();
auto value = setting.value("device");
if (!value.isValid())
return default_device;
auto device = value.toString();
if (!device.isEmpty()) {
auto deviceStr = device.toStdString();
auto newNameStr = LLModel::GPUDevice::updateSelectionName(deviceStr);
if (newNameStr != deviceStr) {
auto newName = QString::fromStdString(newNameStr);
qWarning() << "updating device name:" << device << "->" << newName;
device = newName;
setting.setValue("device", device);
setting.sync();
}
}
return device;
}
void MySettings::setDevice(const QString &u)

Loading…
Cancel
Save