Markus Tavenrath commited on
Commit
760f8c2
·
1 Parent(s): e84b4f5

Enable use to the rebar feature to upload buffers to the device. (llama/9251)

Browse files
Files changed (1) hide show
  1. ggml/src/ggml-vulkan.cpp +7 -2
ggml/src/ggml-vulkan.cpp CHANGED
@@ -1094,7 +1094,8 @@ static vk_buffer ggml_vk_create_buffer_device(vk_device& device, size_t size) {
1094
  // Fall back to host memory type
1095
  buf = ggml_vk_create_buffer(device, size, vk::MemoryPropertyFlagBits::eDeviceLocal, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
1096
  } else {
1097
- buf = ggml_vk_create_buffer(device, size, vk::MemoryPropertyFlagBits::eDeviceLocal);
 
1098
  }
1099
  } catch (const vk::SystemError& e) {
1100
  std::cerr << "ggml_vulkan: Device memory allocation of size " << size << " failed." << std::endl;
@@ -2839,7 +2840,11 @@ static void ggml_vk_buffer_read_async(vk_context subctx, vk_buffer& src, size_t
2839
 
2840
  static void ggml_vk_buffer_read(vk_buffer& src, size_t offset, void * dst, size_t size) {
2841
  VK_LOG_DEBUG("ggml_vk_buffer_read(" << src->buffer << ", " << offset << ", " << size << ")");
2842
- if(src->memory_property_flags & vk::MemoryPropertyFlagBits::eHostVisible) {
 
 
 
 
2843
  GGML_ASSERT(src->memory_property_flags & vk::MemoryPropertyFlagBits::eHostCoherent);
2844
 
2845
  memcpy(dst, (uint8_t *) src->ptr + offset, size);
 
1094
  // Fall back to host memory type
1095
  buf = ggml_vk_create_buffer(device, size, vk::MemoryPropertyFlagBits::eDeviceLocal, vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent);
1096
  } else {
1097
+ // use rebar if available, otherwise fallback to device only visible memory
1098
+ buf = ggml_vk_create_buffer(device, size, vk::MemoryPropertyFlagBits::eDeviceLocal | vk::MemoryPropertyFlagBits::eHostVisible | vk::MemoryPropertyFlagBits::eHostCoherent, vk::MemoryPropertyFlagBits::eDeviceLocal);
1099
  }
1100
  } catch (const vk::SystemError& e) {
1101
  std::cerr << "ggml_vulkan: Device memory allocation of size " << size << " failed." << std::endl;
 
2840
 
2841
  static void ggml_vk_buffer_read(vk_buffer& src, size_t offset, void * dst, size_t size) {
2842
  VK_LOG_DEBUG("ggml_vk_buffer_read(" << src->buffer << ", " << offset << ", " << size << ")");
2843
+
2844
+ // If the device is not an UMA device the memory is host-accessible through rebar. While writing
2845
+ // through PCIe is sufficient fast reading back data from PCIe is slower than going through
2846
+ // the HW device to host copy path.
2847
+ if(src->memory_property_flags & vk::MemoryPropertyFlagBits::eHostVisible && src->device->uma) {
2848
  GGML_ASSERT(src->memory_property_flags & vk::MemoryPropertyFlagBits::eHostCoherent);
2849
 
2850
  memcpy(dst, (uint8_t *) src->ptr + offset, size);