From: Georgi Gerganov Date: Mon, 29 May 2023 18:14:52 +0000 (+0300) Subject: mnist : remove redundant stuff + rename ctx0 X-Git-Tag: upstream/0.0.1642~1423 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=ebba902c1b4d8f0ce247797d65d87a40dadfe426;p=pkg%2Fggml%2Fsources%2Fggml mnist : remove redundant stuff + rename ctx0 --- diff --git a/examples/mnist/main-cpu.cpp b/examples/mnist/main-cpu.cpp index 42a29407..bcb402da 100644 --- a/examples/mnist/main-cpu.cpp +++ b/examples/mnist/main-cpu.cpp @@ -39,7 +39,7 @@ int mnist_eval( struct ggml_cgraph gfi = ggml_graph_import(fname_cgraph, &ctx_data, &ctx_eval); gfi.n_threads = n_threads; - // allocate eval context + // allocate work context // needed during ggml_graph_compute() to allocate a work tensor static size_t buf_size = gfi.work_size; // TODO static void * buf = malloc(buf_size); @@ -50,18 +50,18 @@ int mnist_eval( .no_alloc = false, }; - struct ggml_context * ctx0 = ggml_init(params); + struct ggml_context * ctx_work = ggml_init(params); struct ggml_tensor * input = ggml_graph_get_tensor(&gfi, "input"); memcpy(input->data, digit.data(), ggml_nbytes(input)); - ggml_graph_compute(ctx0, &gfi); + ggml_graph_compute(ctx_work, &gfi); const float * probs_data = ggml_get_data_f32(ggml_graph_get_tensor(&gfi, "probs")); const int prediction = std::max_element(probs_data, probs_data + 10) - probs_data; - ggml_free(ctx0); + ggml_free(ctx_work); ggml_free(ctx_data); ggml_free(ctx_eval); diff --git a/examples/mnist/main-mtl.cpp b/examples/mnist/main-mtl.cpp index fafe8e61..1f9475d8 100644 --- a/examples/mnist/main-mtl.cpp +++ b/examples/mnist/main-mtl.cpp @@ -24,13 +24,11 @@ // evaluate the MNIST compute graph // // - fname_cgraph: path to the compute graph -// - n_threads: number of threads to use // - digit: 784 pixel values // // returns 0 - 9 prediction int mnist_eval( const char * fname_cgraph, - const int n_threads, std::vector digit ) { // load the compute graph @@ -38,10 +36,9 @@ int mnist_eval( struct ggml_context * ctx_eval = NULL; struct ggml_cgraph gf = ggml_graph_import(fname_cgraph, &ctx_data, &ctx_eval); - gf.n_threads = n_threads; + gf.n_threads = 1; - // allocate eval context - // needed during ggml_graph_compute() to allocate a work tensor + // allocate work context static size_t buf_size = gf.work_size; // TODO static void * buf = malloc(buf_size); @@ -121,7 +118,7 @@ int main(int argc, char ** argv) { fprintf(stderr, "\n"); } - const int prediction = mnist_eval(argv[1], 1, digit); + const int prediction = mnist_eval(argv[1], digit); fprintf(stdout, "%s: predicted digit is %d\n", __func__, prediction);