Skip to main content

A library for efficient matrix and kronecker product matrix multiplication on parallel hardware

Project description

FastKron

FastKron is a fast library for computing Generalized Matrix Kronecker-Matrix Multiplication (GeMKM) and Generalized Kronecker-Matrix Matrix Multiplication (GeKMM) on NVIDIA GPUs and X86 CPUs. FastKron contains specialized algorithms and implementations of GeMKM and GeKMM rather than using existing linear algebra operations. FastKron avoids extra transposes and adds more optimizations including fusion of multiple kernels. Therefore, FastKron performs orders of magnitude better than baseline GPyTorch, NVIDIA cuTensor, and HPTT. Fastkron provides a C++ library and a Python library for Numpy and PyTorch autograd functions. FastKron provides fast implementations for float and double data type, while Numpy/PyTorch functions uses Shuffle algorithm for other types.

For more details look Fast Kronecker Matrix-Matrix Multiplication on GPUs.

Performance

We compare FastKron's GeMKM and GeKMM with the existing shuffle algorithm in GPyTorch based on PyTorch 2.5.1. Below table shows the range of speedup on different hardware and data types.

GeMKM

Hardware Float Double
AMD 64-Core CPU with AVX 9.3-45x 5.8-21x
AMD 64-Core CPU with AVX512 9.7-38x 6.3-21x
NVIDIA A100 80 GB 1.5-9.5x 1.1-9.5x
NVIDIA V100 16 GB 2.5-10x 1.9-11x

GeKMM

Hardware Float Double
AMD 64-Core CPU with AVX 2.7-13.7x 1.5-7x
AMD 64-Core CPU with AVX512 2.2-14x 2-7x
NVIDIA A100 80 GB 1.3-4.6x 0.9-4.5x
NVIDIA V100 16 GB 1.4-6.4x 2-7.8x

For more information see documents/performance.md

Hardware and OS Support

Linux WSL2 Windows Mac
x86 โœ… โœ… ๐Ÿ ๐Ÿ
ARM ๐Ÿ ๐Ÿ ๐Ÿ ๐Ÿ
AVX256 โœ… โœ… ๐Ÿ ๐Ÿ
AVX512 โœ… โœ… ๐Ÿ ๐Ÿ
SM50+ CUDA cores โœ… โœ… ๐Ÿ ๐Ÿ
SM80+ Tensor cores โŒ โŒ ๐Ÿ ๐Ÿ
AMD RoCM ๐Ÿ ๐Ÿ ๐Ÿ ๐Ÿ

โœ… FastKron supports optimized implementations for AVX256 and AVX512 CPUs and NVIDIA GPUs.
โŒ Tensor cores for double are not supported.
๐Ÿ Supported in Python module. x86 CPUs older than GLIBC x86-64-v2, ARM CPUs, AMD GPUs, Windows, and Mac OS are not supported in C++ API but PyFastKron fallbacks to the shuffle algorithm in Numpy or PyTorch.

The future roadmap is as follows in terms of priority: Windows, SM80+ Double Tensor cores, AMD GPUs, ARM CPUs.

Example

The directory example/ pinclude examples of using FastKron's CUDA and x86 backend using both C++ and Python. Before using an example, follow below instructions to build FastKron.

Installation

PyFastKron can be installed using pip.

pip install pyfastkron

PyFastKron's CUDA backend is built with CUDA 12.3 but is compatible with CUDA 11.8 and above.

Build

Build the C++ library, libFastKron.so, to use with C++ programs or the Python library, PyFastKron, to use with PyTorch or Numpy programs.

Required Pre-requisites

On Ubuntu :

sudo apt update && sudo apt install gcc linux-headers-$(uname -r) make g++ git python3-dev wget unzip python3-pip build-essential devscripts debhelper fakeroot intel-mkl cmake

CUDA Pre-requisite

Install CUDA 11+ from https://developer.nvidia.com/cuda/ .

Clone repository

Clone repository with submodules using

git clone --recurse-submodules https://github.com/abhijangda/fastkron.git

If already cloned and want to only clone submodules, use

git submodule update --init --recursive

libFastKron

Build FastKron as C++ library using below commands:

cd build/
cmake ..
make -j

To install run make install

By default both x86 and CUDA backends are built. use CMAKE option -DENABLE_CUDA=OFF to disable CUDA backend or -DENABLE_X86=OFF to disable x86 backend.

Run X86 CPU tests using

make run-x86-tests

Run CUDA tests using

make run-cuda-tests

PyFastKron

Install PyFastKron using pip

pip install .

Run tests using

pytest

Documentation

C++ API: documents/cpp-api.md
Python API: documents/python-api.md
Kernel Tuning: documents/autotuning.md
Performance: documents/performance.md
Multi-GPU: documents/multigpu.md
Contributing: documents/contributing.md

Citation

@inproceedings{10.1145/3627535.3638489,
author = {Jangda, Abhinav and Yadav, Mohit},
title = {Fast Kronecker Matrix-Matrix Multiplication on GPUs},
year = {2024},
isbn = {9798400704352},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3627535.3638489},
doi = {10.1145/3627535.3638489},
booktitle = {Proceedings of the 29th ACM SIGPLAN Annual Symposium on Principles and Practice of Parallel Programming},
pages = {390โ€“403},
numpages = {14},
keywords = {graphics processing units, CUDA, kronecker product, linear algebra},
location = {Edinburgh, United Kingdom},
series = {PPoPP '24}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyfastkron-1.1.0-py3-none-any.whl (17.8 kB view details)

Uploaded Python 3

pyfastkron-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (71.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyfastkron-1.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (71.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pyfastkron-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (71.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyfastkron-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (71.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

File details

Details for the file pyfastkron-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyfastkron-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.10

File hashes

Hashes for pyfastkron-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3fbb8e2a2e51d5926f4dd54e409ef76bb5c81ab9dca0c362eab6a38b30e057f3
MD5 13d5a7b9bb15d1f55e98380c5580589c
BLAKE2b-256 b3f738294d3564b9a22eadeec985cf0ee030ce34a6223523657f6d2c5c62f648

See more details on using hashes here.

File details

Details for the file pyfastkron-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyfastkron-1.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d9b6d21d0932a474641e40853d427f87af812510d47e96db8086aa4cc617e7d1
MD5 f793e117b887e0e001bb6ec7cfd09fc2
BLAKE2b-256 d65f93a3ed831ae541945f899a97eefc612cb9a2d71f025b051791e6fef4998f

See more details on using hashes here.

File details

Details for the file pyfastkron-1.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyfastkron-1.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 26716939e925a1a71cf0f7f96ef7db5436b0660b83bcc05180b34875ad5a959e
MD5 3e5307eaf5cd33f7556d8af27241104b
BLAKE2b-256 9893ab764e2a99f1ebef9590923a00c4f236ce001cb24ca3f87be0cf80239ea2

See more details on using hashes here.

File details

Details for the file pyfastkron-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyfastkron-1.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 99f425847f8f313c8d7ffe87c81fdb9c1fc4aad298337eab58785c4d22f852e3
MD5 7789832f2cb772d1dc4d605f0b3b8870
BLAKE2b-256 441fc1751e193a844fc8c27fad0fa89e91897adfb16a8026afaf9138d126134f

See more details on using hashes here.

File details

Details for the file pyfastkron-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyfastkron-1.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 56318b123b0e3125f4360fc778cd816898a4c7fe7fafd1939e78c2230060f2e9
MD5 8454a06d84c75540f571765b8b98469c
BLAKE2b-256 0870121c5f130ad10ba82e91db3d2adce72c71e48d23f47fc2b8fcbcbad61414

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page