"""
"""
import pypto
import torch
import numpy as np
from st.pypto_test import TestBuilder
def op_relu(params, a, b):
n, m = a.shape
view_shape, tile_shape = params
for b_idx in pypto.loop(int(np.ceil(n / view_shape[0])), name="LOOP_RELU_L0", idx_name="b_idx"):
for s_idx in pypto.loop(int(np.ceil(m / view_shape[1])), name="LOOP_RELU_L1", idx_name="s_idx"):
tile_a = pypto.view(a, view_shape, [b_idx * view_shape[0], s_idx * view_shape[1]], valid_shape=[
pypto.min(pypto.symbolic_scalar(n) - b_idx * view_shape[0], pypto.symbolic_scalar(n)),
pypto.min(pypto.symbolic_scalar(m) - b_idx * view_shape[1], pypto.symbolic_scalar(m))])
pypto.set_vec_tile_shapes(tile_shape[0], tile_shape[1])
tile_a.move(pypto.relu(tile_a))
pypto.assemble(tile_a, [b_idx * view_shape[0], s_idx * view_shape[1]], b)
def op_relu_golden(param, a, b):
return torch.relu(a)
class ReluTest(TestBuilder):
def __init__(self, params: tuple, kernel, kernel_golden, tiling: int):
super().__init__(params, kernel, kernel_golden, tiling)
def get_input_from_param(self):
n, m = self.tiling * 1, self.tiling * 1
a_tensor = torch.rand(n, m, dtype=torch.float32) * 100
self.setup_inputs(a_tensor)
self.set_tol(rtol=3e-3, atol=3e-3)
return (a_tensor, )
def test():
st = ReluTest(((16, 16), (8, 8)), op_relu, op_relu_golden, tiling=32)
st()