test : simplify

ggml-ci
This commit is contained in:
Georgi Gerganov 2024-01-17 18:15:15 +02:00
parent 58356e6bba
commit 06b4979149
No known key found for this signature in database
GPG key ID: 449E073F9DC10735

View file

@ -2,25 +2,10 @@
#include <cstdio>
#include <string>
#include <pthread.h>
#include <thread>
#include "llama.h"
static std::string g_fname;
static void * llamacpp_pthread(void * arg) {
(void)arg;
llama_backend_init(false);
auto * model = llama_load_model_from_file(g_fname.c_str(), llama_model_default_params());
auto * ctx = llama_new_context_with_model(model, llama_context_default_params());
llama_free(ctx);
llama_free_model(model);
llama_backend_free();
return NULL;
}
// This creates a new context inside a pthread and then tries to exit cleanly.
int main(int argc, char ** argv) {
if (argc < 2) {
@ -28,11 +13,16 @@ int main(int argc, char ** argv) {
return 0; // intentionally return success
}
g_fname = argv[1];
const std::string fname = argv[1];
pthread_t tid;
pthread_create(&tid, NULL, llamacpp_pthread, NULL);
pthread_join(tid, NULL);
std::thread([&fname]() {
llama_backend_init(false);
auto * model = llama_load_model_from_file(fname.c_str(), llama_model_default_params());
auto * ctx = llama_new_context_with_model(model, llama_context_default_params());
llama_free(ctx);
llama_free_model(model);
llama_backend_free();
}).join();
return 0;
}