Skip to content

Commit

Permalink
#5589: Add binary ops sweeps
Browse files Browse the repository at this point in the history
  • Loading branch information
“Nenad committed Mar 5, 2024
1 parent 5d283ea commit b3f80f4
Show file tree
Hide file tree
Showing 20 changed files with 673 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from loguru import logger
import random
import pytest
import torch
import ttnn

from tests.ttnn.utils_for_testing import assert_with_pcc
from tests.ttnn.python_api_testing.sweep_tests import ttnn_ops


def run_ldexp_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
torch.manual_seed(data_seed)

x = torch.Tensor(size=input_shape[0]).uniform_(-100, 100).to(torch.bfloat16)
y = torch.Tensor(size=input_shape[1]).uniform_(-100, 100).to(torch.bfloat16)

try:
# get ref result
ref_value = torch.ldexp(x, y)

x = ttnn_ops.setup_ttnn_tensor(x, device, dlayout[0], in_mem_config, dtype[0])
y = ttnn_ops.setup_ttnn_tensor(y, device, dlayout[1], in_mem_config, dtype[1])

tt_result = ttnn.ldexp(x, y)
tt_result = ttnn_ops.ttnn_tensor_to_torch(tt_result, output_mem_config)

except Exception as e:
logger.warning(f"Operation execution crashed")
raise e

assert len(tt_result.shape) == len(ref_value.shape)
assert tt_result.shape == ref_value.shape
assert_with_pcc(ref_value, tt_result, 0.99)


test_sweep_args = [
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat16],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat16, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
]


@pytest.mark.parametrize(
"input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed",
(test_sweep_args),
)
def test_ldexp(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
run_ldexp_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from loguru import logger
import random
import pytest
import torch
import ttnn

from tests.ttnn.utils_for_testing import assert_with_pcc
from tests.ttnn.python_api_testing.sweep_tests import ttnn_ops


def run_logaddexp_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
torch.manual_seed(data_seed)

x = torch.Tensor(size=input_shape[0]).uniform_(-100, 100).to(torch.bfloat16)
y = torch.Tensor(size=input_shape[1]).uniform_(-100, 100).to(torch.bfloat16)

try:
# get ref result
ref_value = torch.logaddexp(x, y)

x = ttnn_ops.setup_ttnn_tensor(x, device, dlayout[0], in_mem_config, dtype[0])
y = ttnn_ops.setup_ttnn_tensor(y, device, dlayout[1], in_mem_config, dtype[1])

tt_result = ttnn.logaddexp(x, y)
tt_result = ttnn_ops.ttnn_tensor_to_torch(tt_result, output_mem_config)

except Exception as e:
logger.warning(f"Operation execution crashed")
raise e

assert len(tt_result.shape) == len(ref_value.shape)
assert tt_result.shape == ref_value.shape
assert_with_pcc(ref_value, tt_result, 0.99)


test_sweep_args = [
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat16, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat16],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
]


@pytest.mark.parametrize(
"input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed",
(test_sweep_args),
)
def test_logaddexp(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
run_logaddexp_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from loguru import logger
import random
import pytest
import torch
import ttnn

from tests.ttnn.utils_for_testing import assert_with_pcc
from tests.ttnn.python_api_testing.sweep_tests import ttnn_ops


def run_logaddexp2_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
torch.manual_seed(data_seed)

x = torch.Tensor(size=input_shape[0]).uniform_(-100, 100).to(torch.bfloat16)
y = torch.Tensor(size=input_shape[1]).uniform_(-100, 100).to(torch.bfloat16)

try:
# get ref result
ref_value = torch.logaddexp2(x, y)

x = ttnn_ops.setup_ttnn_tensor(x, device, dlayout[0], in_mem_config, dtype[0])
y = ttnn_ops.setup_ttnn_tensor(y, device, dlayout[1], in_mem_config, dtype[1])

tt_result = ttnn.logaddexp2(x, y)
tt_result = ttnn_ops.ttnn_tensor_to_torch(tt_result, output_mem_config)

except Exception as e:
logger.warning(f"Operation execution crashed")
raise e

assert len(tt_result.shape) == len(ref_value.shape)
assert tt_result.shape == ref_value.shape
assert_with_pcc(ref_value, tt_result, 0.99)


test_sweep_args = [
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat16, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat16],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
]


@pytest.mark.parametrize(
"input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed",
(test_sweep_args),
)
def test_logaddexp2(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
run_logaddexp2_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from loguru import logger
import random
import pytest
import torch
import ttnn

from tests.ttnn.utils_for_testing import assert_with_pcc
from tests.ttnn.python_api_testing.sweep_tests import ttnn_ops


def run_and_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
torch.manual_seed(data_seed)

x = torch.Tensor(size=input_shape[0]).uniform_(-100, 100).to(torch.bfloat16)
y = torch.Tensor(size=input_shape[1]).uniform_(-100, 100).to(torch.bfloat16)

try:
# get ref result
ref_value = torch.logical_and(x, y)

x = ttnn_ops.setup_ttnn_tensor(x, device, dlayout[0], in_mem_config, dtype[0])
y = ttnn_ops.setup_ttnn_tensor(y, device, dlayout[1], in_mem_config, dtype[1])

tt_result = ttnn.logical_and(x, y)
tt_result = ttnn_ops.ttnn_tensor_to_torch(tt_result, output_mem_config)

except Exception as e:
logger.warning(f"Operation execution crashed")
raise e

assert len(tt_result.shape) == len(ref_value.shape)
assert tt_result.shape == ref_value.shape
assert_with_pcc(ref_value, tt_result, 0.99)


test_sweep_args = [
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat16],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat16, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
]


@pytest.mark.parametrize(
"input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed",
(test_sweep_args),
)
def test_and(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
run_and_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device)
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: © 2023 Tenstorrent Inc.

# SPDX-License-Identifier: Apache-2.0

from loguru import logger
import random
import pytest
import torch
import ttnn

from tests.ttnn.utils_for_testing import assert_with_pcc
from tests.ttnn.python_api_testing.sweep_tests import ttnn_ops


def run_or_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
torch.manual_seed(data_seed)

x = torch.Tensor(size=input_shape[0]).uniform_(-100, 100).to(torch.bfloat16)
y = torch.Tensor(size=input_shape[1]).uniform_(-100, 100).to(torch.bfloat16)

try:
# get ref result
ref_value = torch.logical_or(x, y)

x = ttnn_ops.setup_ttnn_tensor(x, device, dlayout[0], in_mem_config, dtype[0])
y = ttnn_ops.setup_ttnn_tensor(y, device, dlayout[1], in_mem_config, dtype[1])

tt_result = ttnn.logical_or(x, y)
tt_result = ttnn_ops.ttnn_tensor_to_torch(tt_result, output_mem_config)

except Exception as e:
logger.warning(f"Operation execution crashed")
raise e

assert len(tt_result.shape) == len(ref_value.shape)
assert tt_result.shape == ref_value.shape
assert_with_pcc(ref_value, tt_result, 0.99)


test_sweep_args = [
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat16],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat16, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
(
[(160, 128), (160, 128)],
[ttnn.bfloat8_b, ttnn.bfloat8_b],
[ttnn.TILE_LAYOUT, ttnn.TILE_LAYOUT],
(ttnn.DRAM_MEMORY_CONFIG),
(ttnn.DRAM_MEMORY_CONFIG),
4171614,
),
]


@pytest.mark.parametrize(
"input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed",
(test_sweep_args),
)
def test_or(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device):
run_or_tests(input_shape, dtype, dlayout, in_mem_config, output_mem_config, data_seed, device)
Loading

0 comments on commit b3f80f4

Please sign in to comment.