| 7388 | |
| 7389 | template<typename F> |
| 7390 | static bool buft_supported(ggml_backend_buffer_type_t buft, ggml_backend_dev_t dev, F & fn) { |
| 7391 | ggml_init_params params = { |
| 7392 | /*.mem_size =*/ ggml_tensor_overhead()*8, |
| 7393 | /*.mem_buffer =*/ NULL, |
| 7394 | /*.no_alloc =*/ true, |
| 7395 | }; |
| 7396 | |
| 7397 | ggml_context_ptr ctx { ggml_init(params) }; |
| 7398 | if (!ctx) { |
| 7399 | throw std::runtime_error(format("failed to create ggml context")); |
| 7400 | } |
| 7401 | |
| 7402 | ggml_backend_buffer_ptr buf { ggml_backend_buft_alloc_buffer(buft, 0) }; |
| 7403 | ggml_tensor * op_tensor = fn(ctx.get()); |
| 7404 | for (int i = 0; i < GGML_MAX_SRC; i++) { |
| 7405 | if (op_tensor->src[i] != nullptr) { |
| 7406 | assert(op_tensor->src[i]->buffer == nullptr); |
| 7407 | op_tensor->src[i]->buffer = buf.get(); |
| 7408 | } |
| 7409 | } |
| 7410 | |
| 7411 | bool op_supported = ggml_backend_dev_supports_op(dev, op_tensor); |
| 7412 | |
| 7413 | return op_supported; |
| 7414 | } |
| 7415 | |
| 7416 | template<typename F> |
| 7417 | static ggml_backend_buffer_type_t select_buft(const buft_list_t & buft_list, const F & fn) { |
no test coverage detected