-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for absolute opeartion #1406
Conversation
python/tvm/intrin.py
Outdated
y : Expr | ||
The result. | ||
""" | ||
return call_pure_intrin(x.dtype, "fabs", x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add support dispatching integer values, implement this function in the c++ side.
Expr tvm::abs(Expr x) {
if (x.type().is_int()) {
return select(x >= make_zero(x.type()), x, -x);
} else if (x.type().is_float()) {
return call_pure_intrin("fabs")...
} else if (x.type().is_uint()) {
return x;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation should go to here https://github.com/dmlc/tvm/blob/master/include/tvm/ir_operator.h#L61
topi/include/topi/elemwise.h
Outdated
@@ -35,6 +35,7 @@ TOPI_DECLARE_UNARY_OP(floor); | |||
TOPI_DECLARE_UNARY_OP(ceil); | |||
TOPI_DECLARE_UNARY_OP(round); | |||
TOPI_DECLARE_UNARY_OP(trunc); | |||
TOPI_DECLARE_UNARY_OP(fabs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
topi function name needs to be consistent with numpy, absolute.
@masahi @zhreshold Can you please review. |
@tqchen thanks for review comments, i will work on it and update. |
Is there an |
dc4bb4b
to
fc7804a
Compare
@zhreshold numpy has aliased 'np.abs' and 'np.absolute'. Now I have kept same name 'abs' to be consistent with numpy, TF, mxnet, onnx. |
@tqchen I have addressed review comments, pls review again. |
@@ -71,6 +70,24 @@ inline Expr pow(Expr x, Expr y) { | |||
return ir::Call::make(x.type(), "pow", { x, y }, ir::Call::PureIntrinsic); | |||
} | |||
|
|||
/*! | |||
* \brief Calculate absolute value of x, elementwise | |||
* \param x The input data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add \return
python/tvm/intrin.py
Outdated
y : Expr | ||
The result. | ||
""" | ||
return call_pure_intrin(x.dtype, "fabs", x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to call abs c++ function here, instead of calling intrinsic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you guide me, how can i make a call from tvm python to tvm cpp function? Can you give me any example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tvm.abs !!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you will need to register functions, and they will appear on the registered namespace. Checkout e.g. https://github.com/dmlc/tvm/blob/master/src/api/api_ir.cc#L76 try register abs under make.abs, and call it from there
fc7804a
to
e1b1731
Compare
@tqchen I have registered absolute op as make.abs in api_ir.cc. Pls check. |
Thanks @srkreddy1238 @zhreshold for code reviews and @PariksheetPinjari909 for contributing the code, this is now merged! |
This PR adds support for absolute operation.