forked from flagos-ai/FlagGems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfmod.py
More file actions
51 lines (36 loc) · 1.26 KB
/
Copy pathfmod.py
File metadata and controls
51 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import logging
import triton
import triton.language as tl
from flag_gems.utils import pointwise_dynamic
from flag_gems.utils.triton_lang_extension import fmod as _fmod
logger = logging.getLogger(__name__)
@pointwise_dynamic(promotion_methods=[(0, 1, "DEFAULT")])
@triton.jit
def fmod_func(x, y):
# Convert to float32 for computation to avoid libdevice float16/bfloat16 issues
dtype = x.dtype
x_fp32 = x.to(tl.float32)
y_fp32 = y.to(tl.float32)
result = _fmod(x_fp32, y_fp32)
return result.to(dtype)
@pointwise_dynamic(is_tensor=[True, False], promotion_methods=[(0, 1, "DEFAULT")])
@triton.jit
def fmod_func_tensor_scalar(x, y):
# Convert to float32 for computation to avoid libdevice float16/bfloat16 issues
dtype = x.dtype
x_fp32 = x.to(tl.float32)
y_fp32 = y.to(tl.float32)
result = _fmod(x_fp32, y_fp32)
return result.to(dtype)
def fmod_tensor(A, B):
logger.debug("GEMS FMOD_TENSOR")
return fmod_func(A, B)
def fmod_scalar(A, B):
logger.debug("GEMS FMOD_SCALAR")
return fmod_func_tensor_scalar(A, B)
def fmod_tensor_(A, B):
logger.debug("GEMS FMOD_TENSOR_")
return fmod_func(A, B, out0=A)
def fmod_scalar_(A, B):
logger.debug("GEMS FMOD_SCALAR_")
return fmod_func_tensor_scalar(A, B, out0=A)