From 9962bfb3c965941b51dbac7a605bf08ec62b17d3 Mon Sep 17 00:00:00 2001 From: Peter Bell Date: Fri, 10 Dec 2021 02:25:44 -0800 Subject: [PATCH] Remove THTensor (#69040) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/69040 Test Plan: Imported from OSS Reviewed By: anjali411 Differential Revision: D32872478 Pulled By: ngimel fbshipit-source-id: f93e16509d64308d91e374744410a6a811e7f4e3 --- BUILD.bazel | 1 - aten/src/TH/CMakeLists.txt | 9 --------- aten/src/TH/TH.h | 1 - aten/src/TH/THTensor.cpp | 22 ---------------------- aten/src/TH/THTensor.h | 12 ------------ aten/src/TH/THTensor.hpp | 21 --------------------- aten/src/TH/generic/THTensor.cpp | 31 ------------------------------- aten/src/TH/generic/THTensor.h | 30 ------------------------------ tools/build_variables.bzl | 1 - torch/csrc/PythonTypes.h | 2 +- torch/csrc/THP.h | 10 ---------- torch/csrc/Types.h | 6 ------ torch/csrc/cuda/Storage.cpp | 3 --- torch/csrc/cuda/override_macros.h | 8 -------- torch/csrc/cuda/undef_macros.h | 14 ++------------ torch/csrc/utils.cpp | 7 ------- 16 files changed, 3 insertions(+), 175 deletions(-) delete mode 100644 aten/src/TH/THTensor.cpp delete mode 100644 aten/src/TH/THTensor.h delete mode 100644 aten/src/TH/THTensor.hpp delete mode 100644 aten/src/TH/generic/THTensor.cpp delete mode 100644 aten/src/TH/generic/THTensor.h diff --git a/BUILD.bazel b/BUILD.bazel index 47ba6b33028..feab0c5fa7b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -352,7 +352,6 @@ filegroup( name = "th_srcs", srcs = [ "aten/src/TH/THGeneral.cpp", - "aten/src/TH/THTensor.cpp", ], ) diff --git a/aten/src/TH/CMakeLists.txt b/aten/src/TH/CMakeLists.txt index 4f9dd08a303..a517998dbe9 100644 --- a/aten/src/TH/CMakeLists.txt +++ b/aten/src/TH/CMakeLists.txt @@ -5,7 +5,6 @@ set(hdr set(ATen_TH_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/THGeneral.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/THTensor.cpp ) # Remember that PARENT_SCOPE variables are not in the current scope set(ATen_TH_SRCS ${ATen_TH_SRCS} PARENT_SCOPE) @@ -34,13 +33,5 @@ install(FILES TH.h ${CMAKE_CURRENT_BINARY_DIR}/THGeneral.h THGenerateByteType.h - THTensor.h THHalf.h - THTensor.hpp DESTINATION "${ATEN_INSTALL_INCLUDE_SUBDIR}/TH") - -install(FILES - generic/THTensor.cpp - generic/THTensor.h - # See Note [TH abstraction violation] - DESTINATION "${ATEN_INSTALL_INCLUDE_SUBDIR}/TH/generic") diff --git a/aten/src/TH/TH.h b/aten/src/TH/TH.h index faba121264e..ce9a7db2ec8 100644 --- a/aten/src/TH/TH.h +++ b/aten/src/TH/TH.h @@ -2,6 +2,5 @@ #define TH_INC #include -#include #endif diff --git a/aten/src/TH/THTensor.cpp b/aten/src/TH/THTensor.cpp deleted file mode 100644 index 8de38b38d49..00000000000 --- a/aten/src/TH/THTensor.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -// NOLINTNEXTLINE(bugprone-suspicious-include) -#include -#include - -#include -#include - -#include - -// NB: This is NOT valid on UndefinedTensorImpl -void THTensor_free(THTensor *self) -{ - if (!self) return; - c10::raw::intrusive_ptr::decref(self); -} - -void THTensor_setStorage(THTensor *self, c10::StorageImpl *storage_, ptrdiff_t storageOffset_, at::IntArrayRef size_, at::IntArrayRef stride_) { - c10::raw::intrusive_ptr::incref(storage_); - THTensor_wrap(self).set_(at::Storage(c10::intrusive_ptr::reclaim(storage_)), storageOffset_, size_, stride_); -} diff --git a/aten/src/TH/THTensor.h b/aten/src/TH/THTensor.h deleted file mode 100644 index 35a870b41f1..00000000000 --- a/aten/src/TH/THTensor.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef TH_TENSOR_INC -#define TH_TENSOR_INC - -#include - -#define THTensor_(NAME) TH_CONCAT_4(TH,Real,Tensor_,NAME) - -/* basics */ -#include -#include - -#endif diff --git a/aten/src/TH/THTensor.hpp b/aten/src/TH/THTensor.hpp deleted file mode 100644 index 3790f9451aa..00000000000 --- a/aten/src/TH/THTensor.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -// STOP!!! Thinking of including this header directly? Please -// read Note [TH abstraction violation] - -#include -#include - -#include -#include - -// Returns a Tensor given a TensorImpl. The TensorImpl remains valid after the -// the Tensor is destroyed. -inline at::Tensor THTensor_wrap(THTensor* tensor) { - c10::raw::intrusive_ptr::incref(tensor); - return at::Tensor(c10::intrusive_ptr::reclaim(tensor)); -} - -TH_API void THTensor_free(THTensor *self); - -TH_CPP_API void THTensor_setStorage(THTensor *self, c10::StorageImpl *storage_, ptrdiff_t storageOffset_, at::IntArrayRef size_, at::IntArrayRef stride_); diff --git a/aten/src/TH/generic/THTensor.cpp b/aten/src/TH/generic/THTensor.cpp deleted file mode 100644 index 63e36972d8d..00000000000 --- a/aten/src/TH/generic/THTensor.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef TH_GENERIC_FILE -#define TH_GENERIC_FILE "TH/generic/THTensor.cpp" -#else - -#include -#include -#include -#include -#include - -/**** creation methods ****/ - -THTensor *THTensor_(newWithStorage1d)(c10::StorageImpl *storage, ptrdiff_t storageOffset, - int64_t size0, int64_t stride0) -{ - c10::raw::intrusive_ptr::incref(storage); - THTensor* self = c10::make_intrusive( - c10::intrusive_ptr::reclaim(storage), - at::DispatchKey::CPU, -#ifdef THQUANTIZED - caffe2::TypeMeta::Make() -#else - caffe2::TypeMeta::Make() -#endif - ) - .release(); - THTensor_setStorage(self, storage, storageOffset, {size0}, {stride0}); - - return self; -} -#endif diff --git a/aten/src/TH/generic/THTensor.h b/aten/src/TH/generic/THTensor.h deleted file mode 100644 index 25ef6f19f06..00000000000 --- a/aten/src/TH/generic/THTensor.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef TH_GENERIC_FILE -#define TH_GENERIC_FILE "TH/generic/THTensor.h" -#else - -/* a la lua? dim, storageoffset, ... et les methodes ? */ - -#include - -#define THTensor at::TensorImpl - -// These used to be distinct types; for some measure of backwards compatibility and documentation -// alias these to the single THTensor type. -#define THFloatTensor THTensor -#define THDoubleTensor THTensor -#define THHalfTensor THTensor -#define THByteTensor THTensor -#define THCharTensor THTensor -#define THShortTensor THTensor -#define THIntTensor THTensor -#define THLongTensor THTensor -#define THBoolTensor THTensor -#define THBFloat16Tensor THTensor -#define THComplexFloatTensor THTensor -#define THComplexDoubleTensor THTensor - -/**** creation methods ****/ -TH_API THTensor *THTensor_(newWithStorage1d)(c10::StorageImpl *storage_, ptrdiff_t storageOffset_, - int64_t size0_, int64_t stride0_); - -#endif diff --git a/tools/build_variables.bzl b/tools/build_variables.bzl index aace0e14be1..960d2a27b64 100644 --- a/tools/build_variables.bzl +++ b/tools/build_variables.bzl @@ -1250,7 +1250,6 @@ aten_native_source_non_codegen_list = [ "aten/src/ATen/native/sparse/SparseUnaryOps.cpp", "aten/src/ATen/native/sparse/SparseCsrTensorMath.cpp", "aten/src/TH/THGeneral.cpp", - "aten/src/TH/THTensor.cpp", "aten/src/ATen/native/utils/Factory.cpp", "aten/src/ATen/native/xnnpack/Activation.cpp", "aten/src/ATen/native/xnnpack/ChannelShuffle.cpp", diff --git a/torch/csrc/PythonTypes.h b/torch/csrc/PythonTypes.h index a154fc93826..335300409ca 100644 --- a/torch/csrc/PythonTypes.h +++ b/torch/csrc/PythonTypes.h @@ -7,7 +7,7 @@ namespace torch { struct THPVoidTensor { PyObject_HEAD - THVoidTensor *cdata; + c10::TensorImpl *cdata; char device_type; char data_type; }; diff --git a/torch/csrc/THP.h b/torch/csrc/THP.h index 146e6c532a7..82302e3db31 100644 --- a/torch/csrc/THP.h +++ b/torch/csrc/THP.h @@ -3,7 +3,6 @@ #include #include -#include #include @@ -17,15 +16,6 @@ #define PyInt_Type PyLong_Type #endif -// By default, don't specify library state (TH doesn't use one) -#define LIBRARY_STATE -#define LIBRARY_STATE_NOARGS -#define LIBRARY_STATE_TYPE -#define LIBRARY_STATE_TYPE_NOARGS - -#define THWTensor THTensor -#define THWTensor_(NAME) THTensor_(NAME) - #include #include #include diff --git a/torch/csrc/Types.h b/torch/csrc/Types.h index 55bd585db01..5ce05e4e5ec 100644 --- a/torch/csrc/Types.h +++ b/torch/csrc/Types.h @@ -10,10 +10,4 @@ template struct THPTypeInfo {}; -namespace torch { - -typedef THTensor THVoidTensor; - -} // namespace torch - #endif diff --git a/torch/csrc/cuda/Storage.cpp b/torch/csrc/cuda/Storage.cpp index e7911f0f2ae..130709f43a9 100644 --- a/torch/csrc/cuda/Storage.cpp +++ b/torch/csrc/cuda/Storage.cpp @@ -4,9 +4,6 @@ #include #include -// See Note [TH abstraction violation] -// - Used to get at allocator from storage -#include #include #include diff --git a/torch/csrc/cuda/override_macros.h b/torch/csrc/cuda/override_macros.h index 87de7fd0f74..e9a34902d04 100644 --- a/torch/csrc/cuda/override_macros.h +++ b/torch/csrc/cuda/override_macros.h @@ -1,7 +1,6 @@ #include #define THPStoragePtr THCPStoragePtr -#define THWTensorPtr THCTensorPtr #define THPTensorPtr THCPTensorPtr #define THWTensor THCTensor @@ -39,11 +38,4 @@ #define THSPTensorStateless THCSPTensorStateless -#define LIBRARY_STATE_NOARGS state -#define LIBRARY_STATE state, -#define LIBRARY_STATE_TYPE THCState*, -#define LIBRARY_STATE_TYPE_NOARGS THCState* #define TH_GENERIC_FILE THC_GENERIC_FILE - -#define THHostTensor TH_CONCAT_3(TH,Real,Tensor) -#define THHostTensor_(NAME) TH_CONCAT_4(TH,Real,Tensor_,NAME) diff --git a/torch/csrc/cuda/undef_macros.h b/torch/csrc/cuda/undef_macros.h index 4bf1710d26d..2f5ef975ba0 100644 --- a/torch/csrc/cuda/undef_macros.h +++ b/torch/csrc/cuda/undef_macros.h @@ -1,8 +1,4 @@ #undef TH_GENERIC_FILE -#undef LIBRARY_STATE -#undef LIBRARY_STATE_NOARGS -#undef LIBRARY_STATE_TYPE -#undef LIBRARY_STATE_TYPE_NOARGS #undef THPTensor_ #undef THPTensor_stateless_ @@ -21,13 +17,11 @@ #undef THPStorageClass #undef THPStorageType -#undef THWTensor -#undef THWTensor_ - #undef THPStoragePtr -#undef THWTensorPtr #undef THPTensorPtr +#undef THWTensor +#undef THWTensor_ #undef THSPTensor_ #undef THSPTensor_stateless_ @@ -41,7 +35,3 @@ #undef THSPTensorType #undef THSPTensorPtr - - -#undef THHostTensor -#undef THHostTensor_ diff --git a/torch/csrc/utils.cpp b/torch/csrc/utils.cpp index 822497e4d6d..98203fc77d7 100644 --- a/torch/csrc/utils.cpp +++ b/torch/csrc/utils.cpp @@ -176,13 +176,6 @@ bool maybeThrowBackCompatKeepdimWarn(char *func) { return true; } -template<> -void THPPointer::free() { - if (ptr) { - c10::raw::intrusive_ptr::decref(ptr); - } -} - template<> void THPPointer::free() { if (ptr)