Skip to content

Conversation

@ezyang
Copy link
Contributor

@ezyang ezyang commented Jul 18, 2018

  • THTensor now stores sizes_ and strides_ which is a std::vector<int64_t>
  • Anywhere a "public" API function made use of a int64_t* of sizes, I opted to just finagle it out of the tensor using THTensor_getSizePtr rather than try to rewrite all of these sites to use ArrayRef. They should use ArrayRef eventually, but not yet.
  • There are new utility functions for resizing sizes/strides in one go (THTensor_resizeDim), or replacing sizes and strides with completely new values (THTensor_setSizesAndStrides)
  • Anywhere you said t->size[n] = 0, we now say THTensor_setSizeAt(t, n, 0), ditto for strides
  • Anywhere you said t->size[n], we now say t->size(n) (coming soon: ditto for strides)

Previous review of just the std::vector change in #9518, but I'm planning to merge this all in one go.

Note for @gchanan: review from commit "ci" and after

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezyang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezyang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@ezyang
Copy link
Contributor Author

ezyang commented Jul 18, 2018

@pytorchbot retest this please

1 similar comment
@ezyang
Copy link
Contributor Author

ezyang commented Jul 18, 2018

@pytorchbot retest this please

@ezyang ezyang force-pushed the pr/size-codemod branch from e73250b to 12609bb Compare July 18, 2018 23:59
@ezyang
Copy link
Contributor Author

ezyang commented Jul 19, 2018

@pytorchbot retest this please

@ezyang ezyang force-pushed the pr/size-codemod branch from 12609bb to 95afe2e Compare July 19, 2018 01:44
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezyang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezyang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@cpuhrsch
Copy link
Contributor

Not sure if std::vector is a good longterm choice since size and stride is so short. It also can't be compiled into very efficient code. Ideally we'd template on that size and branch somewhere, at least that led to the best code within CPUApplyUtils.h. Otherwise SmartVector could be a good choice for now.

@ezyang
Copy link
Contributor Author

ezyang commented Jul 19, 2018

@cpuhrsch Yeah, some sort of inline size/stride is in the roadmap, but it's not blocking for the merge so I haven't done it. When we add a change like this some benchmarking will be needed.

Copy link
Contributor

@gchanan gchanan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you are just trying to figure out where you need the to put the no-strict-overflow? Also, why do you need it?

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

setup.py Outdated

This comment was marked as off-topic.

This comment was marked as off-topic.

CMakeLists.txt Outdated

This comment was marked as off-topic.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezyang is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

ezyang added 9 commits July 19, 2018 11:37
This patch was very carefully constructed to avoid having to modify
too many files; there are some obvious follow ups which I will
be hitting later.

- I didn't do stride.  But the change for stride should look
  very similar.

- I did NOT rename the field in question, so that direct
  accesses of the form foo->size[n] keep working.  I intend
  to do a codemod to fix all of these shortly.

- Anywhere a "public" API function made use of a int64_t*
  of sizes, I opted to just finagle it out of the tensor using
  THTensor_getSizePtr rather than try to rewrite all of these
  sites to use ArrayRef.  They should use ArrayRef eventually,
  but not yet.

- _THSizeDesc got an overload that understands ArrayRef (which
  a vector size is convertible to).  Eventually we should get
  rid of all of these functions (because ArrayRef is printable
  via the AT_ERROR macros), but not today.

- I ran into something very subtle in the implementation of sizes()
  for TensorDerived: I MUST use the dim as per Tensor::dim() (which
  correctly is zero for scalars), otherwise I'll give a nonsense
  sizes().  We can fix this eventually once Scalar is turned on
  internally.

- I added two new functions THTensor_resizeSize and THTensor_setSize.
  Maybe these are eventually worth deifying as methods in the Tensor class, but
  for now I'm keeping them out-of-line just in case.

Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
@ezyang ezyang force-pushed the pr/size-codemod branch from 63d650f to 93a7e61 Compare July 19, 2018 18:38
zdevito pushed a commit to zdevito/ATen that referenced this pull request Jul 19, 2018
…h std::vector (#9561)

Summary:
* THTensor now stores `sizes_` and `strides_` which is a `std::vector<int64_t>`
* Anywhere a "public" API function made use of a int64_t* of sizes, I opted to just finagle it out of the tensor using THTensor_getSizePtr rather than try to rewrite all of these sites to use ArrayRef. They should use ArrayRef eventually, but not yet.
* There are new utility functions for resizing sizes/strides in one go (THTensor_resizeDim), or replacing sizes and strides with completely new values (THTensor_setSizesAndStrides)
* Anywhere you said `t->size[n] = 0`, we now say `THTensor_setSizeAt(t, n, 0)`, ditto for strides
* Anywhere you said `t->size[n]`, we now say `t->size(n)` (coming soon: ditto for strides)

Previous review of just the `std::vector` change in #9518, but I'm planning to merge this all in one go.

Note for gchanan: review from commit "ci" and after
Pull Request resolved: pytorch/pytorch#9561

Reviewed By: cpuhrsch

Differential Revision: D8901926

Pulled By: ezyang

fbshipit-source-id: 483cf275060ab0a13845cba1ece39dd127142510
ezyang added a commit to ezyang/pytorch that referenced this pull request Jul 22, 2018
Summary:
This pops off `refcount_`, `storage_`, `storage_offset_`; there are now no more direct accesses to these fields and we can make them private (with appropriate friending).

Stacked on pytorch#9561
Pull Request resolved: pytorch#9591

Reviewed By: gchanan

Differential Revision: D8922246

Pulled By: gchanan

fbshipit-source-id: 63dd3eb9787c460373c3cc507886d3b0a30e7542
facebook-github-bot pushed a commit that referenced this pull request Jul 22, 2018
Summary:
Pull Request resolved: #9683

This pops off `refcount_`, `storage_`, `storage_offset_`; there are now no more direct accesses to these fields and we can make them private (with appropriate friending).

Stacked on #9561
Pull Request resolved: #9591

Reviewed By: SsnL

Differential Revision: D8922246

Pulled By: ezyang

fbshipit-source-id: dfae023d790e29ce652e2eab9a1628bbe97b318d
jramseyer pushed a commit to jramseyer/pytorch that referenced this pull request Jul 30, 2018
…h std::vector (pytorch#9561)

Summary:
* THTensor now stores `sizes_` and `strides_` which is a `std::vector<int64_t>`
* Anywhere a "public" API function made use of a int64_t* of sizes, I opted to just finagle it out of the tensor using THTensor_getSizePtr rather than try to rewrite all of these sites to use ArrayRef. They should use ArrayRef eventually, but not yet.
* There are new utility functions for resizing sizes/strides in one go (THTensor_resizeDim), or replacing sizes and strides with completely new values (THTensor_setSizesAndStrides)
* Anywhere you said `t->size[n] = 0`, we now say `THTensor_setSizeAt(t, n, 0)`, ditto for strides
* Anywhere you said `t->size[n]`, we now say `t->size(n)` (coming soon: ditto for strides)

Previous review of just the `std::vector` change in pytorch#9518, but I'm planning to merge this all in one go.

Note for gchanan: review from commit "ci" and after
Pull Request resolved: pytorch#9561

Reviewed By: cpuhrsch

Differential Revision: D8901926

Pulled By: ezyang

fbshipit-source-id: 483cf275060ab0a13845cba1ece39dd127142510
jramseyer pushed a commit to jramseyer/pytorch that referenced this pull request Jul 30, 2018
Summary:
Pull Request resolved: pytorch#9683

This pops off `refcount_`, `storage_`, `storage_offset_`; there are now no more direct accesses to these fields and we can make them private (with appropriate friending).

Stacked on pytorch#9561
Pull Request resolved: pytorch#9591

Reviewed By: SsnL

Differential Revision: D8922246

Pulled By: ezyang

fbshipit-source-id: dfae023d790e29ce652e2eab9a1628bbe97b318d
goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
…h std::vector (pytorch#9561)

Summary:
* THTensor now stores `sizes_` and `strides_` which is a `std::vector<int64_t>`
* Anywhere a "public" API function made use of a int64_t* of sizes, I opted to just finagle it out of the tensor using THTensor_getSizePtr rather than try to rewrite all of these sites to use ArrayRef. They should use ArrayRef eventually, but not yet.
* There are new utility functions for resizing sizes/strides in one go (THTensor_resizeDim), or replacing sizes and strides with completely new values (THTensor_setSizesAndStrides)
* Anywhere you said `t->size[n] = 0`, we now say `THTensor_setSizeAt(t, n, 0)`, ditto for strides
* Anywhere you said `t->size[n]`, we now say `t->size(n)` (coming soon: ditto for strides)

Previous review of just the `std::vector` change in pytorch#9518, but I'm planning to merge this all in one go.

Note for gchanan: review from commit "ci" and after
Pull Request resolved: pytorch#9561

Reviewed By: cpuhrsch

Differential Revision: D8901926

Pulled By: ezyang

fbshipit-source-id: 483cf275060ab0a13845cba1ece39dd127142510
goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
Summary:
Pull Request resolved: pytorch#9683

This pops off `refcount_`, `storage_`, `storage_offset_`; there are now no more direct accesses to these fields and we can make them private (with appropriate friending).

Stacked on pytorch#9561
Pull Request resolved: pytorch#9591

Reviewed By: SsnL

Differential Revision: D8922246

Pulled By: ezyang

fbshipit-source-id: dfae023d790e29ce652e2eab9a1628bbe97b318d
@ezyang ezyang added the merged label Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants