Metadata-Version: 2.4
Name: furiosa-tcl
Version: 2026.6.0b0
Summary: Tensor Contraction Language (TCL) for FuriosaAI NPU
Author-email: "FuriosaAI, Inc." <pkg@furiosa.ai>
License-Expression: LicenseRef-Proprietary
Project-URL: Homepage, https://github.com/furiosa-ai/npu-tools
Project-URL: Repository, https://github.com/furiosa-ai/npu-tools
Project-URL: Changelog, https://github.com/furiosa-ai/npu-tools/blob/master/furiosa-tcl/CHANGELOG.md
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: typing-extensions

# Tensor Contraction Language

Tensor Contraction Language (TCL) is a Python-embedded language for writing NPU kernels, provided by `furiosa.tcl`.
Kernels built with it live in `furiosa-kernels`, which depends on this package.

## Installation

### Install from PyPI Package

```bash
uv pip install furiosa-tcl
```

### Install from source

```bash
uv sync
```

## Tests

Runnable examples are in `src/furiosa/tcl/examples`.

```bash
uv run pytest
```

## Changelog

TCL will be released into public in the end of November 2026.

## Compatibility

---

# Tensor Contraction Language

Tensor Contraction Language (TCL) is a Python-embedded language for writing NPU kernels, provided by `furiosa.tcl`.
Kernels built with it live in `furiosa-kernels`, which depends on this package.

## Installation

Python 3.12 or newer is required.

### Install from PyPI Package

```bash
uv pip install furiosa-tcl
```

### Install from source

```bash
uv sync
```

## Usage

Write a kernel with `@tcl.kernel`, then bind its axes with its `instantiate` method to get a `Kernel` with its TCL IR:

```python
from __future__ import annotations

import furiosa.tcl as tcl

@tcl.kernel
def gather(weight: bf16[E, D], index: i32[G]) -> bf16[G, D]:
    return tcl.gather(weight, index, E)

k = gather.instantiate(bindings={'E': 64, 'D': 128, 'G': 8})
print(k.dsl)  # TCL IR: def gather<D=128, E=64, G=8>(...)
```

`instantiate` also takes `config=` for compilation-wide compiler settings, keyed by
`tcl.CompilerOption` members or strings.
Candidates declared with `@tcl.kernel(auto_config=...)` are tuned with `AUTOEXPR_MODE=tune`;
`tcl.CompilerOption.AUTOEXPR_EVALUATION` selects how they are compared.

Runnable examples are in `src/furiosa/tcl/examples`.

### Ordered auto config rules

In the default `AUTOEXPR_MODE=use`, a kernel reads its sibling
`*.auto_config.json` (or its explicit `auto_config_path`). Records are evaluated
in array order, and the **first matching record** supplies all autoexpr values.
The `function` selector can specify only the specialization arguments that
matter. Omitted arguments are unconstrained. A bare function name matches every
specialization of that function, so put it after exceptions to provide a default:

```json
[
  {
    "function": "project_vocabulary<T=2>",
    "revision": "manual",
    "values": {
      "use_cluster_split": true
    }
  },
  {
    "function": "project_vocabulary",
    "revision": "manual",
    "values": {
      "use_cluster_split": false
    }
  }
]
```

Here every `T=2` bucket uses `true`, regardless of `D`, `V_INNER`, `weight_first`,
or other arguments. A bucket such as
`project_vocabulary<D=2880, T=16, V_INNER=204800, V_ORIGINAL=201088, V_OUTER=1, V_PADDED=204800, cluster_split=False, final_logit_softcapping=0.0, output_multiplier=1.0, weight_first=True>`
uses the fallback `false` without enumerating that bucket in JSON.

Multiple conditions, such as `project_vocabulary<D=2880, T=2>`, must all match;
their order does not matter. Values must match their spelling in the TCL IR
function name exactly. Fully specified records continue to work. Duplicate
selectors, including reordered conditions, are errors. Optional arguments appear
as `bias=None` or `bias=Some`; omit `bias` from a manual selector to match both.

Rules do not merge values or prefer more specific conditions. Each selected
record must specify every autoexpr parameter with a valid type and candidate.
A matching record with invalid values raises an error instead of falling through.
Put exceptions before broad rules: any later rule covered by an earlier one is
unreachable. If no rule matches, the declared candidates remain available for
search as before.

`AUTOEXPR_MODE=tune` ignores all stored rules and searches the declared candidates.
The writer removes any existing record with the identical full function name and
puts the tuned full-name record at the beginning of the file. This also moves an
existing result ahead of partial selectors or defaults that previously shadowed
it. Other records keep their relative order and values. Subsequent `use` runs
therefore select the tuned result for that specialization, while other buckets
continue to use the existing rules. Tracing in `use` mode never rewrites the JSON.

## Tests

```bash
uv run pytest
uv run typecheck/run --check
```

`tcl-fuzz`, a fuzzing library for TCL, has its own README.

## Changelog

TCL will be released into public until the end of November 2026.

## Compatibility

| Status | Compatibility | Examples |
| --- | --- | --- |
| Stable | Preserved until deprecated | Unmarked public APIs |
| Preview | Same deprecation policy as Stable; documentation may not yet be comprehensive, and performance and stability are still being refined | `tcl.Dram`, `tcl.autoexpr`, `tcl.core.call`, `tcl.CompilerOption` |
| Experimental | Can change or be removed without deprecation; documentation may be insufficient, and performance and stability are not guaranteed; not recommended for end users | `tcl.experimental.*` |
| Deprecated | Still works and emits a `FutureWarning` with migration guidance; support ends in the next release | `tcl.copy`, `tcl.context`, `tcl.ShardedAxis` |

Preview APIs keep their import paths when stabilized. Experimental APIs live only in `tcl.experimental`;
every other non-stable API is Preview. Deprecation can cover a whole API or only part of it.
