-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: mouliraj-mcw <[email protected]>
- Loading branch information
1 parent
24b210a
commit 95f8ddc
Showing
15 changed files
with
224 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
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
58 changes: 58 additions & 0 deletions
58
tt_metal/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/ckernel_sfpu_fmod.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,58 @@ | ||
// 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" | ||
#include "ckernel_sfpu_converter.h" | ||
#include "ckernel_sfpu_recip.h" | ||
|
||
using namespace sfpi; | ||
namespace ckernel { | ||
namespace sfpu { | ||
|
||
template <bool APPROXIMATION_MODE, int ITERATIONS = 8> | ||
inline void calculate_fmod(const uint value, const uint recip) { | ||
|
||
// SFPU microcode | ||
Converter c_value; | ||
c_value.u = value; | ||
vFloat s = c_value.f; | ||
s = sfpi::abs(s); | ||
|
||
c_value.u = recip; | ||
vFloat recip_val = c_value.f; | ||
recip_val = sfpi::abs(recip_val); | ||
|
||
#pragma GCC unroll 0 | ||
for (int d = 0; d < ITERATIONS; d++) { | ||
vFloat val = dst_reg[0]; | ||
vFloat v = sfpi::abs(val); | ||
|
||
vFloat quotient = v*recip_val; | ||
|
||
vInt tmp = float_to_int16(quotient); //TODO: Replace float_to_int16 to float_to_int32 once it is available | ||
vFloat newquotient= int32_to_float(tmp); | ||
v_if (newquotient > quotient){ | ||
newquotient = newquotient - 1; | ||
} | ||
v_endif; | ||
|
||
v = v - newquotient * s; | ||
v = setsgn(v, val); | ||
|
||
v_if(s==0){ | ||
v = std::numeric_limits<float>::quiet_NaN(); | ||
} | ||
v_endif; | ||
|
||
dst_reg[0] = v; | ||
dst_reg++; | ||
} | ||
} | ||
|
||
} // namespace sfpu | ||
} // 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 |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
#include "ckernel_sfpu_recip.h" | ||
|
||
using namespace sfpi; | ||
|
||
namespace ckernel { | ||
namespace sfpu { | ||
|
||
|
30 changes: 30 additions & 0 deletions
30
tt_metal/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/llk_math_eltwise_unary_sfpu_fmod.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,30 @@ | ||
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "ckernel_sfpu_fmod.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_fmod_init() { | ||
llk_math_eltwise_unary_sfpu_init<SfpuType::fmod, APPROXIMATE>(); | ||
} | ||
|
||
template <bool APPROXIMATE> | ||
inline void llk_math_eltwise_unary_sfpu_fmod(uint dst_index, uint param0, uint param1, int vector_mode = (int)VectorMode::RC) { | ||
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>( | ||
ckernel::sfpu::calculate_fmod<APPROXIMATE>, | ||
dst_index, | ||
vector_mode, | ||
param0, | ||
param1); | ||
} | ||
|
||
} // 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 |
---|---|---|
|
@@ -81,5 +81,6 @@ enum SfpuType { | |
floor, | ||
left_shift, | ||
remainder, | ||
fmod, | ||
unused, | ||
}; |
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,47 @@ | ||
// 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_fmod.h" | ||
#define MAIN math_main() | ||
#define MATH(x) x | ||
#else | ||
#define MATH(x) | ||
#endif | ||
|
||
|
||
|
||
namespace ckernel { | ||
|
||
/** | ||
* Performs element-wise fmod computation on input x by y , where x is each element of a tile | ||
* in DST register at index tile_index. The input can be of float data type. 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 fmod operation | uint32_t | Must be less than the size of the DST register buffer | True | | ||
* | param0 | Denominator value to perform fmod operation | uint32_t | | True | | ||
* | param1 | Reciprocal of param0, calculated on-host | uint32_t | | False | | ||
*/ | ||
|
||
|
||
ALWI void fmod_tile(uint32_t idst, uint32_t param0, uint32_t param1) { | ||
MATH((llk_math_eltwise_unary_sfpu_fmod<APPROX>(idst, param0, param1))); | ||
} | ||
|
||
/** | ||
* Please refer to documentation for any_init. | ||
*/ | ||
ALWI void fmod_tile_init() { MATH((llk_math_eltwise_unary_sfpu_fmod_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