Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5424: Clean up Sfpu Sign kernel api #16809

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions tests/tt_metal/tt_metal/llk/test_sfpu_compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const map<string, std::map<string, string>> sfpu_op_to_op_name = {
{"sigmoid", {{"SFPU_OP_CHAIN_0", "sigmoid_tile_init(); sigmoid_tile(0);"}}},
{"log", {{"SFPU_OP_CHAIN_0", "log_tile_init(); log_tile(0);"}}},
{"tanh", {{"SFPU_OP_CHAIN_0", "tanh_tile_init(); tanh_tile(0);"}}},
{"sign", {{"SFPU_OP_CHAIN_0", "sign_tile_init(); sign_tile(0);"}}},
};

bfloat16 sfpu_function(const string& op_name, const bfloat16& input) {
Expand All @@ -61,6 +62,8 @@ bfloat16 sfpu_function(const string& op_name, const bfloat16& input) {
return bfloat16(logf(input.to_float()));
} else if (op_name == "tanh") {
return bfloat16(std::tanh(input.to_float()));
} else if (op_name == "sign") {
return bfloat16((0.0f < input.to_float()) ? 1.0f : ((input.to_float() < 0.0f) ? -1.0f : 0.0f));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked what it does when you give it -0.0f ?

} else {
TT_THROW("Unsupported op_name in test");
return bfloat16(0.0f);
Expand Down Expand Up @@ -253,14 +256,16 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple(1, "sigmoid"),
std::make_tuple(1, "log"),
std::make_tuple(1, "tanh"),
std::make_tuple(1, "sign"),
std::make_tuple(4, "relu"),
std::make_tuple(4, "exponential"),
std::make_tuple(4, "reciprocal"),
std::make_tuple(4, "gelu"),
std::make_tuple(4, "sqrt"),
std::make_tuple(4, "sigmoid"),
std::make_tuple(4, "log"),
std::make_tuple(4, "tanh")));
std::make_tuple(4, "tanh"),
std::make_tuple(4, "sign")));
class SingleCoreSingleDeviceSfpuParameterizedApproxFixture
: public DeviceFixture,
public testing::WithParamInterface<std::tuple<size_t, string>> {};
Expand Down Expand Up @@ -302,14 +307,16 @@ INSTANTIATE_TEST_SUITE_P(
std::make_tuple(1, "sigmoid"),
std::make_tuple(1, "log"),
std::make_tuple(1, "tanh"),
std::make_tuple(1, "sign"),
std::make_tuple(4, "relu"),
std::make_tuple(4, "exponential"),
std::make_tuple(4, "reciprocal"),
std::make_tuple(4, "gelu"),
std::make_tuple(4, "sqrt"),
std::make_tuple(4, "sigmoid"),
std::make_tuple(4, "log"),
std::make_tuple(4, "tanh")));
std::make_tuple(4, "tanh"),
std::make_tuple(4, "sign")));

TEST_F(DeviceFixture, DISABLED_TensixMultiContinguousCoreSingleTileSfpuApproxCompute) {
CoreRange core_range({0, 0}, {1, 0});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,8 @@ namespace ckernel {
namespace sfpu {

template <bool APPROXIMATION_MODE, int ITERATIONS = 8>
inline void calculate_sign() {
// All params are in FP16 format
for (int d = 0; d < ITERATIONS; d++) {
vFloat v = dst_reg[0];
vFloat result = vConst1;
v_if(v < 0.0f) { result = vConstNeg1; }
v_elseif(v > 0.0f) { result = vConst1; }
v_else { result = vConst0; }
v_endif;

dst_reg[0] = result;
dst_reg++;
}
inline void calculate_sign(const uint exponent_size_8) {
_calculate_sign_<APPROXIMATION_MODE, ITERATIONS>(ITERATIONS, exponent_size_8);
}

} // namespace sfpu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ inline void llk_math_eltwise_unary_sfpu_sign_init() {
}

template <bool APPROXIMATE>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment here explaining the exponent_size_8 flag and why its defaulted to 1?

inline void llk_math_eltwise_unary_sfpu_sign(uint dst_index, int vector_mode = (int)VectorMode::RC) {
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>(ckernel::sfpu::calculate_sign<APPROXIMATE>, dst_index, vector_mode);
inline void llk_math_eltwise_unary_sfpu_sign(
uint dst_index, int vector_mode = (int)VectorMode::RC, uint exponent_size_8 = 1) {
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>(
ckernel::sfpu::calculate_sign<APPROXIMATE>, dst_index, vector_mode, exponent_size_8);
}

} // namespace ckernel
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,8 @@ namespace ckernel {
namespace sfpu {

template <bool APPROXIMATION_MODE, int ITERATIONS = 8>
inline void calculate_sign() {
// All params are in FP16 format
for (int d = 0; d < ITERATIONS; d++) {
vFloat v = dst_reg[0];
vFloat result = vConst1;
v_if(v < 0.0f) { result = vConstNeg1; }
v_elseif(v > 0.0f) { result = vConst1; }
v_else { result = vConst0; }
v_endif;

dst_reg[0] = result;
dst_reg++;
}
inline void calculate_sign(const uint exponent_size_8) {
_calculate_sign_<APPROXIMATION_MODE, ITERATIONS>(exponent_size_8);
}

} // namespace sfpu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ inline void llk_math_eltwise_unary_sfpu_sign_init() {
}

template <bool APPROXIMATE>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, a small comment about exponent_size_8

inline void llk_math_eltwise_unary_sfpu_sign(uint dst_index, int vector_mode = (int)VectorMode::RC) {
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>(ckernel::sfpu::calculate_sign<APPROXIMATE>, dst_index, vector_mode);
inline void llk_math_eltwise_unary_sfpu_sign(
uint dst_index, int vector_mode = (int)VectorMode::RC, uint exponent_size_8 = 1) {
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>(
ckernel::sfpu::calculate_sign<APPROXIMATE>, dst_index, vector_mode, exponent_size_8);
}

} // namespace ckernel
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,8 @@ namespace ckernel {
namespace sfpu {

template <bool APPROXIMATION_MODE, int ITERATIONS = 8>
inline void calculate_sign() {
// All params are in FP16 format
for (int d = 0; d < ITERATIONS; d++) {
vFloat v = dst_reg[0];
vFloat result = vConst1;
v_if(v < 0.0f) { result = vConstNeg1; }
v_elseif(v > 0.0f) { result = vConst1; }
v_else { result = vConst0; }
v_endif;

dst_reg[0] = result;
dst_reg++;
}
inline void calculate_sign(const uint exponent_size_8) {
_calculate_sign_<APPROXIMATION_MODE, ITERATIONS>(ITERATIONS, exponent_size_8);
}

} // namespace sfpu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ inline void llk_math_eltwise_unary_sfpu_sign_init() {
}

template <bool APPROXIMATE>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

inline void llk_math_eltwise_unary_sfpu_sign(uint dst_index, int vector_mode = (int)VectorMode::RC) {
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>(ckernel::sfpu::calculate_sign<APPROXIMATE>, dst_index, vector_mode);
inline void llk_math_eltwise_unary_sfpu_sign(
uint dst_index, int vector_mode = (int)VectorMode::RC, uint exponent_size_8 = 1) {
llk_math_eltwise_unary_sfpu_params<APPROXIMATE>(
ckernel::sfpu::calculate_sign<APPROXIMATE>, dst_index, vector_mode, exponent_size_8);
}

} // namespace ckernel
Loading