LLM inference in C/C++
C++ ggml
vulkan: add fast path for contiguous buffer transfers (#23973)
Winston Mafdc3db9b6577
diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cppindex 47533c2ba9..5f37240452 100644--- a/ggml/src/ggml-vulkan/ggml-vulkan.cpp+++ b/ggml/src/ggml-vulkan/ggml-vulkan.cpp@@ -7615,8 +7615,12 @@ static void ggml_vk_buffer_write_2d(vk_buffer& dst, size_t offset, const void *if(dst->memory_property_flags & vk::MemoryPropertyFlagBits::eHostVisible) {GGML_ASSERT(dst->memory_property_flags & vk::MemoryPropertyFlagBits::eHostCoherent);- for (size_t i = 0; i < height; i++) {- memcpy((uint8_t *)dst->ptr + offset + i * dpitch, (const uint8_t *) src + i * spitch, width);+ if (width == spitch && width == dpitch) {+ memcpy((uint8_t *)dst->ptr + offset, src, width * height);+ } else {+ for (size_t i = 0; i < height; i++) {+ memcpy((uint8_t *)dst->ptr + offset + i * dpitch, (const uint8_t *) src + i * spitch, width);+ }}} else {std::lock_guard<std::recursive_mutex> guard(dst->device->mutex);@@ -7735,8 +7739,12 @@ static void ggml_vk_buffer_read_2d(vk_buffer& src, size_t offset, void * dst, siif(src->memory_property_flags & vk::MemoryPropertyFlagBits::eHostVisible && src->device->uma) {GGML_ASSERT(src->memory_property_flags & vk::MemoryPropertyFlagBits::eHostCoherent);- for (size_t i = 0; i < height; i++) {- memcpy((uint8_t *) dst + i * dpitch, (const uint8_t *) src->ptr + offset + i * spitch, width);+ if (width == spitch && width == dpitch) {+ memcpy(dst, (const uint8_t *) src->ptr + offset, width * height);+ } else {+ for (size_t i = 0; i < height; i++) {+ memcpy((uint8_t *) dst + i * dpitch, (const uint8_t *) src->ptr + offset + i * spitch, width);+ }}} else {std::lock_guard<std::recursive_mutex> guard(src->device->mutex);