Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/source/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ get the latest kernel build from the `v1` branch.
Kernels within a version branch must never break the API or remove builds
for older PyTorch versions. This ensures that your code will continue to work.

Some kernels have not yet been updated to use versioning yet. In these cases,
you can use `get_kernel` without the `version` argument.
Hub kernels must be loaded with either a `version` or an explicit `revision`.

## Checking Kernel Availability

Expand Down
6 changes: 3 additions & 3 deletions docs/source/layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ will get the latest kernel build from the `v1` branch. Kernel layers
within a version branch must never break the API or remove builds for
older PyTorch versions. This ensures that your code will continue to
work.

Some kernels have not yet been updated to use versioning yet. In these cases,
you can use `LayerRepository` without the `version` argument.
Hub-backed `LayerRepository` and `FuncRepository` entries must specify
either a `version` or an explicit `revision`.

You can register a mapping, like the one above, using `register_kernel_mapping`:

Expand Down Expand Up @@ -210,6 +209,7 @@ kernel_layer_mapping = {
"cuda": FuncRepository(
repo_id="kernels-community/activation",
func_name="silu_and_mul",
version=1,
),
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/source/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

Before `kernels` 0.12, kernels could be pulled from a repository
without specifying a version. This is deprecated in kernels 0.12
and will become an error in kernels 0.14. Instead, use of a kernel
should always specify a version (except for local kernels).
and is an error in kernels 0.15. Instead, use of a kernel should
always specify a version or revision (except for local kernels).

Kernels only use a major version. The kernel maintainer is responsible
for never breaking a kernel within a major version and should bump up
Expand Down
4 changes: 2 additions & 2 deletions examples/kernels/cutlass-gemm-tvm-ffi/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
4 changes: 2 additions & 2 deletions examples/kernels/cutlass-gemm/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

from ._ops import ops


def cutlass_gemm(out: torch.Tensor, A: torch.Tensor, B: torch.Tensor) -> None:
ops.cutlass_gemm(out, A, B)
return out


__all__ = ["cutlass_gemm"]
4 changes: 2 additions & 2 deletions examples/kernels/extra-data/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
4 changes: 2 additions & 2 deletions examples/kernels/relu-backprop-compile/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import torch
from torch.library import register_autograd

from ._ops import ops, add_op_namespace_prefix
from ._ops import add_op_namespace_prefix, ops


@torch.library.register_fake(add_op_namespace_prefix("relu_fwd"))
Expand All @@ -28,6 +28,7 @@ def _backward(ctx, grad_outputs: torch.Tensor):
return ops.relu_bwd(grad_outputs_contiguous, input)


register_autograd(
add_op_namespace_prefix("relu_fwd"), _backward, setup_context=_setup_context
)
register_autograd(add_op_namespace_prefix("relu_fwd"), _backward, setup_context=_setup_context)


__all__ = ["relu"]
4 changes: 2 additions & 2 deletions examples/kernels/relu-compiler-flags/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ def relu(x: torch.Tensor, out: Optional[torch.Tensor] = None) -> torch.Tensor:
if out is None:
out = torch.empty_like(x)
ops.relu(out, x)
return out
return out


__all__ = ["relu"]
4 changes: 2 additions & 2 deletions examples/kernels/relu-metal-cpp/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
5 changes: 4 additions & 1 deletion examples/kernels/relu-metal-cpp/torch-ext/relu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ def relu(x: torch.Tensor, out: Optional[torch.Tensor] = None) -> torch.Tensor:
if out is None:
out = torch.empty_like(x)
ops.relu(out, x)
return out
return out


__all__ = ["relu"]
4 changes: 2 additions & 2 deletions examples/kernels/relu-nki/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
4 changes: 2 additions & 2 deletions examples/kernels/relu-specific-torch/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ def relu(x: torch.Tensor, out: Optional[torch.Tensor] = None) -> torch.Tensor:
out = torch.empty_like(x)
ops.relu(out, x)
return out


__all__ = ["relu"]
4 changes: 2 additions & 2 deletions examples/kernels/relu-torch-bounds/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
3 changes: 3 additions & 0 deletions examples/kernels/relu-torch-bounds/torch-ext/relu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ def relu(x: torch.Tensor, out: Optional[torch.Tensor] = None) -> torch.Tensor:
out = torch.empty_like(x)
ops.relu(out, x)
return out


__all__ = ["relu"]
4 changes: 2 additions & 2 deletions examples/kernels/relu-tvm-ffi/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
4 changes: 2 additions & 2 deletions examples/kernels/relu/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
4 changes: 2 additions & 2 deletions examples/kernels/silu-and-mul/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
16 changes: 11 additions & 5 deletions kernel-builder/src/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@ use kernels_data::config::Build;
use crate::util::{check_or_infer_kernel_dir, parse_build};

fn extract_all(kernel_dir: &Path, module_name: &str) -> Option<Vec<String>> {
let init_path = kernel_dir
.join("torch-ext")
.join(module_name)
.join("__init__.py");
let init_path = ["torch-ext", "tvm-ffi-ext"]
.iter()
.map(|ext_dir| {
kernel_dir
.join(ext_dir)
.join(module_name)
.join("__init__.py")
})
.find(|path| path.exists())?;

let content = fs::read_to_string(&init_path).ok()?;
let content = fs::read_to_string(init_path).ok()?;
let stmts = ast::Suite::parse(&content, "<module>").ok()?;

for stmt in stmts {
Expand Down Expand Up @@ -126,6 +131,7 @@ fn render_card(build: &Build, kernel_dir: &Path) -> Result<String> {
.wrap_err("Cannot get card template")?
.render(context! {
repo_id => repo_id,
version => build.general.version,
functions => functions,
layers => layers,
has_benchmark => has_benchmark,
Expand Down
4 changes: 2 additions & 2 deletions kernel-builder/src/init/templates/CARD.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is the repository card of {{ repo_id }} that has been pushed on the Hub. It
# make sure `kernels` is installed: `pip install -U kernels`
from kernels import get_kernel

kernel_module = get_kernel("{{ repo_id }}")
kernel_module = get_kernel("{{ repo_id }}", version={{ version }})
{{ functions[0] }} = kernel_module.{{ functions[0] }}

{{ functions[0] }}(...)
Expand Down Expand Up @@ -42,7 +42,7 @@ Function list not available.
## Benchmarks
{% if has_benchmark %}

Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }}`.
Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`.
{% else %}

No benchmark available yet.
Expand Down
Loading
Loading