interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-zdnn / scratch.hpp

61 lines · 1549 bytes Raw Blame History
1#ifndef GGML_ZDNN_SCRATCH_HPP
2#define GGML_ZDNN_SCRATCH_HPP
3
4#include "ggml.h"
5
6#include <cstddef>
7#include <vector>
8
9// 4K aligned host buffers that are cached for reuse, see ggml_cuda_pool_leg
10struct ggml_zdnn_pool {
11 struct buffer {
12 void * ptr = nullptr;
13 size_t size = 0;
14 };
15
16 std::vector<buffer> cached;
17
18 ~ggml_zdnn_pool();
19
20 void * alloc(size_t size, size_t * actual_size);
21 void free(void * ptr, size_t size);
22};
23
24// a buffer of the pool that goes back to it at the end of its scope, see ggml_cuda_pool_alloc
25template <typename T>
26struct ggml_zdnn_pool_alloc {
27 ggml_zdnn_pool * pool = nullptr;
28 T * ptr = nullptr;
29 size_t actual_size = 0;
30
31 ggml_zdnn_pool_alloc() = default;
32
33 ggml_zdnn_pool_alloc(ggml_zdnn_pool & pool, size_t size) {
34 alloc(pool, size);
35 }
36
37 ~ggml_zdnn_pool_alloc() {
38 if (ptr != nullptr) {
39 pool->free(ptr, actual_size);
40 }
41 }
42
43 // size is in number of elements
44 T * alloc(ggml_zdnn_pool & pool, size_t size) {
45 GGML_ASSERT(ptr == nullptr);
46 this->pool = &pool;
47 ptr = (T *) pool.alloc(size * sizeof(T), &actual_size);
48 return ptr;
49 }
50
51 T * get() {
52 return ptr;
53 }
54
55 ggml_zdnn_pool_alloc(const ggml_zdnn_pool_alloc &) = delete;
56 ggml_zdnn_pool_alloc(ggml_zdnn_pool_alloc &&) = delete;
57 ggml_zdnn_pool_alloc & operator=(const ggml_zdnn_pool_alloc &) = delete;
58 ggml_zdnn_pool_alloc & operator=(ggml_zdnn_pool_alloc &&) = delete;
59};
60
61#endif // GGML_ZDNN_SCRATCH_HPP