Skip to content

Commit

Permalink
Rename DispatchKey::UndefinedTensorId to Undefined (pytorch#32728)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#32728

It doesn't have much to do with tensors anymore.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Test Plan: Imported from OSS

Differential Revision: D19628093

Pulled By: ezyang

fbshipit-source-id: 4d57111cdf44ba347bec8a32bb5b4b47a83c1eaf
  • Loading branch information
ezyang authored and facebook-github-bot committed Jan 30, 2020
1 parent a40a19c commit 3d0a470
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion aten/src/ATen/core/dispatch/DispatchKeyExtractor.h
Expand Up @@ -121,7 +121,7 @@ struct CAFFE2_API DispatchKeyExtractor final {
void setOperatorHasKernelForBackend(DispatchKey k, bool has_kernel);

private:
// NB: If there is no valid dispatch key, this will return UndefinedTensorId
// NB: If there is no valid dispatch key, this will return Undefined
DispatchKey dispatchKeySetToDispatchKey_(DispatchKeySet backendsWithoutFallthrough, const DispatchKeySet& ks) const {
// We must NOT respect the passed in backendsWithoutFallthrough if an operator has
// specifically overridden the backend, since that means we've opted to
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/core/dispatch/DispatchTable.h
Expand Up @@ -33,7 +33,7 @@ class KernelFunctionTable final {

enum class SetKernelResult : uint8_t {ADDED_NEW_KERNEL, OVERWROTE_EXISTING_KERNEL};
C10_NODISCARD SetKernelResult setKernel(DispatchKey dispatchKey, KernelFunction kernel) {
TORCH_INTERNAL_ASSERT(dispatchKey != DispatchKey::UndefinedTensorId);
TORCH_INTERNAL_ASSERT(dispatchKey != DispatchKey::Undefined);
auto& slot = kernels_[static_cast<uint8_t>(dispatchKey)];
SetKernelResult result;;
if (slot.isValid()) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/core/dispatch/Dispatcher.cpp
Expand Up @@ -165,7 +165,7 @@ void Dispatcher::addRegistrationListener(std::unique_ptr<OpRegistrationListener>
}

[[noreturn]] void Dispatcher::reportError(const DispatchTable& dispatchTable, DispatchKey dispatchKey) {
if (dispatchKey == DispatchKey::UndefinedTensorId) {
if (dispatchKey == DispatchKey::Undefined) {
TORCH_CHECK(false,
"There were no tensor arguments to this function (e.g., you passed an "
"empty list of Tensors), but no fallback function is registered for schema ", dispatchTable.operatorName(),
Expand Down
4 changes: 2 additions & 2 deletions c10/core/Backend.h
Expand Up @@ -100,7 +100,7 @@ static inline Backend dispatchKeyToBackend(DispatchKey t) {
return Backend::ComplexCPU;
} else if (t == DispatchKey::ComplexCUDATensorId) {
return Backend::ComplexCUDA;
} else if (t == DispatchKey::UndefinedTensorId) {
} else if (t == DispatchKey::Undefined) {
return Backend::Undefined;
} else {
AT_ERROR("Unrecognized tensor type ID: ", t);
Expand Down Expand Up @@ -134,7 +134,7 @@ static inline DispatchKey backendToDispatchKey(Backend b) {
case Backend::ComplexCUDA:
return DispatchKey::ComplexCUDATensorId;
case Backend::Undefined:
return DispatchKey::UndefinedTensorId;
return DispatchKey::Undefined;
default:
throw std::runtime_error("Unknown backend");
}
Expand Down
4 changes: 2 additions & 2 deletions c10/core/DispatchKey.cpp
Expand Up @@ -4,8 +4,8 @@ namespace c10 {

const char* toString(DispatchKey t) {
switch (t) {
case DispatchKey::UndefinedTensorId:
return "UndefinedTensorId";
case DispatchKey::Undefined:
return "Undefined";
case DispatchKey::CPUTensorId:
return "CPUTensorId";
case DispatchKey::CUDATensorId:
Expand Down
4 changes: 2 additions & 2 deletions c10/core/DispatchKey.h
Expand Up @@ -16,10 +16,10 @@ enum class DispatchKey : uint8_t {
//
// using DispatchKey = optional<RealDispatchKey>
//
// and UndefinedTensorId == nullopt. We didn't actually represent
// and Undefined == nullopt. We didn't actually represent
// it this way because optional<RealDispatchKey> would take two
// words, when DispatchKey fits in eight bits.
UndefinedTensorId = 0,
Undefined = 0,

// This pool of IDs is not really ordered, but it is merged into
// the hierarchy for convenience and performance
Expand Down
2 changes: 1 addition & 1 deletion c10/core/DispatchKeySet.cpp
Expand Up @@ -16,7 +16,7 @@ std::ostream& operator<<(std::ostream& os, DispatchKeySet ts) {
os << "DispatchKeySet(";
DispatchKey tid;
bool first = true;
while ((tid = ts.highestPriorityTypeId()) != DispatchKey::UndefinedTensorId) {
while ((tid = ts.highestPriorityTypeId()) != DispatchKey::Undefined) {
if (!first) {
os << ", ";
}
Expand Down
6 changes: 3 additions & 3 deletions c10/core/DispatchKeySet.h
Expand Up @@ -47,12 +47,12 @@ class DispatchKeySet final {
DispatchKeySet(Raw, uint64_t x)
: repr_(x) {}
explicit DispatchKeySet(DispatchKey t)
: repr_(t == DispatchKey::UndefinedTensorId
: repr_(t == DispatchKey::Undefined
? 0
: 1ULL << (static_cast<uint8_t>(t) - 1)) {}
// Test if a DispatchKey is in the set
bool has(DispatchKey t) const {
TORCH_INTERNAL_ASSERT(t != DispatchKey::UndefinedTensorId);
TORCH_INTERNAL_ASSERT(t != DispatchKey::Undefined);
return static_cast<bool>(repr_ & DispatchKeySet(t).repr_);
}
// Perform set union
Expand Down Expand Up @@ -92,7 +92,7 @@ class DispatchKeySet final {
// type id is the one that should handle dispatch (assuming there
// aren't any further exclusions or inclusions).
DispatchKey highestPriorityTypeId() const {
// TODO: If I put UndefinedTensorId as entry 64 and then adjust the
// TODO: If I put Undefined as entry 64 and then adjust the
// singleton constructor to shift from the right, we can get rid of the
// subtraction here. It's modestly more complicated to get right so I
// didn't do it for now.
Expand Down
2 changes: 1 addition & 1 deletion c10/core/UndefinedTensorImpl.cpp
Expand Up @@ -5,7 +5,7 @@ namespace c10 {

// should this use the globalContext? Can it get a context passed in somehow?
UndefinedTensorImpl::UndefinedTensorImpl()
: TensorImpl(DispatchKey::UndefinedTensorId, caffe2::TypeMeta(), c10::nullopt) {
: TensorImpl(DispatchKey::Undefined, caffe2::TypeMeta(), c10::nullopt) {
}

IntArrayRef UndefinedTensorImpl::sizes() const {
Expand Down
2 changes: 1 addition & 1 deletion c10/test/core/DispatchKeySet_test.cpp
Expand Up @@ -13,7 +13,7 @@ TEST(DispatchKeySet, Empty) {
ASSERT_TRUE(empty_set.empty());
DispatchKeySet empty_set2;
ASSERT_TRUE(empty_set == empty_set2);
ASSERT_EQ(empty_set.highestPriorityTypeId(), DispatchKey::UndefinedTensorId);
ASSERT_EQ(empty_set.highestPriorityTypeId(), DispatchKey::Undefined);
}

TEST(DispatchKeySet, Singleton) {
Expand Down

0 comments on commit 3d0a470

Please sign in to comment.