wyc-ruiker commented on a change in pull request #8402:
URL: https://github.com/apache/tvm/pull/8402#discussion_r665320111
##########
File path: python/tvm/topi/cuda/tensorcore_alter_op.py
##########
@@ -147,30 +155,37 @@ def _dense_legalize(attrs, inputs, arg_types):
return None
candidates = [(16, 16, 16), (32, 16, 8), (8, 16, 32)]
- (dm, dk, dn), extra_flops_ratio = pad_to_tensorcore(M, K, N,
candidates)
-
- if extra_flops_ratio > 2:
- logger.info("dense pad_to_tensorcore skipped, extra_flops_ratio
%s", extra_flops_ratio)
+ elif dtype in ["int4", "uint4"]:
+ if M % 8 == 0 and K % 32 == 0 and N % 8 == 0:
+ # no need to pad
return None
-
- logger.info("dense pad_to_tensorcore, extra_flops_ratio %s",
extra_flops_ratio)
-
- if dm or dk:
- x_ = relay.nn.pad(x, pad_width=((0, dm), (0, dk)))
- else:
- x_ = x
- if dn or dk:
- y_ = relay.nn.pad(y, pad_width=((0, dn), (0, dk)))
- else:
- y_ = y
- out_ = relay.nn.dense(x_, y_)
- if dm or dn:
- original_out_shape = [x.value for x in output_tensor.shape]
- out = relay.strided_slice(out_, begin=[0, 0],
end=original_out_shape)
- else:
- out = out_
- return out
- return None
+ candidates = [(8, 32, 8)]
+ else:
+ return None
+
+ (dm, dk, dn), extra_flops_ratio = pad_to_tensorcore(M, K, N, candidates)
+
+ if extra_flops_ratio > 2:
+ logger.info("dense pad_to_tensorcore skipped, extra_flops_ratio %s",
extra_flops_ratio)
+ return None
+
+ logger.info("dense pad_to_tensorcore, extra_flops_ratio %s",
extra_flops_ratio)
+
+ if dm or dk:
+ x_ = relay.nn.pad(x, pad_width=((0, dm), (0, dk)))
+ else:
+ x_ = x
+ if dn or dk:
+ y_ = relay.nn.pad(y, pad_width=((0, dn), (0, dk)))
+ else:
+ y_ = y
+ out_ = relay.nn.dense(x_, y_, **new_attrs)
+ if dm or dn:
+ original_out_shape = [x.value for x in output_tensor.shape]
+ out = relay.strided_slice(out_, begin=[0, 0], end=original_out_shape)
+ else:
+ out = out_
+ return out
Review comment:
done.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]