Skip to content

Conversation

@ezyang
Copy link
Contributor

@ezyang ezyang commented Sep 26, 2018

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

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
@ezyang
Copy link
Contributor Author

ezyang commented Sep 27, 2018

CC also @gchanan, you asked for this!

Copy link
Contributor

@goldsborough goldsborough left a 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

#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.

/// 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.

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.

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.

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.

}
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.

}
ScalarType dtype() const noexcept;

optional<ScalarType> dtype_opt() const noexcept { return dtype_; }

This comment was marked as off-topic.

}
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.

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.

private:
static TensorOptions options_;
};
// Return the global, immutable default tensor options

This comment was marked as off-topic.

Layout layout() const noexcept {
return layout_;
}
Layout layout() const noexcept;

This comment was marked as off-topic.

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.

Layout layout_{Layout::Strided};
bool requires_grad_{false};
bool is_variable_{false};
optional<ScalarType> dtype_;

This comment was marked as off-topic.

ezyang added 2 commits October 3, 2018 10:34
Differential Revision: D10052523
Differential Version: 59581525
Differential Revision: D10052523
Differential Version: 59740131
@ezyang ezyang changed the title Make TensorOptions contain optional fields. Make TensorOptions contain optional fields, optimize struct size Oct 4, 2018
ezyang added 3 commits October 4, 2018 11:27
Differential Revision: D10052523
Differential Version: 59742335
Differential Revision: D10052523
Differential Version: 59742581
Differential Revision: D10052523
Differential Version: 59745290
@ezyang
Copy link
Contributor Author

ezyang commented Oct 4, 2018

@goldsborough I think all CR comments are addressed. I noticed that use of optional increased size of TensorOptions, so I rewrote it with a bitfield.

ezyang added 2 commits October 4, 2018 15:11
Differential Revision: D10052523
Differential Version: 59777715
Differential Revision: D10052523
Differential Version: 59813029
zdevito pushed a commit to zdevito/ATen that referenced this pull request Oct 5, 2018
…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
@soumith soumith deleted the export-D10052523 branch February 21, 2019 12:11
@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.

3 participants