= 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 |
---|---|---|
.. | ||
benchmarking | Loading commit data... | |
test_adt.py | Loading commit data... | |
test_any.py | Loading commit data... | |
test_autotvm_task_extraction.py | Loading commit data... | |
test_backend_compile_engine.py | Loading commit data... | |
test_backend_graph_runtime.py | Loading commit data... | |
test_backend_interpreter.py | Loading commit data... | |
test_cmp_op.py | Loading commit data... | |
test_cpp_build_module.py | Loading commit data... | |
test_debug.py | Loading commit data... | |
test_error_reporting.py | Loading commit data... | |
test_expr_functor.py | Loading commit data... | |
test_feature.py | Loading commit data... | |
test_ir_bind.py | Loading commit data... | |
test_ir_module.py | Loading commit data... | |
test_ir_nodes.py | Loading commit data... | |
test_ir_op.py | Loading commit data... | |
test_ir_parser.py | Loading commit data... | |
test_ir_text_printer.py | Loading commit data... | |
test_ir_well_formed.py | Loading commit data... | |
test_op_grad_level1.py | Loading commit data... | |
test_op_grad_level3.py | Loading commit data... | |
test_op_level1.py | Loading commit data... | |
test_op_level10.py | Loading commit data... | |
test_op_level2.py | Loading commit data... | |
test_op_level3.py | Loading commit data... | |
test_op_level4.py | Loading commit data... | |
test_op_level5.py | Loading commit data... | |
test_op_level6.py | Loading commit data... | |
test_param_dict.py | Loading commit data... | |
test_pass_alpha_equal.py | Loading commit data... | |
test_pass_alter_op_layout.py | Loading commit data... | |
test_pass_annotation.py | Loading commit data... | |
test_pass_canonicalize_cast.py | Loading commit data... | |
test_pass_check_kind.py | Loading commit data... | |
test_pass_combine_parallel_conv2d.py | Loading commit data... | |
test_pass_dead_code_elimination.py | Loading commit data... | |
test_pass_eliminate_common_subexpr.py | Loading commit data... | |
test_pass_eta_expand.py | Loading commit data... | |
test_pass_fold_constant.py | Loading commit data... | |
test_pass_fold_scale_axis.py | Loading commit data... | |
test_pass_fuse_ops.py | Loading commit data... | |
test_pass_gradient.py | Loading commit data... | |
test_pass_mac_count.py | Loading commit data... | |
test_pass_manager.py | Loading commit data... | |
test_pass_partial_eval.py | Loading commit data... | |
test_pass_quantize.py | Loading commit data... | |
test_pass_simplify_inference.py | Loading commit data... | |
test_pass_to_a_normal_form.py | Loading commit data... | |
test_pass_to_cps.py | Loading commit data... | |
test_pass_to_graph_normal_form.py | Loading commit data... | |
test_pass_unmatched_cases.py | Loading commit data... | |
test_pass_vars.py | Loading commit data... | |
test_py_converter.py | Loading commit data... | |
test_type_infer.py | Loading commit data... | |
test_type_solver.py | Loading commit data... | |
test_typecall.py | Loading commit data... | |
test_vm.py | Loading commit data... |