-
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.
- Loading branch information
Showing
12 changed files
with
255 additions
and
21 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
49 changes: 49 additions & 0 deletions
49
tt_metal/hw/ckernels/grayskull/metal/llk_api/llk_sfpu/ckernel_sfpu_softplus.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,49 @@ | ||
// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "ckernel.h" | ||
#include "ckernel_defs.h" | ||
#include "ckernel_sfpu_converter.h" | ||
#include "ckernel_sfpu_exp.h" | ||
#include "ckernel_sfpu_log.h" | ||
|
||
using namespace sfpi; | ||
|
||
namespace ckernel { | ||
namespace sfpu { | ||
|
||
template <bool APPROXIMATION_MODE> | ||
inline void calculate_softplus_body(vFloat beta, vFloat beta_reciprocal, vFloat threshold) { | ||
vFloat a = dst_reg[0]; | ||
v_if(a < threshold) { | ||
exp_init<APPROXIMATION_MODE, false>(); | ||
a = calculate_exponential_body<APPROXIMATION_MODE>(a * beta) + 1.00f; | ||
|
||
log_init<APPROXIMATION_MODE>(); | ||
dst_reg[0] = a; | ||
calculate_log_body<false>(0); | ||
a = beta_reciprocal * dst_reg[0]; | ||
} | ||
v_endif; | ||
dst_reg[0] = a; | ||
} | ||
|
||
template <bool APPROXIMATION_MODE, int ITERATIONS = 6> | ||
inline void calculate_softplus(uint param0, uint param1, uint param2) { | ||
vFloat beta = Converter::to_float(param0); | ||
vFloat beta_reciprocal = Converter::to_float(param1); | ||
vFloat threshold = Converter::to_float(param2); | ||
for (int d = 0; d < ITERATIONS; d++) { | ||
calculate_softplus_body<APPROXIMATION_MODE>(beta, beta_reciprocal, threshold); | ||
dst_reg++; | ||
} | ||
} | ||
|
||
template <bool APPROXIMATION_MODE> | ||
void softplus_init() {} | ||
|
||
} // namespace sfpu | ||
} // namespace ckernel |
29 changes: 29 additions & 0 deletions
29
tt_metal/hw/ckernels/grayskull/metal/llk_api/llk_sfpu/llk_math_eltwise_unary_sfpu_softplus.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: © 2024 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "ckernel_sfpu_softplus.h" | ||
#include "llk_math_eltwise_unary_sfpu_3_param.h" | ||
#include "llk_math_eltwise_unary_sfpu_init.h" | ||
|
||
namespace ckernel { | ||
|
||
template <bool APPROXIMATE> | ||
inline void llk_math_eltwise_unary_sfpu_softplus_init() { | ||
llk_math_eltwise_unary_sfpu_init<SfpuType::softplus, APPROXIMATE>(); | ||
} | ||
|
||
template <bool APPROXIMATE> | ||
inline void llk_math_eltwise_unary_sfpu_softplus( | ||
uint dst_index, uint param0, uint param1, uint param2, int vector_mode = (int)VectorMode::RC) { | ||
llk_math_eltwise_unary_sfpu_3_param<APPROXIMATE>( | ||
ckernel::sfpu::calculate_softplus<APPROXIMATE>, | ||
ckernel::sfpu::calculate_softplus<APPROXIMATE>, | ||
dst_index, | ||
vector_mode, | ||
param0, param1, param2); | ||
} | ||
|
||
} // namespace ckernel |
49 changes: 49 additions & 0 deletions
49
tt_metal/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/ckernel_sfpu_softplus.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,49 @@ | ||
// SPDX-FileCopyrightText: © 2023 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "ckernel.h" | ||
#include "ckernel_defs.h" | ||
#include "ckernel_sfpu_converter.h" | ||
#include "ckernel_sfpu_exp.h" | ||
#include "ckernel_sfpu_log.h" | ||
|
||
using namespace sfpi; | ||
|
||
namespace ckernel { | ||
namespace sfpu { | ||
|
||
template <bool APPROXIMATION_MODE> | ||
inline void calculate_softplus_body(vFloat beta, vFloat beta_reciprocal, vFloat threshold) { | ||
vFloat a = dst_reg[0]; | ||
v_if(a < threshold) { | ||
exp_init<APPROXIMATION_MODE, false>(); | ||
a = calculate_exponential_body<APPROXIMATION_MODE>(a * beta) + 1.00f; | ||
|
||
log_init<APPROXIMATION_MODE>(); | ||
dst_reg[0] = a; | ||
calculate_log_body<false>(0); | ||
a = beta_reciprocal * dst_reg[0]; | ||
} | ||
v_endif; | ||
dst_reg[0] = a; | ||
} | ||
|
||
template <bool APPROXIMATION_MODE, int ITERATIONS = 8> | ||
inline void calculate_softplus(uint param0, uint param1, uint param2) { | ||
vFloat beta = Converter::to_float(param0); | ||
vFloat beta_reciprocal = Converter::to_float(param1); | ||
vFloat threshold = Converter::to_float(param2); | ||
for (int d = 0; d < ITERATIONS; d++) { | ||
calculate_softplus_body<APPROXIMATION_MODE>(beta, beta_reciprocal, threshold); | ||
dst_reg++; | ||
} | ||
} | ||
|
||
template <bool APPROXIMATION_MODE> | ||
void softplus_init() {} | ||
|
||
} // namespace sfpu | ||
} // namespace ckernel |
29 changes: 29 additions & 0 deletions
29
...tal/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/llk_math_eltwise_unary_sfpu_softplus.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_softplus.h" | ||
#include "llk_math_eltwise_unary_sfpu_3_param.h" | ||
#include "llk_math_eltwise_unary_sfpu_init.h" | ||
|
||
namespace ckernel { | ||
|
||
template <bool APPROXIMATE> | ||
inline void llk_math_eltwise_unary_sfpu_softplus_init() { | ||
llk_math_eltwise_unary_sfpu_init<SfpuType::softplus, APPROXIMATE>(); | ||
} | ||
|
||
template <bool APPROXIMATE> | ||
inline void llk_math_eltwise_unary_sfpu_softplus( | ||
uint dst_index, uint param0, uint param1, uint param2, int vector_mode = (int)VectorMode::RC) { | ||
llk_math_eltwise_unary_sfpu_3_param<APPROXIMATE>( | ||
ckernel::sfpu::calculate_softplus<APPROXIMATE>, | ||
ckernel::sfpu::calculate_softplus<APPROXIMATE>, | ||
dst_index, | ||
vector_mode, | ||
param0, param1, param2); | ||
} | ||
|
||
} // 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 |
---|---|---|
|
@@ -73,6 +73,7 @@ enum SfpuType { | |
unary_ne, | ||
unary_gt, | ||
unary_lt, | ||
softplus, | ||
tiled_prod, | ||
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
35 changes: 35 additions & 0 deletions
35
tt_metal/include/compute_kernel_api/eltwise_unary/softplus.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,35 @@ | ||
// 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_softplus.h" | ||
#define MAIN math_main() | ||
#define MATH(x) x | ||
#else | ||
#define MATH(x) | ||
#endif | ||
|
||
|
||
|
||
namespace ckernel { | ||
|
||
/** | ||
* TODO! | ||
*/ | ||
ALWI void softplus_tile(uint32_t idst, uint32_t param0, uint32_t param1, uint32_t param2) { | ||
MATH(( llk_math_eltwise_unary_sfpu_softplus<APPROX>(idst, param0, param1, param2) )); | ||
} | ||
|
||
/** | ||
* Please refer to documentation for any_init. | ||
*/ | ||
ALWI void softplus_tile_init() { | ||
MATH(( llk_math_eltwise_unary_sfpu_softplus_init<APPROX>() )); | ||
} | ||
|
||
} // namespace ckernel |