| 19016 | } |
| 19017 | |
| 19018 | enum ggml_opt_result ggml_opt( |
| 19019 | struct ggml_context * ctx, |
| 19020 | struct ggml_opt_params params, |
| 19021 | struct ggml_tensor * f) { |
| 19022 | bool free_ctx = false; |
| 19023 | if (ctx == NULL) { |
| 19024 | struct ggml_init_params params_ctx = { |
| 19025 | .mem_size = 16*1024*1024, |
| 19026 | .mem_buffer = NULL, |
| 19027 | .no_alloc = false, |
| 19028 | }; |
| 19029 | |
| 19030 | ctx = ggml_init(params_ctx); |
| 19031 | if (ctx == NULL) { |
| 19032 | return GGML_OPT_NO_CONTEXT; |
| 19033 | } |
| 19034 | |
| 19035 | free_ctx = true; |
| 19036 | } |
| 19037 | |
| 19038 | enum ggml_opt_result result = GGML_OPT_OK; |
| 19039 | |
| 19040 | struct ggml_opt_context * opt = (struct ggml_opt_context *) alloca(sizeof(struct ggml_opt_context)); |
| 19041 | |
| 19042 | ggml_opt_init(ctx, opt, params, 0); |
| 19043 | result = ggml_opt_resume(ctx, opt, f); |
| 19044 | |
| 19045 | if (free_ctx) { |
| 19046 | ggml_free(ctx); |
| 19047 | } |
| 19048 | |
| 19049 | return result; |
| 19050 | } |
| 19051 | |
| 19052 | enum ggml_opt_result ggml_opt_resume( |
| 19053 | struct ggml_context * ctx, |