Make add.Scalar manual_cpp_binding#49203
Conversation
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 4ce76d0 (more details on the Dr. CI page):
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions to the (internal) Dr. CI Users group. This comment has been revised 59 times. |
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 2f3710a Pull Request resolved: #49203
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
|
Looks like it doesn't work |
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
|
Updated with a different approach. One downside here is that if you hit the native:: kernel you're still going to end up doing two dispatches. Might need to do some tricky codegen stuff to get around that problem. |
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 5fc5408 Pull Request resolved: #49203
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: af46773 Pull Request resolved: #49203
robieta
left a comment
There was a problem hiding this comment.
This looks reasonable. What is the plan as more kernels become structured? (manually do this, teach the codegen, etc.)
Also, can you benchmark the change? Skipping a dispatch should be a strict improvement, but we should get in the habit of confirming.
Is the two dispatches here referring to the fact that you have one dispatch for |
Nope, it's the extra dispatch from at::add(Tensor, Tensor). (In the old version of this code, predating the parent of commit of this PR, this was an at::native::add call, so no cost.) |
No plan yet. This diff is pretty short and so in the mid term I might just do all of these kernels this way. |
|
Benchmark: Control: Before: 849190 (This experiment is expected to show no diff.) Python scalar add Before: 1986043 (This experiment is expected to show no diff, as wrapping is supposed to happen in Python bindings bypassing relevant C++) C++ scalar add (expected to exercise) Before: 1726143 Example from benchmark suite Before: 1751566 |
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though. Signed-off-by: Edward Z. Yang <ezyang@fb.com> [ghstack-poisoned]
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 2665c12 Pull Request resolved: #49203
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D25594995](https://our.internmc.facebook.com/intern/diff/D25594995) [ghstack-poisoned]
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 4dafba6 Pull Request resolved: #49203
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D25594995](https://our.internmc.facebook.com/intern/diff/D25594995) [ghstack-poisoned]
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: fb705e4 Pull Request resolved: #49203
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D25594995](https://our.internmc.facebook.com/intern/diff/D25594995) [ghstack-poisoned]
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 3c13d75 Pull Request resolved: #49203
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D25594995](https://our.internmc.facebook.com/intern/diff/D25594995) [ghstack-poisoned]
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Differential Revision: [D25594995](https://our.internmc.facebook.com/intern/diff/D25594995) [ghstack-poisoned]
The comment on native_functions.yaml claims this is just to solve a C++ API problem. If this is true, we don't actually need this in schema, and all I need to do is just manually replicate the API in the C++ bindings. Seeing if this indeed works. If this does work, it solves a performance problem on add.Scalar where I introduced an extra redispatch. If it doesn't work I'll try something else. Signed-off-by: Edward Z. Yang <ezyang@fb.com> ghstack-source-id: 3bcda2f Pull Request resolved: #49203
|
On further reflection, if this isn't fixing a concrete performance problem (which it isn't), I'd rather not copy paste If we do #50953 that would also solve these problems, with less code duplication. So I think this is not worth it for now. |
Stack from ghstack:
Manually do add.Scalar binding, skipping dispatch when you call into it from C++. This doesn't help if you directly get to the kernel via JIT interpreter though.
Signed-off-by: Edward Z. Yang ezyang@fb.com
Differential Revision: D25594995