-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8683: Add Unary left shift support for WH_B0
- Loading branch information
Showing
15 changed files
with
242 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
tests/tt_eager/python_api_testing/sweep_tests/pytests/tt_dnn/test_left_shift.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# SPDX-FileCopyrightText: © 2023-24 Tenstorrent Inc. | ||
|
||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
import torch | ||
from functools import partial | ||
import tt_lib as ttl | ||
|
||
|
||
from tests.tt_eager.python_api_testing.sweep_tests import ( | ||
comparison_funcs, | ||
generation_funcs, | ||
) | ||
from tests.tt_eager.python_api_testing.sweep_tests.run_pytorch_ci_tests import ( | ||
run_single_pytorch_test, | ||
) | ||
from models.utility_functions import skip_for_grayskull | ||
|
||
mem_configs = [ | ||
ttl.tensor.MemoryConfig(ttl.tensor.TensorMemoryLayout.INTERLEAVED, ttl.tensor.BufferType.DRAM), | ||
ttl.tensor.MemoryConfig(ttl.tensor.TensorMemoryLayout.INTERLEAVED, ttl.tensor.BufferType.L1), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"scalar", | ||
(3, 2, 1, 0), | ||
) | ||
@pytest.mark.parametrize( | ||
"input_shapes", | ||
[ | ||
[[1, 1, 32, 32]], | ||
[[4, 3, 32, 32]], | ||
[[2, 2, 32, 32]], | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"dst_mem_config", | ||
mem_configs, | ||
) | ||
@skip_for_grayskull("#TODO: GS implementation needs to be done") | ||
class TestLeftShift: | ||
def test_run_left_shift_op( | ||
self, | ||
scalar, | ||
input_shapes, | ||
dst_mem_config, | ||
device, | ||
): | ||
datagen_func = [ | ||
generation_funcs.gen_func_with_cast(partial(generation_funcs.gen_rand, low=-100, high=100), torch.int) | ||
] | ||
test_args = generation_funcs.gen_default_dtype_layout_device(input_shapes)[0] | ||
test_args.update( | ||
{ | ||
"value": scalar, | ||
"dtype": [(ttl.tensor.DataType.INT32)], | ||
} | ||
) | ||
test_args.update({"output_mem_config": dst_mem_config}) | ||
comparison_func = comparison_funcs.comp_equal | ||
|
||
run_single_pytorch_test( | ||
"eltwise-left_shift", | ||
input_shapes, | ||
datagen_func, | ||
comparison_func, | ||
device, | ||
test_args, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
tt_metal/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/ckernel_sfpu_left_shift.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "ckernel.h" | ||
#include "ckernel_defs.h" | ||
#include "noc_nonblocking_api.h" | ||
|
||
using namespace sfpi; | ||
|
||
namespace ckernel { | ||
namespace sfpu { | ||
|
||
template <bool APPROXIMATION_MODE, int ITERATIONS = 8> | ||
inline void calculate_left_shift(const uint shift_amt) { | ||
#pragma GCC unroll 0 | ||
for (int d = 0; d < ITERATIONS; d++) { | ||
vInt val = dst_reg[0]; | ||
vInt v = val; | ||
|
||
val = val << shift_amt; | ||
val = setsgn(val, v); | ||
dst_reg[0] = val; | ||
|
||
dst_reg++; | ||
} | ||
} | ||
|
||
} // namespace sfpu | ||
} // namespace ckernel |
29 changes: 29 additions & 0 deletions
29
...l/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/llk_math_eltwise_unary_sfpu_left_shift.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "ckernel_sfpu_left_shift.h" | ||
#include "llk_math_eltwise_unary_sfpu_params.h" | ||
#include "llk_math_eltwise_unary_sfpu_init.h" | ||
|
||
namespace ckernel { | ||
|
||
// New LLK SFPU APIs | ||
|
||
template <bool APPROXIMATE> | ||
inline void llk_math_eltwise_unary_sfpu_left_shift_init() { | ||
llk_math_eltwise_unary_sfpu_init<SfpuType::left_shift, APPROXIMATE>(); | ||
} | ||
|
||
template <bool APPROXIMATE> | ||
inline void llk_math_eltwise_unary_sfpu_left_shift(uint dst_index, uint param0, int vector_mode = (int)VectorMode::RC) { | ||
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>( | ||
ckernel::sfpu::calculate_left_shift<APPROXIMATE>, | ||
dst_index, | ||
vector_mode, | ||
param0); | ||
} | ||
|
||
} // namespace ckernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,5 +77,6 @@ enum SfpuType { | |
tiled_prod, | ||
right_shift, | ||
floor, | ||
left_shift, | ||
unused, | ||
}; |
46 changes: 46 additions & 0 deletions
46
tt_metal/include/compute_kernel_api/eltwise_unary/left_shift.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
|
||
#include "compute_kernel_api/common_globals.h" | ||
#ifdef TRISC_MATH | ||
#include "llk_math_eltwise_unary_sfpu_left_shift.h" | ||
#define MAIN math_main() | ||
#define MATH(x) x | ||
#else | ||
#define MATH(x) | ||
#endif | ||
|
||
|
||
|
||
namespace ckernel { | ||
|
||
/** | ||
* Performs element-wise left_shift computation on input x by y bits , where x is each element of a tile | ||
* in DST register at index tile_index. The input must be of int data type only. The value is provided as const param0 The DST register buffer must be in | ||
* acquired state via *acquire_dst* call. This call is blocking and is only | ||
* available on the compute engine. | ||
* | ||
* Return value: None | ||
* | ||
* | Argument | Description | Type | Valid | ||
* Range | Required | | ||
* |-----------------|----------------------------------------------------------------------------|----------|-------------------------------------------------------|----------| | ||
* | idst | The index of the tile in DST register buffer to perform the computation on | uint32_t | Must be | ||
* less than the size of the DST register buffer | True | | param0 | The value the output is if the input | ||
* is greater than 0 | uint32_t | | True | | ||
*/ | ||
ALWI void left_shift_tile(uint32_t idst, uint32_t param0) { | ||
MATH((llk_math_eltwise_unary_sfpu_left_shift<APPROX>(idst, param0))); | ||
} | ||
|
||
/** | ||
* Please refer to documentation for any_init. | ||
*/ | ||
ALWI void left_shift_tile_init() { MATH((llk_math_eltwise_unary_sfpu_left_shift_init<APPROX>())); } | ||
|
||
|
||
} // namespace ckernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters