# Contributing

Contributions are welcome through pull requests on
[GitHub](https://github.com/NextLinearAlgebra/NextLA.jl).

## Modules

| Module                  | Folder      | Depends on            | Loaded with                     |
|:------------------------|:------------|:----------------------|:--------------------------------|
| `NextLA`                | `src/dense` | nothing in the others | `using NextLA`                  |
| `NextLA.MixedPrecision` | `src/mxp`   | `NextLA`              | `using NextLA.MixedPrecision`   |

`MixedPrecision` is a submodule: it lives inside `NextLA`, can use anything from it through
`..NextLA`, and is not re-exported by it. The dependency runs one way only. Code in `src/dense`
never refers to the submodule, so `NextLA` builds and works with its `include` line removed.

## Repository layout

```
src/
├── NextLA.jl                module entry point, includes every feature
├── dense/                   dense matrices in one precision
│   ├── core/                NextLAMatrix.jl (wrapper type routing LinearAlgebra calls to NextLA)
│   ├── blas/
│   │   ├── gemm/            GEMM: extended, batched, grouped, recursive
│   │   ├── trsm/            TRSM/TRMM kernels, unified_rectrxm!, batched TRSM
│   │   ├── syrk/            SYRK: dispatch, batched, portable kernel, recursive
│   │   └── axpy.jl, gerc.jl (BLAS level 1 and 2)
│   └── lapack/
│       ├── cholesky/        potrf!, recursive, blocked and batched Cholesky
│       ├── lu/              pivoted LU (lu_pivot.jl), recursive and tiled unpivoted LU
│       ├── qr/              Householder reflectors, tile QR kernels and their PLASMA
│       │                    helpers parfb, pamm, pemv (one per file)
│       └── rotations/       Givens rotations
└── mxp/                     submodule NextLA.MixedPrecision
    ├── core/                mxp.jl (module definition), the mixed-precision containers,
    │                        adaptive precision selection and quantization
    ├── blas/                gemm/, trsm/, syrk/
    └── lapack/              cholesky/, lu/
ext/
├── NextLACUDAExt.jl     + ext/cuda/      cuBLAS / cuSOLVER methods
├── NextLAAMDGPUExt.jl   + ext/amdgpu/    rocBLAS / rocSOLVER methods
├── NextLAoneAPIExt.jl   + ext/oneapi/    oneMKL methods
└── NextLAMetalExt.jl    + ext/metal/     MPS methods
test/                    mirrors src/ (dense/, mxp/): the test for src/<path>.jl is
                         test/<path>.jl; shared helpers in test/setup/
docs/                    this documentation (Documenter.jl)
```

Each of `dense/` and `mxp/` has the same three folders: `core/` for the types, data
structures and module definition the rest builds on, `blas/` for BLAS-style routines and `lapack/`
for factorizations and LAPACK-style routines. In `dense/`, each routine-group folder has one entry
file named after the folder (`gemm/gemm.jl`, `trsm/trsm.jl`, `qr/qr.jl`, ...) that includes every
other file in it and nothing else. `src/NextLA.jl` includes those entry files and a few single files
(`dense/core/NextLAMatrix.jl`, `dense/blas/axpy.jl`, `dense/blas/gerc.jl`). The submodule is
included as a whole: `src/NextLA.jl` includes `mxp/core/mxp.jl`, which includes its own files from
`core/`, `blas/` and `lapack/`. Exports stay in the file that defines the symbol.

How to run all or some of the tests, on the CPU or a GPU: [`test/README.md`](test/README.md).

## Adding a routine to this repository structure

1. Put the code in the matching folder, for example `src/dense/blas/syrk/`, and include it from that
   folder's entry file (`syrk/syrk.jl`). In `mxp/`, include it from `mxp/core/mxp.jl`.
2. Export the new name in the file that defines it.
3. Add its test at the same path under `test/`, for example `test/dense/blas/syrk/<file>.jl`. The
   test runner finds it automatically.
4. Give it a docstring with a short `# Examples` block.
5. Add the file to the `Pages = [...]` list of its API page in `docs/src/api/`, for example
   `docs/src/api/dense/blas/syrk.md`. API pages show only the files they list, and the documentation
   build fails if an exported, documented name appears on no page.
6. For GPU support through a vendor library, add a method for that backend's array type
   (`CuArray`, `ROCArray`, `oneArray` or `MtlArray`) in `ext/<backend>/`, one file per routine group
   (`ext/cuda/syrk.jl`, `ext/cuda/potrf.jl`, ...), included from `ext/NextLA<Backend>Ext.jl`. Arrays
   without such a method use the portable KernelAbstractions code.

## Reporting a bug

Open an [issue](https://github.com/NextLinearAlgebra/NextLA.jl/issues) with a short example that
reproduces the problem and the output of `versioninfo()` and `Pkg.status()`. For a GPU problem, also
include the GPU package's version information, such as `CUDA.versioninfo()`.
