Skip to main content

No project description provided

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 with state-of-the-art baselines of existing algorithms. GPyTorch implements the traditional shuffle algorithm that uses matrix multiplication and transpose. GPyTorch runs on NVIDIA GPUs and x86 CPUs. NVIDIA cuTensor and TCCG (https://github.com/HPAC/tccg) are tensor contraction engines for NVIDIA GPUs and x86 CPUs respectively. Graphs below shows the performance of FastKron against these baselines. FastKron obtains upto 90% of the maximum FLOPs of a NVIDIA Tesla A100 and same FLOPs as Intel MKL of an AMD EPYC 7742 64-Core with AVX256.

[[TODO: Update]]

NVIDIA A100 SXM 80GB AMD 7742 64-Core with AVX2

The graphs above multiplies a matrix of shape [M, PN] with a Kronecker Product of N matrices of size [P, Q]. FastKron performs significantly better than existing baselines. For more information see documents/performance.md

Hardware and OS Support

Linux WSL2 Windows Mac
x86 :white_check_mark: :white_check_mark: :snake: :snake:
ARM :snake: :snake: :snake: :snake:
AVX256 :white_check_mark: :white_check_mark: :snake: :snake:
AVX512 :white_check_mark: :white_check_mark: :snake: :snake:
SM50+ CUDA cores :white_check_mark: :white_check_mark: :snake: :snake:
SM80+ Tensor cores :x: :x: :snake: :snake:
AMD RoCM :snake: :snake: :snake: :snake:

FastKron supports optimized implementations for AVX256 and AVX512 CPUs and NVIDIA GPUs. 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 .

To disable a backend add --config-settings=cmake.define.ENABLE_<backend>=OFF as argument to above command.

Run tests using

pytest

Documentation

FastKron C++ API: documents/api.md

FastKron Python API: documents/api.md

Kernel Tuning: documents/autotuning.md

Performance: documents/performance.md

Multi-GPU: documents/multigpu.md

Contributing:

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.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

pyfastkron-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl (68.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyfastkron-1.0.0-cp311-cp311-manylinux_2_28_x86_64.whl (68.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pyfastkron-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl (68.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyfastkron-1.0.0-cp39-cp39-manylinux_2_28_x86_64.whl (68.6 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

File details

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

File metadata

  • Download URL: pyfastkron-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84b3c34180644ebf5d23f4bdb759802a2412730c747742045273e8efcb7fdd82
MD5 0ac814188dffe0291e8bc487db13eb43
BLAKE2b-256 9e81db760b07ee77df38d7e52f8ecd86f514ba1bad6a543c97d67a78e9f369a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfastkron-1.0.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 38e97f031b319a60622d3c7ae849f540d87e229706d8fb75ef7617b810b4f09d
MD5 accd015d14756f9030068bea3cb35215
BLAKE2b-256 c1cf37c413d5f7391990c5a8d878c4aaf6759b91de95ca174ef2413fb48879fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfastkron-1.0.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 95c4b3b438c029e9fefd39cd22628160cf50e5b8c05c5c6612e463ad83c77302
MD5 ee51143f7bb424f120f5c9ce2add5504
BLAKE2b-256 bd8a4198e72dacc6ba028f654dcb7f6337e46aacbd98d288e9597950d5e4d4f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfastkron-1.0.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 699a66fc2f4ad00ac7be0368e335bd8012fb803d8a2ca41e84696ccc01c9eeb3
MD5 b9b6e1ae0f3d9ce9e56d0ac9e6a3e5c8
BLAKE2b-256 1903195b00dbae2fc797520fa4fe0e5d139622c82158ff662bdcea41987c18e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyfastkron-1.0.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 03f9a0f3ca5bb0899e38294ac61d6974ee5dfa0108f6acdb50bc45b153501b2b
MD5 5f9e66ceccc4d405bc005aa8b3a72e9c
BLAKE2b-256 7cf6775d57eef63aab1f0ddbd8ecf448bad4532237e0f989a2b05ab8afcc37d9

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