gussmith23 commented on a change in pull request #5812:
URL: https://github.com/apache/incubator-tvm/pull/5812#discussion_r473444408
##########
File path: python/tvm/target/datatype.py
##########
@@ -135,8 +155,40 @@ def lower(op):
dtype = "uint" + str(t.bits)
if t.lanes > 1:
dtype += "x" + str(t.lanes)
- if isinstance(op, (_Cast, _FloatImm)):
- return tvm.tir.call_pure_extern(dtype, extern_func_name, op.value)
- return tvm.tir.call_pure_extern(dtype, extern_func_name, op.a, op.b)
+ if isinstance(op, _Cast):
+ src_bits = bit_length(op.value.dtype)
+ return call_pure_extern(dtype, extern_func_map[(src_bits,
t.bits)], op.value)
+ if isinstance(op, _FloatImm):
+ return call_pure_extern(dtype, extern_func_map[t.bits], op.value)
+ if isinstance(op, _Call):
+ return call_pure_extern(dtype, extern_func_map[t.bits], *op.args)
+ if isinstance(op, _BinaryOpExpr):
+ return call_pure_extern(dtype, extern_func_map[t.bits], op.a, op.b)
+
+ raise RuntimeError(f"lowering unsupported op: {op.astext()}")
return lower
+
+def bit_length(type_str):
+ t = DataType(type_str)
+ return t.bits
+
+def lower_ite(ite_intrin):
+ dtype = ite_intrin.dtype
+ t = tvm.DataType(dtype)
+ assert get_type_registered(t.type_code)
+ dtype = "uint" + str(t.bits)
+ if t.lanes > 1:
+ dtype += "x" + str(t.lanes)
+ return call_intrin(dtype, "tir.if_then_else", convert(ite_intrin.args[0]),
+ convert(ite_intrin.args[1]),
+ convert(ite_intrin.args[2]))
+
+def lower_call_pure_extern(op):
Review comment:
- [x] @gussmith23 Document
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]