Skip to content
SparseLinearAlgebraPublic

About

An open-source generalized sparse linear algebra library with vendor-agnostic GPUs accelerated computations

Topics

Resources

Code of conduct

Contributing

Stars

38 stars

Watchers

12 watching

Forks

Repository files navigation

Build Python Package Python Package (Test) Docs C/C++ Docs Python Clang Format License

spla is an open-source generalized sparse linear algebra framework for mathematical computations with GPUs acceleration. It provides linear algebra primitives, such as matrices, vectors and scalars, supports wide variety of operations. It gives an ability to customize underlying values types treatment and parametrise operations using built-in or custom user-defined functions.

Note: project under heavy development! Not ready for usage.

Installation

Install the release version of the package from PyPI repository for Windows, Linux and MacOS:

$ pip install pyspla

Install the latest test version of the package from Test PyPI repository for Windows, Linux and MacOS:

$ pip install -i https://test.pypi.org/simple/ pyspla

Delete package if no more required:

$ pip uninstall pyspla

Example of usage

This example demonstrates basic library primitives usage and shows how to implement simple breadth-first search algorithm using spla primitives in a few lines of code and run it on your GPU using OpenCL backend for acceleration.

from pyspla import *

def bfs(s: int, A: Matrix):
    v = Vector(A.n_rows, INT)  # to store depths

    front = Vector.from_lists([s], [1], A.n_rows, INT)  # front of new vertices to study
    front_size = 1  # current front size
    depth = Scalar(INT, 0)  # depth of search
    count = 0  # num of reached vertices

    while front_size > 0:  # while have something to study
        depth += 1
        count += front_size
        v.assign(front, depth, op_assign=INT.SECOND, op_select=INT.NQZERO)  # assign depths
        front = front.vxm(v, A, op_mult=INT.LAND, op_add=INT.LOR, op_select=INT.EQZERO)  # do traversal
        front_size = front.reduce(op_reduce=INT.PLUS).get()  # update front count to end algorithm

    return v, count, depth.get()

Create an adjacency matrix for a simple graph containing 4 vertices and 5 edges.

I = [0, 1, 2, 2, 3]
J = [1, 2, 0, 3, 2]
V = [1, 1, 1, 1, 1]
A = Matrix.from_lists(I, J, V, shape=(4, 4), dtype=INT)

Run bfs algorithm starting from 0-vertex with the graph adjacency matrix created earlier. None, that spla will automatically select GPU-based acceleration backed for computations.

v, c, d = bfs(0, A)

Performance

spla is benchmarked against Gunrock (CUDA) and LAGraph (SuiteSparse:GraphBLAST, used as the CPU baseline) on four algorithms — BFS, SSSP, PageRank and Triangle Counting — across 18 real-world sparse graphs on four hosts spanning x86-64 Intel, x86-64 AMD and RISC-V hardware: from discrete datacenter GPUs (NVIDIA Tesla V100, AMD Radeon RX 6750 XT) to integrated GPUs (AMD Radeon Vega 8, Intel Iris Xe, IMG PowerVR) and CPU-only execution via PoCL.

An interactive dashboard with the complete dataset is available at full benchmarking results.

The figures below share the same nine graphs — those with successful runs on every platform shown — ordered by size (number of non-zero entries).

Comparison on a Nvidia GPU

nvidia comparison
Description: Relative speedup of spla on the V100, spla on the CPU (via PoCL) and Gunrock on the V100, compared to LAGraph on the host CPU (dashed line, 1.0), per algorithm. Logarithmic scale.

Configuration: Ubuntu 26.04, AMD Ryzen 7 PRO 5755G 8-core CPU, 57 GB RAM, NVIDIA Tesla V100 dedicated GPU with 32 GB HBM2.

Scalability on Intel, AMD and Nvidia GPUs

gpu scalability
Description: spla throughput in edges/s per smallest shader unit (CUDA cores, AMD stream processors, Intel EU×8) on all five benchmarked GPUs, per algorithm. Logarithmic scale.

Configuration: NVIDIA Tesla V100 (5120 cores), AMD Radeon RX 6750 XT (2560 cores), AMD Radeon Vega 8 iGPU (512 cores), Intel Iris Xe iGPU (640 cores), IMG PowerVR BXE-2-32 iGPU (32 cores, RISC-V Spacemit X60).

Comparison running on integrated GPUs

igpu comparison
Description: Relative speedup of spla on three integrated GPUs compared to LAGraph on each iGPU's own host CPU (dashed line, 1.0), per algorithm. Logarithmic scale.

Configuration: AMD Ryzen 7 PRO 5755G + Radeon Vega 8 (Ubuntu 26.04), Intel Core i5-1340P + Iris Xe (Arch Linux), Spacemit X60 RISC-V + PowerVR BXE-2-32 (Bianbu 3.0.1).

Dataset

Name Vertices Edges Avg Deg Sd Deg Max Deg Link
1138_bus 1.1K 2.9K 2.6 1.8 17.0 link
bcsstk08 1.1K 11.9K 11.1 21.1 338.0 link
bcsstk33 8.7K 583.2K 66.7 16.1 140.0 link
coAuthorsCiteseer 227.3K 1.6M 7.2 10.6 1372.0 link
roadNet-CA 1.97M 5.5M 2.8 1.0 12.0 link
amazon-2008 735.3K 7.0M 9.6 7.6 1077.0 link
coPapersDBLP 540.5K 30.5M 56.4 66.2 3299.0 link
cit-Patents 3.77M 33.0M 8.8 10.5 793.0 link
soc-LiveJournal 4.85M 85.7M 17.7 52.0 20333.0 link

Building from sources

Prerequisites

  • Common:
    • Git (to get source code)
    • CMake (the latest version)
    • Ninja (as build files generator)
    • Python 3.7+
  • OpenCL runtime (for accelerated computation):
    • A GPU OpenCL driver (Intel, AMD or Nvidia), or
    • PoCL to run on a CPU (e.g. sudo apt install pocl-opencl-icd on Ubuntu).
    • The platform and device are selected with the SPLA_OPENCL_PLATFORM and SPLA_OPENCL_DEVICE environment variables (both default to 0); a GPU device is preferred when present, otherwise a CPU device is used.
  • Windows 10:
    • Microsoft Visual C++ Compiler (MSVC) with C++ 17 support
    • x64 Native Tools Command Prompt for VS
  • Ubuntu 20.04:
    • GNU C++ Compiler with C++ 17 support
  • MaсOS Catalina 10.15:
    • Clang Compiler with C++ 17 support

Get source code

The following code snippet downloads project source code repository, and enters project root folder. Must be executed from the folder where you want to locate project.

$ git clone https://github.com/SparseLinearAlgebra/spla.git
$ cd spla

Configure and run build

Attention! On Windows platform building commands must be executed in x64 Native Tools Command Prompt for VS.

The following code snippet runs build.py script, which allows configuring cmake and running of actual build with selected options. You can specify build directory, build type, number of system threads for build, enable or disable optionally building of tests and example applications. Must be executed from project root folder.

$ python ./build.py --build-dir=build --build-type=Release --nt=4 --tests=YES --examples=YES

On macOS, you can optionally specify target binaries architecture to build. Pass option --arch with x86_64 or arm64 respectively. By default, build falls back to CMAKE_SYSTEM_PROCESSOR specified architecture. See example bellow, replace <arch> with desired architecture for your build. Must be executed from project root folder.

$ python ./build.py --build-dir=build --build-type=Release --nt=4 --arch=<arch>

Run unit-tests

The following code snippet executed python script, which allows to run all native C++ library unit-tests, located in build directory, specified in --build-dir option. Must be executed from project root folder.

$ python ./run_tests.py --build-dir=build

Contributors

Citation

@online{spla,
  author = {Orachyov, Egor and Grigorev, Semyon},
  title = {spla: An open-source generalized sparse linear algebra framework for GPU computations},
  year = 2022,
  url = {https://github.com/SparseLinearAlgebra/spla},
  note = {Version 1.0.0}
}

Project structure

Entry Description
📁 .github CI/CD scripts and GitHub related files
📁 deps Third-party project dependencies, stored as submodules
📁 docs Documentations and digital stuff
📁 examples Example applications of library C/C++ usage
📁 include Library public C/C++ header files
📁 src Library private compiled source directory
📁 tests Library C/C++ unit-tests
📁 python Python package bindings for library API
📄 CMakeLists.txt CMake library configuration, add as sub directory to your project
📄 build.py Script to build library sources, tests and examples
📄 bump_version.py Script to increment or update version of package before release
📄 run_tests.py Script to run compiled library unit tests
📄 generate.py Script to re-generate .hpp bindings from .cl source files

License

This project licensed under MIT License. License text can be found in the license file.

About

An open-source generalized sparse linear algebra library with vendor-agnostic GPUs accelerated computations

Topics

Resources

Code of conduct

Contributing

Stars

38 stars

Watchers

12 watching

Forks

Used by

Contributors

Languages