Skip to content

Commit 9c49bb9

Browse files
Yangqingfacebook-github-bot
authored andcommitted
Move registry fully to c10 (pytorch#12077)
Summary: This does 6 things: - add c10/util/Registry.h as the unified registry util - cleaned up some APIs such as export condition - fully remove aten/core/registry.h - fully remove caffe2/core/registry.h - remove a bogus aten/registry.h - unifying all macros - set up registry testing in c10 Also, an important note that we used to mark the templated Registry class as EXPORT - this should not happen, because one should almost never export a template class. This PR fixes that. Pull Request resolved: pytorch#12077 Reviewed By: ezyang Differential Revision: D10050771 Pulled By: Yangqing fbshipit-source-id: 417b249b49fed6a67956e7c6b6d22374bcee24cf
1 parent 383d340 commit 9c49bb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+593
-670
lines changed

.jenkins/pytorch/test.sh

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ test_aten() {
102102
SUDO=sudo
103103
fi
104104

105+
${SUDO} ln -s "$TORCH_LIB_PATH"/libc10* build/bin
105106
${SUDO} ln -s "$TORCH_LIB_PATH"/libcaffe2* build/bin
106107
${SUDO} ln -s "$TORCH_LIB_PATH"/libnccl* build/bin
107108

aten/src/ATen/Registry.h

-2
This file was deleted.

aten/src/ATen/core/LegacyTypeDispatch.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ LegacyTypeDispatch & globalLegacyTypeDispatch() {
99
return singleton;
1010
}
1111

12-
AT_DEFINE_REGISTRY(LegacyTypeInitRegistry, LegacyTypeInitInterface, LegacyTypeInitArgs)
12+
C10_DEFINE_REGISTRY(
13+
LegacyTypeInitRegistry,
14+
LegacyTypeInitInterface,
15+
LegacyTypeInitArgs)
1316

1417
const LegacyTypeInitInterface& getLegacyTypeInit() {
1518
static std::unique_ptr<LegacyTypeInitInterface> legacy_type_init;

aten/src/ATen/core/LegacyTypeDispatch.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ struct CAFFE2_API LegacyTypeInitInterface {
4343
}
4444
};
4545
struct CAFFE2_API LegacyTypeInitArgs {};
46-
AT_DECLARE_REGISTRY(LegacyTypeInitRegistry, LegacyTypeInitInterface, LegacyTypeInitArgs);
47-
#define REGISTER_LEGACY_TYPE_INIT(clsname) AT_REGISTER_CLASS(LegacyTypeInitRegistry, clsname, clsname)
46+
C10_DECLARE_REGISTRY(
47+
LegacyTypeInitRegistry,
48+
LegacyTypeInitInterface,
49+
LegacyTypeInitArgs);
50+
#define REGISTER_LEGACY_TYPE_INIT(clsname) \
51+
C10_REGISTER_CLASS(LegacyTypeInitRegistry, clsname, clsname)
4852

4953
CAFFE2_API const LegacyTypeInitInterface& getLegacyTypeInit();
5054

aten/src/ATen/core/Registry.h

-217
This file was deleted.

aten/src/ATen/core/VariableHooksInterface.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ namespace detail {
2424

2525
}
2626

27-
AT_DEFINE_REGISTRY(VariableHooksRegistry, VariableHooksInterface, VariableHooksArgs)
27+
C10_DEFINE_REGISTRY(
28+
VariableHooksRegistry,
29+
VariableHooksInterface,
30+
VariableHooksArgs)
2831

2932
} // namespace at::detail

aten/src/ATen/core/VariableHooksInterface.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3-
#include <ATen/core/Registry.h>
4-
#include <ATen/core/ScalarType.h>
53
#include <ATen/core/Backend.h>
4+
#include <ATen/core/ScalarType.h>
5+
#include "c10/util/Registry.h"
66

77
namespace at {
88
class LegacyTypeDispatch;
@@ -39,8 +39,12 @@ struct CAFFE2_API VariableHooksInterface {
3939
// for the "..." in a variadic macro"
4040
struct CAFFE2_API VariableHooksArgs {};
4141

42-
AT_DECLARE_REGISTRY(VariableHooksRegistry, VariableHooksInterface, VariableHooksArgs)
43-
#define REGISTER_VARIABLE_HOOKS(clsname) AT_REGISTER_CLASS(VariableHooksRegistry, clsname, clsname)
42+
C10_DECLARE_REGISTRY(
43+
VariableHooksRegistry,
44+
VariableHooksInterface,
45+
VariableHooksArgs);
46+
#define REGISTER_VARIABLE_HOOKS(clsname) \
47+
C10_REGISTER_CLASS(VariableHooksRegistry, clsname, clsname)
4448

4549
namespace detail {
4650
CAFFE2_API const VariableHooksInterface& getVariableHooks();

aten/src/ATen/detail/CUDAHooksInterface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ const CUDAHooksInterface& getCUDAHooks() {
5454
}
5555
} // namespace detail
5656

57-
AT_DEFINE_REGISTRY(CUDAHooksRegistry, CUDAHooksInterface, CUDAHooksArgs)
57+
C10_DEFINE_REGISTRY(CUDAHooksRegistry, CUDAHooksInterface, CUDAHooksArgs)
5858

5959
} // namespace at

aten/src/ATen/detail/CUDAHooksInterface.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
#include <ATen/Allocator.h>
44
#include <ATen/core/Generator.h>
5-
#include <ATen/core/Registry.h>
65
#include <ATen/core/Error.h>
76

7+
#include "c10/util/Registry.h"
8+
89
#include <cstddef>
910
#include <functional>
1011
#include <memory>
@@ -131,9 +132,9 @@ struct CAFFE2_API CUDAHooksInterface {
131132
// for the "..." in a variadic macro"
132133
struct CAFFE2_API CUDAHooksArgs {};
133134

134-
AT_DECLARE_REGISTRY(CUDAHooksRegistry, CUDAHooksInterface, CUDAHooksArgs)
135+
C10_DECLARE_REGISTRY(CUDAHooksRegistry, CUDAHooksInterface, CUDAHooksArgs);
135136
#define REGISTER_CUDA_HOOKS(clsname) \
136-
AT_REGISTER_CLASS(CUDAHooksRegistry, clsname, clsname)
137+
C10_REGISTER_CLASS(CUDAHooksRegistry, clsname, clsname)
137138

138139
namespace detail {
139140
CAFFE2_API const CUDAHooksInterface& getCUDAHooks();

aten/src/ATen/detail/ComplexHooksInterface.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const ComplexHooksInterface& getComplexHooks() {
2020
}
2121
} // namespace detail
2222

23-
AT_DEFINE_REGISTRY(ComplexHooksRegistry, ComplexHooksInterface, ComplexHooksArgs)
24-
23+
C10_DEFINE_REGISTRY(
24+
ComplexHooksRegistry,
25+
ComplexHooksInterface,
26+
ComplexHooksArgs)
2527
}

aten/src/ATen/detail/ComplexHooksInterface.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <ATen/Registry.h>
43
#include <ATen/Error.h>
4+
#include "c10/util/Registry.h"
55

66
namespace at {
77

@@ -16,9 +16,12 @@ struct CAFFE2_API ComplexHooksInterface {
1616
};
1717

1818
struct CAFFE2_API ComplexHooksArgs {};
19-
AT_DECLARE_REGISTRY(ComplexHooksRegistry, ComplexHooksInterface, ComplexHooksArgs)
19+
C10_DECLARE_REGISTRY(
20+
ComplexHooksRegistry,
21+
ComplexHooksInterface,
22+
ComplexHooksArgs);
2023
#define REGISTER_COMPLEX_HOOKS(clsname) \
21-
AT_REGISTER_CLASS(ComplexHooksRegistry, clsname, clsname)
24+
C10_REGISTER_CLASS(ComplexHooksRegistry, clsname, clsname)
2225

2326
namespace detail {
2427
CAFFE2_API const ComplexHooksInterface& getComplexHooks();

aten/src/THC/THCNumerics.cuh

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef THC_NUMERICS_INC
22
#define THC_NUMERICS_INC
33

4+
#include <cstdlib>
45
#include <limits>
56
#include <cuda.h>
67
#include <assert.h>

c10/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ configure_file(
1616
# check with the core PyTorch developers as the dependendency will be
1717
# transitively passed on to all libraries dependent on PyTorch.
1818
file(GLOB_RECURSE C10_SRCS *.cpp)
19+
# exclude test files
20+
file(GLOB_RECURSE C10_ALL_TEST_FILES test/*.cpp)
21+
exclude(C10_SRCS "${C10_SRCS}" ${C10_ALL_TEST_FILES})
1922
file(GLOB_RECURSE C10_HEADERS *.h)
2023
add_library(c10 ${C10_SRCS} ${C10_HEADERS})
2124
# If building shared library, set dllimport/dllexport proper.
@@ -31,6 +34,8 @@ target_include_directories(
3134
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
3235
$<INSTALL_INTERFACE:include>)
3336

37+
add_subdirectory(test)
38+
3439
# ---[ Installation
3540
# Note: for now, we will put all export path into one single Caffe2Targets group
3641
# to deal with the cmake deployment need. Inside the Caffe2Targets set, the

c10/c10_dummy.cpp

-7
This file was deleted.

0 commit comments

Comments
 (0)