Skip to content

Commit

Permalink
Remove remaining THC code (pytorch#69039)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: pytorch#69039

Test Plan: Imported from OSS

Reviewed By: anjali411

Differential Revision: D32872476

Pulled By: ngimel

fbshipit-source-id: 7972aacc24aef9450fb59b707ed6396c501bcb31
  • Loading branch information
peterbell10 authored and facebook-github-bot committed Dec 8, 2021
1 parent 7407e3d commit e279963
Show file tree
Hide file tree
Showing 35 changed files with 20 additions and 289 deletions.
24 changes: 0 additions & 24 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -389,27 +389,6 @@ filegroup(
],
)

filegroup(
name = "thc_srcs_cu",
srcs = [
"aten/src/THC/THCReduceApplyUtils.cu.cc",
"aten/src/THC/THCSortUtils.cu.cc",
"aten/src/THC/THCTensor.cu.cc",
"aten/src/THC/THCTensorCopy.cu.cc",
"aten/src/THC/THCTensorMathScan.cu.cc",
"aten/src/THC/THCTensorScatterGather.cu.cc",
"aten/src/THC/THCTensorSort.cu.cc",
"aten/src/THC/generated/THCTensorSortByte.cu.cc",
"aten/src/THC/generated/THCTensorSortChar.cu.cc",
"aten/src/THC/generated/THCTensorSortDouble.cu.cc",
"aten/src/THC/generated/THCTensorSortFloat.cu.cc",
"aten/src/THC/generated/THCTensorSortHalf.cu.cc",
"aten/src/THC/generated/THCTensorSortInt.cu.cc",
"aten/src/THC/generated/THCTensorSortLong.cu.cc",
"aten/src/THC/generated/THCTensorSortShort.cu.cc",
],
)

filegroup(
name = "aten_srcs_cu",
srcs = [
Expand Down Expand Up @@ -550,9 +529,7 @@ cc_library(
"aten/src/**/*.h",
"aten/src/**/*.hpp",
"aten/src/TH/**/*.cpp",
"aten/src/THC/**/*.cpp",
"aten/src/THC/*.cuh",
"aten/src/THC/generic/*.cu.cc",
],
exclude = [
"aten/src/ATen/Config.h",
Expand Down Expand Up @@ -692,7 +669,6 @@ cu_library(
name = "aten_cuda",
srcs = [
":aten_srcs_cu",
":thc_srcs_cu",
],
copts = ATEN_COPTS + torch_cuda_half_options,
visibility = ["//visibility:public"],
Expand Down
3 changes: 0 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,6 @@ into the repo directory.
* [aten](aten) - C++ tensor library for PyTorch (no autograd support)
* [src](aten/src) - [README](aten/src/README.md)
* [TH](aten/src/TH)
[THC](aten/src/THC) - Legacy library code from the original
Torch. Try not to add things here; we're slowly porting these to
[native](aten/src/ATen/native).
* generic - Contains actual implementations of operators,
parametrized over `scalar_t`. Files here get compiled N times
per supported scalar type in PyTorch.
Expand Down
4 changes: 1 addition & 3 deletions aten/src/ATen/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

namespace at {

Context::Context()
: thc_state(nullptr, [](THCState* p) { /* no-op */ }),
thh_state(nullptr, [](THHState* p) { /* no-op */ }) {}
Context::Context() = default;

// TODO: This could be bad juju if someone calls globalContext() in the
// destructor of an object with static lifetime.
Expand Down
19 changes: 4 additions & 15 deletions aten/src/ATen/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,28 +91,19 @@ class TORCH_API Context {
}
// defined in header so that getNonVariableType has ability to inline
// call_once check. getNonVariableType is called fairly frequently
THCState* lazyInitCUDA() {
void lazyInitCUDA() {
std::call_once(thc_init,[&] {
thc_state = detail::getCUDAHooks().initCUDA();
detail::getCUDAHooks().initCUDA();
});
return thc_state.get();
}
THHState* lazyInitHIP() {
void lazyInitHIP() {
std::call_once(thh_init,[&] {
thh_state = detail::getHIPHooks().initHIP();
detail::getHIPHooks().initHIP();
});
return thh_state.get();
}
static const at::cuda::NVRTC& getNVRTC() {
return detail::getCUDAHooks().nvrtc();
}
THCState* getTHCState() {
// AT_ASSERT(thc_state);
return thc_state.get();
}
THHState* getTHHState() {
return thh_state.get();
}

static bool setFlushDenormal(bool on);

Expand Down Expand Up @@ -261,8 +252,6 @@ class TORCH_API Context {
#endif
bool display_vmap_fallback_warnings_ = false;
c10::optional<at::QEngine> quantized_engine = c10::nullopt;
std::unique_ptr<THCState, void(*)(THCState*)> thc_state;
std::unique_ptr<THHState, void(*)(THHState*)> thh_state;

Allocator* prev_allocator_ptr_{nullptr};
};
Expand Down
14 changes: 1 addition & 13 deletions aten/src/ATen/cuda/detail/CUDAHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#include <c10/util/Exception.h>
#include <c10/cuda/CUDACachingAllocator.h>

#include <THC/THCGeneral.h> // For THCState

#if AT_CUDNN_ENABLED()
#include <ATen/cudnn/cudnn-wrapper.h>
#endif
Expand Down Expand Up @@ -57,16 +55,8 @@ void set_magma_init_fn(void (*fn)()) {
// NB: deleter is dynamic, because we need it to live in a separate
// compilation unit (alt is to have another method in hooks, but
// let's not if we don't need to!)
std::unique_ptr<THCState, void (*)(THCState*)> CUDAHooks::initCUDA() const {
void CUDAHooks::initCUDA() const {
C10_LOG_API_USAGE_ONCE("aten.init.cuda");
// NOTE: THCState is now an empty struct but this pointer is passed
// to every THC function. So we can't remove it before the rest of THC.
auto thc_state = std::unique_ptr<THCState, void (*)(THCState*)>(
new THCState(),
[](THCState* p) {
delete p;
});

// Force the update to enable unit testing. This code get executed before unit tests
// have a chance to enable vitals.
at::vitals::VitalsAPI.setVital("CUDA", "used", "true", /* force = */ true);
Expand All @@ -79,8 +69,6 @@ std::unique_ptr<THCState, void (*)(THCState*)> CUDAHooks::initCUDA() const {
TORCH_INTERNAL_ASSERT(magma_init_fn != nullptr, "Cannot initilaize magma, init routine not set");
magma_init_fn();
#endif

return thc_state;
}

const Generator& CUDAHooks::getDefaultCUDAGenerator(DeviceIndex device_index) const {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/cuda/detail/CUDAHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ TORCH_CUDA_CPP_API c10::optional<int64_t> getDeviceIndexWithPrimaryContext();
// The real implementation of CUDAHooksInterface
struct CUDAHooks : public at::CUDAHooksInterface {
CUDAHooks(at::CUDAHooksArgs) {}
std::unique_ptr<THCState, void(*)(THCState*)> initCUDA() const override;
void initCUDA() const override;
Device getDeviceFromPtr(void* data) const override;
bool isPinnedPtr(void* data) const override;
const Generator& getDefaultCUDAGenerator(DeviceIndex device_index = -1) const override;
Expand Down
5 changes: 1 addition & 4 deletions aten/src/ATen/detail/CUDAHooksInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#include <functional>
#include <memory>

// Forward-declares THCState
struct THCState;

// Forward-declares at::cuda::NVRTC
namespace at { namespace cuda {
struct NVRTC;
Expand Down Expand Up @@ -73,7 +70,7 @@ struct TORCH_API CUDAHooksInterface {
virtual ~CUDAHooksInterface() {}

// Initialize THCState and, transitively, the CUDA state
virtual std::unique_ptr<THCState, void (*)(THCState*)> initCUDA() const {
virtual void initCUDA() const {
TORCH_CHECK(false, "Cannot initialize CUDA without ATen_cuda library. ", CUDA_HELP);
}

Expand Down
7 changes: 2 additions & 5 deletions aten/src/ATen/detail/HIPHooksInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#include <functional>
#include <memory>

// Forward-declares THHState
struct THHState;

namespace at {
class Context;
}
Expand All @@ -29,8 +26,8 @@ struct TORCH_API HIPHooksInterface {
// squelch -Werror=non-virtual-dtor
virtual ~HIPHooksInterface() {}

// Initialize THHState and, transitively, the HIP state
virtual std::unique_ptr<THHState, void (*)(THHState*)> initHIP() const {
// Initialize the HIP library state
virtual void initHIP() const {
AT_ERROR("Cannot initialize HIP without ATen_hip library.");
}

Expand Down
2 changes: 0 additions & 2 deletions aten/src/ATen/miopen/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <stdexcept>
#include <sstream>

struct THCState;

namespace at { namespace native {

class miopen_exception : public std::runtime_error {
Expand Down
1 change: 0 additions & 1 deletion aten/src/ATen/miopen/Utils.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <ATen/ATen.h>
#include <aten/src/THH/THH.h>
#include <ATen/miopen/miopen-wrapper.h>
#include <ATen/miopen/Handle.h>

Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/native/miopen/Conv_miopen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ std::tuple<at::Tensor,at::Tensor,at::Tensor> miopen_depthwise_convolution_backwa
#include <ATen/native/ConvUtils.h>
#include <c10/util/irange.h>

#include <c10/cuda/CUDACachingAllocator.h>
#include <c10/hip/HIPCachingAllocator.h>

#include <functional>
#include <iterator>
Expand Down
2 changes: 0 additions & 2 deletions aten/src/ATen/native/miopen/RNN_miopen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ namespace at { namespace native {

#else // AT_ROCM_ENABLED()

#include <aten/src/THH/THH.h>

#include <ATen/miopen/miopen-wrapper.h>
#include <ATen/miopen/Descriptors.h>
#include <ATen/miopen/Types.h>
Expand Down
16 changes: 1 addition & 15 deletions aten/src/THC/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,8 @@ set(ATen_CUDA_INCLUDE ${ATen_CUDA_INCLUDE}
"${CMAKE_CURRENT_SOURCE_DIR}"
PARENT_SCOPE)

set(ATen_CUDA_SRCS ${ATen_CUDA_SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/THCTensor.cpp
PARENT_SCOPE)

install(FILES
THC.h
THCGeneral.h
THCGeneral.hpp
THCTensor.h
THCAtomics.cuh
THCDeviceUtils.cuh
THCGenerateByteType.h
# See Note [TH abstraction violation]
THCTensor.hpp
DESTINATION "${ATEN_INSTALL_INCLUDE_SUBDIR}/THC")

install(FILES
generic/THCTensor.cpp
generic/THCTensor.h
DESTINATION "${ATEN_INSTALL_INCLUDE_SUBDIR}/THC/generic")
8 changes: 0 additions & 8 deletions aten/src/THC/THC.h

This file was deleted.

18 changes: 0 additions & 18 deletions aten/src/THC/THCGeneral.h

This file was deleted.

3 changes: 0 additions & 3 deletions aten/src/THC/THCGeneral.hpp

This file was deleted.

14 changes: 0 additions & 14 deletions aten/src/THC/THCTensor.cpp

This file was deleted.

18 changes: 0 additions & 18 deletions aten/src/THC/THCTensor.h

This file was deleted.

18 changes: 0 additions & 18 deletions aten/src/THC/THCTensor.hpp

This file was deleted.

24 changes: 0 additions & 24 deletions aten/src/THC/generic/THCTensor.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions aten/src/THC/generic/THCTensor.h

This file was deleted.

Loading

0 comments on commit e279963

Please sign in to comment.