import pytest
import triton
import triton.language as tl
import triton.language.extra.ascend.libdevice as libdevice
import test_common
import torch
import torch_npu
def torch_acosh(x0):
return torch.acosh(x0)
@triton.jit
def triton_acosh(in_ptr0, out_ptr0, XBLOCK : tl.constexpr, XBLOCK_SUB : tl.constexpr):
offset = tl.program_id(0) * XBLOCK
base1 = tl.arange(0, XBLOCK_SUB)
loops1: tl.constexpr = XBLOCK // XBLOCK_SUB
for loop1 in range(loops1):
x0 = offset + (loop1 * XBLOCK_SUB) + base1
tmp0 = tl.load(in_ptr0 + (x0), None)
tmp1 = libdevice.acosh(tmp0)
tl.store(out_ptr0 + (x0), tmp1, None)
@pytest.mark.parametrize('param_list',
[
['float32', (2, 4096, 8), 2, 32768, 1024],
['float16', (2, 4096, 8), 2, 32768, 1024],
['bfloat16', (2, 4096, 8), 2, 32768, 1024],
])
def test_acosh_common(param_list):
dtype, shape, ncore, xblock, xblock_sub = param_list
x0 = test_common.generate_tensor(shape, dtype).npu().abs() + 1.0
y_ref = torch_acosh(x0)
y_cal = torch.zeros(shape, dtype = eval('torch.' + dtype)).npu()
triton_acosh[ncore, 1, 1](x0, y_cal, xblock, xblock_sub)
test_common.validate_cmp(dtype, y_cal, y_ref)
@pytest.mark.parametrize('param_list',
[
['float32', (2, 4096, 8), 2, 32768, 1024],
['float16', (2, 4096, 8), 2, 32768, 1024],
['bfloat16', (2, 4096, 8), 2, 32768, 1024],
])
def test_acosh_special(param_list):
dtype, shape, ncore, xblock, xblock_sub = param_list
x0 = -test_common.generate_tensor(shape, dtype).npu().abs() + 1.0
y_ref = torch_acosh(x0)
y_cal = torch.zeros(shape, dtype = eval('torch.' + dtype)).npu()
triton_acosh[ncore, 1, 1](x0, y_cal, xblock, xblock_sub)
test_common.validate_cmp(dtype, y_cal, y_ref)