Skip to content

Commit 9aec524

Browse files
committed
metal : refactor context
ggml-ci
1 parent 76e8816 commit 9aec524

File tree

12 files changed

+5717
-5561
lines changed

12 files changed

+5717
-5561
lines changed

ggml/include/ggml-metal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern "C" {
3939
// user-code should use only these functions
4040
//
4141

42+
// TODO: remove in the future
4243
GGML_BACKEND_API ggml_backend_t ggml_backend_metal_init(void);
4344

4445
GGML_BACKEND_API bool ggml_backend_is_metal(ggml_backend_t backend);

ggml/src/ggml-metal/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ggml_add_backend_library(ggml-metal
99
ggml-metal-device.m
1010
ggml-metal-device.cpp
1111
ggml-metal-common.cpp
12+
ggml-metal-context.m
13+
ggml-metal-ops.cpp
1214
)
1315

1416
target_link_libraries(ggml-metal PRIVATE

ggml/src/ggml-metal/ggml-metal-common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static std::vector<int> ggml_metal_graph_optimize_reorder(const std::vector<node
375375
return res;
376376
}
377377

378-
void ggml_metal_graph_optimize(ggml_cgraph * gf) {
378+
void ggml_graph_optimize(ggml_cgraph * gf) {
379379
constexpr int MAX_FUSE = 16;
380380

381381
const int n = gf->n_nodes;

ggml/src/ggml-metal/ggml-metal-common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool ggml_mem_ranges_check(ggml_mem_ranges_t mrs, const struct ggml_tensor * ten
4545
//
4646
// note: this implementation is generic and not specific to metal
4747
// if it proves to work well, we can start using it for other backends in the future
48-
void ggml_metal_graph_optimize(struct ggml_cgraph * gf);
48+
void ggml_graph_optimize(struct ggml_cgraph * gf);
4949

5050
#ifdef __cplusplus
5151
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#pragma once
2+
3+
#include "ggml-metal-device.h"
4+
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
//
10+
// MTLFunctionConstantValues wrapper
11+
//
12+
13+
typedef struct ggml_metal_cv * ggml_metal_cv_t;
14+
15+
ggml_metal_cv_t ggml_metal_cv_init(void);
16+
void ggml_metal_cv_free(ggml_metal_cv_t cv);
17+
18+
void ggml_metal_cv_set_int32(ggml_metal_cv_t cv, int32_t value, int32_t idx);
19+
void ggml_metal_cv_set_bool (ggml_metal_cv_t cv, bool value, int32_t idx);
20+
21+
//
22+
// backend
23+
//
24+
25+
typedef struct ggml_metal * ggml_metal_t;
26+
27+
ggml_metal_t ggml_metal_init(ggml_metal_device_t ctx_dev);
28+
void ggml_metal_free(ggml_metal_t ctx);
29+
30+
typedef void * ggml_metal_pipeline_t;
31+
32+
ggml_metal_pipeline_t ggml_metal_get_pipeline(ggml_metal_t ctx, const char * name);
33+
34+
ggml_metal_pipeline_t ggml_metal_compile_pipeline(ggml_metal_t ctx, const char * base, const char * name, ggml_metal_cv_t cv);
35+
36+
void ggml_metal_synchronize(ggml_metal_t ctx);
37+
38+
void ggml_metal_set_tensor_async(ggml_metal_t ctx, struct ggml_tensor * tensor, const void * data, size_t offset, size_t size);
39+
void ggml_metal_get_tensor_async(ggml_metal_t ctx, const struct ggml_tensor * tensor, void * data, size_t offset, size_t size);
40+
41+
enum ggml_status ggml_metal_graph_compute(ggml_metal_t ctx, struct ggml_cgraph * gf);
42+
43+
void ggml_metal_graph_optimize(ggml_metal_t ctx, struct ggml_cgraph * gf);
44+
45+
void ggml_metal_set_n_cb (ggml_metal_t ctx, int n_cb);
46+
void ggml_metal_set_abort_callback (ggml_metal_t ctx, ggml_abort_callback abort_callback, void * user_data);
47+
bool ggml_metal_supports_family (ggml_metal_t ctx, int family);
48+
void ggml_metal_capture_next_compute(ggml_metal_t ctx);
49+
50+
#ifdef __cplusplus
51+
}
52+
#endif

0 commit comments

Comments
 (0)