traits.cpp 1.2 KB

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