Open jdh8 opened 2 weeks ago
Hi @jdh8 ,
I examined your approach and found that it doesn't address rounding to a specific number of decimal places (i.e., 2 or 3 decimal places).
Could you please share your thoughts on how this could be managed?
Thanks for pointing it out! I missed the parameter decimals
.
It can be managed with multiplication by 10n. To be specific,
round(x, n) = 10**-n * round(10**n * x)
I have two proposals:
roundeven(x)
as conceptually round(x, 0)
, and then make round(x, n)
on top of roundeven
. (Named after C23 roundeven
)round(x, n)
.Which approach looks better?
I think approach two would be more suitable, as it has a straightforward structure.
Rounding is only supported by Wormhole, and Wormhole, and Wormhole has the exact function
float_to_int16
if the value is in range. https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tt_metal/apis/kernel_apis/sfpu/llk.rst#wormhole-onlyHowever,
ttnn.round
is implemented as a combination ofttnn.floor
,ttnn.add
, etc. https://github.com/tenstorrent/tt-metal/blob/679b8d59834358e34a080cfa743b324930c8c364/ttnn/cpp/ttnn/operations/eltwise/unary/device/unary_composite_op.cpp#L640-L653Then in turn,
ttnn.floor
calls functions that effectively computesttnn.round
. https://github.com/tenstorrent/tt-metal/blob/679b8d59834358e34a080cfa743b324930c8c364/tt_metal/hw/ckernels/wormhole_b0/metal/llk_api/llk_sfpu/ckernel_sfpu_floor.h#L25-L26Rounding to a nearest integer is extremely useful for argument reduction. We can reuse a direct implementation in other mathematical functions (mostly elementary functions) such as:
ttnn.pow