Remove THGeneral (#69041)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/69041

`TH_CONCAT_{N}` is still being used by THP so I've moved that into
it's own header but all the compiled code is gone.

Test Plan: Imported from OSS

Reviewed By: anjali411

Differential Revision: D32872477

Pulled By: ngimel

fbshipit-source-id: 06c82d8f96dbcee0715be407c61dfc7d7e8be47a
This commit is contained in:
Peter Bell
2021-12-13 16:12:58 -08:00
committed by Facebook GitHub Bot
parent 8dfdc3df82
commit b08d64202a
24 changed files with 33 additions and 336 deletions

View File

@ -347,13 +347,6 @@ filegroup(
),
)
filegroup(
name = "th_srcs",
srcs = [
"aten/src/TH/THGeneral.cpp",
],
)
filegroup(
name = "aten_cuda_srcs",
srcs = [
@ -510,14 +503,6 @@ header_template_rule(
},
)
header_template_rule(
name = "aten_src_TH_THGeneral",
src = "aten/src/TH/THGeneral.h.in",
out = "aten/src/TH/THGeneral.h",
substitutions = {
},
)
cc_library(
name = "aten_headers",
hdrs = [
@ -541,7 +526,6 @@ cc_library(
],
deps = [
":c10_headers",
":aten_src_TH_THGeneral",
],
)
@ -565,20 +549,6 @@ intern_build_aten_ops(
],
)
cc_library(
name = "th",
srcs = [
":th_srcs",
],
copts = ATEN_COPTS + [
"-mavx",
],
deps = [
":aten_headers",
"@fbgemm",
],
)
cc_library(
name = "aten",
srcs = [
@ -606,7 +576,6 @@ cc_library(
":ATen_CPU",
":aten_headers",
":caffe2_for_aten_headers",
":th",
":torch_headers",
"@fbgemm",
"@ideep",

View File

@ -242,10 +242,6 @@ into the repo directory.
directly.)
* [aten](aten) - C++ tensor library for PyTorch (no autograd support)
* [src](aten/src) - [README](aten/src/README.md)
* [TH](aten/src/TH)
* generic - Contains actual implementations of operators,
parametrized over `scalar_t`. Files here get compiled N times
per supported scalar type in PyTorch.
* [ATen](aten/src/ATen)
* [core](aten/src/ATen/core) - Core functionality of ATen. This
is migrating to top-level c10 folder.

View File

@ -149,7 +149,6 @@ if(BUILD_LITE_INTERPRETER)
append_filelist("jit_core_sources" all_cpu_cpp)
append_filelist("aten_cpu_source_non_codegen_list" all_cpu_cpp)
append_filelist("aten_native_source_non_codegen_list" all_cpu_cpp)
list(APPEND all_cpu_cpp ${Aten_TH_AVX_extra_src})
else()
set(
all_cpu_cpp ${base_cpp} ${ATen_CORE_SRCS} ${native_cpp}

View File

@ -1,37 +1,13 @@
set(Aten_TH_AVX_extra_src)
set(hdr
THGeneral.h THHalf.h THTensor.h)
set(ATen_TH_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/THGeneral.cpp
)
# Remember that PARENT_SCOPE variables are not in the current scope
set(ATen_TH_SRCS ${ATen_TH_SRCS} PARENT_SCOPE)
set(ATen_CPU_SRCS ${ATen_CPU_SRCS} ${ATen_TH_SRCS} PARENT_SCOPE)
# Aten_TH_AVX_extra_src is used in aten/src/ATen/CMakeLists.txt
# when built with BUILD_LITE_INTERPRETER=1
set(Aten_TH_AVX_extra_src ${Aten_TH_AVX_extra_src} PARENT_SCOPE)
######################################################
set(ATen_CPU_INCLUDE ${ATen_CPU_INCLUDE}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
PARENT_SCOPE)
set(ATen_CUDA_INCLUDE ${ATen_CUDA_INCLUDE}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
PARENT_SCOPE)
configure_file(THGeneral.h.in "${CMAKE_CURRENT_BINARY_DIR}/THGeneral.h")
install(FILES
TH.h
${CMAKE_CURRENT_BINARY_DIR}/THGeneral.h
THGenerateByteType.h
THHalf.h
DESTINATION "${ATEN_INSTALL_INCLUDE_SUBDIR}/TH")

View File

@ -1,6 +0,0 @@
#ifndef TH_INC
#define TH_INC
#include <TH/THGeneral.h>
#endif

View File

@ -1,105 +0,0 @@
#include <TH/THGeneral.h>
#ifdef __cplusplus
#include <c10/core/CPUAllocator.h>
#endif
#ifndef TH_HAVE_THREAD
#define __thread
#elif _MSC_VER
#define __thread __declspec( thread )
#endif
#if (defined(__unix) || defined(_WIN32))
#if defined(__FreeBSD__)
#include <malloc_np.h>
#else
#include <malloc.h>
#endif
#elif defined(__APPLE__)
#include <malloc/malloc.h>
#endif
/* Torch Error Handling */
static void defaultErrorHandlerFunction(const char *msg, void *data)
{
throw std::runtime_error(msg);
}
static THErrorHandlerFunction defaultErrorHandler = defaultErrorHandlerFunction;
static void *defaultErrorHandlerData;
// NOLINTNEXTLINE(modernize-use-nullptr,cppcoreguidelines-avoid-non-const-global-variables)
static __thread THErrorHandlerFunction threadErrorHandler = NULL;
static __thread void *threadErrorHandlerData;
void _THError(const char *file, const int line, const char *fmt, ...)
{
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers)
char msg[2048];
va_list args;
/* vasprintf not standard */
/* vsnprintf: how to handle if does not exists? */
va_start(args, fmt);
int n = vsnprintf(msg, 2048, fmt, args);
va_end(args);
if(n < 2048) {
snprintf(msg + n, 2048 - n, " at %s:%d", file, line);
}
if (threadErrorHandler)
(*threadErrorHandler)(msg, threadErrorHandlerData);
else
(*defaultErrorHandler)(msg, defaultErrorHandlerData);
TH_UNREACHABLE;
}
void _THAssertionFailed(const char *file, const int line, const char *exp, const char *fmt, ...) {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers)
char msg[1024];
va_list args;
va_start(args, fmt);
vsnprintf(msg, 1024, fmt, args);
va_end(args);
_THError(file, line, "Assertion `%s' failed. %s", exp, msg);
}
/* Torch Arg Checking Handling */
static void defaultArgErrorHandlerFunction(int argNumber, const char *msg, void *data)
{
std::stringstream new_error;
new_error << "invalid argument " << argNumber << ": " << msg;
throw std::runtime_error(new_error.str());
}
static THArgErrorHandlerFunction defaultArgErrorHandler = defaultArgErrorHandlerFunction;
static void *defaultArgErrorHandlerData;
// NOLINTNEXTLINE(modernize-use-nullptr,cppcoreguidelines-avoid-non-const-global-variables)
static __thread THArgErrorHandlerFunction threadArgErrorHandler = NULL;
static __thread void *threadArgErrorHandlerData;
void _THArgCheck(const char *file, int line, int condition, int argNumber, const char *fmt, ...)
{
if(!condition) {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers)
char msg[2048];
va_list args;
/* vasprintf not standard */
/* vsnprintf: how to handle if does not exists? */
va_start(args, fmt);
int n = vsnprintf(msg, 2048, fmt, args);
va_end(args);
if(n < 2048) {
snprintf(msg + n, 2048 - n, " at %s:%d", file, line);
}
if (threadArgErrorHandler)
(*threadArgErrorHandler)(argNumber, msg, threadArgErrorHandlerData);
else
(*defaultArgErrorHandler)(argNumber, msg, defaultArgErrorHandlerData);
TH_UNREACHABLE;
}
}

View File

@ -1,141 +0,0 @@
#ifndef TH_GENERAL_INC
#define TH_GENERAL_INC
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>
#include <limits.h>
#include <float.h>
#include <time.h>
#include <string.h>
#include <stddef.h>
#include <inttypes.h>
#ifdef TH_BLAS_MKL
#include <mkl_vsl.h>
#endif
# define TH_EXTERNC extern "C"
// Note(jiayq): copied from ATen/core/Macros.h. Because internal build of TH
// and ATen are not unified yet, we need to duplicate code for now. Long term
// we should merge macros.
#ifdef _WIN32
#if !defined(AT_CORE_STATIC_WINDOWS)
// TODO: unify the controlling macros.
#if defined(CAFFE2_BUILD_MAIN_LIBS) || defined(ATen_cpu_EXPORTS) || defined(caffe2_EXPORTS)
#define TH_CPP_API __declspec(dllexport)
#else // defined(CAFFE2_BUILD_MAIN_LIBS) || defined(ATen_cpu_EXPORTS) || defined(caffe2_EXPORTS)
#define TH_CPP_API __declspec(dllimport)
#endif // defined(CAFFE2_BUILD_MAIN_LIBS) || defined(ATen_cpu_EXPORTS) || defined(caffe2_EXPORTS)
#else // !defined(AT_CORE_STATIC_WINDOWS)
#define TH_CPP_API
#endif // !defined(AT_CORE_STATIC_WINDOWS)
#else // _WIN32
#if defined(__GNUC__)
#define TH_CPP_API __attribute__((__visibility__("default")))
#endif // defined(__GNUC__)
#endif // _WIN32
#ifdef NO_EXPORT
#undef TH_CPP_API
#define TH_CPP_API
#endif
#define TH_API TH_CPP_API
#ifdef _WIN32
# define TH_NO_RETURN __declspec(noreturn)
# define TH_UNREACHABLE
#else
# define TH_NO_RETURN __attribute__((noreturn))
# define TH_UNREACHABLE __builtin_unreachable();
#endif
#if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ > 4))
# define TH_UNUSED __attribute__((unused))
#else
# define TH_UNUSED
#endif
typedef void (*THErrorHandlerFunction)(const char *msg, void *data);
typedef void (*THArgErrorHandlerFunction)(int argNumber, const char *msg, void *data);
TH_API TH_NO_RETURN void _THError(const char *file, const int line, const char *fmt, ...);
TH_API void _THAssertionFailed(const char *file, const int line, const char *exp, const char *fmt, ...);
TH_API void _THArgCheck(const char *file, int line, int condition, int argNumber, const char *fmt, ...);
#define THError(...) _THError(__FILE__, __LINE__, __VA_ARGS__)
#define THCleanup(...) __VA_ARGS__
#define THArgCheck(...) \
do { \
_THArgCheck(__FILE__, __LINE__, __VA_ARGS__); \
} while(0)
#define THArgError(...) \
do { \
_THArgCheck(__FILE__, __LINE__, false, __VA_ARGS__); \
TH_UNREACHABLE \
} while(0)
#define THArgCheckWithCleanup(condition, cleanup, ...) \
do if (!(condition)) { \
cleanup \
_THArgCheck(__FILE__, __LINE__, 0, __VA_ARGS__); \
} while(0)
#define THAssert(exp) \
do { \
if (!(exp)) { \
_THAssertionFailed(__FILE__, __LINE__, #exp, ""); \
} \
} while(0)
#define THAssertMsg(exp, ...) \
do { \
if (!(exp)) { \
_THAssertionFailed(__FILE__, __LINE__, #exp, __VA_ARGS__); \
} \
} while(0)
#define TH_CONCAT_STRING_2(x,y) TH_CONCAT_STRING_2_EXPAND(x,y)
#define TH_CONCAT_STRING_2_EXPAND(x,y) #x #y
#define TH_CONCAT_STRING_3(x,y,z) TH_CONCAT_STRING_3_EXPAND(x,y,z)
#define TH_CONCAT_STRING_3_EXPAND(x,y,z) #x #y #z
#define TH_CONCAT_STRING_4(x,y,z,w) TH_CONCAT_STRING_4_EXPAND(x,y,z,w)
#define TH_CONCAT_STRING_4_EXPAND(x,y,z,w) #x #y #z #w
#define TH_CONCAT_2(x,y) TH_CONCAT_2_EXPAND(x,y)
#define TH_CONCAT_2_EXPAND(x,y) x ## y
#define TH_CONCAT_3(x,y,z) TH_CONCAT_3_EXPAND(x,y,z)
#define TH_CONCAT_3_EXPAND(x,y,z) x ## y ## z
#define TH_CONCAT_4_EXPAND(x,y,z,w) x ## y ## z ## w
#define TH_CONCAT_4(x,y,z,w) TH_CONCAT_4_EXPAND(x,y,z,w)
#define THMin(X, Y) ((X) < (Y) ? (X) : (Y))
#define THMax(X, Y) ((X) > (Y) ? (X) : (Y))
#if (defined(_MSC_VER) || defined(__MINGW32__))
#define snprintf _snprintf
#define popen _popen
#define pclose _pclose
#include <BaseTsd.h>
#if !defined(HAVE_SSIZE_T)
typedef SSIZE_T ssize_t;
#endif
#endif
#endif

View File

@ -1,8 +0,0 @@
#ifndef TH_HALF_H
#define TH_HALF_H
#include <c10/util/Half.h>
#define THHalf at::Half
#endif

View File

@ -551,6 +551,11 @@ namespace detail {
_TORCH_WARN_ONCE(__VA_ARGS__); \
}
// Report an error with a specific argument
// NOTE: using the argument name in TORCH_CHECK's message is preferred
#define TORCH_CHECK_ARG(cond, argN, ...) \
TORCH_CHECK(cond, "invalid argument ", argN, ": ", __VA_ARGS__)
// ----------------------------------------------------------------------------
// Deprecated macros
// ----------------------------------------------------------------------------

View File

@ -1250,7 +1250,6 @@ aten_native_source_non_codegen_list = [
"aten/src/ATen/native/sparse/SparseTensorMath.cpp",
"aten/src/ATen/native/sparse/SparseUnaryOps.cpp",
"aten/src/ATen/native/sparse/SparseCsrTensorMath.cpp",
"aten/src/TH/THGeneral.cpp",
"aten/src/ATen/native/utils/Factory.cpp",
"aten/src/ATen/native/xnnpack/Activation.cpp",
"aten/src/ATen/native/xnnpack/ChannelShuffle.cpp",

View File

@ -4,7 +4,6 @@
#include <ATen/ATen.h>
#include <ATen/CPUGeneratorImpl.h>
#include <TH/TH.h>
#include <torch/csrc/THP.h>
#include <torch/csrc/Device.h>
#include <torch/csrc/Exceptions.h>

View File

@ -15,7 +15,7 @@
#include <ATen/VmapMode.h>
#include <ATen/dlpack.h>
#include <ATen/core/Vitals.h>
#include <TH/TH.h>
#include <torch/csrc/THConcat.h>
#include <c10/util/Logging.h>
#include <c10/util/irange.h>
#include <cstdlib>

View File

@ -4,9 +4,6 @@
#endif
#include <structmember.h>
#include <TH/TH.h>
// See Note [TH abstraction violation]
// - Used to get at the allocator associated with a storage
#include <libshm.h>
#include <torch/csrc/THP.h>
#include <torch/csrc/copy_utils.h>

View File

@ -1,5 +1,6 @@
#ifndef THP_STORAGE_INC
#define THP_STORAGE_INC
#include <torch/csrc/THConcat.h>
#define THPStorageStr TH_CONCAT_STRING_3(torch.,Real,Storage)
#define THPStorageClass TH_CONCAT_3(THP,Real,StorageClass)

19
torch/csrc/THConcat.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
#define TH_CONCAT_STRING_2(x,y) TH_CONCAT_STRING_2_EXPAND(x,y)
#define TH_CONCAT_STRING_2_EXPAND(x,y) #x #y
#define TH_CONCAT_STRING_3(x,y,z) TH_CONCAT_STRING_3_EXPAND(x,y,z)
#define TH_CONCAT_STRING_3_EXPAND(x,y,z) #x #y #z
#define TH_CONCAT_STRING_4(x,y,z,w) TH_CONCAT_STRING_4_EXPAND(x,y,z,w)
#define TH_CONCAT_STRING_4_EXPAND(x,y,z,w) #x #y #z #w
#define TH_CONCAT_2(x,y) TH_CONCAT_2_EXPAND(x,y)
#define TH_CONCAT_2_EXPAND(x,y) x ## y
#define TH_CONCAT_3(x,y,z) TH_CONCAT_3_EXPAND(x,y,z)
#define TH_CONCAT_3_EXPAND(x,y,z) x ## y ## z
#define TH_CONCAT_4_EXPAND(x,y,z,w) x ## y ## z ## w
#define TH_CONCAT_4(x,y,z,w) TH_CONCAT_4_EXPAND(x,y,z,w)

View File

@ -2,8 +2,6 @@
#define THP_H
#include <torch/csrc/python_headers.h>
#include <TH/TH.h>
#include <torch/csrc/Export.h>
// Back-compatibility macros, Thanks to http://cx-oracle.sourceforge.net/

View File

@ -2,7 +2,6 @@
#define THP_TYPES_INC
#include <cstddef>
#include <TH/TH.h>
#ifndef INT64_MAX
#include <cstdint>

View File

@ -37,7 +37,6 @@
#include <typeinfo>
#include <sstream>
#include <queue>
#include <TH/TH.h>
namespace torch { namespace autograd {

View File

@ -1,4 +1,3 @@
#include <TH/TH.h>
#include <ATen/ATen.h>
#include <ATen/cuda/CUDAContext.h>
#include <ATen/CUDAGeneratorImpl.h>

View File

@ -1,3 +1,4 @@
#include <torch/csrc/THConcat.h>
#define THWTensor TH_CONCAT_3(TH,Real,Tensor)
#define THWTensor_(NAME) TH_CONCAT_4(TH,Real,Tensor_,NAME)

View File

@ -303,7 +303,7 @@ static PyObject * THPStorage_(fromFile)(PyObject *_unused, PyObject *args, PyObj
shared = at::ALLOCATOR_MAPPED_SHARED;
#ifdef THC_GENERIC_FILE
THError("not available yet for CUDA");
TORCH_CHECK(false, "not available yet for CUDA");
return nullptr;
#else
size_t actual_nbytes = -1;

View File

@ -5,6 +5,7 @@
#include <string>
#include <type_traits>
#include <ATen/ATen.h>
#include <torch/csrc/THConcat.h>
#include <torch/csrc/utils/object_ptr.h>
#include <torch/csrc/utils/python_numbers.h>
#include <torch/csrc/utils/python_compat.h>

View File

@ -148,11 +148,11 @@ void THP_decodeInt64Buffer(int64_t* dst, const uint8_t* src, THPByteOrder order,
}
}
void THP_decodeHalfBuffer(THHalf* dst, const uint8_t* src, THPByteOrder order, size_t len)
void THP_decodeHalfBuffer(c10::Half* dst, const uint8_t* src, THPByteOrder order, size_t len)
{
for(const auto i : c10::irange(len)) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
union { uint16_t x; THHalf f; };
union { uint16_t x; c10::Half f; };
x = (order == THP_BIG_ENDIAN ? decodeUInt16BE(src) : decodeUInt16LE(src));
dst[i] = f;
src += sizeof(uint16_t);

View File

@ -1,6 +1,6 @@
#pragma once
#include <TH/THHalf.h>
#include <c10/util/Half.h>
#include <c10/util/BFloat16.h>
#include <torch/csrc/Export.h>
#include <cstddef>
@ -32,7 +32,7 @@ TORCH_API void THP_decodeInt64Buffer(
THPByteOrder order,
size_t len);
TORCH_API void THP_decodeHalfBuffer(
THHalf* dst,
c10::Half* dst,
const uint8_t* src,
THPByteOrder order,
size_t len);