Skip to main content

A domain-specific language based on Triton but providing higher-level abstraction.

Project description

NineToothed

NineToothed Logo

Document PyPI Version License star

NineToothed is a Triton-based domain-specific language (DSL). By introducing tensor-oriented meta-programming (TOM), it makes writing high-performance GPU kernels easier.

Installation

We can use pip to install ninetoothed.

pip install ninetoothed

After successfully running the above command, ninetoothed will be installed. However, to fully utilize its capabilities, you also need to install a deep learning framework supported by ninetoothed. For trial purposes, we recommend installing torch.

Usage

Thanks to tensor-oriented meta-programming, NineToothed can be written using the arrange-and-apply paradigm, which involves separately defining arrangement, application, and tensors, and then integrating them using ninetoothed.make to generate the kernel.

Matrix Multiplication

Here is the code we need for matrix multiplication:

import ninetoothed
import ninetoothed.language as ntl
from ninetoothed import Tensor, block_size

BLOCK_SIZE_M = block_size()
BLOCK_SIZE_N = block_size()
BLOCK_SIZE_K = block_size()


def arrangement(input, other, output):
    output_arranged = output.tile((BLOCK_SIZE_M, BLOCK_SIZE_N))

    input_arranged = input.tile((BLOCK_SIZE_M, BLOCK_SIZE_K))
    input_arranged = input_arranged.tile((1, -1))
    input_arranged = input_arranged.expand((-1, output_arranged.shape[1]))
    input_arranged.dtype = input_arranged.dtype.squeeze(0)

    other_arranged = other.tile((BLOCK_SIZE_K, BLOCK_SIZE_N))
    other_arranged = other_arranged.tile((-1, 1))
    other_arranged = other_arranged.expand((output_arranged.shape[0], -1))
    other_arranged.dtype = other_arranged.dtype.squeeze(1)

    return input_arranged, other_arranged, output_arranged


def application(input, other, output):
    accumulator = ntl.zeros(output.shape, dtype=ntl.float32)

    for k in range(input.shape[0]):
        accumulator += ntl.dot(input[k], other[k])

    output = accumulator


tensors = (Tensor(2), Tensor(2), Tensor(2))

kernel = ninetoothed.make(arrangement, application, tensors)

Useful Links

License

This project is distributed under the Apache-2.0 license. See the included LICENSE file for details.

Project details


Download files

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

Source Distribution

ninetoothed-0.25.0.tar.gz (68.6 kB view details)

Uploaded Source

Built Distribution

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

ninetoothed-0.25.0-py3-none-any.whl (45.8 kB view details)

Uploaded Python 3

File details

Details for the file ninetoothed-0.25.0.tar.gz.

File metadata

  • Download URL: ninetoothed-0.25.0.tar.gz
  • Upload date:
  • Size: 68.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ninetoothed-0.25.0.tar.gz
Algorithm Hash digest
SHA256 c7e3ba1bea2742505e038f9b725a8b7151199ac3fe95384f1b8d44f2171f6e74
MD5 4b75841e12e8d20ecb2c208fd0a53ea5
BLAKE2b-256 6ed5bedc47f3caccb48c19a21b07383af57491ea768219704f1d5b7e00b6fcb4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ninetoothed-0.25.0.tar.gz:

Publisher: publish-to-pypi.yml on InfiniTensor/ninetoothed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ninetoothed-0.25.0-py3-none-any.whl.

File metadata

  • Download URL: ninetoothed-0.25.0-py3-none-any.whl
  • Upload date:
  • Size: 45.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ninetoothed-0.25.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6628e512c458801d6387ee5c658ab9fbe1cf3a906739337cb85fbe567cdfefb
MD5 e1ecccfa156dfa6bc25e4c37d097413a
BLAKE2b-256 05ac91dde3d3e6fbdbb3dcab6055c209083fb565af51acf6c65523a221f55602

See more details on using hashes here.

Provenance

The following attestation bundles were made for ninetoothed-0.25.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on InfiniTensor/ninetoothed

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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