Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Confusing description on custom mutable operators #3175

Unanswered
hzhangxyz asked this question in Q&A
Discussion options

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 ! ?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /