= 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 |
---|---|---|
.. | ||
datatype | Loading commit data... | |
llvm | Loading commit data... | |
opt | Loading commit data... | |
spirv | Loading commit data... | |
stackvm | Loading commit data... | |
build_common.h | Loading commit data... | |
build_module.cc | Loading commit data... | |
codegen.cc | Loading commit data... | |
codegen_aocl.cc | Loading commit data... | |
codegen_c.cc | Loading commit data... | |
codegen_c.h | Loading commit data... | |
codegen_c_host.cc | Loading commit data... | |
codegen_c_host.h | Loading commit data... | |
codegen_cuda.cc | Loading commit data... | |
codegen_cuda.h | Loading commit data... | |
codegen_metal.cc | Loading commit data... | |
codegen_metal.h | Loading commit data... | |
codegen_opencl.cc | Loading commit data... | |
codegen_opencl.h | Loading commit data... | |
codegen_opengl.cc | Loading commit data... | |
codegen_opengl.h | Loading commit data... | |
codegen_source_base.cc | Loading commit data... | |
codegen_source_base.h | Loading commit data... | |
codegen_vhls.cc | Loading commit data... | |
codegen_vhls.h | Loading commit data... | |
intrin_rule.cc | Loading commit data... | |
intrin_rule.h | Loading commit data... | |
intrin_rule_aocl.cc | Loading commit data... | |
intrin_rule_cuda.cc | Loading commit data... | |
intrin_rule_metal.cc | Loading commit data... | |
intrin_rule_opencl.cc | Loading commit data... | |
intrin_rule_opengl.cc | Loading commit data... | |
intrin_rule_vhls.cc | Loading commit data... | |
source_module.cc | Loading commit data... |