import asc
from asc.runtime import config
def setup_function():
config.set_platform(config.Backend.Model, check=False)
def test_adds_kernel(mock_launcher_run):
@asc.jit
def adds_kernel():
x_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECIN, addr=0, tile_size=512)
z_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECOUT, addr=0, tile_size=512)
asc.adds(z_local, x_local, 1, count=512)
params = asc.UnaryRepeatParams(1, 1, 8, 8)
asc.adds(z_local, x_local, 1, mask=512, repeat_times=1, repeat_params=params)
uint64_max = 2**64 - 1
mask = [uint64_max, uint64_max]
asc.adds(z_local, x_local, 1, mask=mask, repeat_times=1, repeat_params=params)
adds_kernel[1]()
assert mock_launcher_run.call_count == 1
def test_leaky_relu_kernel(mock_launcher_run):
@asc.jit
def leaky_relu_kernel():
x_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECIN, addr=0, tile_size=512)
z_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECOUT, addr=0, tile_size=512)
asc.leaky_relu(z_local, x_local, 1, count=512)
params = asc.UnaryRepeatParams(1, 1, 8, 8)
asc.leaky_relu(z_local, x_local, 1, mask=512, repeat_times=1, repeat_params=params)
uint64_max = 2**64 - 1
mask = [uint64_max, uint64_max]
asc.leaky_relu(z_local, x_local, 1, mask=mask, repeat_times=1, repeat_params=params)
leaky_relu_kernel[1]()
assert mock_launcher_run.call_count == 1
def test_muls_kernel(mock_launcher_run):
@asc.jit
def muls_kernel():
x_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECIN, addr=0, tile_size=512)
z_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECOUT, addr=0, tile_size=512)
asc.muls(z_local, x_local, 1, count=512)
params = asc.UnaryRepeatParams(1, 1, 8, 8)
asc.muls(z_local, x_local, 1, mask=512, repeat_times=1, repeat_params=params)
uint64_max = 2**64 - 1
mask = [uint64_max, uint64_max]
asc.muls(z_local, x_local, 1, mask=mask, repeat_times=1, repeat_params=params)
muls_kernel[1]()
assert mock_launcher_run.call_count == 1
def test_maxs_kernel(mock_launcher_run):
@asc.jit
def maxs_kernel():
x_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECIN, addr=0, tile_size=512)
z_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECOUT, addr=0, tile_size=512)
asc.maxs(z_local, x_local, 1, count=512)
params = asc.UnaryRepeatParams(1, 1, 8, 8)
asc.maxs(z_local, x_local, 1, mask=512, repeat_times=1, repeat_params=params)
uint64_max = 2**64 - 1
mask = [uint64_max, uint64_max]
asc.maxs(z_local, x_local, 1, mask=mask, repeat_times=1, repeat_params=params)
maxs_kernel[1]()
assert mock_launcher_run.call_count == 1
def test_mins_kernel(mock_launcher_run):
@asc.jit
def mins_kernel():
x_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECIN, addr=0, tile_size=512)
z_local = asc.LocalTensor(dtype=asc.float16, pos=asc.TPosition.VECOUT, addr=0, tile_size=512)
asc.mins(z_local, x_local, 1, count=512)
params = asc.UnaryRepeatParams(1, 1, 8, 8)
asc.mins(z_local, x_local, 1, mask=512, repeat_times=1, repeat_params=params)
uint64_max = 2**64 - 1
mask = [uint64_max, uint64_max]
asc.mins(z_local, x_local, 1, mask=mask, repeat_times=1, repeat_params=params)
mins_kernel[1]()
assert mock_launcher_run.call_count == 1
def test_shift_left_kernel(mock_launcher_run):
@asc.jit
def shift_left_kernel():
x_local = asc.LocalTensor(dtype=asc.int16, pos=asc.TPosition.VECIN, addr=0, tile_size=512)
z_local = asc.LocalTensor(dtype=asc.int16, pos=asc.TPosition.VECOUT, addr=0, tile_size=512)
asc.shift_left(z_local, x_local, 1, count=512)
params = asc.UnaryRepeatParams(1, 1, 8, 8)
asc.shift_left(z_local, x_local, 1, mask=512, repeat_times=1, repeat_params=params)
uint64_max = 2**64 - 1
mask = [uint64_max, uint64_max]
asc.shift_left(z_local, x_local, 1, mask=mask, repeat_times=1, repeat_params=params)
shift_left_kernel[1]()
assert mock_launcher_run.call_count == 1
def test_shift_right_kernel(mock_launcher_run):
@asc.jit
def shift_right_kernel():
x_local = asc.LocalTensor(dtype=asc.int16, pos=asc.TPosition.VECIN, addr=0, tile_size=512)
z_local = asc.LocalTensor(dtype=asc.int16, pos=asc.TPosition.VECOUT, addr=0, tile_size=512)
asc.shift_right(z_local, x_local, 1, count=512)
params = asc.UnaryRepeatParams(1, 1, 8, 8)
asc.shift_right(z_local, x_local, 1, mask=512, repeat_times=1, repeat_params=params)
uint64_max = 2**64 - 1
mask = [uint64_max, uint64_max]
asc.shift_right(z_local, x_local, 1, mask=mask, repeat_times=1, repeat_params=params)
shift_right_kernel[1]()
assert mock_launcher_run.call_count == 1