-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[7102][fb_bootcamp] Moved Gesv to ATen #9742
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
Conversation
aten/src/ATen/native/Gesv.cpp
Outdated
| if (!batched) { | ||
| Tensor A_; | ||
| Tensor b_; | ||
| return _gesv_single_helper(self, A, b_, A_); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
ssnl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_gesv_single_helper doesn't work for cuda. _th_gesv_single isn't removed.
ssnl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to remove thc gesv code too.
aten/src/ATen/native/cuda/Gesv.cu
Outdated
| ALLOCATE_ARRAY(info_array, magma_int_t, 1, result0); | ||
| ALLOCATE_ARRAY(ipiv_array, magma_int_t*, 1, result0); | ||
|
|
||
| magmaGesvBatched<scalar_t>( |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
test failure still looks legit |
|
@pytorchbot retest this please |
aten/src/ATen/native/Gesv.cpp
Outdated
| AT_DISPATCH_FLOATING_TYPES(self.type(), "gesv", [&]{ | ||
| auto A_ptr = result1.data<scalar_t>(); | ||
| auto b_ptr = result0.data<scalar_t>(); | ||
| auto ipiv = at::empty({bx}, result0.type().toScalarType(kInt)); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| CPU: _gesv_helper_cpu | ||
| CUDA: _gesv_helper_cuda | ||
|
|
||
| - func: _gesv_single(Tensor self, Tensor A) -> (Tensor, Tensor) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
@pytorchbot retest this please |
ssnl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks great! Some small nits.
aten/src/ATen/native/Gesv.cpp
Outdated
|
|
||
| std::tuple<Tensor&,Tensor&> gesv_out( | ||
| Tensor& solution, Tensor& lu, const Tensor& self, const Tensor& A) { | ||
| Tensor& result0, Tensor& result1, const Tensor& self, const Tensor& A) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| - func: gesv(Tensor self, Tensor A) -> (Tensor, Tensor) | ||
|
|
||
| - func: gesv_out(Tensor solution, Tensor lu, Tensor self, Tensor A) -> (Tensor, Tensor) | ||
| - func: gesv_out(Tensor result0, Tensor result1, Tensor self, Tensor A) -> (Tensor, Tensor) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| - name: _gesv_single(Tensor self, Tensor A) | ||
| self: gesv_backward_self(grad, self, A) | ||
| A: gesv_backward_A(grad, self, A, solution) | ||
| A: gesv_backward_A(grad, self, A, result0) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/native/cuda/Gesv.cu
Outdated
| return std::tuple<Tensor,Tensor>(b_working_copy, A_working_copy); | ||
| } | ||
|
|
||
| std::tuple<Tensor&,Tensor&> _gesv_single_out_cuda(Tensor& result0, Tensor& result1, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SsnL has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
aten/src/ATen/native/cuda/Gesv.cu
Outdated
| int info; | ||
| int* ipiv; | ||
|
|
||
| result1 = A.t().clone(); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/native/cuda/Gesv.cu
Outdated
| "compilation. Please rebuild with MAGMA."); | ||
| #else | ||
| int64_t bx = self.size(0); | ||
| int64_t by = (self.dim() == 1) ? 1 : self.size(1); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/native/Gesv.h
Outdated
| (long long)A.size(0), (long long)A.size(1)); | ||
| } else if (A.size(0) != self.size(0)) { | ||
| AT_ERROR("A,B size incompatible - A has %ld " | ||
| "rows, B has %ld cols", A.size(0), self.size(0)); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, @animesht! I had a few minor comments and questions, in particular:
- As @ssnl mentioned, it would be nice if we could rename (result0, result1) to (solution, lu) (or whatever the ordering is) if the code generation allows for it.
2) Tensors sent into the magma/lapack gesv bindings are required to be in column-major format: I'm not sure if thenvm, this is fine!.t().clone()that is being done is sufficient for this
aten/src/ATen/native/Gesv.cpp
Outdated
| int64_t by = (self.dim() == 1) ? 1 : self.size(1); | ||
| int info = 0; | ||
|
|
||
| result1 = A.t().clone(); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
animesht has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
aten/src/ATen/native/Gesv.cpp
Outdated
| * - clone and copy input_tensor.t() to output_tensor (same tensor) | ||
| * b) &input_tensor != &output_tensor: | ||
| * - copy input_tensor.t() to output_tensor | ||
| */ |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/native/cuda/Gesv.cu
Outdated
| AT_ERROR("gesv: MAGMA library not found in " | ||
| "compilation. Please rebuild with MAGMA."); | ||
| #else | ||
| /* See Gesv.cpp for comments */ |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
zou3519
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't gone through the code in detail yet. I left some comments on refactoring the code to be a little nicer
facebook-github-bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
animesht has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@pytorchbot retest this please |
aten/src/ATen/native/Gesv.h
Outdated
| * (i) &in == &out: copy in.t().clone() to out (same tensor) | ||
| * (ii) &in != &out: copy in.t() to out | ||
| */ | ||
| static inline void prepareIOTensors( |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/native/Gesv.h
Outdated
| */ | ||
| static inline void prepareIOTensors( | ||
| const Tensor& in, Tensor& out, Tensor& temp, | ||
| int64_t& x, int64_t& y) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| * Before passing pointers to Lapack, we need to ensure that these pointers | ||
| * represent Fortran-contiguous tensors in column-major format | ||
| * | ||
| * Cases: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| * (ii) for 2D matrices, .t_() represents their column-major format | ||
| * | ||
| * Before passing pointers to Lapack, we need to ensure that these pointers | ||
| * represent Fortran-contiguous tensors in column-major format |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| * copy the buffer to the output tensor. | ||
| * | ||
| * 2) out.t() is contiguous: | ||
| * (i) &in == &out: use out.data() as is. Do nothing |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| // view potential 1D `in` as 2D | ||
| auto in_t = in.view({x, y}).t_(); | ||
|
|
||
| if (!out_tc && !out.is_contiguous() && out_correct_shape) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/native/Gesv.cpp
Outdated
| Tensor temp_sol; | ||
| Tensor temp_lu; | ||
| prepareTensorsForLapack(self, sol, temp_sol); | ||
| prepareTensorsForLapack(A, lu, temp_lu); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/native/Gesv.cpp
Outdated
| prepareTensorsForLapack(A, lu, temp_lu); | ||
|
|
||
| AT_DISPATCH_FLOATING_TYPES(self.type(), "gesv", [&]{ | ||
| const int64_t bx = sol.size(0); |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
ping @animesht :) |
|
Addressed most comments @zou3519 . Still need to add the tests for each case to Hoping for that to come back up soon, otherwise I can rewrite those and add them |
|
@zou3519 added tests for all cases. Can I get a codeowner review? |
|
This got superseded by #6100 |
#7102
Moved _gesv_single and _gesv_single_out to ATen