| 1 | #include "traits.h" |
|---|---|
| 2 | |
| 3 | #include "ggml-backend-impl.h" |
| 4 | #include "ggml-backend.h" |
| 5 | |
| 6 | namespace ggml::cpu { |
| 7 | tensor_traits::~tensor_traits() {} |
| 8 | |
| 9 | extra_buffer_type::~extra_buffer_type() {} |
| 10 | } // namespace ggml::cpu |
| 11 | |
| 12 | bool ggml_cpu_extra_compute_forward(struct ggml_compute_params * params, struct ggml_tensor * op) { |
| 13 | for (auto extra : ggml_backend_cpu_get_extra_buffer_types()) { |
| 14 | if (extra && extra->context) { |
| 15 | auto buf_extra = (ggml::cpu::extra_buffer_type *) extra->context; |
| 16 | auto tensor_traits = buf_extra->get_tensor_traits(op); |
| 17 | if (tensor_traits && tensor_traits->compute_forward(params, op)) { |
| 18 | return true; |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | return false; |
| 23 | } |
| 24 | |
| 25 | bool ggml_cpu_extra_work_size(int n_threads, const struct ggml_tensor * op, size_t * size) { |
| 26 | for (auto extra : ggml_backend_cpu_get_extra_buffer_types()) { |
| 27 | if (extra && extra->context) { |
| 28 | auto buf_extra = (ggml::cpu::extra_buffer_type *) extra->context; |
| 29 | auto tensor_traits = buf_extra->get_tensor_traits(op); |
| 30 | if (tensor_traits && tensor_traits->work_size(n_threads, op, size&: *size)) { |
| 31 | return true; |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | return false; |
| 36 | } |
| 37 |