-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Move addcmul to Aten #22874
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
Closed
Closed
Move addcmul to Aten #22874
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
55920aa
Move addcmul to Aten (w/o Vec)
VitalyFedyunin 03bfa92
Adding Vec256
VitalyFedyunin e9406f4
Fix operator name
VitalyFedyunin 49db163
Merge branch 'master' of https://github.com/pytorch/pytorch into port…
VitalyFedyunin 984a9c4
Merge branch 'master' of https://github.com/pytorch/pytorch into port…
VitalyFedyunin a9d73d4
Fix code to match TensorIterator changes
VitalyFedyunin 9a50fc7
Merge branch 'master' of https://github.com/pytorch/pytorch into port…
VitalyFedyunin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // Ternary and higher-order pointwise operations | ||
| #include <ATen/native/PointwiseOps.h> | ||
|
|
||
| #include <ATen/ATen.h> | ||
| #include <ATen/NativeFunctions.h> | ||
| #include <ATen/MemoryOverlap.h> | ||
| #include <ATen/native/TensorIterator.h> | ||
|
|
||
| #ifdef BUILD_NAMEDTENSOR | ||
| #include <ATen/NamedTensorUtils.h> | ||
| #endif | ||
|
|
||
| namespace at { | ||
| namespace native { | ||
|
|
||
| Tensor addcmul_cpu( | ||
| const Tensor& self, | ||
| const Tensor& tensor1, | ||
| const Tensor& tensor2, | ||
| Scalar value) { | ||
| Tensor result = at::empty({0}, self.options()); | ||
| return at::addcmul_out(result, self, tensor1, tensor2, value); | ||
| } | ||
|
|
||
| Tensor& addcmul_cpu_( | ||
| Tensor& self, | ||
| const Tensor& tensor1, | ||
| const Tensor& tensor2, | ||
| Scalar value) { | ||
| return at::addcmul_out(self, self, tensor1, tensor2, value); | ||
| } | ||
|
|
||
| Tensor& addcmul_cpu_out( | ||
| Tensor& result, | ||
| const Tensor& self, | ||
| const Tensor& tensor1, | ||
| const Tensor& tensor2, | ||
| Scalar value) { | ||
| checkBackend("addcmul_cpu", result, self.type().backend()); | ||
| auto iter = at::TensorIterator(); | ||
| iter.check_and_add_output(result); | ||
| iter.add_input(self); | ||
| iter.add_input(tensor1); | ||
| iter.add_input(tensor2); | ||
| iter.build(); | ||
| addcmul_stub(kCPU, iter, value); | ||
| #ifdef BUILD_NAMEDTENSOR | ||
| at::namedinference::propagate_names(result, self); | ||
| #endif | ||
| return result; | ||
| } | ||
|
|
||
| DEFINE_DISPATCH(addcmul_stub); | ||
|
|
||
| } // namespace native | ||
| } // namespace at | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Ternary and higher-order pointwise operations | ||
| #pragma once | ||
|
|
||
| #include <ATen/ATen.h> | ||
| #include <ATen/native/DispatchStub.h> | ||
|
|
||
| namespace at { | ||
|
|
||
| struct TensorIterator; | ||
|
|
||
| namespace native { | ||
|
|
||
| using addcmul_fn = void (*)(TensorIterator&, Scalar scalar); | ||
|
|
||
| DECLARE_DISPATCH(addcmul_fn, addcmul_stub); | ||
| } // namespace native | ||
| } // namespace at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Ternary and higher-order pointwise operations | ||
| #include <ATen/ATen.h> | ||
|
|
||
| #include <ATen/Dispatch.h> | ||
| #include <ATen/native/PointwiseOps.h> | ||
| #include <ATen/native/TensorIterator.h> | ||
| #include <ATen/native/cpu/Loops.h> | ||
|
|
||
| namespace at { | ||
| namespace native { | ||
| namespace { | ||
|
|
||
| static void addcmul_cpu_kernel(TensorIterator& iter, Scalar value) { | ||
| ScalarType dtype = iter.dtype(0); | ||
| AT_DISPATCH_ALL_TYPES(dtype, "addcmul_cpu_out", [&] { | ||
| scalar_t scalar_val = value.to<scalar_t>(); | ||
| auto scalar_vec = Vec256<scalar_t>(scalar_val); | ||
| cpu_kernel_vec( | ||
| iter, | ||
| [=](scalar_t self_val, scalar_t t1_val, scalar_t t2_val) -> scalar_t { | ||
| return self_val + scalar_val * t1_val * t2_val; | ||
| }, | ||
| [=](Vec256<scalar_t> self_vec, | ||
| Vec256<scalar_t> t1_vec, | ||
| Vec256<scalar_t> t2_vec) { | ||
| return self_vec + scalar_vec * t1_vec * t2_vec; | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| } // anonymous namespace | ||
|
|
||
| REGISTER_DISPATCH(addcmul_stub, &addcmul_cpu_kernel); | ||
|
|
||
| } // namespace native | ||
| } // namespace at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.