diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2026-07-28 20:53:57 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2026-07-29 11:26:40 +0800 |
| commit | 522db0c5b1dc28b4f3255d959e6cb9135064962d (patch) | |
| tree | 99341558cf0f2a86b589bb61019df2f330a6ab3d | |
| parent | 8c419c6efe69adfc4424e598b4fa65bbb06c1b5a (diff) | |
| download | lex-522db0c5b1dc28b4f3255d959e6cb9135064962d.tar.gz | |
Compile with march=native and measure perf.
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | main.c | 29 |
2 files changed, 19 insertions, 19 deletions
@@ -1,7 +1,7 @@ CC = cc CXX = c++ -CFLAGS = -O2 -std=c11 -Wall -Wextra -CXXFLAGS = -O2 -Wall -Wextra +CFLAGS = -march=native -O2 -std=c11 -Wall -Wextra +CXXFLAGS = -march=native -O2 -O2 -Wall -Wextra INCLUDES = -Ideps/include LLAMA_TAG = b10107 @@ -56,11 +56,12 @@ deps/lib/libllama.a deps/lib/libggml.a deps/lib/libggml-cpu.a: cmake -S $(LLAMA_SRC_DIR) -B $(LLAMA_BUILD) \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=OFF \ - -DGGML_OPENMP=OFF \ # Disable OpenMP; use native OpenBSD pthreads - -DGGML_VULKAN=OFF \ # Disable Vulkan GPU backend for CPU-only build + -DGGML_OPENMP=OFF \ + -DGGML_VULKAN=OFF \ -DLLAMA_BUILD_APP=OFF \ -DLLAMA_BUILD_COMMON=OFF \ -DLLAMA_BUILD_TESTS=OFF \ + -DLLAMA_BUILD_UI=OFF \ -DLLAMA_BUILD_EXAMPLES=OFF \ -DLLAMA_BUILD_SERVER=OFF \ -DLLAMA_BUILD_TOOLS=OFF @@ -59,14 +59,14 @@ static void process_request(struct llama_model *model, const char *word) int prompt_len; int n_prompt_tokens, i; - struct llama_context_params cparams; - struct llama_context *ctx; llama_token *prompt_tokens; + llama_token new_token_id; + + struct llama_context *ctx; + struct llama_context_params cparams; struct llama_batch batch; - struct llama_sampler_chain_params sparams; struct llama_sampler *smpl; - - llama_token new_token_id; + struct llama_sampler_chain_params sparams; prompt = NULL; prompt_len = build_prompt(&prompt, word); @@ -77,8 +77,8 @@ static void process_request(struct llama_model *model, const char *word) } cparams = llama_context_default_params(); - cparams.n_ctx = 512; /* keep context small to keep RAM usage low */ - cparams.n_threads = 4; /* todo: tune */ + cparams.n_ctx = 512; /* context size -> RAM usage */ + cparams.n_threads = 4; ctx = llama_init_from_model(model, cparams); if (!ctx) { @@ -89,8 +89,8 @@ static void process_request(struct llama_model *model, const char *word) const struct llama_vocab *vocab = llama_model_get_vocab(model); - n_prompt_tokens = -llama_tokenize(vocab, prompt, prompt_len, NULL, - 0, true, true); + n_prompt_tokens = -llama_tokenize(vocab, + prompt, prompt_len, NULL, 0, true, true); if (n_prompt_tokens <= 0) { fprintf(stderr, "Error: tokenization sizing failed\n"); @@ -103,14 +103,14 @@ static void process_request(struct llama_model *model, const char *word) if (llama_tokenize(vocab, prompt, prompt_len, prompt_tokens, n_prompt_tokens, true, true) < 0) { - fprintf(stderr, "Error: Tokenization execution failed\n"); + fprintf(stderr, "Error: Tokenization failed\n"); free(prompt_tokens); llama_free(ctx); free(prompt); return; } - free(prompt); /* no longer required */ + free(prompt); /* prompt string no longer required */ batch = llama_batch_get_one(prompt_tokens, n_prompt_tokens); if (llama_decode(ctx, batch) != 0) { @@ -124,7 +124,6 @@ static void process_request(struct llama_model *model, const char *word) /* Generation loop */ sparams = llama_sampler_chain_default_params(); - smpl = llama_sampler_chain_init(sparams); llama_sampler_chain_add(smpl, llama_sampler_init_penalties( @@ -134,10 +133,8 @@ static void process_request(struct llama_model *model, const char *word) 0.0f /* presence_penalty */ )); - /* Add Top-P sampling (p = 0.9f, min_keep = 1) */ llama_sampler_chain_add(smpl, llama_sampler_init_top_p(0.9f, 1)); - - llama_sampler_chain_add(smpl, llama_sampler_init_temp(0.1f)); /* todo: tune */ + llama_sampler_chain_add(smpl, llama_sampler_init_temp(0.1f)); llama_sampler_chain_add(smpl, llama_sampler_init_dist(LLAMA_DEFAULT_SEED)); for (i = 0; i < MAX_TOKENS; i++) { @@ -162,6 +159,8 @@ static void process_request(struct llama_model *model, const char *word) printf("\n"); fflush(stdout); + llama_perf_context_print(ctx); + llama_sampler_free(smpl); llama_free(ctx); } |
