-
Notifications
You must be signed in to change notification settings - Fork 4.3k
-
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:
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 ! ?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment