tropical-gemm

Crates.iotropical-gemm
lib.rstropical-gemm
version0.1.0
created_at2026-01-13 13:23:34.01397+00
updated_at2026-01-13 13:23:34.01397+00
descriptionHigh-performance tropical matrix multiplication with SIMD and CUDA backends
homepage
repositoryhttps://github.com/TensorBFS/tropical-gemm
max_upload_size
id2040154
size311,998
Jinguo Liu (GiggleLiu)

documentation

README

tropical-gemm

CI Coverage Docs

High-performance tropical matrix multiplication in Rust with SIMD and CUDA backends.

Features

  • Multiple Semirings: MaxPlus, MinPlus, MaxMul
  • SIMD Acceleration: AVX-512, AVX2, SSE4.1, NEON auto-detection
  • CUDA Backend: GPU-accelerated kernels via NVRTC
  • Argmax Tracking: For backpropagation in tropical neural networks
  • Python Bindings: NumPy and PyTorch integration

Installation

[dependencies]
tropical-gemm = "0.1"
tropical-gemm-cuda = "0.1"  # Optional GPU support

Quick Start

use tropical_gemm::{Mat, MaxPlus};

let a = Mat::<MaxPlus<f32>>::from_row_major(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], 2, 3);
let b = Mat::<MaxPlus<f32>>::from_row_major(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0], 3, 2);

// C[i,j] = max_k(A[i,k] + B[k,j])
let c = a.matmul(&b);
assert_eq!(c.get_value(0, 0), 8.0); // max(1+1, 2+3, 3+5) = 8

Python

import numpy as np
import tropical_gemm

a = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)
b = np.array([[1.0, 2.0], [3.0, 4.0]], dtype=np.float32)

c = tropical_gemm.maxplus_matmul(a, b)

Documentation

📖 User Guide - Installation, tutorials, examples

📚 API Reference - Rust API documentation

Semirings

Type ⊕ ⊗ Use Case
MaxPlus<T> max + Longest path, Viterbi
MinPlus<T> min + Shortest path
MaxMul<T> max × Max probability

Performance

Size CPU (ms) GPU (ms) Speedup
256 4.1 0.03 128x
1024 262 0.36 728x
2048 2092 2.5 837x

License

MIT

Commit count: 34

cargo fmt