Skip to content

Commit

Permalink
Update ggml
Browse files Browse the repository at this point in the history
  • Loading branch information
abetlen committed Feb 11, 2024
1 parent d88f325 commit 66ccdfe
Show file tree
Hide file tree
Showing 9 changed files with 521 additions and 917 deletions.
23 changes: 10 additions & 13 deletions ggml/experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def cpu():
raise ValueError("Failed to initialize CPU backend")
return Backend(backend=backend)

def new_measure(self) -> "Allocr":
allocr = ggml.ggml_allocr_new_measure_from_backend(self.backend)
return Allocr(allocr)
def new_graph_allocator(self) -> "GraphAllocator":
allocr = ggml.ggml_gallocr_new(ggml.ggml_backend_get_default_buffer_type(self.backend))
return GraphAllocator(allocr)

def alloc_buffer(self, size: int) -> "BackendBuffer":
def new_backend_buffer(self, size: int) -> "BackendBuffer":
buffer = ggml.ggml_backend_alloc_buffer(self.backend, size)
return BackendBuffer(buffer)

Expand All @@ -102,20 +102,17 @@ def __init__(self, buffer: ggml.ggml_backend_buffer_t):
def __del__(self):
ggml.ggml_backend_buffer_free(self.buffer)

def new_allocr(self) -> "Allocr":
allocr = ggml.ggml_allocr_new_from_buffer(self.buffer)
return Allocr(allocr)


class Allocr:
def __init__(self, allocr: ggml.ggml_allocr_t):
class GraphAllocator:
def __init__(self, allocr: ggml.ggml_gallocr):
self.allocr = allocr

def __del__(self):
ggml.ggml_allocr_free(self.allocr)
ggml.ggml_gallocr_free(self.allocr)

def alloc_graph(self, graph: "CGraph") -> int:
return ggml.ggml_allocr_alloc_graph(self.allocr, graph.cgraph)
def allocate_graph(self, graph: "CGraph"):
ggml.ggml_gallocr_reserve(self.allocr, graph.cgraph)
ggml.ggml_gallocr_alloc_graph(self.allocr, graph.cgraph)


class GGML_TYPE(enum.IntEnum):
Expand Down
Loading

0 comments on commit 66ccdfe

Please sign in to comment.