Uploaded using `kernel-builder`.
Browse files- build/torch211-cxx11-cu128-x86_64-linux/__init__.py +71 -0
- build/torch211-cxx11-cu128-x86_64-linux/_bf16_linear_gemv_cuda_1683349.abi3.so +3 -0
- build/torch211-cxx11-cu128-x86_64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu128-x86_64-linux/bf16_linear_gemv/__init__.py +26 -0
- build/torch211-cxx11-cu128-x86_64-linux/metadata.json +13 -0
- build/torch211-cxx11-cu130-x86_64-linux/__init__.py +71 -0
- build/torch211-cxx11-cu130-x86_64-linux/_bf16_linear_gemv_cuda_1683349.abi3.so +3 -0
- build/torch211-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu130-x86_64-linux/bf16_linear_gemv/__init__.py +26 -0
- build/torch211-cxx11-cu130-x86_64-linux/metadata.json +13 -0
- build/torch212-cxx11-cu130-x86_64-linux/__init__.py +71 -0
- build/torch212-cxx11-cu130-x86_64-linux/_bf16_linear_gemv_cuda_1683349.abi3.so +3 -0
- build/torch212-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu130-x86_64-linux/bf16_linear_gemv/__init__.py +26 -0
- build/torch212-cxx11-cu130-x86_64-linux/metadata.json +13 -0
- build/torch212-cxx11-cu132-x86_64-linux/__init__.py +71 -0
- build/torch212-cxx11-cu132-x86_64-linux/_bf16_linear_gemv_cuda_1683349.abi3.so +3 -0
- build/torch212-cxx11-cu132-x86_64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu132-x86_64-linux/bf16_linear_gemv/__init__.py +26 -0
- build/torch212-cxx11-cu132-x86_64-linux/metadata.json +13 -0
build/torch211-cxx11-cu128-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT BF16 decode GEMV kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.library.register_fake(add_op_namespace_prefix("bf16_decode_gemv_bf16"))
|
| 13 |
+
def _bf16_decode_gemv_fake(
|
| 14 |
+
x: torch.Tensor,
|
| 15 |
+
weight: torch.Tensor,
|
| 16 |
+
alpha: float,
|
| 17 |
+
variant: int,
|
| 18 |
+
out: torch.Tensor,
|
| 19 |
+
) -> None:
|
| 20 |
+
k = x.shape[0] if x.dim() == 1 else x.shape[1]
|
| 21 |
+
if weight.dim() != 2 or weight.shape[1] != k or out.shape != (weight.shape[0],):
|
| 22 |
+
raise RuntimeError("expected x (K,) or (1,K), weight (N,K), out (N,)")
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@torch.library.register_fake(add_op_namespace_prefix("bf16_decode_gemv_unrolled_bf16"))
|
| 27 |
+
def _bf16_decode_gemv_unrolled_fake(
|
| 28 |
+
x: torch.Tensor,
|
| 29 |
+
weight: torch.Tensor,
|
| 30 |
+
out: torch.Tensor,
|
| 31 |
+
) -> None:
|
| 32 |
+
k = x.shape[0] if x.dim() == 1 else x.shape[1]
|
| 33 |
+
if weight.dim() != 2 or weight.shape[1] != k or out.shape != (weight.shape[0],):
|
| 34 |
+
raise RuntimeError("expected x (K,) or (1,K), weight (N,K), out (N,)")
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def bf16_decode_gemv_bf16(
|
| 39 |
+
x: torch.Tensor,
|
| 40 |
+
weight: torch.Tensor,
|
| 41 |
+
*,
|
| 42 |
+
alpha: float = 1.0,
|
| 43 |
+
variant: int = 0,
|
| 44 |
+
out: Optional[torch.Tensor] = None,
|
| 45 |
+
) -> torch.Tensor:
|
| 46 |
+
"""Compute BF16 M=1 decode GEMV: ``out = x @ weight.T * alpha``."""
|
| 47 |
+
|
| 48 |
+
if out is None:
|
| 49 |
+
out = torch.empty((weight.shape[0],), device=x.device, dtype=torch.bfloat16)
|
| 50 |
+
ops.bf16_decode_gemv_bf16(x, weight, float(alpha), int(variant), out)
|
| 51 |
+
return out
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def bf16_decode_gemv_unrolled_bf16(
|
| 55 |
+
x: torch.Tensor,
|
| 56 |
+
weight: torch.Tensor,
|
| 57 |
+
*,
|
| 58 |
+
out: Optional[torch.Tensor] = None,
|
| 59 |
+
) -> torch.Tensor:
|
| 60 |
+
"""Compute BF16 M=1 GEMV with the unrolled memory-level-parallel kernel."""
|
| 61 |
+
|
| 62 |
+
if out is None:
|
| 63 |
+
out = torch.empty((weight.shape[0],), device=x.device, dtype=torch.bfloat16)
|
| 64 |
+
ops.bf16_decode_gemv_unrolled_bf16(x, weight, out)
|
| 65 |
+
return out
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
__all__ = [
|
| 69 |
+
"bf16_decode_gemv_bf16",
|
| 70 |
+
"bf16_decode_gemv_unrolled_bf16",
|
| 71 |
+
]
|
build/torch211-cxx11-cu128-x86_64-linux/_bf16_linear_gemv_cuda_1683349.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:88328fac3bfb2cbd7dfff66ea724593984a203ba7255ab75df5f0d3e7ffcce83
|
| 3 |
+
size 155928
|
build/torch211-cxx11-cu128-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _bf16_linear_gemv_cuda_1683349
|
| 3 |
+
ops = torch.ops._bf16_linear_gemv_cuda_1683349
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_bf16_linear_gemv_cuda_1683349::{op_name}"
|
build/torch211-cxx11-cu128-x86_64-linux/bf16_linear_gemv/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch211-cxx11-cu128-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "bf16-linear-gemv",
|
| 3 |
+
"id": "_bf16_linear_gemv_cuda_1683349",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"12.0a"
|
| 11 |
+
]
|
| 12 |
+
}
|
| 13 |
+
}
|
build/torch211-cxx11-cu130-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT BF16 decode GEMV kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.library.register_fake(add_op_namespace_prefix("bf16_decode_gemv_bf16"))
|
| 13 |
+
def _bf16_decode_gemv_fake(
|
| 14 |
+
x: torch.Tensor,
|
| 15 |
+
weight: torch.Tensor,
|
| 16 |
+
alpha: float,
|
| 17 |
+
variant: int,
|
| 18 |
+
out: torch.Tensor,
|
| 19 |
+
) -> None:
|
| 20 |
+
k = x.shape[0] if x.dim() == 1 else x.shape[1]
|
| 21 |
+
if weight.dim() != 2 or weight.shape[1] != k or out.shape != (weight.shape[0],):
|
| 22 |
+
raise RuntimeError("expected x (K,) or (1,K), weight (N,K), out (N,)")
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@torch.library.register_fake(add_op_namespace_prefix("bf16_decode_gemv_unrolled_bf16"))
|
| 27 |
+
def _bf16_decode_gemv_unrolled_fake(
|
| 28 |
+
x: torch.Tensor,
|
| 29 |
+
weight: torch.Tensor,
|
| 30 |
+
out: torch.Tensor,
|
| 31 |
+
) -> None:
|
| 32 |
+
k = x.shape[0] if x.dim() == 1 else x.shape[1]
|
| 33 |
+
if weight.dim() != 2 or weight.shape[1] != k or out.shape != (weight.shape[0],):
|
| 34 |
+
raise RuntimeError("expected x (K,) or (1,K), weight (N,K), out (N,)")
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def bf16_decode_gemv_bf16(
|
| 39 |
+
x: torch.Tensor,
|
| 40 |
+
weight: torch.Tensor,
|
| 41 |
+
*,
|
| 42 |
+
alpha: float = 1.0,
|
| 43 |
+
variant: int = 0,
|
| 44 |
+
out: Optional[torch.Tensor] = None,
|
| 45 |
+
) -> torch.Tensor:
|
| 46 |
+
"""Compute BF16 M=1 decode GEMV: ``out = x @ weight.T * alpha``."""
|
| 47 |
+
|
| 48 |
+
if out is None:
|
| 49 |
+
out = torch.empty((weight.shape[0],), device=x.device, dtype=torch.bfloat16)
|
| 50 |
+
ops.bf16_decode_gemv_bf16(x, weight, float(alpha), int(variant), out)
|
| 51 |
+
return out
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def bf16_decode_gemv_unrolled_bf16(
|
| 55 |
+
x: torch.Tensor,
|
| 56 |
+
weight: torch.Tensor,
|
| 57 |
+
*,
|
| 58 |
+
out: Optional[torch.Tensor] = None,
|
| 59 |
+
) -> torch.Tensor:
|
| 60 |
+
"""Compute BF16 M=1 GEMV with the unrolled memory-level-parallel kernel."""
|
| 61 |
+
|
| 62 |
+
if out is None:
|
| 63 |
+
out = torch.empty((weight.shape[0],), device=x.device, dtype=torch.bfloat16)
|
| 64 |
+
ops.bf16_decode_gemv_unrolled_bf16(x, weight, out)
|
| 65 |
+
return out
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
__all__ = [
|
| 69 |
+
"bf16_decode_gemv_bf16",
|
| 70 |
+
"bf16_decode_gemv_unrolled_bf16",
|
| 71 |
+
]
|
build/torch211-cxx11-cu130-x86_64-linux/_bf16_linear_gemv_cuda_1683349.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6a49b37560075e028eb18d463b05af29dd72a2569cc3b2df738afb793363d769
|
| 3 |
+
size 159832
|
build/torch211-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _bf16_linear_gemv_cuda_1683349
|
| 3 |
+
ops = torch.ops._bf16_linear_gemv_cuda_1683349
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_bf16_linear_gemv_cuda_1683349::{op_name}"
|
build/torch211-cxx11-cu130-x86_64-linux/bf16_linear_gemv/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch211-cxx11-cu130-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "bf16-linear-gemv",
|
| 3 |
+
"id": "_bf16_linear_gemv_cuda_1683349",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"12.0a"
|
| 11 |
+
]
|
| 12 |
+
}
|
| 13 |
+
}
|
build/torch212-cxx11-cu130-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT BF16 decode GEMV kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.library.register_fake(add_op_namespace_prefix("bf16_decode_gemv_bf16"))
|
| 13 |
+
def _bf16_decode_gemv_fake(
|
| 14 |
+
x: torch.Tensor,
|
| 15 |
+
weight: torch.Tensor,
|
| 16 |
+
alpha: float,
|
| 17 |
+
variant: int,
|
| 18 |
+
out: torch.Tensor,
|
| 19 |
+
) -> None:
|
| 20 |
+
k = x.shape[0] if x.dim() == 1 else x.shape[1]
|
| 21 |
+
if weight.dim() != 2 or weight.shape[1] != k or out.shape != (weight.shape[0],):
|
| 22 |
+
raise RuntimeError("expected x (K,) or (1,K), weight (N,K), out (N,)")
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@torch.library.register_fake(add_op_namespace_prefix("bf16_decode_gemv_unrolled_bf16"))
|
| 27 |
+
def _bf16_decode_gemv_unrolled_fake(
|
| 28 |
+
x: torch.Tensor,
|
| 29 |
+
weight: torch.Tensor,
|
| 30 |
+
out: torch.Tensor,
|
| 31 |
+
) -> None:
|
| 32 |
+
k = x.shape[0] if x.dim() == 1 else x.shape[1]
|
| 33 |
+
if weight.dim() != 2 or weight.shape[1] != k or out.shape != (weight.shape[0],):
|
| 34 |
+
raise RuntimeError("expected x (K,) or (1,K), weight (N,K), out (N,)")
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def bf16_decode_gemv_bf16(
|
| 39 |
+
x: torch.Tensor,
|
| 40 |
+
weight: torch.Tensor,
|
| 41 |
+
*,
|
| 42 |
+
alpha: float = 1.0,
|
| 43 |
+
variant: int = 0,
|
| 44 |
+
out: Optional[torch.Tensor] = None,
|
| 45 |
+
) -> torch.Tensor:
|
| 46 |
+
"""Compute BF16 M=1 decode GEMV: ``out = x @ weight.T * alpha``."""
|
| 47 |
+
|
| 48 |
+
if out is None:
|
| 49 |
+
out = torch.empty((weight.shape[0],), device=x.device, dtype=torch.bfloat16)
|
| 50 |
+
ops.bf16_decode_gemv_bf16(x, weight, float(alpha), int(variant), out)
|
| 51 |
+
return out
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def bf16_decode_gemv_unrolled_bf16(
|
| 55 |
+
x: torch.Tensor,
|
| 56 |
+
weight: torch.Tensor,
|
| 57 |
+
*,
|
| 58 |
+
out: Optional[torch.Tensor] = None,
|
| 59 |
+
) -> torch.Tensor:
|
| 60 |
+
"""Compute BF16 M=1 GEMV with the unrolled memory-level-parallel kernel."""
|
| 61 |
+
|
| 62 |
+
if out is None:
|
| 63 |
+
out = torch.empty((weight.shape[0],), device=x.device, dtype=torch.bfloat16)
|
| 64 |
+
ops.bf16_decode_gemv_unrolled_bf16(x, weight, out)
|
| 65 |
+
return out
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
__all__ = [
|
| 69 |
+
"bf16_decode_gemv_bf16",
|
| 70 |
+
"bf16_decode_gemv_unrolled_bf16",
|
| 71 |
+
]
|
build/torch212-cxx11-cu130-x86_64-linux/_bf16_linear_gemv_cuda_1683349.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8e69262a9dc1029a69945311b3e4a1a7437ab2942c5a448c0e63c8ce89ad115c
|
| 3 |
+
size 170344
|
build/torch212-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _bf16_linear_gemv_cuda_1683349
|
| 3 |
+
ops = torch.ops._bf16_linear_gemv_cuda_1683349
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_bf16_linear_gemv_cuda_1683349::{op_name}"
|
build/torch212-cxx11-cu130-x86_64-linux/bf16_linear_gemv/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch212-cxx11-cu130-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "bf16-linear-gemv",
|
| 3 |
+
"id": "_bf16_linear_gemv_cuda_1683349",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"12.0a"
|
| 11 |
+
]
|
| 12 |
+
}
|
| 13 |
+
}
|
build/torch212-cxx11-cu132-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT BF16 decode GEMV kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.library.register_fake(add_op_namespace_prefix("bf16_decode_gemv_bf16"))
|
| 13 |
+
def _bf16_decode_gemv_fake(
|
| 14 |
+
x: torch.Tensor,
|
| 15 |
+
weight: torch.Tensor,
|
| 16 |
+
alpha: float,
|
| 17 |
+
variant: int,
|
| 18 |
+
out: torch.Tensor,
|
| 19 |
+
) -> None:
|
| 20 |
+
k = x.shape[0] if x.dim() == 1 else x.shape[1]
|
| 21 |
+
if weight.dim() != 2 or weight.shape[1] != k or out.shape != (weight.shape[0],):
|
| 22 |
+
raise RuntimeError("expected x (K,) or (1,K), weight (N,K), out (N,)")
|
| 23 |
+
return None
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@torch.library.register_fake(add_op_namespace_prefix("bf16_decode_gemv_unrolled_bf16"))
|
| 27 |
+
def _bf16_decode_gemv_unrolled_fake(
|
| 28 |
+
x: torch.Tensor,
|
| 29 |
+
weight: torch.Tensor,
|
| 30 |
+
out: torch.Tensor,
|
| 31 |
+
) -> None:
|
| 32 |
+
k = x.shape[0] if x.dim() == 1 else x.shape[1]
|
| 33 |
+
if weight.dim() != 2 or weight.shape[1] != k or out.shape != (weight.shape[0],):
|
| 34 |
+
raise RuntimeError("expected x (K,) or (1,K), weight (N,K), out (N,)")
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def bf16_decode_gemv_bf16(
|
| 39 |
+
x: torch.Tensor,
|
| 40 |
+
weight: torch.Tensor,
|
| 41 |
+
*,
|
| 42 |
+
alpha: float = 1.0,
|
| 43 |
+
variant: int = 0,
|
| 44 |
+
out: Optional[torch.Tensor] = None,
|
| 45 |
+
) -> torch.Tensor:
|
| 46 |
+
"""Compute BF16 M=1 decode GEMV: ``out = x @ weight.T * alpha``."""
|
| 47 |
+
|
| 48 |
+
if out is None:
|
| 49 |
+
out = torch.empty((weight.shape[0],), device=x.device, dtype=torch.bfloat16)
|
| 50 |
+
ops.bf16_decode_gemv_bf16(x, weight, float(alpha), int(variant), out)
|
| 51 |
+
return out
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def bf16_decode_gemv_unrolled_bf16(
|
| 55 |
+
x: torch.Tensor,
|
| 56 |
+
weight: torch.Tensor,
|
| 57 |
+
*,
|
| 58 |
+
out: Optional[torch.Tensor] = None,
|
| 59 |
+
) -> torch.Tensor:
|
| 60 |
+
"""Compute BF16 M=1 GEMV with the unrolled memory-level-parallel kernel."""
|
| 61 |
+
|
| 62 |
+
if out is None:
|
| 63 |
+
out = torch.empty((weight.shape[0],), device=x.device, dtype=torch.bfloat16)
|
| 64 |
+
ops.bf16_decode_gemv_unrolled_bf16(x, weight, out)
|
| 65 |
+
return out
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
__all__ = [
|
| 69 |
+
"bf16_decode_gemv_bf16",
|
| 70 |
+
"bf16_decode_gemv_unrolled_bf16",
|
| 71 |
+
]
|
build/torch212-cxx11-cu132-x86_64-linux/_bf16_linear_gemv_cuda_1683349.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c420e09798f32d3e619d2f12e458e51efe43c4105a2013edcffaf5f203359d31
|
| 3 |
+
size 170344
|
build/torch212-cxx11-cu132-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _bf16_linear_gemv_cuda_1683349
|
| 3 |
+
ops = torch.ops._bf16_linear_gemv_cuda_1683349
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_bf16_linear_gemv_cuda_1683349::{op_name}"
|
build/torch212-cxx11-cu132-x86_64-linux/bf16_linear_gemv/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch212-cxx11-cu132-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "bf16-linear-gemv",
|
| 3 |
+
"id": "_bf16_linear_gemv_cuda_1683349",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"12.0a"
|
| 11 |
+
]
|
| 12 |
+
}
|
| 13 |
+
}
|