Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
12 changes: 12 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Local experiments and unused vendor trees; excluded from //... discovery.
share/google_benchmark
share/benchmarks
third_party/cblas
third_party/csparse
third_party/hdf5
third_party/jburkardt
third_party/matmul
third_party/mesch12b
third_party/mm_offloading
third_party/spmatrix
third_party/spblas
3 changes: 0 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ build:openmp_only --define=MATRIX_BACKEND=openmp
# macOS defaults: OpenMP + Accelerate. MPS stays available as an optional
# runtime backend via sm_set_backend(SM_BACKEND_MPS).
build:macos --config=accelerate
build:macos --repo_env=SUITESPARSE_ROOT=/opt/homebrew/opt/suite-sparse

# Linux defaults: OpenMP + OpenBLAS.
build:linux --config=openblas
build:linux --repo_env=OPENBLAS_ROOT=/home/linuxbrew/.linuxbrew/opt/openblas
build:linux --repo_env=SUITESPARSE_ROOT=/home/linuxbrew/.linuxbrew/opt/suite-sparse

1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9.3.0
22 changes: 2 additions & 20 deletions .clangd
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
CompileFlags:
Add:
# matio Include paths
- "-Ithird_party/matio"
- "-Ibazel-out/darwin_arm64-fastbuild/bin/external/+http_archive+matio"
- "-Ibazel-out/darwin_arm64-fastbuild/bin/external/+http_archive+matio/src"
- "-Iexternal/+http_archive+matio"
- "-Iexternal/+http_archive+matio/src"
# matrix public headers
- "-Iapp/matrix/include"
# third-party benchmark dependencies used by share/google_benchmark
- "-Ithird_party/matmul/include"
- "-Ithird_party/mm_offloading"
# bazel external repo symlink for google benchmark headers
- "-Iexternal/google_benchmark+/include"

---
If:
PathMatch: ^share/google_benchmark/benchmarks/legacy/.*
Diagnostics:
Suppress:
- pp_file_not_found
- unused-includes
- "-Iapp/vector/include"
- "-Iapp/tensor/include"
1 change: 0 additions & 1 deletion .envrc

This file was deleted.

61 changes: 44 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,50 @@ name: BUILD

on:
push:
branches:
- master
branches: [master]
pull_request:
branches:
- master
branches: [master]
workflow_dispatch:

jobs:
test:
# virtual environments: https://github.com/actions/virtual-environments
runs-on: macos-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Test the code (unit tests)
run: bazel test //tests/...
permissions:
contents: read

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
jobs:
test:
name: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-24.04]
runs-on: ${{ matrix.os }}
timeout-minutes: 45
env:
OPENBLAS_NUM_THREADS: "1"
OMP_NUM_THREADS: "2"
steps:
- uses: actions/checkout@v7
- uses: bazel-contrib/setup-bazel@0.19.1
with:
bazelisk-cache: true
disk-cache: true
repository-cache: true
- name: Prepare system OpenBLAS and LAPACKE
if: runner.os == 'Linux'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y libopenblas-pthread-dev liblapacke-dev gfortran ruby
prefix="$RUNNER_TEMP/mmatrix-openblas"
multiarch="$(gcc -print-multiarch)"
mkdir -p "$prefix/include" "$prefix/lib"
for header in /usr/include/"$multiarch"/openblas-pthread/*.h /usr/include/lapack*.h; do
ln -s "$header" "$prefix/include/$(basename "$header")"
done
ln -s /usr/lib/"$multiarch"/openblas-pthread/libopenblas.a "$prefix/lib/libopenblas.a"
ln -s /usr/lib/"$multiarch"/liblapacke.a "$prefix/lib/liblapacke.a"
echo "OPENBLAS_ROOT=$prefix" >> "$GITHUB_ENV"
- name: Build and test all published targets
run: bazel test //... --test_output=errors --color=no --curses=no
- name: Verify installed libraries
shell: bash
run: bash tools/ci/test_install.sh
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ Temporary Items
/bazel-*
/bazel.iml
/output/
.bazelversion
.bazelignore
user.bazelrc
MODULE.bazel.lock

#-------------------------------------------------------------------------------
# Temporary files
Expand All @@ -108,6 +105,7 @@ MODULE.bazel.lock
/share/simple_benchmark/*
!/share/simple_benchmark/BUILD
!/share/simple_benchmark/bench_sm_mps.c
!/share/simple_benchmark/simple_bench.h
/lib/*
/_archive/*
/archive/*
Expand All @@ -129,19 +127,21 @@ MODULE.bazel.lock
/third_party/cblas

#-------------------------------------------------------------------------------
*.in
.clang-tidy
.clangd
.envrc
compile_commands.json
*.png
StyleGuide.md

MODULE.bazel.lock
profile.gz

/.venv-bench/
.github/skills/api-return-conventions/SKILL.md
TENSOR_ARCHITECTURE_ANALYSIS.md
TENSOR_PATTERNS_QUICK_REF.md
app/tensor/docs/mps-performance.md

# Generated benchmark and documentation output
*.profraw
*.profdata
/site/
25 changes: 12 additions & 13 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@ load("@mkdocs//:defs.bzl", "mkdocs_build", "mkdocs_config", "mkdocs_serve")
load("@rules_docs//docgen:defs.bzl", "docs")
load("//tools/install:def.bzl", "installer")

exports_files(["compile_commands.json"])

installer(
name = "matrix_installer",
data = [
"//:LICENSE.txt", # if available
"//app/matrix", # the target to be installed
"//app/matrix:matrix_header", # must be collected in a filegroup
"//:LICENSE.txt",
"//app/matrix",
"//app/matrix:matrix_header",
"//app/vector",
"//app/vector:vector_header",
"@log",
"@matio",
"@openblas//:install_files",
"@openmp//:libomp",
"@pcg",
"@suitesparse//:install_files",
"@zlib",
],
] + select({
"//app/matrix:macos": [
"//app/matrix:sm_mps",
"//app/tensor:st",
"//app/tensor:tensor_header",
],
"//conditions:default": [],
}),
system_integration = False, # set "True" symlink to /usr/local/lib and /usr/local/include
)

Expand All @@ -43,6 +41,7 @@ alias(
docs(
name = "docs_src",
srcs = glob(["doc/**/*.md"]) + [
"CHANGELOG.md",
"//doc/examples:tensor_basic.md",
],
readme_content = "MMatrix Dokumentation.",
Expand Down
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Changelog

## 0.4.0 (unreleased)

Changes since `v0.3.1`.

### Added

- Vector modules for float/double, strided views, sparse vectors, geometry, and vector/tensor bridges.
- Flat-buffer SGD, momentum, RMSProp, Adam, and gradient norm clipping kernels.
- Shared NN activation/backward kernels, fused GEMM + bias + activation, and row/loss kernels.
- Tensor storage abstraction, Metal buffer support, and f32/bf16 conversion utilities.
- Interpreter kernels: broadcast binary arithmetic, LayerNorm, ReduceMax, batched matmul, gather, and materializing permute.
- IEEE binary16 scalar/bulk conversion helpers.
- GPU-resident matrix GEMM streams/plans and reproducible benchmark sources.

### Changed / migration

- SuiteSparse is no longer a library or build dependency. Sparse matrices continue to use COO with a lazy CSR row cache.
- Removed `dms_to_cs`, `dms_from_cs`, and `cs_to_dms`, and the CSparse cache fields in `DoubleSparseMatrix`. Code accessing those APIs/fields must migrate; recompile consumers.
- Matrix/tensor conversions now live in `st_convert.h` and `//app/tensor:st`, rather than `m_convert.h`. `st_from_sm` creates a rank-2 `[rows, cols]` tensor; `sm_from_st` requires a rank-2 f32 tensor.
- Tensor implementation files are grouped into core, backend, runtime, and operation directories. Depend on public Bazel targets rather than source paths.
- Bazel version and module lockfile are included for reproducible dependency resolution. Linux OpenBLAS remains a system installation.

### Fixed during release preparation

- Produce ordinary Linux object archives rather than forcing LLVM LTO; check system-linker consumption and choose the platform archive bundler.
- Link separately packaged LAPACKE on Linux and preserve NN-kernel NaN/thread semantics under optimized builds.

- Exercise actual OpenMP branches in interpreter thread-comparison tests and remove an unmatched floating-point pragma.
- Reject size overflows before gather/permute byte copies; validate permutation indices before shape access; preserve arbitrary unaligned byte payloads.
- Remove stale SuiteSparse and local HDF5 wiring, obsolete vendor build wrappers, and benchmark targets whose sources were not published.
- Include the MPS benchmark helper header in the source release and exclude local experiments from Bazel discovery.
- Install transitive library archives and required external headers; include tensor artifacts on macOS; use portable macOS/Linux install flags.
- Add macOS/Ubuntu CI coverage with standard/bundle installation consumer checks.
- Repair CI test discovery and document the platform boundaries and new API entrypoints.
40 changes: 4 additions & 36 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For more details, please check https://github.com/bazelbuild/bazel/issues/18958

module(
name = "mmatrix",
version = "0.1.0",
version = "0.4.0",
)

######################################################################
Expand All @@ -22,10 +22,9 @@ module(

bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "zlib", version = "1.3.1.bcr.5")
bazel_dep(name = "apple_support", version = "1.24.2")
bazel_dep(name = "apple_support", version = "2.5.2")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "google_benchmark", version = "1.9.2")
bazel_dep(name = "rules_cc", version = "0.2.17")
bazel_dep(name = "rules_python", version = "1.7.0")
bazel_dep(name = "rules_docs", version = "0.3.0")
Expand All @@ -44,7 +43,7 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pypi",
python_version = "3.11",
requirements_lock = "//doc:requirements.txt",
requirements_lock = "//:doc/requirements.txt",
)
use_repo(pip, "pypi")

Expand Down Expand Up @@ -91,25 +90,7 @@ bazel_dep(name = "wolfd_bazel_compile_commands", version = "0.5.2", dev_dependen

host_local_library = use_repo_rule("//tools:host_local_library.bzl", "host_local_library")

#############################
# Hombrew Local Libraries (MacOS)
#############################

# define new_local_repository rule for local installed non-Bazel libraries:
new_local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "new_local_repository")

# due to license issues in private lib folder.
new_local_repository(
name = "hdf5",
path = "third_party/hdf5",
)

new_local_repository(
name = "log",
build_file = "@//:third_party/log.c/log.c.BUILD",
path = "third_party/log.c",
)

# System OpenBLAS (only fetched when the OpenBLAS backend is selected).
# openblas is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.
host_local_library(
name = "openblas",
Expand All @@ -122,16 +103,3 @@ host_local_library(
"lib",
],
)

# Optional Homebrew SuiteSparse wrapper for the GraphBLAS benchmark only.
host_local_library(
name = "suitesparse_graphblas_host",
build_file = "@//:third_party/suitesparse.BUILD",
env_var = "SUITESPARSE_ROOT",
linux_path = "/home/linuxbrew/.linuxbrew/opt/suite-sparse",
macos_path = "/opt/homebrew/opt/suite-sparse",
required_subdirs = [
"include",
"lib",
],
)
Loading
Loading