skillfed

slangtorch

A package for calling Slang modules from Python and PyTorch.

slangtorch v1.3.22 92.2K downloads/30d#13,466 on PyPI
Permissive license Active released

What it is and what it does

slangtorch bridges the Slang shading language and PyTorch, allowing you to write GPU kernels in Slang and call them from Python. Slang is a language designed for graphics and compute shaders; slangtorch compiles Slang code to CUDA and integrates it with PyTorch's tensor operations. This is useful when you need fine-grained control over GPU computation or want to leverage existing Slang code within a PyTorch workflow.

The package requires external setup: CUDA Toolkit v12.0 or later and PyTorch v2.x built with CUDA support must be installed before slangtorch. It depends on torch, ninja (for build acceleration), filelock, and hatchling. The package is actively maintained and supports Python 3.10 and later on Linux and Windows.

Use it for:

  • Write custom PyTorch operations in Slang for performance-critical GPU compute tasks.
  • Integrate existing Slang shaders or compute kernels into a PyTorch training or inference pipeline.
  • Prototype GPU algorithms using Slang's language features before optimizing further.
  • Combine graphics and compute workloads by reusing Slang code across PyTorch and graphics applications.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

slangtorch lets you write PyTorch kernels in the Slang shading language, compiling them to run on CUDA-capable GPUs.

Yes, if you need to write or integrate Slang-based GPU kernels with PyTorch and have the required CUDA and PyTorch setup. The package is actively maintained, permissively licensed, and has no known vulnerabilities. The main barrier is the external dependency on CUDA Toolkit v12.0+ and PyTorch v2.x with CUDA support; if those are already in your environment, installation is straightforward.

Install

slangtorch on PyPI

pip

pip install slangtorch

uv

uv add slangtorch

poetry

poetry add slangtorch

Installing slangtorch

Before you install

Medium install friction due to runtime dependencies on torch, ninja, and hatchling; requires CUDA Toolkit v12.0 or later and PyTorch v2.x with CUDA support as external prerequisites. Package itself is actively maintained with a release 14 days old.

License in practice

Licensed under MIT (permissive), so you can use, modify, and distribute slangtorch and code built with it freely, including in commercial projects, provided you retain the license notice.

Quickstart

pip install slangtorch
import slangtorch
# Requires CUDA Toolkit v12.0+ and PyTorch v2.x with CUDA support installed first

CUDA Toolkit v12.0 or later and PyTorch v2.x with CUDA support must be installed before slangtorch; a CUDA-capable GPU is required to run kernels.

Verify before relying

  • Whether Slang kernel compilation is transparent to the user or requires explicit build steps beyond import.
  • What performance characteristics or overhead slangtorch adds compared to native PyTorch CUDA kernels.
  • Whether the package supports AMD GPUs or only NVIDIA CUDA devices.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.10)
Install friction medium — platform-specific wheel
Runtime dependencies 4 — filelock, hatchling, ninja, torch
Maintenance actively maintained — 14 days since the last release
First released
Downloads 92,224/month — #13,466 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: slangtorch-1.3.22-py3-none-manylinux_2_27_x86_64.whl; slangtorch-1.3.22-py3-none-manylinux_2_28_aarch64.whl; slangtorch-1.3.22-py3-none-win_amd64.whl

License :: OSI Approved :: MIT LicenseOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: Python :: 3

Tags

pytorch custom kernelsslang gpu computecuda kernel writingpytorch shader languagegpu kernel compilationslang pytorch integrationcustom cuda kernels
gpu-computeshader-languagepytorch-extension

More Artificial Intelligence packages