Uploaded using `kernel-builder`.
Browse files- build/torch210-cxx11-cu128-x86_64-linux/__init__.py +138 -0
- build/torch210-cxx11-cu128-x86_64-linux/_ops.py +9 -0
- build/torch210-cxx11-cu128-x86_64-linux/_torch_harmonics_kernels_cuda_19700101000000.abi3.so +3 -0
- build/torch210-cxx11-cu128-x86_64-linux/metadata.json +20 -0
- build/torch210-cxx11-cu128-x86_64-linux/torch_harmonics_kernels/__init__.py +26 -0
build/torch210-cxx11-cu128-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import Tuple
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
from ._ops import ops
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _stable_argsort(x: torch.Tensor) -> torch.Tensor:
|
| 11 |
+
try:
|
| 12 |
+
return torch.argsort(x, stable=True)
|
| 13 |
+
except TypeError:
|
| 14 |
+
return torch.argsort(x)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def preprocess_psi(
|
| 18 |
+
kernel_size: int,
|
| 19 |
+
nlat_out: int,
|
| 20 |
+
ker_idx: torch.Tensor,
|
| 21 |
+
row_idx: torch.Tensor,
|
| 22 |
+
col_idx: torch.Tensor,
|
| 23 |
+
vals: torch.Tensor,
|
| 24 |
+
) -> torch.Tensor:
|
| 25 |
+
device = ker_idx.device
|
| 26 |
+
order = _stable_argsort(ker_idx.to("cpu"))
|
| 27 |
+
|
| 28 |
+
sorted_ker = ker_idx.to("cpu").index_select(0, order)
|
| 29 |
+
sorted_row = row_idx.to("cpu").index_select(0, order)
|
| 30 |
+
sorted_col = col_idx.to("cpu").index_select(0, order)
|
| 31 |
+
sorted_vals = vals.to("cpu").index_select(0, order)
|
| 32 |
+
|
| 33 |
+
ker_idx.copy_(sorted_ker.to(device))
|
| 34 |
+
row_idx.copy_(sorted_row.to(device))
|
| 35 |
+
col_idx.copy_(sorted_col.to(device))
|
| 36 |
+
vals.copy_(sorted_vals.to(device))
|
| 37 |
+
|
| 38 |
+
if sorted_row.numel() == 0:
|
| 39 |
+
return torch.zeros(1, dtype=row_idx.dtype, device=device)
|
| 40 |
+
|
| 41 |
+
row_breaks = torch.nonzero(sorted_row[1:] != sorted_row[:-1], as_tuple=False).flatten() + 1
|
| 42 |
+
roff_idx = torch.empty(row_breaks.numel() + 2, dtype=row_idx.dtype, device=device)
|
| 43 |
+
roff_idx[0] = 0
|
| 44 |
+
if row_breaks.numel():
|
| 45 |
+
roff_idx[1:-1] = row_breaks.to(device=device, dtype=row_idx.dtype)
|
| 46 |
+
roff_idx[-1] = sorted_row.numel()
|
| 47 |
+
|
| 48 |
+
max_rows = kernel_size * nlat_out
|
| 49 |
+
if roff_idx.numel() - 1 > max_rows:
|
| 50 |
+
raise RuntimeError(
|
| 51 |
+
f"found more rows in the K COOs than Ho*K ({max_rows})"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
return roff_idx
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def cuda_kernels_is_available() -> bool:
|
| 58 |
+
return True
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def optimized_kernels_is_available() -> bool:
|
| 62 |
+
return True
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def disco_forward(
|
| 66 |
+
inp: torch.Tensor,
|
| 67 |
+
roff_idx: torch.Tensor,
|
| 68 |
+
ker_idx: torch.Tensor,
|
| 69 |
+
row_idx: torch.Tensor,
|
| 70 |
+
col_idx: torch.Tensor,
|
| 71 |
+
vals: torch.Tensor,
|
| 72 |
+
kernel_size: int,
|
| 73 |
+
nlat_out: int,
|
| 74 |
+
nlon_out: int,
|
| 75 |
+
) -> torch.Tensor:
|
| 76 |
+
return ops.disco_forward(
|
| 77 |
+
inp, roff_idx, ker_idx, row_idx, col_idx, vals, kernel_size, nlat_out, nlon_out
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def disco_backward(
|
| 82 |
+
inp: torch.Tensor,
|
| 83 |
+
roff_idx: torch.Tensor,
|
| 84 |
+
ker_idx: torch.Tensor,
|
| 85 |
+
row_idx: torch.Tensor,
|
| 86 |
+
col_idx: torch.Tensor,
|
| 87 |
+
vals: torch.Tensor,
|
| 88 |
+
kernel_size: int,
|
| 89 |
+
nlat_out: int,
|
| 90 |
+
nlon_out: int,
|
| 91 |
+
) -> torch.Tensor:
|
| 92 |
+
return ops.disco_backward(
|
| 93 |
+
inp, roff_idx, ker_idx, row_idx, col_idx, vals, kernel_size, nlat_out, nlon_out
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def attention_forward(
|
| 98 |
+
kx: torch.Tensor,
|
| 99 |
+
vx: torch.Tensor,
|
| 100 |
+
qy: torch.Tensor,
|
| 101 |
+
quad_weights: torch.Tensor,
|
| 102 |
+
col_idx: torch.Tensor,
|
| 103 |
+
row_off: torch.Tensor,
|
| 104 |
+
nlon_in: int,
|
| 105 |
+
nlat_out: int,
|
| 106 |
+
nlon_out: int,
|
| 107 |
+
) -> torch.Tensor:
|
| 108 |
+
return ops.attention_forward(
|
| 109 |
+
kx, vx, qy, quad_weights, col_idx, row_off, nlon_in, nlat_out, nlon_out
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def attention_backward(
|
| 114 |
+
kx: torch.Tensor,
|
| 115 |
+
vx: torch.Tensor,
|
| 116 |
+
qy: torch.Tensor,
|
| 117 |
+
dy: torch.Tensor,
|
| 118 |
+
quad_weights: torch.Tensor,
|
| 119 |
+
col_idx: torch.Tensor,
|
| 120 |
+
row_off: torch.Tensor,
|
| 121 |
+
nlon_in: int,
|
| 122 |
+
nlat_out: int,
|
| 123 |
+
nlon_out: int,
|
| 124 |
+
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
|
| 125 |
+
return ops.attention_backward(
|
| 126 |
+
kx, vx, qy, dy, quad_weights, col_idx, row_off, nlon_in, nlat_out, nlon_out
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
__all__ = [
|
| 130 |
+
"attention_backward",
|
| 131 |
+
"attention_forward",
|
| 132 |
+
"cuda_kernels_is_available",
|
| 133 |
+
"disco_backward",
|
| 134 |
+
"disco_forward",
|
| 135 |
+
"ops",
|
| 136 |
+
"optimized_kernels_is_available",
|
| 137 |
+
"preprocess_psi",
|
| 138 |
+
]
|
build/torch210-cxx11-cu128-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _torch_harmonics_kernels_cuda_19700101000000
|
| 3 |
+
ops = torch.ops._torch_harmonics_kernels_cuda_19700101000000
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_torch_harmonics_kernels_cuda_19700101000000::{op_name}"
|
build/torch210-cxx11-cu128-x86_64-linux/_torch_harmonics_kernels_cuda_19700101000000.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:45f06869044fe89b321c8cc772623452a4f8701cae21632afd77487ca99d3158
|
| 3 |
+
size 144599960
|
build/torch210-cxx11-cu128-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"version": 1,
|
| 3 |
+
"python-depends": [],
|
| 4 |
+
"backend": {
|
| 5 |
+
"type": "cuda",
|
| 6 |
+
"archs": [
|
| 7 |
+
"10.0",
|
| 8 |
+
"10.1",
|
| 9 |
+
"12.0+PTX",
|
| 10 |
+
"7.0",
|
| 11 |
+
"7.2",
|
| 12 |
+
"7.5",
|
| 13 |
+
"8.0",
|
| 14 |
+
"8.6",
|
| 15 |
+
"8.7",
|
| 16 |
+
"8.9",
|
| 17 |
+
"9.0"
|
| 18 |
+
]
|
| 19 |
+
}
|
| 20 |
+
}
|
build/torch210-cxx11-cu128-x86_64-linux/torch_harmonics_kernels/__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")))
|