{"id":47942201,"url":"https://github.com/malk97sc/neural-networks","last_synced_at":"2026-04-07T11:00:42.557Z","repository":{"id":348994475,"uuid":"1197535234","full_name":"Malk97sc/Neural-Networks","owner":"Malk97sc","description":"A Neural Network implementation in C","archived":false,"fork":false,"pushed_at":"2026-04-05T23:20:12.000Z","size":154,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-06T10:10:47.048Z","etag":null,"topics":["deep-learning","deep-neural-networks","mlp-networks","posix","pthreads","slg"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Malk97sc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-31T16:56:19.000Z","updated_at":"2026-04-05T23:17:17.000Z","dependencies_parsed_at":"2026-04-06T10:00:26.641Z","dependency_job_id":null,"html_url":"https://github.com/Malk97sc/Neural-Networks","commit_stats":null,"previous_names":["malk97sc/neural-networks"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Malk97sc/Neural-Networks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FNeural-Networks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FNeural-Networks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FNeural-Networks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FNeural-Networks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Malk97sc","download_url":"https://codeload.github.com/Malk97sc/Neural-Networks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Malk97sc%2FNeural-Networks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31509941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","deep-neural-networks","mlp-networks","posix","pthreads","slg"],"created_at":"2026-04-04T08:11:49.075Z","updated_at":"2026-04-07T11:00:42.522Z","avatar_url":"https://github.com/Malk97sc.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Neural Networks in C\n\nLow-level neural network implementation in C and POSIX threads parallelism.\n\n## Overview\n\nThis project implements from scratch:\n\n- Single Layer Perceptron (SLP)\n- Multi-Layer Perceptron (MLP)\n- Explicit backpropagation\n- Custom BLAS-like linear algebra core\n- Parallelization using POSIX threads (pthreads)\n\nThe goal is not to build a framework, is to understand how neural networks operate at a low level:\nmemory layout, numerical computation, and parallel execution.\n\n## Roadmap\n\n### Phase 1: Numerical Foundations\n- [x] Matrix representation in row-major\n- [x] Manual memory control\n- [x] Vector operations\n- [x] Linear Algebra core\n- [x] Unit testing \u0026 Valgrind validation\n\n### Phase 2: Low-Level Parallelization\n- [x] Row partitioning strategy using pthreads\n- [x] Parallel matrix-vector multiplication \u0026 matrix-matrix multiplication\n- [x] Parallel batch operations\n- [x] Persistent Thread Pool (Minimalist BLAS-style)\n- [x] Speedup benchmarking (Sequential vs Parallel tool)\n\n### Phase 3: NN Infrastructure\n- [ ] Activation functions \u0026 Derivatives\n- [ ] Loss functions\n- [ ] Weight Initialization (Xavier/He)\n\n### Phase 4: SLP (Single Layer Perceptron)\n- [ ] 4.1 Forward: `y = activation(Wx + b)`\n- [ ] 4.2 Explicit Backward: `dW = dL/dy * x^T`, `db = dL/dy`\n- [ ] 4.3 Training Loop: Forward -\u003e Loss -\u003e Backward -\u003e Update\n- [ ] 4.4 Validation: Data linearly separable convergence\n\n### Phase 5: MLP (Multi Layer Perceptron)\n- [ ] 5.1 Structure: Multi-layer model representation\n- [ ] 5.2 Layer Caching: Storing Z and A states for backprop\n- [ ] 5.3 General Backpropagation: Iterative chain rule implementation\n- [ ] 5.4 Numerical Gradient Checking: Comparative validation\n\n### Phase 6: Batch Processing\n- [ ] 6.1 Vectorized input (Batch x Features)\n- [ ] 6.2 Batched Matmul optimization\n- [ ] 6.3 Aggregated gradient calculation\n\n### Phase 7: Parallel Batch Training\n- [ ] 7.1 Thread-level batch partitioning\n- [ ] 7.2 Gradient reduction buffers and synchronization\n\n### Phase 8 \u0026 9: Performance Engineering\n- [x] Persistent Thread Pool implementation (eliminates pthread overhead)\n- [x] Worker synchronization via Condition Variables\n- [ ] 9.1 Cache-aware optimization (Loop Tiling / Blocking)\n- [ ] 9.2 Memory alignment \u0026 Branch avoidance\n\n### Phase 10: Robustness \u0026 Tooling\n- [ ] 10.1 Data loader (CSV/Binary)\n- [ ] 10.2 Integration tests (MLP training)\n- [ ] 10.3 CLI for hyperparameter tuning\n- [ ] 10.4 Shape assertions \u0026 Debug mode\n\n### Phase 11: Extensions\n- [ ] Advanced Optimizers (Adam, Momentum)\n- [ ] Regularization (L2, Dropout)\n- [ ] Model serialization (Save/Load binaries)\n\n## Design Principles\n\n- **C**\n- **Row-major memory layout**\n- **Manual memory management**\n- **Explicit parallelism (pthreads)**\n- **No hidden abstractions**\n\nThis project prioritizes clarity of execution over abstraction.\n\n## Project Structure\n\n```bash\nNeural-Networks-in-C\n├── assets/\n├── include/\n│   ├── matrix.h\n│   ├── parallel.h\n│   ├── linalg.h\n│   ├── runtime.h\n│   └── thread_pool.h\n├── src/\n│   ├── parallel/\n│   │   ├── mat_add_rowwise_parallel.c\n│   │   ├── mat_apply_parallel.c\n│   │   ├── matmul_parallel.c\n│   │   └── matvec_parallel.c\n│   ├── matrix.c\n│   ├── linalg.c\n│   ├── runtime.c\n│   └── thread_pool.c\n├── tests/\n│   └── test_*.c\n├── build/ # compiled binaries\n├── main.c # soon\n├── run_valgrind.sh\n└── Makefile\n```\n\n## Performance Note: Thread Pool\n\nThe project uses a persistent Thread Pool (BLAS-style) to manage parallel tasks. Unlike a naive approach where threads are created and joined on every operation, this implementation spawns workers once at startup (`runtime_init`) and signals work using condition variables. This eliminates the significant overhead of `pthread_create`/`pthread_join` syscalls, making small-to-medium matrix operations much more efficient.\n\n## Build\n\n```bash\nmake\n```\nCompile all tests:\n\n```bash\nmake test\n```\n\nrun:\n\n```bash\n./build/test_matmul\n./build/test_matvec\n./build/test_performance\n```\n\n## Test Memory Leak\n\nTo use this feature, you need to install valgrind:\n\n```bash\nsudo apt-get install valgrind\n```\n\nYou need to give permission to run the script:\n\n```bash\nchmod +x run_valgrind.sh\n```\n\nThen run:\n\n```bash\n./run_valgrind.sh test_runtime\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalk97sc%2Fneural-networks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalk97sc%2Fneural-networks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalk97sc%2Fneural-networks/lists"}