Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d548db6
tokenizer: Optimize DataLoader with OpenMP parallelization and merges
Eamon2009 Jul 22, 2026
4441c9f
Update README.md
Eamon2009 Jul 22, 2026
51fcee6
Enhance project structure documentation in README
Eamon2009 Jul 22, 2026
f6c6f74
tensor: Add OpenMP multi-threading to AVX/SSE vector operations
Eamon2009 Jul 22, 2026
7bef070
tensor: Add OpenMP multi-threading to AVX/SSE (#LMGNU 59)
Eamon2009 Jul 23, 2026
20ad05e
added python-version that we use
Eamon2009 Jul 24, 2026
08aaf1e
matmul: Add unrolled CPU forward pass kernel and benchmarking harness
Eamon2009 Jul 24, 2026
84521b9
Modify image height for better alignment in README
Eamon2009 Jul 24, 2026
2fdcd48
Update README with training output and instructions
Eamon2009 Jul 24, 2026
740eb56
main: Add CLI entry point supporting training, inference, and interac…
Eamon2009 Jul 24, 2026
91912ef
submodule: removed PyTorch submodule to .gitmodules
Eamon2009 Jul 24, 2026
40bd761
Add additional image to README
Eamon2009 Jul 25, 2026
31042cd
Clean up README by removing HTML elements
Eamon2009 Jul 25, 2026
7bd10d5
Add hardware support information to README
Eamon2009 Jul 25, 2026
996c8e0
Delete run_20260530_165216 (1).png
Eamon2009 Jul 25, 2026
e9dd3fa
Merge branch 'master' of https://github.com/LMGNU/llm.cpp
Eamon2009 Jul 25, 2026
9d9faf6
Delete benchmark_training.py
Eamon2009 Jul 25, 2026
697e9d6
Delete run_20260430_192930.png
Eamon2009 Jul 25, 2026
aa42608
Delete run_2026-07-16 165731.png
Eamon2009 Jul 25, 2026
947af95
Create a100.png
Eamon2009 Jul 25, 2026
84f90a7
Create apple_silicon.jpg
Eamon2009 Jul 25, 2026
b1fe6b2
Create b200.jpg
Eamon2009 Jul 25, 2026
6cd92a0
Create cpu.jpg
Eamon2009 Jul 25, 2026
e27713f
Create dgx_spark.jpg
Eamon2009 Jul 25, 2026
39cc731
Create jetson.jpg
Eamon2009 Jul 25, 2026
acd4549
Create m_max.png
Eamon2009 Jul 25, 2026
8353718
Create m_pro.png
Eamon2009 Jul 25, 2026
8511b7f
Create m_ultra.jpg
Eamon2009 Jul 25, 2026
634c32c
Create t4.png
Eamon2009 Jul 25, 2026
08a45e6
Create rtx5090.jpg
Eamon2009 Jul 25, 2026
a9a34ea
Create rtx4090.jpg
Eamon2009 Jul 25, 2026
a876704
Create radeon.jpg
Eamon2009 Jul 25, 2026
abc3c62
Create mi300.jpg
Eamon2009 Jul 25, 2026
0e2837a
docs: Add GPU package render to README assets for h100 gpu
Eamon2009 Jul 25, 2026
b8cbbfb
Revise hardware support details in README
Eamon2009 Jul 25, 2026
9947e8b
Update README.md by modifying images and GPU instructions
Eamon2009 Jul 25, 2026
969ec90
Delete data/input.txt missed by .gitignore
Eamon2009 Jul 26, 2026
f69fe87
docs : Revise GPU section and enhance clarity
Eamon2009 Jul 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
frontend/** linguist-vendored
frontend/** linguist-vendored
[submodule "pytorch"]
path = pytorch
url = https://github.com/pytorch/pytorch


2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
type=raw,value=latest,enable=${{ inputs.push_image == 'true' }}

- name: Build and push
uses: docker/build-push-action@v6
uses: docker/build-push-action@v7
with:
context: .
file: .devops/Dockerfile.backend
Expand Down
File renamed without changes.
302 changes: 180 additions & 122 deletions README.md

Large diffs are not rendered by default.

Binary file added assets/hardware/a100.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/apple_silicon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/b200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/cpu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/dgx_spark.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/h100.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/jetson.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/m_max.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/m_pro.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/m_ultra.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/mi300.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/radeon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/rtx4090.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/rtx5090.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/hardware/t4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/run_2026-07-16 165731.png
Binary file not shown.
Binary file removed assets/run_20260430_192930.png
Binary file not shown.
Binary file removed assets/run_20260508_110726.png
Binary file not shown.
Binary file removed assets/run_20260530_165216 (1).png
Binary file not shown.
366,605 changes: 0 additions & 366,605 deletions data/input.txt

This file was deleted.

246 changes: 246 additions & 0 deletions engine/llm.cpp/include/matmul.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

void matmul_forward_cpu(float *out,
const float *inp,
const float *weight,
const float *bias,
int B,
int T,
int C,
int OC)
{
for (int b = 0; b < B; b++)
{
for (int t = 0; t < T; t++)
{
float *out_bt = out + b * T * OC + t * OC;
const float *inp_bt = inp + b * T * C + t * C;
for (int o = 0; o < OC; o++)
{
float val = (bias != NULL) ? bias[o] : 0.0f;
const float *wrow = weight + o * C;
for (int i = 0; i < C; i++)
{
val += inp_bt[i] * wrow[i];
}
out_bt[o] = val;
}
}
}
}

void matmul_forward_ngc92(float *out,
const float *inp,
const float *weight,
const float *bias,
int B,
int T,
int C,
int OC)
{
#define LOOP_UNROLL 8

if (B * T % LOOP_UNROLL != 0)
{
printf("should be a MULTIPLE of 8");
return;
}

for (int obt = 0; obt < B * T; obt += LOOP_UNROLL)
{
for (int o = 0; o < OC; o++)
{
float result[LOOP_UNROLL];
for (int ibt = 0; ibt < LOOP_UNROLL; ++ibt)
{
result[ibt] = (bias != NULL) ? bias[o] : 0.0f;
}

for (int i = 0; i < C; i++)
{
float w = weight[i + o * C];
for (int ibt = 0; ibt < LOOP_UNROLL; ++ibt)
{
int bt = obt + ibt;
result[ibt] += inp[bt * C + i] * w;
}
}

// write back results to main memory
for (int ibt = 0; ibt < LOOP_UNROLL; ++ibt)
{
int bt = obt + ibt;
out[bt * OC + o] = result[ibt];
}
}
}
}

#define NUM_KERNELS 2

void matmul_forward(int kernel_num,
float *out,
const float *inp,
const float *weight,
const float *bias,
int B,
int T,
int C,
int OC)
{

switch (kernel_num)
{
case 0:
matmul_forward_cpu(out, inp, weight, bias, B, T, C, OC);
break;
case 1:
matmul_forward_ngc92(out, inp, weight, bias, B, T, C, OC);
break;
default:
printf("Invalid kernel number\n");
exit(1);
}
}

void validate_results_cpu(const float *device_result,
const float *cpu_reference,
const char *name,
int num_elements,
float tolerance);
float *make_random_float(size_t N);

int main(int argc, char **argv)
{
srand(0);

int B = 8;
int T = 1024;
int C = 768;
int OC = 768 * 4;
int RUNS = 4;
srand(137);

float *out = make_random_float(B * T * OC);
float *inp = make_random_float(B * T * C);
float *weight = make_random_float(OC * C);
float *bias = make_random_float(OC);

float *grad_out = make_random_float(B * T * OC);
float *grad_inp = make_random_float(B * T * C);
float *grad_weight = make_random_float(OC * C);
float *grad_bias = make_random_float(OC);

printf("> Calculating reference\n");
matmul_forward_cpu(out, inp, weight, bias, B, T, C, OC);

for (int kernel_num = 0; kernel_num < NUM_KERNELS; kernel_num++)
{
printf("> Verifying kernel #%d\n", kernel_num);

srand(137);

float *kernel_out = make_random_float(B * T * OC);
float *kernel_inp = make_random_float(B * T * C);
float *kernel_weight = make_random_float(OC * C);
float *kernel_bias = make_random_float(OC);

matmul_forward(kernel_num,
kernel_out,
kernel_inp,
kernel_weight,
kernel_bias,
B,
T,
C,
OC);

validate_results_cpu(kernel_out, out, "out", B * T * OC, 1e-5);

free(kernel_out);
free(kernel_inp);
free(kernel_weight);
free(kernel_bias);
}

printf("All kernels passed! Starting benchmarks.\n\n");

for (int kernel_num = 0; kernel_num < NUM_KERNELS; kernel_num++)
{
printf("> Running kernel #%d\n", kernel_num);
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);

for (int i = 0; i < RUNS; i++)
{
matmul_forward(kernel_num, out, inp, weight, bias, B, T, C, OC);
}

clock_gettime(CLOCK_MONOTONIC, &end);
double time_elapsed_s =
(end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1e9;
printf("> Kernel #%d, (took %f ms)\n", kernel_num, time_elapsed_s * 1000);
}
free(out);
free(inp);
free(weight);
free(bias);

free(grad_out);
free(grad_inp);
free(grad_weight);
free(grad_bias);

return 0;
}

float *make_random_float(size_t N)
{
float *arr = (float *)malloc(N * sizeof(float));
for (size_t i = 0; i < N; i++)
{
arr[i] = ((float)rand() / RAND_MAX) * 2.0 - 1.0;
}
return arr;
}

void validate_results_cpu(const float *kernel_result,
const float *cpu_reference,
const char *name,
int num_elements,
float tolerance)
{
int nfaults = 0;
for (int i = 0; i < num_elements; i++)
{
// print the first few comparisons
if (i < 5)
{
printf("%f %f\n", cpu_reference[i], kernel_result[i]);
}
float t_eff = tolerance + fabs(cpu_reference[i]);
// ensure correctness for all elements.
if (fabs(cpu_reference[i] - kernel_result[i]) > t_eff)
{
printf("Mismatch of %s at %d: CPU_ref: %f vs CPU_new: %f\n",
name,
i,
cpu_reference[i],
kernel_result[i]);
nfaults++;
if (nfaults >= 10)
{
exit(EXIT_FAILURE);
}
}
}
if (nfaults > 0)
{
exit(EXIT_FAILURE);
}
printf("OK\n");
}
Loading
Loading