Skip to content

Commit b947ad5

Browse files
committed
Merge branch 'master' of github.com:InfiniTensor/ntops into develop-softmax
2 parents 682c5a0 + 31f93af commit b947ad5

29 files changed

Lines changed: 674 additions & 2 deletions

src/ntops/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import torch
2+
3+
__all__ = ["torch"]

src/ntops/kernels/cos.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import functools
2+
3+
import ninetoothed
4+
import ninetoothed.language as ntl
5+
from ninetoothed import Tensor
6+
7+
from ntops.kernels.element_wise import arrangement
8+
9+
10+
def application(input, output):
11+
output = ntl.cos(input) # noqa: F841
12+
13+
14+
@functools.cache
15+
def make(ndim):
16+
return ninetoothed.make(arrangement, application, (Tensor(ndim), Tensor(ndim)))

src/ntops/kernels/element_wise.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import ninetoothed
22

33

4-
def arrangement(*tensors):
4+
def arrangement(*tensors, block_size=ninetoothed.block_size()):
55
ndim = max(tensor.ndim for tensor in tensors)
66

77
assert all(tensor.ndim == ndim or tensor.ndim == 0 for tensor in tensors)
88

9-
block_shape = tuple(1 for _ in range(ndim - 1)) + (ninetoothed.block_size(),)
9+
block_shape = tuple(1 for _ in range(ndim - 1)) + (block_size,)
1010

1111
return tuple(
1212
tensor.tile(block_shape) if tensor.ndim != 0 else tensor for tensor in tensors

src/ntops/kernels/eq.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import functools
2+
3+
import ninetoothed
4+
from ninetoothed import Tensor
5+
6+
from ntops.kernels.element_wise import arrangement
7+
8+
9+
def application(input, other, output):
10+
output = input == other # noqa: F841
11+
12+
13+
@functools.cache
14+
def make(ndim):
15+
tensors = (Tensor(ndim), Tensor(ndim), Tensor(ndim))
16+
17+
return ninetoothed.make(arrangement, application, tensors)

src/ntops/kernels/ge.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import functools
2+
3+
import ninetoothed
4+
from ninetoothed import Tensor
5+
6+
from ntops.kernels.element_wise import arrangement
7+
8+
9+
def application(input, other, output):
10+
output = input >= other # noqa: F841
11+
12+
13+
@functools.cache
14+
def make(ndim):
15+
tensors = (Tensor(ndim), Tensor(ndim), Tensor(ndim))
16+
17+
return ninetoothed.make(arrangement, application, tensors)

src/ntops/kernels/gt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import functools
2+
3+
import ninetoothed
4+
from ninetoothed import Tensor
5+
6+
from ntops.kernels.element_wise import arrangement
7+
8+
9+
def application(input, other, output):
10+
output = input > other # noqa: F841
11+
12+
13+
@functools.cache
14+
def make(ndim):
15+
tensors = (Tensor(ndim), Tensor(ndim), Tensor(ndim))
16+
17+
return ninetoothed.make(arrangement, application, tensors)

src/ntops/kernels/isinf.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import functools
2+
3+
import ninetoothed
4+
from ninetoothed import Tensor
5+
6+
from ntops.kernels.element_wise import arrangement
7+
8+
9+
def application(input, output):
10+
pos_result = input == float("+inf")
11+
neg_result = input == float("-inf")
12+
output = pos_result or neg_result # noqa: F841
13+
14+
15+
@functools.cache
16+
def make(ndim):
17+
return ninetoothed.make(arrangement, application, (Tensor(ndim), Tensor(ndim)))

src/ntops/kernels/isnan.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import functools
2+
3+
import ninetoothed
4+
from ninetoothed import Tensor
5+
6+
from ntops.kernels.element_wise import arrangement
7+
8+
9+
def application(input, output):
10+
output = input != input # noqa: F841
11+
12+
13+
@functools.cache
14+
def make(ndim):
15+
return ninetoothed.make(arrangement, application, (Tensor(ndim), Tensor(ndim)))

src/ntops/kernels/le.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import functools
2+
3+
import ninetoothed
4+
from ninetoothed import Tensor
5+
6+
from ntops.kernels.element_wise import arrangement
7+
8+
9+
def application(input, other, output):
10+
output = input <= other # noqa: F841
11+
12+
13+
@functools.cache
14+
def make(ndim):
15+
tensors = (Tensor(ndim), Tensor(ndim), Tensor(ndim))
16+
17+
return ninetoothed.make(arrangement, application, tensors)

src/ntops/kernels/lt.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import functools
2+
3+
import ninetoothed
4+
from ninetoothed import Tensor
5+
6+
from ntops.kernels.element_wise import arrangement
7+
8+
9+
def application(input, other, output):
10+
output = input < other # noqa: F841
11+
12+
13+
@functools.cache
14+
def make(ndim):
15+
tensors = (Tensor(ndim), Tensor(ndim), Tensor(ndim))
16+
17+
return ninetoothed.make(arrangement, application, tensors)

0 commit comments

Comments
 (0)