# Kernels API Reference

## Main Functions

### get_kernel[[kernels.get_kernel]]

#### kernels.get_kernel[[kernels.get_kernel]]

[Source](https://github.com/huggingface/kernels/blob/v0.12.2/src/kernels/utils.py#L276)

Load a kernel from the kernel hub.

This function downloads a kernel to the local Hugging Face Hub cache directory (if it was not downloaded before)
and then loads the kernel.

Example:
```python
import torch
from kernels import get_kernel

activation = get_kernel("kernels-community/relu", version=1)
x = torch.randn(10, 20, device="cuda")
out = torch.empty_like(x)
result = activation.relu(out, x)
```

**Parameters:**

repo_id (`str`) : The Hub repository containing the kernel.

revision (`str`, *optional*, defaults to `"main"`) : The specific revision (branch, tag, or commit) to download. Cannot be used together with `version`.

version (`int|str`, *optional*) : The kernel version to download as an integer. The `str` variant is deprecated and will be removed in a future release. Cannot be used together with `revision`.

user_agent (`Union[str, dict]`, *optional*) : The `user_agent` info to pass to `snapshot_download()` for internal telemetry.

**Returns:**

``ModuleType``

The imported kernel module.

### get_local_kernel[[kernels.get_local_kernel]]

#### kernels.get_local_kernel[[kernels.get_local_kernel]]

[Source](https://github.com/huggingface/kernels/blob/v0.12.2/src/kernels/utils.py#L318)

Import a kernel from a local kernel repository path.

**Parameters:**

repo_path (`Path`) : The local path to the kernel repository.

package_name (`str`) : The name of the package to import from the repository.

**Returns:**

``ModuleType``

The imported kernel module.

### has_kernel[[kernels.has_kernel]]

#### kernels.has_kernel[[kernels.has_kernel]]

[Source](https://github.com/huggingface/kernels/blob/v0.12.2/src/kernels/utils.py#L347)

Check whether a kernel build exists for the current environment (Torch version and compute framework).

**Parameters:**

repo_id (`str`) : The Hub repository containing the kernel.

revision (`str`, *optional*, defaults to `"main"`) : The specific revision (branch, tag, or commit) to download. Cannot be used together with `version`.

version (`int|str`, *optional*) : The kernel version to download as an integer. The `str` variant is deprecated and will be removed in a future release. Cannot be used together with `revision`.

**Returns:**

``bool``

`True` if a kernel is available for the current environment.

## Loading locked kernels

### load_kernel[[kernels.load_kernel]]

#### kernels.load_kernel[[kernels.load_kernel]]

[Source](https://github.com/huggingface/kernels/blob/v0.12.2/src/kernels/utils.py#L380)

Get a pre-downloaded, locked kernel.

If `lockfile` is not specified, the lockfile will be loaded from the caller's package metadata.

**Parameters:**

repo_id (`str`) : The Hub repository containing the kernel.

lockfile (`Path`, *optional*) : Path to the lockfile. If not provided, the lockfile will be loaded from the caller's package metadata.

**Returns:**

``ModuleType``

The imported kernel module.

### get_locked_kernel[[kernels.get_locked_kernel]]

#### kernels.get_locked_kernel[[kernels.get_locked_kernel]]

[Source](https://github.com/huggingface/kernels/blob/v0.12.2/src/kernels/utils.py#L428)

Get a kernel using a lock file.

**Parameters:**

repo_id (`str`) : The Hub repository containing the kernel.

local_files_only (`bool`, *optional*, defaults to `False`) : Whether to only use local files and not download from the Hub.

**Returns:**

``ModuleType``

The imported kernel module.

