-
Notifications
You must be signed in to change notification settings - Fork 22.2k
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
[pt1][tensor] caffe2::DeviceType -> at::DeviceType #11254
Closed
Closed
Conversation
This file contains 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
Differential Revision: D9545704 Differential Version: 56924075
ezyang
reviewed
Sep 5, 2018
caffe2/core/tensor.h
Outdated
@@ -222,17 +222,18 @@ class CAFFE2_API TensorImpl : public c10::intrusive_ptr_target { | |||
if (size() > 0) { | |||
if (storage_.dtype().copy()) { | |||
CAFFE_ENFORCE( | |||
GetDeviceType() == CPU, | |||
GetDeviceType() == DeviceType::CPU, |
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.
ezyang
reviewed
Sep 5, 2018
@@ -0,0 +1,12 @@ | |||
from __future__ import absolute_import, division, print_function, unicode_literals | |||
from caffe2.proto import caffe2_pb2 | |||
# TODO: refactor & remove the following alias |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
ezyang
approved these changes
Sep 5, 2018
Differential Revision: D9545704 Differential Version: 56965830
jerryzh168
changed the title
[wip][pt1][tensor] caffe2::DeviceType -> at::DeviceType
[pt1][tensor] caffe2::DeviceType -> at::DeviceType
Sep 5, 2018
PenghuiCheng
pushed a commit
to PenghuiCheng/pytorch
that referenced
this pull request
Sep 11, 2018
Summary: Pull Request resolved: pytorch#11254 Previously we use DeviceType in caffe2.proto directly, but it's an `enum` and have implicit conversion to int, which does not have type safety, e.g. we have to explicitly check for a device type is valid in event.h: ``` template <int d> struct EventCreateFunctionRegisterer { explicit EventCreateFunctionRegisterer(EventCreateFunction f) { static_assert(d < MaxDeviceTypes, ""); Event::event_creator_[d] = f; } }; ``` at::DeviceType is an `enum class`, and it does not have implicit conversion to int, and provides better type safety guarantees. In this diff we have done the following refactor(taking CPU as an example): 1. caffe2::DeviceType → caffe2::DeviceTypeProto 2. caffe2::CPU → caffe2::PROTO_CPU 3. caffe2::DeviceType = at::DeviceType 4. caffe2::CPU = at::DeviceType::CPU codemod -d caffe2/caffe2 --extensions h,cc,cpp 'device_type\(\), ' 'device_type(), PROTO_' + some manual changes In short, after this diff, in c++, caffe2::CPU refers to the at::DeviceType::CPU and the old proto caffe2::CPU will be caffe2::PROTO_CPU. In python side, we have a temporary workaround that alias `caffe2_pb2.CPU = caffe2_pb2.PROOT_CPU` to make the change easier to review and this will be removed later. Reviewed By: ezyang Differential Revision: D9545704 fbshipit-source-id: 461a28a4ca74e616d3ee183a607078a717fd38a7
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
[pt1][tensor] caffe2::DeviceType -> at::DeviceType
Previously we use DeviceType in caffe2.proto directly, but it's an
enum
and have implicit conversion to int, which does not have type safety, e.g. we have to explicitly check for a device type is valid in event.h:at::DeviceType is an
enum class
, and it does not have implicit conversion to int, and provides better type safety guarantees. In this diff we have done the following refactor(taking CPU as an example):codemod -d caffe2/caffe2 --extensions h,cc,cpp 'device_type(), ' 'device_type(), PROTO_'
In short, after this diff, in c++, caffe2::CPU refers to the at::DeviceType::CPU and the old proto caffe2::CPU will be caffe2::PROTO_CPU.
In python side, we have a temporary workaround that alias
caffe2_pb2.CPU = caffe2_pb2.PROOT_CPU
to make the change easier to review and this will be removed later.Differential Revision: D9545704