ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-metal / ggml-metal-device.h
| 1 | #pragma once |
| 2 | |
| 3 | #include "ggml.h" |
| 4 | |
| 5 | #ifdef __cplusplus |
| 6 | extern "C" { |
| 7 | #endif |
| 8 | |
| 9 | struct ggml_metal_buffer_id { |
| 10 | void * metal; // id<MTLBuffer> |
| 11 | size_t offs; |
| 12 | }; |
| 13 | |
| 14 | typedef struct ggml_metal_device * ggml_metal_device_t; |
| 15 | |
| 16 | // |
| 17 | // MTLFunctionConstantValues wrapper |
| 18 | // |
| 19 | |
| 20 | typedef struct ggml_metal_cv * ggml_metal_cv_t; |
| 21 | |
| 22 | ggml_metal_cv_t ggml_metal_cv_init(void); |
| 23 | void ggml_metal_cv_free(ggml_metal_cv_t cv); |
| 24 | |
| 25 | void ggml_metal_cv_set_int16(ggml_metal_cv_t cv, int16_t value, int32_t idx); |
| 26 | void ggml_metal_cv_set_int32(ggml_metal_cv_t cv, int32_t value, int32_t idx); |
| 27 | void ggml_metal_cv_set_bool (ggml_metal_cv_t cv, bool value, int32_t idx); |
| 28 | |
| 29 | // |
| 30 | // MTLComputePipelineState wrapper |
| 31 | // |
| 32 | |
| 33 | typedef struct ggml_metal_pipeline * ggml_metal_pipeline_t; |
| 34 | |
| 35 | ggml_metal_pipeline_t ggml_metal_pipeline_init(void); |
| 36 | void ggml_metal_pipeline_free(ggml_metal_pipeline_t pipeline); |
| 37 | |
| 38 | // a collection of pipelines |
| 39 | typedef struct ggml_metal_pipelines * ggml_metal_pipelines_t; |
| 40 | |
| 41 | ggml_metal_pipelines_t ggml_metal_pipelines_init(void); |
| 42 | void ggml_metal_pipelines_free(ggml_metal_pipelines_t ppls); |
| 43 | |
| 44 | void ggml_metal_pipelines_add(ggml_metal_pipelines_t ppls, const char * name, ggml_metal_pipeline_t pipeline); |
| 45 | ggml_metal_pipeline_t ggml_metal_pipelines_get(ggml_metal_pipelines_t ppls, const char * name); |
| 46 | |
| 47 | struct ggml_metal_pipeline_with_params { |
| 48 | ggml_metal_pipeline_t pipeline; |
| 49 | |
| 50 | int nsg; |
| 51 | |
| 52 | int nr0; |
| 53 | int nr1; |
| 54 | |
| 55 | size_t smem; |
| 56 | |
| 57 | bool c4; |
| 58 | bool cnt; |
| 59 | }; |
| 60 | |
| 61 | int ggml_metal_pipeline_max_theads_per_threadgroup(struct ggml_metal_pipeline_with_params pipeline); |
| 62 | |
| 63 | // |
| 64 | // MTLCommandBuffer wrapper |
| 65 | // |
| 66 | |
| 67 | typedef void * ggml_metal_cmd_buf_t; |
| 68 | |
| 69 | // |
| 70 | // MTLComputeCommandEncoder wrapper |
| 71 | // |
| 72 | |
| 73 | typedef struct ggml_metal_encoder * ggml_metal_encoder_t; |
| 74 | |
| 75 | ggml_metal_encoder_t ggml_metal_encoder_init(ggml_metal_cmd_buf_t cmd_buf_raw, bool concurrent); |
| 76 | void ggml_metal_encoder_free(ggml_metal_encoder_t encoder); |
| 77 | |
| 78 | void ggml_metal_encoder_debug_group_push(ggml_metal_encoder_t encoder, const char * name); |
| 79 | void ggml_metal_encoder_debug_group_pop (ggml_metal_encoder_t encoder); |
| 80 | |
| 81 | void ggml_metal_encoder_set_pipeline(ggml_metal_encoder_t encoder, struct ggml_metal_pipeline_with_params pipeline); |
| 82 | |
| 83 | void ggml_metal_encoder_set_bytes (ggml_metal_encoder_t encoder, void * data, size_t size, int idx); |
| 84 | void ggml_metal_encoder_set_buffer(ggml_metal_encoder_t encoder, struct ggml_metal_buffer_id buffer, int idx); |
| 85 | |
| 86 | void ggml_metal_encoder_set_threadgroup_memory_size(ggml_metal_encoder_t encoder, size_t size, int idx); |
| 87 | |
| 88 | void ggml_metal_encoder_dispatch_threadgroups(ggml_metal_encoder_t encoder, int tg0, int tg1, int tg2, int tptg0, int tptg1, int tptg2); |
| 89 | |
| 90 | void ggml_metal_encoder_memory_barrier(ggml_metal_encoder_t encoder); |
| 91 | |
| 92 | void ggml_metal_encoder_end_encoding(ggml_metal_encoder_t encoder); |
| 93 | |
| 94 | // |
| 95 | // MTLLibrary wrapper |
| 96 | // |
| 97 | |
| 98 | typedef struct ggml_metal_library * ggml_metal_library_t; |
| 99 | |
| 100 | ggml_metal_library_t ggml_metal_library_init (ggml_metal_device_t dev); |
| 101 | ggml_metal_library_t ggml_metal_library_init_from_source(ggml_metal_device_t dev, const char * source, bool verbose); |
| 102 | |
| 103 | void ggml_metal_library_free(ggml_metal_library_t lib); |
| 104 | |
| 105 | ggml_metal_device_t ggml_metal_library_get_device(ggml_metal_library_t lib); |
| 106 | |
| 107 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline (ggml_metal_library_t lib, const char * name); |
| 108 | struct ggml_metal_pipeline_with_params ggml_metal_library_compile_pipeline(ggml_metal_library_t lib, const char * base, const char * name, ggml_metal_cv_t cv); |
| 109 | |
| 110 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_base (ggml_metal_library_t lib, enum ggml_op op); |
| 111 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_cpy (ggml_metal_library_t lib, enum ggml_type tsrc, enum ggml_type tdst); |
| 112 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_pool_1d (ggml_metal_library_t lib, const struct ggml_tensor * op, enum ggml_op_pool op_pool); |
| 113 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_pool_2d (ggml_metal_library_t lib, const struct ggml_tensor * op, enum ggml_op_pool op_pool); |
| 114 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_get_rows (ggml_metal_library_t lib, enum ggml_type tsrc); |
| 115 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_set_rows (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 116 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_diag (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 117 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_repeat (ggml_metal_library_t lib, enum ggml_type tsrc); |
| 118 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_concat (ggml_metal_library_t lib, enum ggml_type tsrc); |
| 119 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_unary (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 120 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_silu_back (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 121 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_glu (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 122 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_sum (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 123 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_sum_rows (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 124 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_cumsum_blk (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 125 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_cumsum_add (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 126 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_tri (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 127 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_soft_max (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 128 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_lightning_indexer (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 129 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_top_k_mask (ggml_metal_library_t lib, const struct ggml_tensor * op, bool fill, bool has_score, bool has_blocks, bool has_extra, bool vec); |
| 130 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_dsv4_hc (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 131 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_conv (ggml_metal_library_t lib, const struct ggml_tensor * op, int32_t nc, bool use_silu); |
| 132 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_conv_batched (ggml_metal_library_t lib, const struct ggml_tensor * op, int ssm_conv_bs, int32_t nc, bool use_silu); |
| 133 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_scan (ggml_metal_library_t lib, const struct ggml_tensor * op, bool tail); |
| 134 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_ssm_scan_ssd_mma (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 135 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_rwkv (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 136 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_gated_delta_net (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 137 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_solve_tri (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 138 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv_ext (ggml_metal_library_t lib, const struct ggml_tensor * op, int nsg, int nxpsg, int r1ptg); |
| 139 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv_mma (ggml_metal_library_t lib, const struct ggml_tensor * op, int nsg, int nt, int rt, bool add); |
| 140 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv_mma_auto (ggml_metal_library_t lib, const struct ggml_tensor * op, bool add); |
| 141 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mm (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 142 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 143 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mm_id_map0 (ggml_metal_library_t lib, int ne02, int ne20); |
| 144 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mm_id_zero (ggml_metal_library_t lib); |
| 145 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mm_id (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 146 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_mul_mv_id (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 147 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_argmax (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 148 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_argmax_part (ggml_metal_library_t lib); |
| 149 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_argmax_final (ggml_metal_library_t lib); |
| 150 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_argsort (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 151 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_argsort_merge (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 152 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_fwht (ggml_metal_library_t lib, int n, enum ggml_type tsrc); |
| 153 | |
| 154 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_top_k (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 155 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_top_k_radix (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 156 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_top_k_merge (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 157 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_topk_moe (ggml_metal_library_t lib, int32_t n_expert, int32_t top_k, bool with_norm); |
| 158 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_moe_reduce (ggml_metal_library_t lib, int32_t n_expert_used); |
| 159 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_bin (ggml_metal_library_t lib, const struct ggml_tensor * op, int32_t n_fuse); |
| 160 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_bin_one (ggml_metal_library_t lib, enum ggml_op op); |
| 161 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_l2_norm (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 162 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_group_norm (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 163 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_norm (ggml_metal_library_t lib, const struct ggml_tensor * op, int32_t n_fuse); |
| 164 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_norm_scale (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 165 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_rope (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 166 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_im2col (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 167 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_transpose_1d (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 168 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_transpose_2d (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 169 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_col2im_1d (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 170 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_snake (ggml_metal_library_t lib, enum ggml_type type); |
| 171 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_2d (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 172 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_2d_dw (ggml_metal_library_t lib, const struct ggml_tensor * op, bool tiled); |
| 173 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_conv_3d (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 174 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_upscale (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 175 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_pad (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 176 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_pad_reflect_1d (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 177 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_roll (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 178 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_arange (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 179 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_timestep_embedding(ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 180 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_opt_step_adamw (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 181 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_opt_step_sgd (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 182 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_memset (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 183 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_count_equal (ggml_metal_library_t lib, const struct ggml_tensor * op); |
| 184 | |
| 185 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext_pad( |
| 186 | ggml_metal_library_t lib, |
| 187 | const struct ggml_tensor * op, |
| 188 | bool has_mask, |
| 189 | int32_t ncpsg); |
| 190 | |
| 191 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext_kv_f16( |
| 192 | ggml_metal_library_t lib, |
| 193 | const struct ggml_tensor * op); |
| 194 | |
| 195 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext_blk( |
| 196 | ggml_metal_library_t lib, |
| 197 | const struct ggml_tensor * op, |
| 198 | int32_t nqptg, |
| 199 | int32_t ncpsg); |
| 200 | |
| 201 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext_tensor( |
| 202 | ggml_metal_library_t lib, |
| 203 | const struct ggml_tensor * op, |
| 204 | bool has_mask, |
| 205 | bool has_sinks, |
| 206 | bool has_bias, |
| 207 | bool has_scap); |
| 208 | |
| 209 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext( |
| 210 | ggml_metal_library_t lib, |
| 211 | const struct ggml_tensor * op, |
| 212 | bool has_mask, |
| 213 | bool has_sinks, |
| 214 | bool has_bias, |
| 215 | bool has_scap, |
| 216 | bool has_kvpad, |
| 217 | int32_t nsg, |
| 218 | bool use_kv_f16, |
| 219 | int32_t ns10, |
| 220 | int32_t ns20); |
| 221 | |
| 222 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext_rows( |
| 223 | ggml_metal_library_t lib, |
| 224 | const struct ggml_tensor * op); |
| 225 | |
| 226 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext_vec_idx( |
| 227 | ggml_metal_library_t lib, |
| 228 | const struct ggml_tensor * op); |
| 229 | |
| 230 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext_vec( |
| 231 | ggml_metal_library_t lib, |
| 232 | const struct ggml_tensor * op, |
| 233 | bool has_mask, |
| 234 | bool has_sinks, |
| 235 | bool has_bias, |
| 236 | bool has_scap, |
| 237 | bool has_kvpad, |
| 238 | bool has_sparse, |
| 239 | bool has_rows, |
| 240 | int32_t nqpsg, |
| 241 | int32_t ne, |
| 242 | int32_t nsg, |
| 243 | int32_t nwg, |
| 244 | bool use_kv_f16, |
| 245 | int32_t ns10, |
| 246 | int32_t ns20); |
| 247 | |
| 248 | struct ggml_metal_pipeline_with_params ggml_metal_library_get_pipeline_flash_attn_ext_vec_reduce( |
| 249 | ggml_metal_library_t lib, |
| 250 | const struct ggml_tensor * op, |
| 251 | int32_t dv, |
| 252 | int32_t nwg); |
| 253 | |
| 254 | // MTLResidencySet wrapper |
| 255 | |
| 256 | typedef void * ggml_metal_rset_t; |
| 257 | |
| 258 | // a collection of residency sets (non-owning) |
| 259 | typedef struct ggml_metal_rsets * ggml_metal_rsets_t; |
| 260 | |
| 261 | ggml_metal_rsets_t ggml_metal_rsets_init(ggml_metal_device_t dev); |
| 262 | void ggml_metal_rsets_free(ggml_metal_rsets_t rsets); |
| 263 | |
| 264 | // |
| 265 | // device |
| 266 | // |
| 267 | |
| 268 | enum ggml_metal_device_id { |
| 269 | GGML_METAL_DEVICE_GENERIC = 0, |
| 270 | |
| 271 | GGML_METAL_DEVICE_M1, |
| 272 | GGML_METAL_DEVICE_M1_PRO, |
| 273 | GGML_METAL_DEVICE_M1_MAX, |
| 274 | GGML_METAL_DEVICE_M1_ULTRA, |
| 275 | GGML_METAL_DEVICE_M2, |
| 276 | GGML_METAL_DEVICE_M2_PRO, |
| 277 | GGML_METAL_DEVICE_M2_MAX, |
| 278 | GGML_METAL_DEVICE_M2_ULTRA, |
| 279 | GGML_METAL_DEVICE_M3, |
| 280 | GGML_METAL_DEVICE_M3_PRO, |
| 281 | GGML_METAL_DEVICE_M3_MAX, |
| 282 | GGML_METAL_DEVICE_M3_ULTRA, |
| 283 | GGML_METAL_DEVICE_M4, |
| 284 | GGML_METAL_DEVICE_M4_PRO, |
| 285 | GGML_METAL_DEVICE_M4_MAX, |
| 286 | GGML_METAL_DEVICE_M5, |
| 287 | GGML_METAL_DEVICE_M5_PRO, |
| 288 | GGML_METAL_DEVICE_M5_MAX, |
| 289 | GGML_METAL_DEVICE_M5_ULTRA, |
| 290 | GGML_METAL_DEVICE_A18_PRO, |
| 291 | }; |
| 292 | |
| 293 | const char * ggml_metal_device_id_token(enum ggml_metal_device_id id); |
| 294 | |
| 295 | struct ggml_metal_device_props { |
| 296 | int device; |
| 297 | int device_phys; |
| 298 | int device_virt; |
| 299 | char name[128]; |
| 300 | char desc[128]; |
| 301 | |
| 302 | size_t max_buffer_size; |
| 303 | size_t max_working_set_size; |
| 304 | size_t max_theadgroup_memory_size; |
| 305 | |
| 306 | bool has_simdgroup_reduction; |
| 307 | bool has_simdgroup_mm; |
| 308 | bool has_unified_memory; |
| 309 | bool has_bfloat; |
| 310 | bool has_tensor; |
| 311 | bool use_residency_sets; |
| 312 | bool use_shared_buffers; |
| 313 | |
| 314 | enum ggml_metal_device_id device_id; |
| 315 | int gpu_family; |
| 316 | |
| 317 | int op_offload_min_batch_size; |
| 318 | }; |
| 319 | |
| 320 | typedef struct ggml_metal_event * ggml_metal_event_t; |
| 321 | |
| 322 | void ggml_metal_event_encode_signal(ggml_metal_event_t ev, ggml_metal_cmd_buf_t cmd_buf); |
| 323 | void ggml_metal_event_encode_wait (ggml_metal_event_t ev, ggml_metal_cmd_buf_t cmd_buf); |
| 324 | |
| 325 | ggml_metal_device_t ggml_metal_device_init(int device, int n_devices); |
| 326 | void ggml_metal_device_free(ggml_metal_device_t dev); |
| 327 | |
| 328 | ggml_metal_device_t ggml_metal_device_get(int device, int n_devices); |
| 329 | |
| 330 | void * ggml_metal_device_get_obj (ggml_metal_device_t dev); // id<MTLDevice> |
| 331 | void * ggml_metal_device_get_queue(ggml_metal_device_t dev); // id<MTLCommandQueue> |
| 332 | |
| 333 | ggml_metal_library_t ggml_metal_device_get_library(ggml_metal_device_t dev); |
| 334 | |
| 335 | void ggml_metal_device_rsets_add(ggml_metal_device_t dev, ggml_metal_rset_t rset); |
| 336 | void ggml_metal_device_rsets_rm (ggml_metal_device_t dev, ggml_metal_rset_t rset); |
| 337 | |
| 338 | void ggml_metal_device_rsets_keep_alive(ggml_metal_device_t dev); |
| 339 | |
| 340 | ggml_metal_event_t ggml_metal_device_event_init(ggml_metal_device_t dev); |
| 341 | void ggml_metal_device_event_free(ggml_metal_device_t dev, ggml_metal_event_t ev); |
| 342 | void ggml_metal_device_event_synchronize(ggml_metal_device_t dev, ggml_metal_event_t ev); |
| 343 | |
| 344 | void ggml_metal_device_get_memory(ggml_metal_device_t dev, size_t * free, size_t * total); |
| 345 | bool ggml_metal_device_supports_op(ggml_metal_device_t dev, const struct ggml_tensor * op); |
| 346 | |
| 347 | const struct ggml_metal_device_props * ggml_metal_device_get_props(ggml_metal_device_t dev); |
| 348 | |
| 349 | struct ggml_metal_fusion_info; |
| 350 | |
| 351 | // the device-owned fusion debugging context (NULL unless fusion debugging is enabled) |
| 352 | struct ggml_metal_fusion_info * ggml_metal_device_get_fusion_info(ggml_metal_device_t dev); |
| 353 | |
| 354 | // |
| 355 | // device buffers |
| 356 | // |
| 357 | |
| 358 | typedef struct ggml_metal_buffer * ggml_metal_buffer_t; |
| 359 | |
| 360 | ggml_metal_buffer_t ggml_metal_buffer_init(ggml_metal_device_t dev, size_t size, bool shared); |
| 361 | ggml_metal_buffer_t ggml_metal_buffer_map (ggml_metal_device_t dev, void * ptr, size_t size, size_t max_tensor_size); |
| 362 | |
| 363 | void ggml_metal_buffer_free (ggml_metal_buffer_t buf); |
| 364 | void * ggml_metal_buffer_get_base (ggml_metal_buffer_t buf); |
| 365 | bool ggml_metal_buffer_is_shared(ggml_metal_buffer_t buf); |
| 366 | |
| 367 | void ggml_metal_buffer_memset_tensor(ggml_metal_buffer_t buf, struct ggml_tensor * tensor, uint8_t value, size_t offset, size_t size); |
| 368 | void ggml_metal_buffer_set_tensor (ggml_metal_buffer_t buf, struct ggml_tensor * tensor, const void * data, size_t offset, size_t size); |
| 369 | void ggml_metal_buffer_get_tensor (ggml_metal_buffer_t buf, const struct ggml_tensor * tensor, void * data, size_t offset, size_t size); |
| 370 | void ggml_metal_buffer_set_tensor_n (ggml_metal_buffer_t buf, struct ggml_tensor * const * tensors, const void * const * data, const size_t * offsets, const size_t * sizes, size_t n_tensors); |
| 371 | void ggml_metal_buffer_get_tensor_n (ggml_metal_buffer_t buf, const struct ggml_tensor * const * tensors, void * const * data, const size_t * offsets, const size_t * sizes, size_t n_tensors); |
| 372 | bool ggml_metal_buffer_cpy_tensor (ggml_metal_buffer_t buf, const struct ggml_tensor * src, struct ggml_tensor * dst); |
| 373 | bool ggml_metal_buffer_cpy_tensor_n (ggml_metal_buffer_t buf, const struct ggml_tensor * const * srcs, struct ggml_tensor * const * dsts, size_t n_tensors); |
| 374 | void ggml_metal_buffer_clear (ggml_metal_buffer_t buf, uint8_t value); |
| 375 | |
| 376 | // finds the Metal buffer that contains the tensor data on the GPU device |
| 377 | // the assumption is that there is 1-to-1 mapping between the host and device memory buffers, so we can find the |
| 378 | // Metal buffer based on the host memory pointer |
| 379 | // |
| 380 | struct ggml_metal_buffer_id ggml_metal_buffer_get_id(ggml_metal_buffer_t buf, const struct ggml_tensor * t); |
| 381 | |
| 382 | #ifdef __cplusplus |
| 383 | } |
| 384 | #endif |