You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TORCH_LIBRARY(extension_cpp, m) {
m.def("mymuladd(Tensor a, Tensor b, float c) -> Tensor");
m.def("mymul(Tensor a, Tensor b) -> Tensor");
// New!
m.def("myadd_out(Tensor a, Tensor b, Tensor(a!) out) -> ()");
}
TORCH_LIBRARY_IMPL(extension_cpp, CPU, m) {
m.impl("mymuladd", &mymuladd_cpu);
m.impl("mymul", &mymul_cpu);
// New!
m.impl("myadd_out", &myadd_out_cpu);
}
It says
You may wish to author a custom operator that mutates its inputs. Use Tensor(a!) to specify each mutable Tensor in the schema; otherwise, there will be undefined behavior. If there are multiple mutated Tensors, use different names (for example, Tensor(a!), Tensor(b!), Tensor(c!)) for each mutable Tensor.
But I do not know why we need a name a or b for mutable tensor, it seems myadd_out(Tensor a, Tensor b, Tensor(!) out) -> () is enough to represent out is mutable, what is the meaning of the name after ! ?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am trying to write a custom operator, but the document in https://pytorch.org/tutorials/advanced/cpp_custom_ops.html#creating-mutable-operators is confusing at:
It says
But I do not know why we need a name
a
orb
for mutable tensor, it seemsmyadd_out(Tensor a, Tensor b, Tensor(!) out) -> ()
is enough to representout
is mutable, what is the meaning of the name after!
?Beta Was this translation helpful? Give feedback.
All reactions