Skip to content

Commit

Permalink
#15483: Binary sfpu ops for FP32
Browse files Browse the repository at this point in the history
  • Loading branch information
KalaivaniMCW committed Dec 9, 2024
1 parent 880f3d5 commit 5cc6b18
Show file tree
Hide file tree
Showing 27 changed files with 2,485 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"input_shape": [
{"value": 10000, "shape": [128]},
],
"input_a_dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
"input_b_dtype": [ttnn.bfloat16, ttnn.bfloat8_b],
"input_a_dtype": [ttnn.bfloat16],
"input_b_dtype": [ttnn.bfloat16],
"input_a_layout": [ttnn.TILE_LAYOUT],
"input_b_layout": [ttnn.TILE_LAYOUT],
"input_a_memory_config": [ttnn.DRAM_MEMORY_CONFIG, ttnn.L1_MEMORY_CONFIG],
Expand Down Expand Up @@ -54,12 +54,12 @@ def run(
) -> list:
torch.manual_seed(0)
torch_input_tensor_a = gen_func_with_cast_tt(
partial(torch_random, low=-100, high=100, dtype=torch.float32), input_a_dtype
partial(torch_random, low=-10, high=10, dtype=torch.bfloat16), input_a_dtype
)(input_shape["shape"])

value = input_shape["value"]
golden_function = ttnn.get_golden_function(ttnn.pow)
torch_output_tensor = golden_function(torch_input_tensor_a, value)
torch_output_tensor = golden_function(value, torch_input_tensor_a)

input_tensor_a = ttnn.from_torch(
torch_input_tensor_a,
Expand All @@ -70,8 +70,8 @@ def run(
)

start_time = start_measuring_time()
output_tensor = ttnn.pow(value, exponent=input_tensor_a, memory_config=output_memory_config)
output_tensor = ttnn.to_torch(output_tensor)
output_tensor = ttnn.pow(value, input_tensor_a, memory_config=output_memory_config)
output_tensor = ttnn.to_torch(output_tensor, torch_rank=len(torch_input_tensor_a.shape))
e2e_perf = stop_measuring_time(start_time)

return [check_with_pcc(torch_output_tensor, output_tensor, 0.999), e2e_perf]
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ def test_run_div(
if round_mode in ["trunc", "floor"]:
pytest.skip("does not work for Grayskull -skipping")
if accurate_mode == False: # If input_b is non-zero tensor
pytest.skip("will be enabled after #15780 is resolved")
datagen_func = [
generation_funcs.gen_func_with_cast(
partial(generation_funcs.gen_rand, low=-1e6, high=1e6), torch.bfloat16
partial(generation_funcs.gen_rand, low=-10, high=10), torch.bfloat16
)
] + [
generation_funcs.gen_func_with_cast(
partial(generation_funcs.gen_rand, low=-1e6, high=-1), torch.bfloat16
partial(generation_funcs.gen_rand, low=-10, high=-10), torch.bfloat16
)
]
else:
datagen_func = [
generation_funcs.gen_func_with_cast(
partial(generation_funcs.gen_rand, low=-1e6, high=1e6), torch.bfloat16
partial(generation_funcs.gen_rand, low=-10, high=10), torch.bfloat16
)
] * 2
test_args = generation_funcs.gen_default_dtype_layout_device(input_shapes)[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
]


@pytest.mark.skip(reason="This test will be enabled after #15780 is resolved")
@pytest.mark.parametrize(
"input_shapes",
[
Expand All @@ -44,6 +45,7 @@ def test_run_fmod(
dst_mem_config,
device,
):
# The ranges need to be retested and updated for respective dtypes in issue #15780
datagen_func = [
generation_funcs.gen_func_with_cast(partial(generation_funcs.gen_rand, low=-100, high=100), torch.bfloat16)
] + [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,11 @@ def test_nei_ttnn(input_shapes, scalar, device):
)
@skip_for_grayskull("#ToDo: GS implementation needs to be done for remainder")
def test_binary_gcd_ttnn(input_shapes, device):
in_data1, input_tensor1 = data_gen_with_range_int(input_shapes, -1024, 1024, device)
in_data2, input_tensor2 = data_gen_with_range_int(input_shapes, -1024, 1024, device)
in_data1 = torch.randint(-100, 100, input_shapes, dtype=torch.int32)
in_data2 = torch.randint(-80, 180, input_shapes, dtype=torch.int32)
input_tensor1 = ttnn.from_torch(in_data1, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device)
input_tensor2 = ttnn.from_torch(in_data2, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device)

output_tensor = ttnn.gcd(input_tensor1, input_tensor2)
golden_function = ttnn.get_golden_function(ttnn.gcd)
golden_tensor = golden_function(in_data1, in_data2)
Expand All @@ -986,8 +989,10 @@ def test_binary_gcd_ttnn(input_shapes, device):
)
@skip_for_grayskull("#ToDo: GS implementation needs to be done for remainder")
def test_binary_lcm_ttnn(input_shapes, device):
in_data1, input_tensor1 = data_gen_with_range_int(input_shapes, -1024, 1024, device)
in_data2, input_tensor2 = data_gen_with_range_int(input_shapes, -1024, 1024, device)
in_data1 = torch.randint(-100, 100, input_shapes, dtype=torch.int32)
in_data2 = torch.randint(-80, 180, input_shapes, dtype=torch.int32)
input_tensor1 = ttnn.from_torch(in_data1, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device)
input_tensor2 = ttnn.from_torch(in_data2, dtype=ttnn.bfloat16, layout=ttnn.TILE_LAYOUT, device=device)
output_tensor = ttnn.lcm(input_tensor1, input_tensor2)
golden_function = ttnn.get_golden_function(ttnn.lcm)
golden_tensor = golden_function(in_data1, in_data2)
Expand Down
Loading

0 comments on commit 5cc6b18

Please sign in to comment.