From 63db95dd11775b062bb1263c4f8a02e61631c59f Mon Sep 17 00:00:00 2001 From: Sebastian Messmer Date: Tue, 11 Dec 2018 20:40:33 -0800 Subject: Move UndefinedTensorImpl to c10 (meh) (#14817) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/14817 unfortunately, we still need this. Reviewed By: ezyang Differential Revision: D13348041 fbshipit-source-id: e8dcc89f5c71bd1ea2c9813990dac6e58e63b1fd --- c10/core/UndefinedTensorImpl.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ c10/core/UndefinedTensorImpl.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 c10/core/UndefinedTensorImpl.cpp create mode 100644 c10/core/UndefinedTensorImpl.h (limited to 'c10') diff --git a/c10/core/UndefinedTensorImpl.cpp b/c10/core/UndefinedTensorImpl.cpp new file mode 100644 index 0000000000..2e2265397e --- /dev/null +++ b/c10/core/UndefinedTensorImpl.cpp @@ -0,0 +1,40 @@ +#include +#include + +namespace c10 { + +// should this use the globalContext? Can it get a context passed in somehow? +UndefinedTensorImpl::UndefinedTensorImpl() +: TensorImpl(UndefinedTensorId(), caffe2::TypeMeta(), nullptr, /* is variable */ false) { +} + +IntList UndefinedTensorImpl::sizes() const { + AT_ERROR("sizes() called on undefined Tensor"); +} + +int64_t UndefinedTensorImpl::size(int64_t d) const { + AT_ERROR("size(dim) called on an undefined Tensor"); +} + +int64_t UndefinedTensorImpl::stride(int64_t d) const { + AT_ERROR("stride(dim) called on an undefined Tensor"); +} + +int64_t UndefinedTensorImpl::dim() const { + AT_ERROR("dim() called on undefined Tensor"); +} + +const Storage& UndefinedTensorImpl::storage() const { + AT_ERROR("storage() called on undefined Tensor"); +} + +int64_t UndefinedTensorImpl::storage_offset() const { + AT_ERROR("storage_offset() called on an undefined Tensor"); +} + +IntList UndefinedTensorImpl::strides() const { + AT_ERROR("strides() called on undefined Tensor"); +} +UndefinedTensorImpl UndefinedTensorImpl::_singleton; + +} diff --git a/c10/core/UndefinedTensorImpl.h b/c10/core/UndefinedTensorImpl.h new file mode 100644 index 0000000000..5d268b7b82 --- /dev/null +++ b/c10/core/UndefinedTensorImpl.h @@ -0,0 +1,34 @@ +#pragma once + +#include + +namespace c10 { + +struct C10_API UndefinedTensorImpl final : public TensorImpl { + public: + // Without this, we get: + // error: identifier "at::UndefinedTensorImpl::_singleton" is undefined in device code + // (ostensibly because the constexpr tricks MSVC into trying to compile this + // function for device as well). +#ifdef _WIN32 + static inline TensorImpl * singleton() { +#else + static constexpr inline TensorImpl * singleton() { +#endif + return &_singleton; + } + IntList sizes() const override; + IntList strides() const override; + int64_t size(int64_t d) const override; + int64_t stride(int64_t d) const override; + int64_t dim() const override; + const Storage& storage() const override; + int64_t storage_offset() const override; +private: + UndefinedTensorImpl(); + static UndefinedTensorImpl _singleton; +public: + friend struct UndefinedType; +}; + +} // namespace c10 -- cgit v1.2.3