Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ggml/src/ggml-vulkan/ggml-vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ DispatchLoaderDynamic & ggml_vk_default_dispatcher();
#include <map>
#include <set>
#include <unordered_map>
#include <shared_mutex>
#include <mutex>
#include <future>
#include <thread>
Expand Down Expand Up @@ -595,6 +596,7 @@ static constexpr std::initializer_list<std::array<int, 3>> rms_norm_mul_rope_vie

struct vk_device_struct {
std::recursive_mutex mutex;
mutable std::shared_mutex pinned_memory_mutex;

vk::PhysicalDevice physical_device;
vk::PhysicalDeviceProperties properties;
Expand Down Expand Up @@ -6633,7 +6635,7 @@ static void * ggml_vk_host_malloc(vk_device& device, size_t size) {
return nullptr;
}

std::lock_guard<std::recursive_mutex> guard(device->mutex);
std::unique_lock<std::shared_mutex> guard(device->pinned_memory_mutex);
Comment thread
0cc4m marked this conversation as resolved.
Outdated
device->pinned_memory.push_back(std::make_tuple(buf->ptr, size, buf));

return buf->ptr;
Expand All @@ -6644,7 +6646,7 @@ static void ggml_vk_host_free(vk_device& device, void* ptr) {
return;
}
VK_LOG_MEMORY("ggml_vk_host_free(" << ptr << ")");
std::lock_guard<std::recursive_mutex> guard(device->mutex);
std::unique_lock<std::shared_mutex> guard(device->pinned_memory_mutex);

vk_buffer buf;
size_t index;
Expand All @@ -6668,7 +6670,7 @@ static void ggml_vk_host_free(vk_device& device, void* ptr) {
}

static void ggml_vk_host_get(const vk_device& device, const void * ptr, vk_buffer& buf, size_t& buf_offset) {
std::lock_guard<std::recursive_mutex> guard(device->mutex);
std::shared_lock<std::shared_mutex> guard(device->pinned_memory_mutex);
buf = nullptr;
buf_offset = 0;
for (size_t i = 0; i < device->pinned_memory.size(); i++) {
Expand Down
Loading