Remove Type dispatch (#21964)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/21964
ghimport-source-id: fdfb555ac4efbf31ae7d2c700a5aa44ad0cc4d7f
Test Plan: Imported from OSS
Differential Revision: D15897424
Pulled By: li-roy
fbshipit-source-id: 3cd6744254e34d70e6875ffde749b5cf959b663c
diff --git a/aten/src/ATen/ATen.h b/aten/src/ATen/ATen.h
index 0796679..63ee74e 100644
--- a/aten/src/ATen/ATen.h
+++ b/aten/src/ATen/ATen.h
@@ -23,6 +23,7 @@
#include <ATen/core/Scalar.h>
#include <c10/core/Storage.h>
#include <c10/core/TensorOptions.h>
+#include <ATen/core/Reduction.h>
#include <c10/util/Exception.h>
#include <ATen/core/ATenDispatch.h>
#include <ATen/core/UnsafeFromTH.h>
diff --git a/aten/src/ATen/CPUTypeDefault.cpp b/aten/src/ATen/CPUTypeDefault.cpp
deleted file mode 100644
index b0ec3ac..0000000
--- a/aten/src/ATen/CPUTypeDefault.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <ATen/CPUTypeDefault.h>
-
-#include <ATen/Context.h>
-
-namespace at {
-
-} // namespace at
diff --git a/aten/src/ATen/CPUTypeDefault.h b/aten/src/ATen/CPUTypeDefault.h
deleted file mode 100644
index 3c969b5..0000000
--- a/aten/src/ATen/CPUTypeDefault.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-#include <ATen/TypeDefault.h>
-
-namespace at {
-
-struct CAFFE2_API CPUTypeDefault : public TypeDefault {
- CPUTypeDefault()
- : TypeDefault() {}
-};
-
-} // namespace at
diff --git a/aten/src/ATen/Context.cpp b/aten/src/ATen/Context.cpp
index d8f721e..6648c27 100644
--- a/aten/src/ATen/Context.cpp
+++ b/aten/src/ATen/Context.cpp
@@ -10,7 +10,6 @@
#include <string>
#include <stdexcept>
-#include <ATen/RegisterCPU.h>
#include <ATen/Tensor.h>
#include <ATen/cpu/FlushDenormal.h>
@@ -18,25 +17,9 @@
namespace at {
-static inline void errorHandler(const char * msg, void * data) {
- throw std::runtime_error(msg);
-}
-static inline void argErrorHandler(int arg, const char * msg, void * data) {
- std::stringstream new_error;
- new_error << "invalid argument " << arg << ": " << msg;
- throw std::runtime_error(new_error.str());
-}
-
Context::Context()
-: next_id(static_cast<size_t>(TypeID::NumOptions))
-, thc_state(nullptr, [](THCState* p){ /* no-op */ } )
-, thh_state(nullptr, [](THHState* p){ /* no-op */ } )
-{
-
- THSetDefaultErrorHandler(errorHandler,nullptr);
- THSetDefaultArgErrorHandler(argErrorHandler,nullptr);
- register_cpu_types(this);
-}
+: thc_state(nullptr, [](THCState* p){ /* no-op */ } )
+, thh_state(nullptr, [](THHState* p){ /* no-op */ } ) {}
// TODO: This could be bad juju if someone calls globalContext() in the
// destructor of an object with static lifetime.
@@ -108,38 +91,6 @@
return at::cpu::set_flush_denormal(on);
}
-// NOTE: We also check `at::NonVariableTypeMode`, and if it's enabled we always
-// return non-Variable type in this function.
-// See NOTE [ Treating Variables as non-Variables in type dispatch ]
-TypeExtendedInterface& getType(TensorOptions options) {
- return globalContext().getType(
- options.backend(), typeMetaToScalarType(options.dtype()), options.is_variable() && !at::NonVariableTypeMode::is_enabled());
-}
-
-// NOTE: We also check `at::NonVariableTypeMode`, and if it's enabled we always
-// return non-Variable type in this function.
-// See NOTE [ Treating Variables as non-Variables in type dispatch ]
-TypeExtendedInterface& getType(const TensorImpl* impl) {
- Backend backend = tensorTypeIdToBackend(impl->type_id());
- return globalContext().getType(
- backend, typeMetaToScalarType(impl->dtype()), impl->is_variable());
-}
-
-TypeExtendedInterface& getType(const Tensor& t) {
- return getType(t.unsafeGetTensorImpl());
-}
-
-LegacyTHDispatcher& getLegacyTHDispatcher(TensorOptions options) {
- return globalContext().getLegacyTHDispatcher(
- options.backend(), typeMetaToScalarType(options.dtype()));
-}
-
-LegacyTHDispatcher& getLegacyTHDispatcher(const TensorImpl* impl) {
- Backend backend = tensorTypeIdToBackend(impl->type_id());
- return globalContext().getLegacyTHDispatcher(
- backend, typeMetaToScalarType(impl->dtype()));
-}
-
Allocator* getCPUAllocator() {
return getTHDefaultAllocator();
}
@@ -155,9 +106,6 @@
void initHIP() const override {
globalContext().lazyInitHIP();
}
- void initComplex() const override {
- globalContext().lazyInitComplex();
- }
};
REGISTER_LEGACY_TYPE_INIT(LegacyDeviceTypeInit);
diff --git a/aten/src/ATen/Context.h b/aten/src/ATen/Context.h
index 7b94d4e..a564b72 100644
--- a/aten/src/ATen/Context.h
+++ b/aten/src/ATen/Context.h
@@ -2,18 +2,13 @@
#include <ATen/core/ATenGeneral.h>
#include <ATen/Tensor.h>
-#include <ATen/TypeExtendedInterface.h>
#include <ATen/Utils.h>
-#include <ATen/LegacyTHDispatch.h>
-#include <ATen/LegacyTHDispatcher.h>
#include <ATen/core/ATenGeneral.h>
#include <ATen/core/Generator.h>
#include <ATen/CPUGenerator.h>
#include <ATen/core/LegacyTypeDispatch.h>
-#include <ATen/core/VariableHooksInterface.h>
#include <ATen/detail/CUDAHooksInterface.h>
#include <ATen/detail/HIPHooksInterface.h>
-#include <ATen/detail/ComplexHooksInterface.h>
#include <c10/util/Exception.h>
#include <c10/core/impl/DeviceGuardImplInterface.h>
@@ -28,35 +23,6 @@
class CAFFE2_API Context {
public:
Context();
- TypeExtendedInterface* getNonVariableTypeRaw(Backend p, ScalarType s) {
- return static_cast<TypeExtendedInterface*>(globalLegacyTypeDispatch().getNonVariableTypeRaw(p, s));
- }
- TypeExtendedInterface * getNonVariableTypeOpt(Backend p, ScalarType s) {
- return static_cast<TypeExtendedInterface*>(globalLegacyTypeDispatch().getNonVariableTypeOpt(p, s));
- }
- TypeExtendedInterface & getNonVariableType(Backend p, ScalarType s) {
- return static_cast<TypeExtendedInterface&>(globalLegacyTypeDispatch().getNonVariableType(p, s));
- }
- TypeExtendedInterface & getVariableType(Backend p, ScalarType s) {
- return static_cast<TypeExtendedInterface&>(globalLegacyTypeDispatch().getVariableType(p, s));
- }
- TypeExtendedInterface & getType(Backend p, ScalarType s, bool is_variable) {
- return static_cast<TypeExtendedInterface&>(globalLegacyTypeDispatch().getType(p, s, is_variable));
- }
- LegacyTHDispatcher& getLegacyTHDispatcher(Backend p, ScalarType s) {
- return globalLegacyTHDispatch().getLegacyTHDispatcher(p, s);
- }
- // The passed in Type must be delete'able
- // TODO: Just make it take a unique_ptr
- void registerType(Backend b, Type* t) {
- globalLegacyTypeDispatch().registerType(b,
- LegacyTypeDispatch::TypeUniquePtr{t, LegacyTypeDeleter([](Type* p) { delete p; }) });
- }
-
- void registerLegacyTHDispatcher(Backend b, ScalarType s, LegacyTHDispatcher* t) {
- globalLegacyTHDispatch().registerDispatcher(b, s,
- LegacyTHDispatch::LegacyTHDispatcherUniquePtr{t, LegacyTHDispatcherDeleter([](LegacyTHDispatcher* p) { delete p; }) });
- }
Generator & defaultGenerator(Device device) {
DeviceType device_type = device.type();
@@ -102,22 +68,15 @@
THCState* lazyInitCUDA() {
std::call_once(thc_init,[&] {
thc_state = detail::getCUDAHooks().initCUDA();
- detail::getCUDAHooks().registerCUDATypes(this);
});
return thc_state.get();
}
THHState* lazyInitHIP() {
std::call_once(thh_init,[&] {
thh_state = detail::getHIPHooks().initHIP();
- detail::getHIPHooks().registerHIPTypes(this);
});
return thh_state.get();
}
- void lazyInitComplex() {
- std::call_once(complex_init_, [&] {
- detail::getComplexHooks().registerComplexTypes(this);
- });
- }
THCState* getTHCState() {
// AT_ASSERT(thc_state);
@@ -127,9 +86,6 @@
return thh_state.get();
}
- size_t freshTypeID() {
- return next_id++;
- }
bool setFlushDenormal(bool on);
// NB: This method is *purely* whether or not a user requested
@@ -153,21 +109,13 @@
lazyInitHIP();
}
}
- void initComplexIfNeeded(ScalarType s) {
- if (isComplexType(s)) {
- lazyInitComplex();
- }
- }
std::once_flag thc_init;
std::once_flag thh_init;
- std::once_flag complex_init_;
bool enabled_cudnn = true;
bool deterministic_cudnn = false;
bool benchmark_cudnn = false;
- std::atomic<size_t> next_id;
std::unique_ptr<THCState, void(*)(THCState*)> thc_state;
std::unique_ptr<THHState, void(*)(THHState*)> thh_state;
- friend struct Type;
};
CAFFE2_API Context& globalContext();
@@ -176,14 +124,6 @@
globalContext();
}
-static inline TypeExtendedInterface& getNonVariableType(Backend p, ScalarType s) {
- return globalContext().getNonVariableType(p, s);
-}
-
-CAFFE2_API TypeExtendedInterface& getType(TensorOptions options);
-CAFFE2_API TypeExtendedInterface& getType(const TensorImpl*);
-CAFFE2_API TypeExtendedInterface& getType(const Tensor&);
-
CAFFE2_API Allocator* getCPUAllocator();
static inline DeprecatedTypeProperties& getNonVariableDeprecatedTypeProperties(Backend p, ScalarType s) {
@@ -206,9 +146,6 @@
Backend::HIP, s, /*is_variable*/false);
}
-CAFFE2_API LegacyTHDispatcher& getLegacyTHDispatcher(TensorOptions options);
-CAFFE2_API LegacyTHDispatcher& getLegacyTHDispatcher(const Tensor&);
-
static inline bool hasCUDA() {
return globalContext().hasCUDA();
}
diff --git a/aten/src/ATen/LegacyTHDispatch.cpp b/aten/src/ATen/LegacyTHDispatch.cpp
deleted file mode 100644
index 6223874..0000000
--- a/aten/src/ATen/LegacyTHDispatch.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include <ATen/LegacyTHDispatch.h>
-
-namespace at {
-
-// TODO: This could be bad juju if someone calls globalContext() in the
-// destructor of an object with static lifetime.
-LegacyTHDispatch & globalLegacyTHDispatch() {
- static LegacyTHDispatch singleton;
- return singleton;
-}
-
-}
diff --git a/aten/src/ATen/LegacyTHDispatch.h b/aten/src/ATen/LegacyTHDispatch.h
deleted file mode 100644
index a97a8e4..0000000
--- a/aten/src/ATen/LegacyTHDispatch.h
+++ /dev/null
@@ -1,127 +0,0 @@
-#pragma once
-
-// LegacyTHDispatcher is the legacy mechanism for dispatching directly
-// to TH/THNN/THC/THCUNN functions in ATen, which is essentially a giant virtual
-// dispatch table for every TH function we support dynamically dispatching over.
-//
-// NB: We do not actually dispatch to *operators* here, the usual pattern is for
-// ATen operators to call this mechanism for their implementation, but the
-// operator itself is declared separately (e.g. as a native function "wrapper").
-//
-// Q: Why don't we just use LegacyTypeDispatch here?
-// A: Mainly separation of concerns:
-// 1) Type is for implementation of operators, which requires codegen of
-// Variables, JIT, etc. That is handled by the native function "wrappers";
-// just calling into TH does not require that.
-// 2) Type does not require scalar-specific dispatch, whereas calling into TH
-// does. Thus, this separation allows us to evolve operator dispatch
-// separately (i.e. to use the C10 dispatcher) from details of how to
-// call TH functionality.
-//
-// The implmentation here is very similar to the LegacyTypeDispatch design, with
-// the following simplications:
-// 1) This is not required for a mobile build, so does not have to live in /core.
-// 2) Because these only contain function implementations, we do not have to
-// handle the Variable/Tensor split; that is handled at the native function
-// "wrapper" level.
-// 3) Because an operator must have been previously dispatched via the Type
-// mechanism, we do need to handle device initialization. This means it is
-// WRONG to call directly into these functions without first going through
-// Type dispatch (i.e. the usual operator -> Type -> LegacyTHDispatch pattern).
-// 4) Because an operator must have been previously dispatched via the Type
-// mechanism, we do not need to handle undefined Tensors.
-//
-// NB: We don't use Registry for this, because we don't want to
-// pay for a hash table lookup every time we do an operation.
-//
-// NB: we can delete this when we don't call into any TH implementations.
-
-#include <c10/core/Backend.h>
-#include <c10/core/ScalarType.h>
-#include <ATen/core/LegacyDeviceTypeInit.h>
-#include <ATen/LegacyTHDispatcher.h>
-
-namespace at {
-
-struct Type;
-
-struct CAFFE2_API LegacyTHDispatcherDeleter {
- using LegacyTHDispatcherDeleterFun = void(LegacyTHDispatcher*);
- LegacyTHDispatcherDeleterFun *fn_ = nullptr;
- LegacyTHDispatcherDeleter() {}
- /* implicit */ LegacyTHDispatcherDeleter(LegacyTHDispatcherDeleterFun *fn) : fn_(fn) {}
- void operator()(LegacyTHDispatcher * ptr) {
- if (fn_) {
- (*fn_)(ptr);
- }
- }
-};
-
-class CAFFE2_API LegacyTHDispatch {
- public:
- using LegacyTHDispatcherUniquePtr = std::unique_ptr<LegacyTHDispatcher, LegacyTHDispatcherDeleter>;
- // WARNING: This function has the precondition that you have
- // initialized the type you want to call. This initialization
- // step is generally done by Context, or assumed because you
- // have a Tensor and thus the Type of that Tensor must already
- // be initialized.
-
- void registerDispatcher(Backend b, ScalarType s, LegacyTHDispatcherUniquePtr&& t) {
- dispatcher_registry[static_cast<int>(b)][static_cast<int>(s)] = std::move(t);
- }
-
- LegacyTHDispatcher & getLegacyTHDispatcher(Backend p, ScalarType s) {
- auto* dispatcher = getLegacyTHDispatcherOpt(p, s);
- if (!dispatcher) AT_ERROR(toString(p), toString(s), "THDispatcher is not enabled.");
- return *dispatcher;
- }
-private:
- LegacyTHDispatcher* getLegacyTHDispatcherRaw(Backend p, ScalarType s) {
- return dispatcher_registry[static_cast<int>(p)][static_cast<int>(s)].get();
- }
-
- LegacyTHDispatcher* getLegacyTHDispatcherOpt(Backend p, ScalarType s) {
- if (p != Backend::Undefined) {
- initForDeviceType(backendToDeviceType(p));
- // NB: there is no Complex for TH, so no initialization to be done.
- }
- auto dispatcher = getLegacyTHDispatcherRaw(p, s);
-
- if(!dispatcher) {
- if (p == Backend::Undefined || s == ScalarType::Undefined) {
- AT_ERROR("Requested Undefined THDispatcher which is invalid. Backend:",
- toString(p), "ScalarType: ", toString(s));
- }
- }
-
- return dispatcher;
- }
-
- void initForDeviceType(DeviceType p) {
- static std::once_flag cpu_once;
- static std::once_flag cuda_once;
- if (p == DeviceType::CPU) {
- std::call_once(cpu_once, [] {
- getLegacyDeviceTypeInit().initCPU();
- });
- } else if (p == DeviceType::CUDA) {
- std::call_once(cuda_once, [] {
- getLegacyDeviceTypeInit().initCUDA();
- });
- } else if (p == DeviceType::HIP) {
- std::call_once(cuda_once, [] {
- getLegacyDeviceTypeInit().initHIP();
- });
- }
- }
-
- // NB: dispatcher_registry has nullptr for all CUDA backends until
- // CUDA initialization has occurred
- LegacyTHDispatcherUniquePtr dispatcher_registry
- [static_cast<int>(Backend::NumOptions)]
- [static_cast<int>(ScalarType::NumOptions)];
-};
-
-CAFFE2_API LegacyTHDispatch& globalLegacyTHDispatch();
-
-} // namespace at
diff --git a/aten/src/ATen/TensorGeometry.h b/aten/src/ATen/TensorGeometry.h
index 1e43919..291892a 100644
--- a/aten/src/ATen/TensorGeometry.h
+++ b/aten/src/ATen/TensorGeometry.h
@@ -1,7 +1,7 @@
#pragma once
-#include <ATen/Type.h>
#include <ATen/WrapDimUtils.h>
+#include <ATen/core/Tensor.h>
namespace at {
diff --git a/aten/src/ATen/TensorOperators.h b/aten/src/ATen/TensorOperators.h
index 367d362..1828e7c9 100644
--- a/aten/src/ATen/TensorOperators.h
+++ b/aten/src/ATen/TensorOperators.h
@@ -2,7 +2,6 @@
#include <c10/core/Scalar.h>
#include <ATen/Tensor.h>
-#include <ATen/Type.h>
#include <string>
#include <stdexcept>
diff --git a/aten/src/ATen/Type.h b/aten/src/ATen/Type.h
deleted file mode 100644
index cef05f5..0000000
--- a/aten/src/ATen/Type.h
+++ /dev/null
@@ -1,2 +0,0 @@
-#pragma once
-#include <ATen/core/Tensor.h>
diff --git a/aten/src/ATen/UndefinedType.cpp b/aten/src/ATen/UndefinedType.cpp
deleted file mode 100644
index 58f95c0..0000000
--- a/aten/src/ATen/UndefinedType.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <ATen/UndefinedType.h>
-#include <c10/util/Exception.h>
-
-namespace at {
-
-UndefinedType::UndefinedType()
- : TypeDefault() {}
-
-const char * UndefinedType::toString() const {
- return "UndefinedType";
-}
-
-TypeID UndefinedType::ID() const {
- return TypeID::Undefined;
-}
-
-}
diff --git a/aten/src/ATen/UndefinedType.h b/aten/src/ATen/UndefinedType.h
deleted file mode 100644
index dc3cf8e..0000000
--- a/aten/src/ATen/UndefinedType.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include <ATen/TypeDefault.h>
-#include <ATen/Utils.h>
-
-#ifdef _MSC_VER
-#ifdef Type
-#undef Type
-#endif
-#endif
-
-namespace at {
-
-struct UndefinedType final : public TypeDefault {
- explicit UndefinedType();
- virtual const char * toString() const override;
- virtual TypeID ID() const override;
-};
-
-} // namespace at
diff --git a/aten/src/ATen/WrapDimUtils.h b/aten/src/ATen/WrapDimUtils.h
index 8fd5fb9..1cdbe15 100644
--- a/aten/src/ATen/WrapDimUtils.h
+++ b/aten/src/ATen/WrapDimUtils.h
@@ -2,6 +2,7 @@
#include <c10/core/WrapDimMinimal.h>
#include <c10/core/TensorImpl.h>
+#include <ATen/core/Tensor.h>
namespace at {
diff --git a/aten/src/ATen/core/DeprecatedTypeProperties.cpp b/aten/src/ATen/core/DeprecatedTypeProperties.cpp
index 5288863..15231f9 100644
--- a/aten/src/ATen/core/DeprecatedTypeProperties.cpp
+++ b/aten/src/ATen/core/DeprecatedTypeProperties.cpp
@@ -21,8 +21,4 @@
return src.to(src.options().dtype(scalarType()), non_blocking, /*copy=*/true);
}
-Type & DeprecatedTypeProperties::getDispatchType() const {
- return globalLegacyTypeDispatch().getType(backend_, scalar_type_, is_variable_);
-}
-
} // namespace at
diff --git a/aten/src/ATen/core/DeprecatedTypeProperties.h b/aten/src/ATen/core/DeprecatedTypeProperties.h
index d7b8edd..360c445 100644
--- a/aten/src/ATen/core/DeprecatedTypeProperties.h
+++ b/aten/src/ATen/core/DeprecatedTypeProperties.h
@@ -12,7 +12,6 @@
namespace at {
class Tensor;
-struct Type;
// This class specifies a Backend and a ScalarType. Currently, it primarily
// serves as a replacement return value for Tensor::type(). Previously,
@@ -133,8 +132,6 @@
Tensor copy(const Tensor & src, bool non_blocking=false, c10::optional<Device> to_device={}) const;
private:
- Type & getDispatchType() const;
-
Backend backend_;
ScalarType scalar_type_;
bool is_variable_;
diff --git a/aten/src/ATen/core/Formatting.cpp b/aten/src/ATen/core/Formatting.cpp
index 0abedca..af38559 100644
--- a/aten/src/ATen/core/Formatting.cpp
+++ b/aten/src/ATen/core/Formatting.cpp
@@ -33,10 +33,6 @@
std::ios saved;
};
-std::ostream& operator<<(std::ostream & out, const Type& t) {
- return out << t.toString();
-}
-
std::ostream& operator<<(std::ostream & out, const DeprecatedTypeProperties& t) {
return out << t.toString();
}
diff --git a/aten/src/ATen/core/Formatting.h b/aten/src/ATen/core/Formatting.h
index 04b7c5c..63c5e12 100644
--- a/aten/src/ATen/core/Formatting.h
+++ b/aten/src/ATen/core/Formatting.h
@@ -2,7 +2,6 @@
#include <c10/core/Scalar.h>
#include <ATen/core/Tensor.h>
-#include <ATen/core/Type.h>
#include <iostream>
@@ -11,7 +10,6 @@
}
namespace at {
-CAFFE2_API std::ostream& operator<<(std::ostream& out, const Type& t);
CAFFE2_API std::ostream& operator<<(std::ostream& out, const DeprecatedTypeProperties& t);
CAFFE2_API std::ostream& print(
std::ostream& stream,
diff --git a/aten/src/ATen/core/LegacyDeviceTypeInit.h b/aten/src/ATen/core/LegacyDeviceTypeInit.h
index fd64362..dd3a552 100644
--- a/aten/src/ATen/core/LegacyDeviceTypeInit.h
+++ b/aten/src/ATen/core/LegacyDeviceTypeInit.h
@@ -1,7 +1,7 @@
#pragma once
// The legacy mechanism for initializing device types; this is used by
-// both LegacyTypeDispatch and LegacyTHDispatch.
+// LegacyTypeDispatch.
#include <c10/core/DeviceType.h>
#include <c10/macros/Macros.h>
@@ -21,9 +21,6 @@
virtual void initHIP() const {
AT_ERROR("cannot use HIP without ATen HIP library");
}
- virtual void initComplex() const {
- AT_ERROR("cannot use complex without ATen Complex library");
- }
};
struct CAFFE2_API LegacyDeviceTypeInitArgs {};
diff --git a/aten/src/ATen/core/LegacyTypeDispatch.h b/aten/src/ATen/core/LegacyTypeDispatch.h
index 102e162..dd0fb5d 100644
--- a/aten/src/ATen/core/LegacyTypeDispatch.h
+++ b/aten/src/ATen/core/LegacyTypeDispatch.h
@@ -4,109 +4,24 @@
// object, which is essentially a giant virtual dispatch table
// for every operation we support dynamically dispatching over.
//
-// We intend to deprecate this design for a more extensible one
-// that permits addition of extra operators *out-of-band*. However,
-// for the time being, it's the only mechanism which works for
-// dispatching PyTorch operators, so we are supporting it for now.
-//
-// The use of Type in ATen/core poses another problem: on a
-// mobile build, we don't want to assume that Type is available.
-// But all methods on Tensor which route to PyTorch operators
-// need to somehow *get* a Type, and then do a virtual call on it.
-// How are we going to get the Type? Why, by another indirection!
-//
-// This registry is the mechanism for getting a concrete Type.
-// For a regular build, we register all types here; for a
-// mobile build, there are no registrations and instead we
-// return a stub which errors for all functions.
-//
-// NB: We don't use Registry for this, because we don't want to
-// pay for a hash table lookup every time we do an operation.
+// This has been deprecated in favor of ATenDispatch, and in the future,
+// c10 dispatcher.
+// TODO: Clean up what remains here
#include <c10/core/Backend.h>
#include <c10/core/ScalarType.h>
-#include <ATen/core/VariableHooksInterface.h>
#include <c10/util/Exception.h>
#include <ATen/core/LegacyDeviceTypeInit.h>
#include <c10/core/TensorImpl.h>
namespace at {
-struct Type;
-
-struct CAFFE2_API LegacyTypeDeleter {
- using TypeDeleterFun = void(Type*);
- TypeDeleterFun *fn_ = nullptr;
- LegacyTypeDeleter() {}
- /* implicit */ LegacyTypeDeleter(TypeDeleterFun *fn) : fn_(fn) {}
- void operator()(Type * ptr) {
- if (fn_) {
- (*fn_)(ptr);
- }
- }
-};
-
class CAFFE2_API LegacyTypeDispatch {
public:
- using TypeUniquePtr = std::unique_ptr<Type, LegacyTypeDeleter>;
- // WARNING: This function has the precondition that you have
- // initialized the type you want to call. This initialization
- // step is generally done by Context, or assumed because you
- // have a Tensor and thus the Type of that Tensor must already
- // be initialized.
- Type* getNonVariableTypeRaw(Backend p, ScalarType s) {
- return type_registry[static_cast<int>(p)].get();
- }
- Type * getNonVariableTypeOpt(Backend p, ScalarType s) {
- if (p != Backend::Undefined) {
- initForBackend(p);
- }
- auto type = getNonVariableTypeRaw(p, s);
-
- if(!type) {
- // there is only a single Undefined Type.
- if (p == Backend::Undefined || s == ScalarType::Undefined) {
- return getNonVariableTypeRaw(Backend::Undefined, ScalarType::Undefined);
- }
- }
-
- return type;
- }
-
- Type & getNonVariableType(Backend p, ScalarType s) {
- auto* type = getNonVariableTypeOpt(p, s);
- if (!type) AT_ERROR(toString(p), toString(s), "Type is not enabled.");
- return *type;
- }
-
- Type* getTypeRaw(Backend p, ScalarType s, bool is_variable) {
- auto baseType = getNonVariableTypeRaw(p, s);
- if (is_variable) {
- return &detail::getVariableHooks().getVariableTypeFromBaseType(*baseType);
- } else {
- return baseType;
- }
- }
- Type & getVariableType(Backend p, ScalarType s) {
- auto& baseType = getNonVariableType(p, s);
- return detail::getVariableHooks().getVariableTypeFromBaseType(baseType);
- }
- Type & getType(Backend p, ScalarType s, bool is_variable) {
- if (is_variable) {
- return getVariableType(p, s);
- } else {
- return getNonVariableType(p, s);
- }
- }
- void registerType(Backend b, TypeUniquePtr&& t) {
- type_registry[static_cast<int>(b)] = std::move(t);
- detail::getVariableHooks().registerVariableTypeFor(this, b);
- }
void initForBackend(Backend b) {
auto p = backendToDeviceType(b);
static std::once_flag cpu_once;
static std::once_flag cuda_once;
- static std::once_flag complex_once;
if (p == DeviceType::CPU) {
std::call_once(cpu_once, [] {
getLegacyDeviceTypeInit().initCPU();
@@ -120,17 +35,7 @@
getLegacyDeviceTypeInit().initHIP();
});
}
- if (b == Backend::ComplexCPU || b == Backend::ComplexCUDA) {
- std::call_once(complex_once, [] {
- getLegacyDeviceTypeInit().initComplex();
- });
- }
}
- private:
- // NB: type_registry has nullptr for all CUDA backends until
- // CUDA initialization has occurred
- TypeUniquePtr type_registry
- [static_cast<int>(Backend::NumOptions)];
};
CAFFE2_API LegacyTypeDispatch& globalLegacyTypeDispatch();
@@ -153,33 +58,4 @@
bool prev_mode;
};
-/**
- * Return the Type object corresponding to this Tensor, which we can
- * use to do dynamic dispatch to operators from. This method is NOT
- * intended to be used by end-users; it is purely an implementation
- * detail.
- *
- * NOTE: We also check `at::NonVariableTypeMode`, and if it's enabled
- * we always return non-Variable type in this function.
- * See NOTE [ Treating Variables as non-Variables in type dispatch ]
- */
-inline Type& legacyTensorType(const TensorImpl& tensor) {
- // NB: It's valid to use getTypeRaw here, because the TensorImpl
- // could not have been created without initializing the Type first.
- // NB: This is not actually true via the Caffe2 codepath! But we call
- // initializeLegacyTypeDispatchFor in the right place.
- return *globalLegacyTypeDispatch().getTypeRaw(
- tensorTypeIdToBackend(tensor.type_id()),
- typeMetaToScalarType(tensor.dtype()),
- tensor.is_variable());
-}
-
-inline void initializeLegacyTypeDispatchFor(const TensorImpl& tensor) {
- // getType calls the right initialization
- globalLegacyTypeDispatch().getType(
- tensorTypeIdToBackend(tensor.type_id()),
- typeMetaToScalarType(tensor.dtype()),
- tensor.is_variable());
-}
-
} // namespace at
diff --git a/aten/src/ATen/core/Tensor.cpp b/aten/src/ATen/core/Tensor.cpp
index 4597432..61c98c2 100644
--- a/aten/src/ATen/core/Tensor.cpp
+++ b/aten/src/ATen/core/Tensor.cpp
@@ -1,6 +1,5 @@
#include <ATen/core/Tensor.h>
#include <ATen/core/Formatting.h>
-#include <ATen/core/Type.h>
#include <iostream>
@@ -26,10 +25,6 @@
impl_->storage_initialized(),
"Partially-initialized tensor not supported by at::Tensor");
}
- // Ensure LegacyTypeDispatch is initialized. In ATen it's done in tensor
- // factory functions, but when we get a tensor from Caffe2 we might bypass
- // those factory functions.
- initializeLegacyTypeDispatchFor(*impl_);
}
}
diff --git a/aten/src/ATen/core/Tensor.h b/aten/src/ATen/core/Tensor.h
index 0fb3219..8f82d98 100644
--- a/aten/src/ATen/core/Tensor.h
+++ b/aten/src/ATen/core/Tensor.h
@@ -1,6 +1,5 @@
#pragma once
-#include <ATen/core/Type.h>
#include <c10/core/Device.h>
#include <c10/core/Layout.h>
#include <c10/core/MemoryFormat.h>
@@ -211,9 +210,6 @@
scalar_type(),
is_variable());
}
- Type & dispatch_type() const {
- return legacyTensorType(*impl_);
- }
TensorTypeId type_id() const {
return impl_->type_id();
}
diff --git a/aten/src/ATen/core/Type.h b/aten/src/ATen/core/Type.h
deleted file mode 100644
index 72a68b5..0000000
--- a/aten/src/ATen/core/Type.h
+++ /dev/null
@@ -1,80 +0,0 @@
-#pragma once
-
-#include <ATen/core/ATenGeneral.h>
-#include <c10/core/Allocator.h>
-#include <c10/util/Deprecated.h>
-#include <ATen/core/Generator.h>
-#include <c10/core/Layout.h>
-#include <c10/core/MemoryFormat.h>
-#include <c10/core/QScheme.h>
-#include <c10/core/Scalar.h>
-#include <c10/core/ScalarType.h>
-#include <c10/util/ArrayRef.h>
-#include <c10/util/Half.h>
-#include <c10/core/TensorTypeIdRegistration.h>
-#include <ATen/core/Reduction.h>
-#include <c10/core/TensorOptions.h>
-#include <c10/util/intrusive_ptr.h>
-
-#include <c10/util/Optional.h>
-
-#include <array>
-#include <cstddef>
-#include <functional>
-#include <limits>
-#include <memory>
-
-#ifdef NAMEDTENSOR_ENABLED
-#include <ATen/Dimname.h>
-#endif
-
-// To solve the conflict of s_addr in inaddr.h
-#ifdef _MSC_VER
-#ifdef s_addr
-#undef s_addr
-#endif
-#endif
-
-namespace c10 {
-struct Storage;
-}
-
-namespace at {
-
-class Tensor;
-using TensorList = ArrayRef<Tensor>;
-
-class Context;
-struct Generator;
-
-struct Quantizer;
-// This is temporary typedef to enable Quantizer in aten native function API
-// we'll remove them when we are actually exposing Quantizer class
-// to frontend
-using ConstQuantizerPtr = const c10::intrusive_ptr<Quantizer>&;
-
-static inline void noop_deleter(void*) {}
-
-enum class TypeID {
- CPU,
- SparseCPU,
- MkldnnCPU,
- CUDA,
- SparseCUDA,
- QuantizedCPU,
- MSNPU,
- XLA,
- ComplexCPU,
- Undefined,
- NumOptions
-};
-
-struct CAFFE2_API Type {
- explicit Type() {}
-
- virtual ~Type() {}
- virtual const char * toString() const = 0;
- virtual TypeID ID() const = 0;
-};
-
-} // namespace at
diff --git a/aten/src/ATen/core/VariableHooksInterface.cpp b/aten/src/ATen/core/VariableHooksInterface.cpp
deleted file mode 100644
index b9d90f5..0000000
--- a/aten/src/ATen/core/VariableHooksInterface.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <ATen/core/VariableHooksInterface.h>
-
-namespace at {
-
-namespace detail {
-
- // NB: The VariableHooks returned by this function may CHANGE after dlopen()
- // NB: This function takes a lock, don't call it from perf critical paths
- const VariableHooksInterface& getVariableHooks() {
- static std::mutex var_hooks_mutex;
- static std::unique_ptr<VariableHooksInterface> var_hooks = nullptr;
- static std::unique_ptr<VariableHooksInterface> default_var_hooks =
- std::unique_ptr<VariableHooksInterface>(new VariableHooksInterface());
- std::lock_guard<std::mutex> lock(var_hooks_mutex);
-
- if (!var_hooks) {
- var_hooks = VariableHooksRegistry()->Create("VariableHooks", VariableHooksArgs{});
- }
- if (var_hooks) {
- return *var_hooks;
- }
- return *default_var_hooks;
- }
-
-}
-
-C10_DEFINE_REGISTRY(
- VariableHooksRegistry,
- VariableHooksInterface,
- VariableHooksArgs)
-
-} // namespace at::detail
diff --git a/aten/src/ATen/core/VariableHooksInterface.h b/aten/src/ATen/core/VariableHooksInterface.h
deleted file mode 100644
index 947a4c8..0000000
--- a/aten/src/ATen/core/VariableHooksInterface.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#pragma once
-
-#include <c10/core/Backend.h>
-#include <c10/core/ScalarType.h>
-#include <c10/util/Registry.h>
-
-namespace at {
- class LegacyTypeDispatch;
- struct Type;
-}
-
-// NB: Registry class not actually in the namespace detail, due to limitations
-// of Registry.h
-namespace at {
-
-// The VariableHooksInterface is an interface for autograd functionality
-// which currently doesn't live in libATen.so AND needs to be called from
-// ATen. In this case, it is only the type registry for Variable types,
-// letting us add extra variables types if CUDA types are initialized lazily.
-//
-// We may choose to absorb autograd into ATen, in which case this interface is obsolete.
-//
-struct CAFFE2_API VariableHooksInterface {
- // This should never actually be implemented, but it is used to
- // squelch -Werror=non-virtual-dtor
- virtual ~VariableHooksInterface() {}
-
- virtual Type& getVariableTypeFromBaseType(const at::Type& baseType) const {
- AT_ERROR("cannot getVariableTypeFromBaseType without libtorch");
- }
-
- virtual void registerVariableTypeFor(LegacyTypeDispatch*, Backend backend) const {
- // no-op if Variable not available; it'll get handled (if at all) when
- // libtorch.so gets loaded
- }
-};
-
-// NB: dummy argument to suppress "ISO C++11 requires at least one argument
-// for the "..." in a variadic macro"
-struct CAFFE2_API VariableHooksArgs {};
-
-C10_DECLARE_REGISTRY(
- VariableHooksRegistry,
- VariableHooksInterface,
- VariableHooksArgs);
-#define REGISTER_VARIABLE_HOOKS(clsname) \
- C10_REGISTER_CLASS(VariableHooksRegistry, clsname, clsname)
-
-namespace detail {
-CAFFE2_API const VariableHooksInterface& getVariableHooks();
-}
-
-} // namespace at
diff --git a/aten/src/ATen/cuda/CUDATypeDefault.cpp b/aten/src/ATen/cuda/CUDATypeDefault.cpp
deleted file mode 100644
index 7be2b27..0000000
--- a/aten/src/ATen/cuda/CUDATypeDefault.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <ATen/cuda/CUDATypeDefault.h>
-
-#include <ATen/cuda/CUDAContext.h>
-#include <ATen/cuda/CUDADevice.h>
-
-namespace at {
-
-} // namespace at
diff --git a/aten/src/ATen/cuda/CUDATypeDefault.h b/aten/src/ATen/cuda/CUDATypeDefault.h
deleted file mode 100644
index d38e598..0000000
--- a/aten/src/ATen/cuda/CUDATypeDefault.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#pragma once
-#include <ATen/TypeDefault.h>
-#include <ATen/cuda/ATenCUDAGeneral.h>
-
-namespace at {
-
-struct AT_CUDA_API CUDATypeDefault : public TypeDefault {
- CUDATypeDefault()
- : TypeDefault() {}
-};
-
-} // namespace at
diff --git a/aten/src/ATen/cuda/detail/CUDAHooks.cpp b/aten/src/ATen/cuda/detail/CUDAHooks.cpp
index dd549df..ea5c661 100644
--- a/aten/src/ATen/cuda/detail/CUDAHooks.cpp
+++ b/aten/src/ATen/cuda/detail/CUDAHooks.cpp
@@ -2,7 +2,6 @@
#include <ATen/CUDAGenerator.h>
#include <ATen/Context.h>
-#include <ATen/RegisterCUDA.h>
#include <ATen/cuda/CUDAConfig.h>
#include <ATen/cuda/CUDADevice.h>
#include <ATen/cuda/PinnedMemoryAllocator.h>
@@ -91,10 +90,6 @@
return at::cuda::getPinnedMemoryAllocator();
}
-void CUDAHooks::registerCUDATypes(Context* context) const {
- register_cuda_types(context);
-}
-
bool CUDAHooks::compiledWithCuDNN() const {
return AT_CUDNN_ENABLED();
}
diff --git a/aten/src/ATen/cuda/detail/CUDAHooks.h b/aten/src/ATen/cuda/detail/CUDAHooks.h
index d329340..f9ef501 100644
--- a/aten/src/ATen/cuda/detail/CUDAHooks.h
+++ b/aten/src/ATen/cuda/detail/CUDAHooks.h
@@ -18,7 +18,6 @@
bool hasCuDNN() const override;
int64_t current_device() const override;
Allocator* getPinnedMemoryAllocator() const override;
- void registerCUDATypes(Context*) const override;
bool compiledWithCuDNN() const override;
bool compiledWithMIOpen() const override;
bool supportsDilatedConvolutionWithCuDNN() const override;
diff --git a/aten/src/ATen/detail/CUDAHooksInterface.h b/aten/src/ATen/detail/CUDAHooksInterface.h
index bdddea3..083b32d 100644
--- a/aten/src/ATen/detail/CUDAHooksInterface.h
+++ b/aten/src/ATen/detail/CUDAHooksInterface.h
@@ -86,10 +86,6 @@
AT_ERROR("Pinned memory requires CUDA. ", CUDA_HELP);
}
- virtual void registerCUDATypes(Context*) const {
- AT_ERROR("Cannot registerCUDATypes() without ATen_cuda library. ", CUDA_HELP);
- }
-
virtual bool compiledWithCuDNN() const {
return false;
}
diff --git a/aten/src/ATen/detail/ComplexHooksInterface.cpp b/aten/src/ATen/detail/ComplexHooksInterface.cpp
deleted file mode 100644
index a7ffcf1..0000000
--- a/aten/src/ATen/detail/ComplexHooksInterface.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <ATen/detail/ComplexHooksInterface.h>
-
-namespace at {
-
-namespace detail {
-const ComplexHooksInterface& getComplexHooks() {
- static std::unique_ptr<ComplexHooksInterface> complex_hooks;
- // NB: The once_flag here implies that if you try to call any Complex
- // functionality before you load the complex library, you're toast.
- // Same restriction as in getCUDAHooks()
- static std::once_flag once;
- std::call_once(once, [] {
- complex_hooks = ComplexHooksRegistry()->Create("ComplexHooks", ComplexHooksArgs{});
- if (!complex_hooks) {
- complex_hooks =
- std::unique_ptr<ComplexHooksInterface>(new ComplexHooksInterface());
- }
- });
- return *complex_hooks;
-}
-} // namespace detail
-
-C10_DEFINE_REGISTRY(
- ComplexHooksRegistry,
- ComplexHooksInterface,
- ComplexHooksArgs)
-}
diff --git a/aten/src/ATen/detail/ComplexHooksInterface.h b/aten/src/ATen/detail/ComplexHooksInterface.h
deleted file mode 100644
index ad8d629..0000000
--- a/aten/src/ATen/detail/ComplexHooksInterface.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-#include <c10/util/Exception.h>
-#include <c10/util/Registry.h>
-
-namespace at {
-
-class Context;
-
-struct CAFFE2_API ComplexHooksInterface {
- virtual ~ComplexHooksInterface() {}
-
- virtual void registerComplexTypes(Context*) const {
- AT_ERROR("Cannot register complex types without loading a library with complex support");
- }
-};
-
-struct CAFFE2_API ComplexHooksArgs {};
-C10_DECLARE_REGISTRY(
- ComplexHooksRegistry,
- ComplexHooksInterface,
- ComplexHooksArgs);
-#define REGISTER_COMPLEX_HOOKS(clsname) \
- C10_REGISTER_CLASS(ComplexHooksRegistry, clsname, clsname)
-
-namespace detail {
-CAFFE2_API const ComplexHooksInterface& getComplexHooks();
-}
-
-}
diff --git a/aten/src/ATen/gen.py b/aten/src/ATen/gen.py
index c49dec5..1143f3d 100644
--- a/aten/src/ATen/gen.py
+++ b/aten/src/ATen/gen.py
@@ -13,7 +13,6 @@
import native_parse
import preprocess_declarations
import function_wrapper
-from function_wrapper import scalar_types
from code_template import CodeTemplate
from env import NAMEDTENSOR_ENABLED
@@ -117,25 +116,12 @@
TYPE_DERIVED_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeDerived.cpp")
SPARSE_TYPE_DERIVED_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/SparseTypeDerived.cpp")
TYPE_DERIVED_H = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeDerived.h")
-TYPE_H = CodeTemplate.from_file(TEMPLATE_PATH + "/Type.h")
-TYPE_EXTENDED_INTERFACE_H = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeExtendedInterface.h")
TYPE_DEFAULT_H = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeDefault.h")
TYPE_DEFAULT_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeDefault.cpp")
TYPE_EXTENSION_H = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeExtension.h")
TYPE_EXTENSION_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/TypeExtension.cpp")
REGISTRATION_DECLARATIONS_H = CodeTemplate.from_file(TEMPLATE_PATH + "/RegistrationDeclarations.h")
-LEGACY_TH_DISPATCHER_H = CodeTemplate.from_file(TEMPLATE_PATH + "/LegacyTHDispatcher.h")
-LEGACY_TH_DISPATCHER_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/LegacyTHDispatcher.cpp")
-LEGACY_TH_DISPATCHER_DERIVED_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/LegacyTHDispatcherDerived.cpp")
-LEGACY_TH_DISPATCHER_DERIVED_H = CodeTemplate.from_file(TEMPLATE_PATH + "/LegacyTHDispatcherDerived.h")
-
-REGISTER_CPU_H = CodeTemplate.from_file(TEMPLATE_PATH + "/RegisterCPU.h")
-REGISTER_CPU_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/RegisterCPU.cpp")
-
-REGISTER_CUDA_H = CodeTemplate.from_file(TEMPLATE_PATH + "/RegisterCUDA.h")
-REGISTER_CUDA_CPP = CodeTemplate.from_file(TEMPLATE_PATH + "/RegisterCUDA.cpp")
-
TENSOR_H = CodeTemplate.from_file(TEMPLATE_PATH + "/Tensor.h")
TENSOR_METHODS_H = CodeTemplate.from_file(TEMPLATE_PATH + "/TensorMethods.h")
@@ -148,10 +134,6 @@
EXTENSION_BACKEND_REGISTRATION_H = CodeTemplate.from_file(TEMPLATE_PATH + "/ExtensionBackendRegistration.h")
-TYPE_REGISTER = CodeTemplate("""\
-context->registerType(Backend::${backend}, new ${type_name}());
-""")
-
EXTENSION_BACKEND_REGISTER_SWITCH = CodeTemplate("""\
case Backend::${Backend}:
${Type}Dispatch::register_function(schema, fn);
@@ -182,11 +164,9 @@
]
-# shared environment for non-derived base classes Type.h Tensor.h Storage.h
+# shared environment for non-derived base classes Tensor.h Storage.h
top_env = {
- 'cpu_type_registrations': [],
'cpu_type_headers': [],
- 'cuda_type_registrations': [],
'cuda_type_headers': [],
'function_registrations': [],
'type_method_declarations': [],
@@ -276,7 +256,6 @@
]
env['extra_cuda_headers'].append('#include <ATen/hip/ATenHIPGeneral.h>')
env['extra_cuda_headers'].append('#include <ATen/hip/HIPDevice.h>')
- env['extra_cuda_headers'].append('#include <ATen/hip/HIPTypeDefault.h>')
env['extra_cuda_headers'].append('#include <ATen/hip/HIPContext.h>')
else:
env['th_headers'] = [
@@ -288,7 +267,6 @@
]
env['extra_cuda_headers'].append('#include <ATen/cuda/ATenCUDAGeneral.h>')
env['extra_cuda_headers'].append('#include <ATen/cuda/CUDADevice.h>')
- env['extra_cuda_headers'].append('#include <ATen/cuda/CUDATypeDefault.h>')
env['extra_cuda_headers'].append('#include <ATen/cuda/CUDAContext.h>')
env['state'] = ['globalContext().getTHCState()']
env['isCUDA'] = 'true'
@@ -333,14 +311,11 @@
fm.write(env['Type'] + ".cpp", SPARSE_TYPE_DERIVED_CPP, env)
fm.write(env['Type'] + ".h", TYPE_DERIVED_H, env)
- type_register = TYPE_REGISTER.substitute(backend=env['Backend'], type_name=env['Type'])
if env['DeviceType'] == 'CPU':
- top_env['cpu_type_registrations'].append(type_register)
top_env['cpu_type_headers'].append(
'#include "ATen/{}.h"'.format(env['Type']))
else:
assert env['DeviceType'] == 'CUDA'
- top_env['cuda_type_registrations'].append(type_register)
top_env['cuda_type_headers'].append(
'#include "ATen/{}.h"'.format(env['Type']))
@@ -359,9 +334,7 @@
env['type_method_definitions'] = definitions
env['function_registrations'] = registrations
- type_register = TYPE_REGISTER.substitute(backend=env['Backend'], type_name=env['Type'])
top_env['cpu_type_headers'].append('#include "ATen/{}.h"'.format(env['Type']))
- top_env['cpu_type_registrations'].append(type_register)
file_manager.write(env['Type'] + ".cpp", TYPE_EXTENSION_CPP, env)
file_manager.write(env['Type'] + ".h", TYPE_EXTENSION_H, env)
@@ -371,37 +344,6 @@
'#include <ATen/{}.h>'.format(env['Type']))
-def generate_legacy_th_dispatcher(backend, density, scalar_type, declarations):
- assert density == 'Dense'
- scalar_name, c_type, accreal, is_floating_type = scalar_type
- env = {}
- env['Backend'] = backend
- env['Dispatcher'] = "LegacyTH{}{}Dispatcher".format(backend, scalar_name)
-
- fm = file_manager
- if backend == 'CUDA':
- fm = cuda_file_manager
-
- fm.write(env['Dispatcher'] + ".cpp", LEGACY_TH_DISPATCHER_DERIVED_CPP, env)
- fm.write(env['Dispatcher'] + ".h", LEGACY_TH_DISPATCHER_DERIVED_H, env)
-
- return env
-
-
-# yields (backend, density, scalar_type) tuples
-def legacy_iterate_types():
- for backend in backends:
- for density in densities:
- for scalar_type in (scalar_types + quantized_scalar_types):
- if density == 'Mkldnn' and (backend != 'CPU' or scalar_type[0] != 'Float'):
- continue
- else:
- yield (backend, density, scalar_type)
- for backend in quantized_backends:
- for scalar_type in quantized_scalar_types:
- yield (backend, 'Dense', scalar_type)
-
-
# yields (backend, density) tuples
def iterate_types():
for backend in backends:
@@ -419,17 +361,14 @@
# so that the script runs quickly when we are just querying the
# outputs
def declare_outputs():
- core_files = ['Type.h', 'Tensor.h', 'TensorMethods.h']
+ core_files = ['Tensor.h', 'TensorMethods.h']
for f in core_files:
core_file_manager.will_write(f)
- files = ['Declarations.yaml', 'TypeExtendedInterface.h', 'TypeDefault.cpp', 'TypeDefault.h',
- 'LegacyTHDispatcher.h', 'LegacyTHDispatcher.cpp', 'Functions.h', 'NativeFunctions.h',
- 'RegisterCPU.cpp', 'RegisterCPU.h', 'ExtensionBackendRegistration.h', 'RegistrationDeclarations.h']
+ files = ['Declarations.yaml', 'TypeDefault.cpp', 'TypeDefault.h',
+ 'Functions.h', 'NativeFunctions.h',
+ 'ExtensionBackendRegistration.h', 'RegistrationDeclarations.h']
for f in files:
file_manager.will_write(f)
- cuda_files = ['RegisterCUDA.cpp', 'RegisterCUDA.h']
- for f in cuda_files:
- cuda_file_manager.will_write(f)
for backend, density in iterate_types():
full_backend = backend if density == "Dense" else density + backend
fm = file_manager
@@ -444,14 +383,6 @@
if backend == 'CPU' or backend == 'CUDA':
fm.will_write("LegacyTHFunctions{}.h".format(backend))
fm.will_write("LegacyTHFunctions{}.cpp".format(backend))
- # output LegacyTHDispatchers
- for backend, density, scalar_type in legacy_iterate_types():
- fm = file_manager
- if backend == 'CUDA':
- fm = cuda_file_manager
- if density == 'Dense':
- fm.will_write("{}{}{}{}.h".format('LegacyTH', backend, scalar_type[0], 'Dispatcher'))
- fm.will_write("{}{}{}{}.cpp".format('LegacyTH', backend, scalar_type[0], 'Dispatcher'))
for backend in extension_backends:
file_manager.will_write("{}Type.h".format(backend))
file_manager.will_write("{}Type.cpp".format(backend))
@@ -518,12 +449,7 @@
for backend in extension_backends:
generate_type_extension_backend(backend, declarations)
- for backend, density, scalar_type in legacy_iterate_types():
- if density == 'Dense':
- generate_legacy_th_dispatcher(backend, density, scalar_type, [])
-
core_files = {
- 'Type.h': TYPE_H,
'Tensor.h': TENSOR_H,
'TensorMethods.h': TENSOR_METHODS_H
}
@@ -531,20 +457,10 @@
for core_file, core_template_file in core_files.items():
core_file_manager.write(core_file, core_template_file, top_env)
- file_manager.write('TypeExtendedInterface.h', TYPE_EXTENDED_INTERFACE_H, top_env)
file_manager.write('TypeDefault.h', TYPE_DEFAULT_H, top_env)
file_manager.write('TypeDefault.cpp', TYPE_DEFAULT_CPP, top_env)
file_manager.write('RegistrationDeclarations.h', REGISTRATION_DECLARATIONS_H, top_env)
- file_manager.write('LegacyTHDispatcher.h', LEGACY_TH_DISPATCHER_H, top_env)
- file_manager.write('LegacyTHDispatcher.cpp', LEGACY_TH_DISPATCHER_CPP, top_env)
-
- file_manager.write('RegisterCPU.h', REGISTER_CPU_H, top_env)
- file_manager.write('RegisterCPU.cpp', REGISTER_CPU_CPP, top_env)
-
- cuda_file_manager.write('RegisterCUDA.h', REGISTER_CUDA_H, top_env)
- cuda_file_manager.write('RegisterCUDA.cpp', REGISTER_CUDA_CPP, top_env)
-
file_manager.write('Functions.h', FUNCTIONS_H, top_env)
file_manager.write('NativeFunctions.h', NATIVE_FUNCTIONS_H, top_env)
diff --git a/aten/src/ATen/native/TensorFactories.cpp b/aten/src/ATen/native/TensorFactories.cpp
index 2592d09..8c7603c 100644
--- a/aten/src/ATen/native/TensorFactories.cpp
+++ b/aten/src/ATen/native/TensorFactories.cpp
@@ -9,7 +9,6 @@
#include <ATen/Utils.h>
#include <ATen/Dispatch.h>
#include <ATen/NativeFunctions.h>
-#include <ATen/LegacyTHDispatcher.h>
#include <c10/core/ScalarType.h>
#include <c10/util/Deprecated.h>
#include <ATen/native/Resize.h>
@@ -52,11 +51,6 @@
window_length);
}
-// FIXME: point to LegacyTHDispatcher.
-const TypeExtendedInterface& getFactoryType(const TensorOptions& options) {
- return at::getType(options);
-}
-
} // namespace
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ arange ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/aten/src/ATen/native/quantized/cpu/qadd.cpp b/aten/src/ATen/native/quantized/cpu/qadd.cpp
index cd9dce1..b14d863 100644
--- a/aten/src/ATen/native/quantized/cpu/qadd.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qadd.cpp
@@ -1,5 +1,4 @@
#include <ATen/ATen.h>
-#include <ATen/core/Type.h>
#include <ATen/core/op_registration/op_registration.h>
#include <ATen/native/TensorIterator.h>
#include <ATen/native/cpu/Loops.h>
diff --git a/aten/src/ATen/native/quantized/cpu/qconv.cpp b/aten/src/ATen/native/quantized/cpu/qconv.cpp
index a98d89f..842a398 100644
--- a/aten/src/ATen/native/quantized/cpu/qconv.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qconv.cpp
@@ -1,5 +1,4 @@
#include <ATen/ATen.h>
-#include <ATen/core/Type.h>
#include <ATen/core/op_registration/op_registration.h>
#include <ATen/cpp_custom_type_hack.h>
#include <ATen/native/quantized/cpu/fbgemm_utils.h>
diff --git a/aten/src/ATen/native/quantized/cpu/qconv_prepack.cpp b/aten/src/ATen/native/quantized/cpu/qconv_prepack.cpp
index c257258..31b41b3 100644
--- a/aten/src/ATen/native/quantized/cpu/qconv_prepack.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qconv_prepack.cpp
@@ -1,5 +1,4 @@
#include <ATen/ATen.h>
-#include <ATen/core/Type.h>
#include <ATen/core/op_registration/op_registration.h>
#include <ATen/cpp_custom_type_hack.h>
#include <ATen/native/quantized/cpu/fbgemm_utils.h>
diff --git a/aten/src/ATen/native/quantized/cpu/qlinear.cpp b/aten/src/ATen/native/quantized/cpu/qlinear.cpp
index 25a5bb2..aef102e 100644
--- a/aten/src/ATen/native/quantized/cpu/qlinear.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qlinear.cpp
@@ -1,5 +1,4 @@
#include <ATen/ATen.h>
-#include <ATen/core/Type.h>
#include <ATen/core/op_registration/op_registration.h>
#include <ATen/cpp_custom_type_hack.h>
#include <ATen/native/quantized/cpu/fbgemm_utils.h>
diff --git a/aten/src/ATen/native/quantized/cpu/qlinear_prepack.cpp b/aten/src/ATen/native/quantized/cpu/qlinear_prepack.cpp
index 0283168..f0889cd 100644
--- a/aten/src/ATen/native/quantized/cpu/qlinear_prepack.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qlinear_prepack.cpp
@@ -1,5 +1,4 @@
#include <ATen/ATen.h>
-#include <ATen/core/Type.h>
#include <ATen/core/op_registration/op_registration.h>
#include <ATen/cpp_custom_type_hack.h>
#include <ATen/native/quantized/cpu/fbgemm_utils.h>
diff --git a/aten/src/ATen/native/quantized/cpu/qlinear_unpack.cpp b/aten/src/ATen/native/quantized/cpu/qlinear_unpack.cpp
index ffc8f81..2a69c52 100644
--- a/aten/src/ATen/native/quantized/cpu/qlinear_unpack.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qlinear_unpack.cpp
@@ -1,5 +1,4 @@
#include <ATen/ATen.h>
-#include <ATen/core/Type.h>
#include <ATen/core/op_registration/op_registration.h>
#include <ATen/cpp_custom_type_hack.h>
#include <ATen/native/quantized/cpu/fbgemm_utils.h>
diff --git a/aten/src/ATen/native/quantized/cpu/qpool.cpp b/aten/src/ATen/native/quantized/cpu/qpool.cpp
index 532e4d9..81b47b4 100644
--- a/aten/src/ATen/native/quantized/cpu/qpool.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qpool.cpp
@@ -1,6 +1,5 @@
#include <ATen/ATen.h>
#include <ATen/Parallel.h>
-#include <ATen/core/Type.h>
#include <ATen/core/op_registration/op_registration.h>
#include <ATen/native/TensorIterator.h>
#include <ATen/native/cpu/Loops.h>
diff --git a/aten/src/ATen/native/quantized/cpu/qrelu.cpp b/aten/src/ATen/native/quantized/cpu/qrelu.cpp
index 0366b8c..fb1e065 100644
--- a/aten/src/ATen/native/quantized/cpu/qrelu.cpp
+++ b/aten/src/ATen/native/quantized/cpu/qrelu.cpp
@@ -1,5 +1,4 @@
#include <ATen/ATen.h>
-#include <ATen/core/Type.h>
#include <ATen/core/op_registration/op_registration.h>
#include <ATen/native/TensorIterator.h>
#include <ATen/native/cpu/Loops.h>
diff --git a/aten/src/ATen/quantized/Quantizer.cpp b/aten/src/ATen/quantized/Quantizer.cpp
index 17c1e0a..fcbd951 100644
--- a/aten/src/ATen/quantized/Quantizer.cpp
+++ b/aten/src/ATen/quantized/Quantizer.cpp
@@ -3,7 +3,6 @@
#include <c10/core/Allocator.h>
#include <ATen/Dispatch.h>
#include <ATen/NativeFunctions.h>
-#include <ATen/Type.h>
#include <ATen/native/TensorFactories.h>
#include <ATen/quantized/QTensorImpl.h>
#include <ATen/core/Tensor.h>
diff --git a/aten/src/ATen/templates/Functions.h b/aten/src/ATen/templates/Functions.h
index e97a9d9..eb0921b 100644
--- a/aten/src/ATen/templates/Functions.h
+++ b/aten/src/ATen/templates/Functions.h
@@ -3,8 +3,6 @@
// ${generated_comment}
#include <c10/core/Scalar.h>
-#include <ATen/Type.h>
-#include <ATen/TypeExtendedInterface.h>
#include <ATen/Tensor.h>
#include <c10/core/Storage.h>
#include <ATen/core/Generator.h>
diff --git a/aten/src/ATen/templates/LegacyTHDispatcher.cpp b/aten/src/ATen/templates/LegacyTHDispatcher.cpp
deleted file mode 100644
index bd45c27..0000000
--- a/aten/src/ATen/templates/LegacyTHDispatcher.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "ATen/LegacyTHDispatcher.h"
-
-// ${generated_comment}
-
-namespace at {
-
-// template: legacy_type_method_definitions
-
-}
diff --git a/aten/src/ATen/templates/LegacyTHDispatcher.h b/aten/src/ATen/templates/LegacyTHDispatcher.h
deleted file mode 100644
index c9ae89c..0000000
--- a/aten/src/ATen/templates/LegacyTHDispatcher.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-// ${generated_comment}
-
-#include <c10/core/TensorTypeIdRegistration.h>
-
-namespace at {
-
-struct CAFFE2_API LegacyTHDispatcher {
- explicit LegacyTHDispatcher(TensorTypeId type_id)
- : type_id_(type_id) {}
-
- virtual ~LegacyTHDispatcher() {}
-
-protected:
- TensorTypeId type_id_;
-};
-
-} // namespace th
-
diff --git a/aten/src/ATen/templates/LegacyTHDispatcherDerived.cpp b/aten/src/ATen/templates/LegacyTHDispatcherDerived.cpp
deleted file mode 100644
index 310a63d..0000000
--- a/aten/src/ATen/templates/LegacyTHDispatcherDerived.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "ATen/${Dispatcher}.h"
-
-// ${generated_comment}
-
-namespace at {
-
-${Dispatcher}::${Dispatcher}()
- : LegacyTHDispatcher(${Backend}TensorId()) {}
-
-}
diff --git a/aten/src/ATen/templates/LegacyTHDispatcherDerived.h b/aten/src/ATen/templates/LegacyTHDispatcherDerived.h
deleted file mode 100644
index 679f6b7..0000000
--- a/aten/src/ATen/templates/LegacyTHDispatcherDerived.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-// ${generated_comment}
-
-#include "ATen/LegacyTHDispatcher.h"
-
-namespace at {
-
-struct ${Dispatcher} final : public LegacyTHDispatcher {
- explicit ${Dispatcher}();
-
-};
-
-} // namespace at
diff --git a/aten/src/ATen/templates/NativeFunctions.h b/aten/src/ATen/templates/NativeFunctions.h
index cadd207..6f47ef3 100644
--- a/aten/src/ATen/templates/NativeFunctions.h
+++ b/aten/src/ATen/templates/NativeFunctions.h
@@ -5,6 +5,7 @@
#include <ATen/Context.h>
#include <c10/core/ScalarType.h>
#include <c10/core/TensorOptions.h>
+#include <ATen/core/Reduction.h>
#include <array>
#include <functional>
diff --git a/aten/src/ATen/templates/RegisterCPU.cpp b/aten/src/ATen/templates/RegisterCPU.cpp
deleted file mode 100644
index 0876b49..0000000
--- a/aten/src/ATen/templates/RegisterCPU.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#include <ATen/RegisterCPU.h>
-
-// ${generated_comment}
-
-#include <ATen/core/Tensor.h>
-#include <ATen/Context.h>
-#include <ATen/UndefinedType.h>
-#include <ATen/core/VariableHooksInterface.h>
-
-${cpu_type_headers}
-
-namespace at {
-
-void register_cpu_types(Context * context) {
- ${cpu_type_registrations}
- context->registerType(Backend::Undefined, new UndefinedType());
-}
-
-} // namespace at
diff --git a/aten/src/ATen/templates/RegisterCPU.h b/aten/src/ATen/templates/RegisterCPU.h
deleted file mode 100644
index b923c18..0000000
--- a/aten/src/ATen/templates/RegisterCPU.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-
-// ${generated_comment}
-
-namespace at {
-
-class Context;
-void register_cpu_types(Context * context);
-
-} // namespace at
diff --git a/aten/src/ATen/templates/RegisterCUDA.cpp b/aten/src/ATen/templates/RegisterCUDA.cpp
deleted file mode 100644
index b327b78..0000000
--- a/aten/src/ATen/templates/RegisterCUDA.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <ATen/RegisterCUDA.h>
-
-// ${generated_comment}
-
-#include <ATen/Type.h>
-#include <ATen/Context.h>
-#include <ATen/core/VariableHooksInterface.h>
-
-${cuda_type_headers}
-
-namespace at {
-
-void register_cuda_types(Context * context) {
- ${cuda_type_registrations}
-}
-
-} // namespace at
diff --git a/aten/src/ATen/templates/RegisterCUDA.h b/aten/src/ATen/templates/RegisterCUDA.h
deleted file mode 100644
index 3fa97c6..0000000
--- a/aten/src/ATen/templates/RegisterCUDA.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-
-// ${generated_comment}
-
-namespace at {
-
-class Context;
-void register_cuda_types(Context * context);
-
-} // namespace at
diff --git a/aten/src/ATen/templates/SparseTypeDerived.cpp b/aten/src/ATen/templates/SparseTypeDerived.cpp
index dc9f2d0..a706ac0 100644
--- a/aten/src/ATen/templates/SparseTypeDerived.cpp
+++ b/aten/src/ATen/templates/SparseTypeDerived.cpp
@@ -28,17 +28,6 @@
namespace at {
-${Type}::${Type}()
- : ${DeviceType}TypeDefault() {}
-
-const char * ${Type}::toString() const {
- return "${Type}";
-}
-
-TypeID ${Type}::ID() const {
- return ${TypeID};
-}
-
${type_derived_method_definitions}
static auto& registerer = globalATenDispatch()
diff --git a/aten/src/ATen/templates/Tensor.h b/aten/src/ATen/templates/Tensor.h
index b71b248..47f377c 100644
--- a/aten/src/ATen/templates/Tensor.h
+++ b/aten/src/ATen/templates/Tensor.h
@@ -1,6 +1,5 @@
#pragma once
-#include <ATen/core/Type.h>
#include <c10/core/Device.h>
#include <c10/core/Layout.h>
#include <c10/core/MemoryFormat.h>
@@ -211,9 +210,6 @@
scalar_type(),
is_variable());
}
- Type & dispatch_type() const {
- return legacyTensorType(*impl_);
- }
TensorTypeId type_id() const {
return impl_->type_id();
}
diff --git a/aten/src/ATen/templates/Type.h b/aten/src/ATen/templates/Type.h
deleted file mode 100644
index 4888704..0000000
--- a/aten/src/ATen/templates/Type.h
+++ /dev/null
@@ -1,73 +0,0 @@
-#pragma once
-
-#include <ATen/core/ATenGeneral.h>
-#include <c10/core/Allocator.h>
-#include <c10/util/Deprecated.h>
-#include <ATen/core/Generator.h>
-#include <c10/core/Layout.h>
-#include <c10/core/MemoryFormat.h>
-#include <c10/core/QScheme.h>
-#include <c10/core/Scalar.h>
-#include <c10/core/ScalarType.h>
-#include <c10/util/ArrayRef.h>
-#include <c10/util/Half.h>
-#include <c10/core/TensorTypeIdRegistration.h>
-#include <ATen/core/Reduction.h>
-#include <c10/core/TensorOptions.h>
-#include <c10/util/intrusive_ptr.h>
-
-#include <c10/util/Optional.h>
-
-#include <array>
-#include <cstddef>
-#include <functional>
-#include <limits>
-#include <memory>
-
-#ifdef NAMEDTENSOR_ENABLED
-#include <ATen/Dimname.h>
-#endif
-
-// To solve the conflict of s_addr in inaddr.h
-#ifdef _MSC_VER
-#ifdef s_addr
-#undef s_addr
-#endif
-#endif
-
-namespace c10 {
-struct Storage;
-}
-
-namespace at {
-
-class Tensor;
-using TensorList = ArrayRef<Tensor>;
-
-class Context;
-struct Generator;
-
-struct Quantizer;
-// This is temporary typedef to enable Quantizer in aten native function API
-// we'll remove them when we are actually exposing Quantizer class
-// to frontend
-using ConstQuantizerPtr = const c10::intrusive_ptr<Quantizer>&;
-
-static inline void noop_deleter(void*) {}
-
-enum class TypeID {
- ${type_ids}
- ComplexCPU,
- Undefined,
- NumOptions
-};
-
-struct CAFFE2_API Type {
- explicit Type() {}
-
- virtual ~Type() {}
- virtual const char * toString() const = 0;
- virtual TypeID ID() const = 0;
-};
-
-} // namespace at
diff --git a/aten/src/ATen/templates/TypeDefault.h b/aten/src/ATen/templates/TypeDefault.h
index f4c18d2..1f1a769 100644
--- a/aten/src/ATen/templates/TypeDefault.h
+++ b/aten/src/ATen/templates/TypeDefault.h
@@ -1,14 +1,12 @@
#pragma once
-// ${generated_comment}
+#include <ATen/ATen.h>
-#include <ATen/TypeExtendedInterface.h>
+// ${generated_comment}
namespace at {
-struct CAFFE2_API TypeDefault : public TypeExtendedInterface {
- explicit TypeDefault() {}
-
+struct CAFFE2_API TypeDefault {
${type_method_declarations}
};
diff --git a/aten/src/ATen/templates/TypeDerived.cpp b/aten/src/ATen/templates/TypeDerived.cpp
index ea47d44..9883cbf 100644
--- a/aten/src/ATen/templates/TypeDerived.cpp
+++ b/aten/src/ATen/templates/TypeDerived.cpp
@@ -35,17 +35,6 @@
namespace at {
-${Type}::${Type}()
- : ${DeviceType}TypeDefault() {}
-
-const char * ${Type}::toString() const {
- return "${Type}";
-}
-
-TypeID ${Type}::ID() const {
- return ${TypeID};
-}
-
/* example
Tensor * ${Type}::add(Tensor & a, Tensor & b) {
std::cout << "add Tensor with backend ${Backend}\n";
diff --git a/aten/src/ATen/templates/TypeDerived.h b/aten/src/ATen/templates/TypeDerived.h
index 5b12072..a44580c 100644
--- a/aten/src/ATen/templates/TypeDerived.h
+++ b/aten/src/ATen/templates/TypeDerived.h
@@ -2,27 +2,14 @@
// ${generated_comment}
-#include <ATen/CPUTypeDefault.h>
#include <ATen/Context.h>
#include <ATen/Utils.h>
$extra_cuda_headers
-#ifdef _MSC_VER
-#ifdef Type
-#undef Type
-#endif
-#endif
-
namespace at {
-struct ${Type} final : public ${DeviceType}TypeDefault {
- explicit ${Type}();
- virtual const char * toString() const override;
- virtual TypeID ID() const override;
-
- // example
- // virtual Tensor * add(Tensor & a, Tensor & b) override;
+struct ${Type} final {
${type_derived_method_declarations}
};
diff --git a/aten/src/ATen/templates/TypeExtendedInterface.h b/aten/src/ATen/templates/TypeExtendedInterface.h
deleted file mode 100644
index 9578c3e..0000000
--- a/aten/src/ATen/templates/TypeExtendedInterface.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-#include <ATen/core/Tensor.h>
-
-namespace at {
-
-struct CAFFE2_API TypeExtendedInterface : public Type {
- explicit TypeExtendedInterface()
- : Type() {}
-};
-
-} // namespace at
diff --git a/aten/src/ATen/templates/TypeExtension.cpp b/aten/src/ATen/templates/TypeExtension.cpp
index cb5583c..ec16d12 100644
--- a/aten/src/ATen/templates/TypeExtension.cpp
+++ b/aten/src/ATen/templates/TypeExtension.cpp
@@ -9,17 +9,6 @@
return fn_table;
}
-${Type}::${Type}()
- : TypeDefault() {}
-
-const char * ${Type}::toString() const {
- return "${Type}";
-}
-
-TypeID ${Type}::ID() const {
- return ${TypeID};
-}
-
${type_method_definitions}
static auto& registerer = globalATenDispatch()
diff --git a/aten/src/ATen/templates/TypeExtension.h b/aten/src/ATen/templates/TypeExtension.h
index 7672479..ea88425 100644
--- a/aten/src/ATen/templates/TypeExtension.h
+++ b/aten/src/ATen/templates/TypeExtension.h
@@ -29,12 +29,7 @@
static std::unordered_map<std::string, void *>& get_fn_table();
};
-struct CAFFE2_API ${Type} : public TypeDefault {
- explicit ${Type}();
-
- virtual const char * toString() const override;
- virtual TypeID ID() const override;
-
+struct CAFFE2_API ${Type} {
${type_method_declarations}
};
diff --git a/aten/src/TH/THGeneral.cpp b/aten/src/TH/THGeneral.cpp
index f8f8a3b..41e4839 100644
--- a/aten/src/TH/THGeneral.cpp
+++ b/aten/src/TH/THGeneral.cpp
@@ -23,8 +23,7 @@
/* Torch Error Handling */
static void defaultErrorHandlerFunction(const char *msg, void *data)
{
- printf("$ Error: %s\n", msg);
- exit(-1);
+ throw std::runtime_error(msg);
}
static THErrorHandlerFunction defaultErrorHandler = defaultErrorHandlerFunction;
@@ -81,11 +80,9 @@
/* Torch Arg Checking Handling */
static void defaultArgErrorHandlerFunction(int argNumber, const char *msg, void *data)
{
- if(msg)
- printf("$ Invalid argument %d: %s\n", argNumber, msg);
- else
- printf("$ Invalid argument %d\n", argNumber);
- exit(-1);
+ std::stringstream new_error;
+ new_error << "invalid argument " << argNumber << ": " << msg;
+ throw std::runtime_error(new_error.str());
}
static THArgErrorHandlerFunction defaultArgErrorHandler = defaultArgErrorHandlerFunction;
diff --git a/cmake/Codegen.cmake b/cmake/Codegen.cmake
index 8a2c3b1..03ccde9 100644
--- a/cmake/Codegen.cmake
+++ b/cmake/Codegen.cmake
@@ -179,7 +179,6 @@
# these are files that are generated by the script and checked in -- the script checks
# that they are equivalent so it must be a dependency of the script
set(core_gen_checked_inputs
- ${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/core/Type.h
${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/core/Tensor.h
${CMAKE_CURRENT_LIST_DIR}/../aten/src/ATen/core/TensorMethods.h)
diff --git a/test/cpp_extensions/complex_registration_extension.cpp b/test/cpp_extensions/complex_registration_extension.cpp
index 2c947ed..5dc020f 100644
--- a/test/cpp_extensions/complex_registration_extension.cpp
+++ b/test/cpp_extensions/complex_registration_extension.cpp
@@ -1,10 +1,5 @@
#include <torch/extension.h>
-#include <ATen/Type.h>
-#include <ATen/core/VariableHooksInterface.h>
-#include <ATen/detail/ComplexHooksInterface.h>
-
-#include <ATen/CPUTypeDefault.h>
#include <c10/core/Allocator.h>
#include <ATen/CPUGenerator.h>
#include <ATen/DeviceGuard.h>
@@ -26,59 +21,36 @@
namespace at {
-struct ComplexCPUType : public at::CPUTypeDefault {
- ComplexCPUType()
- : CPUTypeDefault() {}
+static Tensor empty_complex(IntArrayRef size, const TensorOptions & options, c10::optional<c10::MemoryFormat> optional_memory_format) {
+ TORCH_CHECK(!optional_memory_format.has_value(), "memory format is not supported")
+ AT_ASSERT(options.device().is_cpu());
- const char* toString() const override;
- TypeID ID() const override;
-
- static Tensor empty(IntArrayRef size, const TensorOptions & options, c10::optional<c10::MemoryFormat> optional_memory_format) {
- TORCH_CHECK(!optional_memory_format.has_value(), "memory format is not supported")
- AT_ASSERT(options.device().is_cpu());
-
- for (auto x: size) {
- TORCH_CHECK(x >= 0, "Trying to create tensor using size with negative dimension: ", size);
- }
- auto* allocator = at::getCPUAllocator();
- int64_t nelements = at::prod_intlist(size);
- auto dtype = options.dtype();
- auto storage_impl = c10::make_intrusive<StorageImpl>(
- dtype,
- nelements,
- allocator->allocate(nelements * dtype.itemsize()),
- allocator,
- /*resizable=*/true);
-
- auto tensor = detail::make_tensor<TensorImpl>(storage_impl, at::ComplexCPUTensorId());
- // Default TensorImpl has size [0]
- if (size.size() != 1 || size[0] != 0) {
- tensor.unsafeGetTensorImpl()->set_sizes_contiguous(size);
- }
- return tensor;
+ for (auto x: size) {
+ TORCH_CHECK(x >= 0, "Trying to create tensor using size with negative dimension: ", size);
}
-};
+ auto* allocator = at::getCPUAllocator();
+ int64_t nelements = at::prod_intlist(size);
+ auto dtype = options.dtype();
+ auto storage_impl = c10::make_intrusive<StorageImpl>(
+ dtype,
+ nelements,
+ allocator->allocate(nelements * dtype.itemsize()),
+ allocator,
+ /*resizable=*/true);
-struct ComplexHooks : public at::ComplexHooksInterface {
- ComplexHooks(ComplexHooksArgs) {}
- void registerComplexTypes(Context* context) const override {
- context->registerType(Backend::ComplexCPU, new ComplexCPUType());
+ auto tensor = detail::make_tensor<TensorImpl>(storage_impl, at::ComplexCPUTensorId());
+ // Default TensorImpl has size [0]
+ if (size.size() != 1 || size[0] != 0) {
+ tensor.unsafeGetTensorImpl()->set_sizes_contiguous(size);
}
-};
-
-const char* ComplexCPUType::toString() const {
- return "ComplexCPUType";
+ return tensor;
}
-TypeID ComplexCPUType::ID() const {
- return TypeID::ComplexCPU;
+static auto& complex_empty_registration = globalATenDispatch().registerOp(
+ Backend::ComplexCPU,
+ "aten::empty(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor",
+ &empty_complex);
+
}
-static auto& complex_empty_registration = globalATenDispatch()
- .registerOp(Backend::ComplexCPU, "aten::empty(int[] size, *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None, MemoryFormat? memory_format=None) -> Tensor", &ComplexCPUType::empty);
-
-REGISTER_COMPLEX_HOOKS(ComplexHooks);
-
-} // namespace at
-
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { }
diff --git a/tools/autograd/templates/VariableType.cpp b/tools/autograd/templates/VariableType.cpp
index 3b4a7a4..6b4e33b 100644
--- a/tools/autograd/templates/VariableType.cpp
+++ b/tools/autograd/templates/VariableType.cpp
@@ -1,5 +1,7 @@
#include "torch/csrc/autograd/VariableTypeUtils.h"
+#include <ATen/TypeDefault.h>
+
// ${generated_comment}
// NOTE [Sharded File]: on this file's split-into-shards state
diff --git a/tools/autograd/templates/VariableType.h b/tools/autograd/templates/VariableType.h
index 9809a76..f529ac8 100644
--- a/tools/autograd/templates/VariableType.h
+++ b/tools/autograd/templates/VariableType.h
@@ -4,8 +4,6 @@
#include <ATen/ATen.h>
-#include <ATen/TypeDefault.h>
-
#include <c10/util/intrusive_ptr.h>
#include <torch/csrc/WindowsTorchApiMacro.h>
@@ -44,15 +42,9 @@
// we'll remove them when we are actually exposing Quantizer class
// to frontend
using ConstQuantizerPtr = const c10::intrusive_ptr<Quantizer>&;
-using at::Type;
using c10::optional;
-struct TORCH_API VariableType final : public at::TypeDefault {
- VariableType(Context* context, at::TypeExtendedInterface* baseType);
- const char * toString() const override;
- at::TypeID ID() const override;
-
- static at::TypeExtendedInterface* getVariableTypeFromBaseType(const at::Type& baseType);
+struct TORCH_API VariableType final {
static std::vector<at::DeprecatedTypeProperties*> allCUDATypes();
static std::vector<at::DeprecatedTypeProperties*> allCPUTypes();
@@ -66,10 +58,6 @@
static const at::Tensor & unpack(const Tensor & t, const char * name, int pos);
static at::Tensor unpack_opt(const Tensor & t, const char * name, int pos);
static std::vector<at::Tensor> unpack(at::TensorList tl, const char *name, int pos);
-
- at::TypeExtendedInterface* baseType;
- std::string str;
- size_t id_;
};
}} // namespace torch::autograd
diff --git a/torch/csrc/DynamicTypes.h b/torch/csrc/DynamicTypes.h
index 6e0c4c7..3df3ed5 100644
--- a/torch/csrc/DynamicTypes.h
+++ b/torch/csrc/DynamicTypes.h
@@ -18,10 +18,6 @@
struct Storage;
}
-namespace at {
-struct Type;
-} // namespace at
-
namespace torch {
// Register a PyTypeObject* with the given attributes
void registerStoragePyTypeObject(
diff --git a/torch/csrc/autograd/VariableTypeManual.cpp b/torch/csrc/autograd/VariableTypeManual.cpp
index e4b8e91..0682297 100644
--- a/torch/csrc/autograd/VariableTypeManual.cpp
+++ b/torch/csrc/autograd/VariableTypeManual.cpp
@@ -9,21 +9,6 @@
namespace torch { namespace autograd {
-VariableType::VariableType(Context* context, TypeExtendedInterface* baseType)
- : TypeDefault()
- , baseType(baseType)
- , id_(context->freshTypeID()) {
- str = std::string("Variable[") + baseType->toString() + "]";
-}
-
-const char * VariableType::toString() const {
- return str.c_str();
-}
-
-TypeID VariableType::ID() const {
- return static_cast<TypeID>(id_);
-}
-
namespace {
std::vector<at::DeprecatedTypeProperties*> allTypesForBackends(at::ArrayRef<at::Backend> backends) {
std::vector<DeprecatedTypeProperties*> res;
diff --git a/torch/csrc/autograd/VariableTypeUtils.h b/torch/csrc/autograd/VariableTypeUtils.h
index c9b3267..3f74694 100644
--- a/torch/csrc/autograd/VariableTypeUtils.h
+++ b/torch/csrc/autograd/VariableTypeUtils.h
@@ -18,8 +18,6 @@
#include <torch/csrc/utils/variadic.h>
#include <torch/csrc/autograd/functions/utils.h>
-#include <ATen/core/VariableHooksInterface.h>
-
#include <array>
#include <cstddef>
#include <functional>
@@ -42,8 +40,6 @@
namespace torch { namespace autograd {
-extern std::vector<std::unique_ptr<Type>> type_to_variable_type;
-
inline void check_inplace(const Tensor& tensor) {
auto& var = static_cast<const Variable&>(tensor);
if (var.requires_grad() && var.is_leaf() && GradMode::is_enabled()) {
diff --git a/torch/csrc/jit/python_arg_flatten.h b/torch/csrc/jit/python_arg_flatten.h
index 777afb0..82cf48d 100644
--- a/torch/csrc/jit/python_arg_flatten.h
+++ b/torch/csrc/jit/python_arg_flatten.h
@@ -67,7 +67,7 @@
std::ostream& out,
const IODescriptor::VariableMetadata& meta) {
at::Device meta_device = meta.device;
- auto& t = at::getNonVariableType(
+ auto& t = at::getNonVariableDeprecatedTypeProperties(
meta_device.is_cpu() ? at::Backend::CPU : at::Backend::CUDA, meta.type);
out << t << "(requires_grad=" << meta.requires_grad;
if (meta_device.is_cuda()) {
diff --git a/torch/csrc/jit/script/function_schema_parser.cpp b/torch/csrc/jit/script/function_schema_parser.cpp
index d62e1a2..91c5906 100644
--- a/torch/csrc/jit/script/function_schema_parser.cpp
+++ b/torch/csrc/jit/script/function_schema_parser.cpp
@@ -3,6 +3,7 @@
#include <torch/csrc/jit/script/parse_string_literal.h>
#include <torch/csrc/jit/script/schema_type_parser.h>
#include <c10/util/string_utils.h>
+#include <ATen/core/Reduction.h>
#include <functional>
#include <memory>
diff --git a/torch/csrc/tensor/python_tensor.h b/torch/csrc/tensor/python_tensor.h
index f38267e..a6c7a28 100644
--- a/torch/csrc/tensor/python_tensor.h
+++ b/torch/csrc/tensor/python_tensor.h
@@ -9,7 +9,6 @@
}
namespace at {
-struct Type;
class Tensor;
} // namespace at