= Motivation It's useful to expose the tvm::reinterpret functionality to Relay/TOPI users, as this allows them to build (fused) operators leveraging the bitwise reinterpretation of an operator. An example is approximate transcendental functions, which can be implemented similar to: ```.py def C(x): return relay.expr.const(x, "float32") def approx_exp(x): x = relay.minimum(relay.maximum(x, C(-88.0)), C(88.0)) x = C(127.0) + x * C(1.44269504) xf = relay.floor(x) i = relay.cast(xf, "int32") x = x - xf Y = C(0.99992522) + x * (C(0.69583354) + x * (C(0.22606716) + x * C(0.078024523))) exponent = relay.left_shift(i, relay.expr.const(23, "int32")) exponent = relay.reinterpret(exponent, "float32") return exponent * Y def approx_sigmoid(x): # <2.0e-5 absolute error over [-5, 5] y = approx_exp(x) return y / (y + C(1.0)) def approx_tanh(x): # <4.0e-5 absolute error over [-5, 5] x = x * C(2.0) y = approx_exp(x) return (y - C(1.0)) / (y + C(1.0)) ``` See unit tests for implementations of these approximate transendentals.
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
common.py | Loading commit data... | |
test_topi_basic.py | Loading commit data... | |
test_topi_batch_matmul.py | Loading commit data... | |
test_topi_bitserial_conv2d.py | Loading commit data... | |
test_topi_bitserial_conv2d_rasp.py | Loading commit data... | |
test_topi_bitserial_dense.py | Loading commit data... | |
test_topi_bnn.py | Loading commit data... | |
test_topi_broadcast.py | Loading commit data... | |
test_topi_clip.py | Loading commit data... | |
test_topi_conv2d_NCHWc.py | Loading commit data... | |
test_topi_conv2d_hwcn.py | Loading commit data... | |
test_topi_conv2d_int8.py | Loading commit data... | |
test_topi_conv2d_nchw.py | Loading commit data... | |
test_topi_conv2d_nhwc.py | Loading commit data... | |
test_topi_conv2d_nhwc_pack_int8.py | Loading commit data... | |
test_topi_conv2d_transpose_nchw.py | Loading commit data... | |
test_topi_conv2d_winograd.py | Loading commit data... | |
test_topi_deformable_conv2d.py | Loading commit data... | |
test_topi_dense.py | Loading commit data... | |
test_topi_depthwise_conv2d.py | Loading commit data... | |
test_topi_depthwise_conv2d_back_input.py | Loading commit data... | |
test_topi_depthwise_conv2d_back_weight.py | Loading commit data... | |
test_topi_dilate.py | Loading commit data... | |
test_topi_group_conv2d.py | Loading commit data... | |
test_topi_group_conv2d_NCHWc_int8.py | Loading commit data... | |
test_topi_l2norm.py | Loading commit data... | |
test_topi_lrn.py | Loading commit data... | |
test_topi_math.py | Loading commit data... | |
test_topi_matmul.py | Loading commit data... | |
test_topi_pooling.py | Loading commit data... | |
test_topi_reduce.py | Loading commit data... | |
test_topi_relu.py | Loading commit data... | |
test_topi_reorg.py | Loading commit data... | |
test_topi_resize.py | Loading commit data... | |
test_topi_softmax.py | Loading commit data... | |
test_topi_sort.py | Loading commit data... | |
test_topi_sparse.py | Loading commit data... | |
test_topi_tensor.py | Loading commit data... | |
test_topi_transform.py | Loading commit data... | |
test_topi_upsampling.py | Loading commit data... | |
test_topi_util.py | Loading commit data... | |
test_topi_vision.py | Loading commit data... |