-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#13385: Direct kernel function for
ttnn.round
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
tt_metal/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/ckernel_sfpu_round.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,39 @@ | ||
// SPDX-FileCopyrightText: © 2024 Tenstorrent Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#pragma once | ||
|
||
#include "ckernel.h" | ||
#include "ckernel_defs.h" | ||
#include "sfpi.h" | ||
|
||
using namespace sfpi; | ||
|
||
namespace ckernel { | ||
namespace sfpu { | ||
|
||
inline vInt float_to_int31(vFloat v) { | ||
vInt q = float_to_int16(v * 0x1p-15f, 0); | ||
vInt r = float_to_int16(v - int32_to_float(q, 0) * 0x1p15f, 0); | ||
return (q << 15) + r; | ||
} | ||
|
||
inline vFloat round_even(vFloat v) { | ||
v_if (sfpi::abs(v) < 0x1p30f) { | ||
v = int32_to_float(float_to_int31(v), 0); | ||
} | ||
v_endif; | ||
return v; | ||
} | ||
|
||
template <bool APPROX, int ITERATIONS = 8> | ||
void calculate_round() { | ||
for (int _ = 0; _ < ITERATIONS; ++_) { | ||
*dst_reg = round_even(*dst_reg); | ||
++dst_reg; | ||
} | ||
} | ||
|
||
} // namespace sfpu | ||
} // namespace ckernel |