-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Make TensorOptions contain optional fields, optimize struct size #12103
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
Differential Revision: D10052523 Differential Version: 58936952
Differential Revision: D10052523 Differential Version: 58951676
Differential Revision: D10052523 Differential Version: 58957413
Differential Revision: D10052523 Differential Version: 58961023
Differential Revision: D10052523 Differential Version: 58965097
Differential Revision: D10052523 Differential Version: 59013668
|
CC also @gchanan, you asked for this! |
goldsborough
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.
I think this behavior could use some tests in test/cpp/api/tensor_options.cpp
aten/src/ATen/core/OptionsGuard.cpp
Outdated
| #else | ||
|
|
||
| TensorOptions DefaultTensorOptions::options_(/*use_thread_local_default_options=*/false); | ||
| static DefaultTensorOptions options_; |
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/core/OptionsGuard.h
Outdated
| /// to Windows and other compilers. | ||
| /// TODO: The inability to use optional in headers is no longer true | ||
| CAFFE2_API static TensorOptions& get(); | ||
| DefaultTensorOptions() {} |
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/core/OptionsGuard.h
Outdated
| DefaultTensorOptions(DefaultTensorOptions&&) = default; | ||
| DefaultTensorOptions& operator=(DefaultTensorOptions&&) = default; | ||
|
|
||
| ScalarType dtype() const { return dtype_; } |
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/core/OptionsGuard.h
Outdated
| bool requires_grad() const { return requires_grad_; } | ||
| bool is_variable() const { return is_variable_; } | ||
|
|
||
| DefaultTensorOptions& apply(const TensorOptions& options) { |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/core/OptionsGuard.h
Outdated
| ScalarType dtype() const { return dtype_; } | ||
| Device device() const { return device_; } | ||
| Layout layout() const { return layout_; } | ||
| bool requires_grad() const { return requires_grad_; } |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/core/TensorOptions.h
Outdated
| } | ||
| Device device() const noexcept; | ||
|
|
||
| optional<Device> device_opt() const noexcept { return device_; } |
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/core/TensorOptions.h
Outdated
| } | ||
| ScalarType dtype() const noexcept; | ||
|
|
||
| optional<ScalarType> dtype_opt() const noexcept { return dtype_; } |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/core/TensorOptions.h
Outdated
| } | ||
| Device device() const noexcept; | ||
|
|
||
| optional<Device> device_opt() const noexcept { return device_; } |
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/core/OptionsGuard.h
Outdated
| CAFFE2_API static TensorOptions& get(); | ||
| DefaultTensorOptions() {} | ||
| DefaultTensorOptions(const DefaultTensorOptions&) = default; | ||
| DefaultTensorOptions& operator=(const DefaultTensorOptions&) = default; |
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/core/OptionsGuard.h
Outdated
| private: | ||
| static TensorOptions options_; | ||
| }; | ||
| // Return the global, immutable default tensor options |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/core/TensorOptions.h
Outdated
| Layout layout() const noexcept { | ||
| return layout_; | ||
| } | ||
| Layout layout() const noexcept; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
| optional<bool> is_variable_opt() const noexcept { return is_variable_; } | ||
|
|
||
| // Resolves the ATen backend specified by the current construction axes. | ||
| Backend backend() const noexcept { |
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/core/TensorOptions.h
Outdated
| Layout layout_{Layout::Strided}; | ||
| bool requires_grad_{false}; | ||
| bool is_variable_{false}; | ||
| optional<ScalarType> dtype_; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Differential Revision: D10052523 Differential Version: 59581525
Differential Revision: D10052523 Differential Version: 59740131
Differential Revision: D10052523 Differential Version: 59742335
Differential Revision: D10052523 Differential Version: 59742581
Differential Revision: D10052523 Differential Version: 59745290
|
@goldsborough I think all CR comments are addressed. I noticed that use of |
Differential Revision: D10052523 Differential Version: 59777715
Differential Revision: D10052523 Differential Version: 59813029
…103) Summary: Pull Request resolved: pytorch/pytorch#12103 This defers lookup of defaults to the site where we read out of TensorOptions. THIS IS A BC-BREAKING BEHAVIOR CHANGE, but we expect the bulk of uses of OptionsGuard don't allocate TensorOptions inside the OptionsGuard region, and then use it outside of the region (the situation where behavior could change.) I also optimize the size of TensorOptions by rearranging fields, so that we always fit in two 64-bit words. Reviewed By: goldsborough Differential Revision: D10052523 fbshipit-source-id: f454a15b4dbf8cd17bc902ab7d2016f2f689ed13
Stack:
:black_circle: #12103 Make TensorOptions contain optional fields, optimize struct size 💛
This defers lookup of defaults to the site where we read
out of TensorOptions. THIS IS A BC-BREAKING BEHAVIOR CHANGE,
but we expect the bulk of uses of OptionsGuard don't allocate TensorOptions
inside the OptionsGuard region, and then use it outside of the region
(the situation where behavior could change.)
I also optimize the size of TensorOptions by rearranging fields, so that we
always fit in two 64-bit words.
Differential Revision: D10052523