forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.bzl
282 lines (256 loc) · 9.69 KB
/
build.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
load(
":ufunc_defs.bzl",
"aten_ufunc_generated_cpu_kernel_sources",
"aten_ufunc_generated_cpu_sources",
"aten_ufunc_generated_cuda_sources",
)
def define_targets(rules):
rules.cc_library(
name = "caffe2_serialize",
srcs = [
"caffe2/serialize/file_adapter.cc",
"caffe2/serialize/inline_container.cc",
"caffe2/serialize/istream_adapter.cc",
"caffe2/serialize/read_adapter_interface.cc",
],
tags = [
"supermodule:android/default/pytorch",
"supermodule:ios/default/public.pytorch",
"-fbcode",
"xplat",
],
visibility = ["//visibility:public"],
deps = [
":caffe2_headers",
"@com_github_glog//:glog",
"//c10",
"//third_party/miniz-2.1.0:miniz",
],
)
#
# ATen generated code
# You need to keep this is sync with the files written out
# by gen.py (in the cmake build system, we track generated files
# via generated_cpp.txt and generated_cpp.txt-cuda
#
# Sure would be nice to use gen.py to create this list dynamically
# instead of hardcoding, no? Well, we can't, as discussed in this
# thread:
# https://fb.facebook.com/groups/askbuck/permalink/1924258337622772/
gen_aten_srcs = [
"aten/src/ATen/native/native_functions.yaml",
"aten/src/ATen/native/tags.yaml",
] + rules.glob(["aten/src/ATen/templates/*"])
gen_aten_cmd = " ".join([
"$(execpath //torchgen:gen)",
"--install_dir=$(RULEDIR)",
"--source-path aten/src/ATen",
] + (["--static_dispatch_backend CPU"] if rules.is_cpu_static_dispatch_build() else []))
gen_aten_outs_cuda = (
GENERATED_H_CUDA + GENERATED_CPP_CUDA +
aten_ufunc_generated_cuda_sources()
)
gen_aten_outs = (
GENERATED_H + GENERATED_H_CORE +
GENERATED_CPP + GENERATED_CPP_CORE +
aten_ufunc_generated_cpu_sources() +
aten_ufunc_generated_cpu_kernel_sources() + [
"Declarations.yaml",
] + gen_aten_outs_cuda
)
rules.genrule(
name = "gen_aten",
srcs = gen_aten_srcs,
tools = ["//torchgen:gen"],
outs = gen_aten_outs,
cmd = gen_aten_cmd,
)
rules.genrule(
name = "gen_aten_hip",
srcs = gen_aten_srcs,
tools = ["//torchgen:gen"],
outs = gen_aten_outs_cuda,
cmd = gen_aten_cmd + " --rocm",
features = ["-create_bazel_outputs"],
tags = ["-bazel"],
)
rules.genrule(
name = "generate-code",
srcs = [
":DispatchKeyNativeFunctions.cpp",
":DispatchKeyNativeFunctions.h",
":LazyIr.h",
":LazyNonNativeIr.h",
":RegisterDispatchKey.cpp",
":native_functions.yaml",
":shape_inference.h",
":tags.yaml",
":ts_native_functions.cpp",
":ts_native_functions.yaml",
],
tools = ["//tools/setup_helpers:generate_code"],
outs = GENERATED_AUTOGRAD_CPP + GENERATED_AUTOGRAD_PYTHON + GENERATED_TESTING_PY,
cmd = "$(execpath //tools/setup_helpers:generate_code) " +
"--gen-dir=$(RULEDIR) " +
"--native-functions-path $(location :native_functions.yaml) " +
"--tags-path=$(location :tags.yaml) " +
"--gen_lazy_ts_backend",
)
rules.cc_library(
name = "generated-autograd-headers",
hdrs = [":{}".format(h) for h in _GENERATED_AUTOGRAD_CPP_HEADERS + _GENERATED_AUTOGRAD_PYTHON_HEADERS],
visibility = ["//visibility:public"],
)
rules.genrule(
name = "version_h",
srcs = [
":torch/csrc/api/include/torch/version.h.in",
":version.txt",
],
outs = ["torch/csrc/api/include/torch/version.h"],
cmd = "$(execpath //tools/setup_helpers:gen_version_header) " +
"--template-path $(location :torch/csrc/api/include/torch/version.h.in) " +
"--version-path $(location :version.txt) --output-path $@ ",
tools = ["//tools/setup_helpers:gen_version_header"],
)
#
# ATen generated code
# You need to keep this is sync with the files written out
# by gen.py (in the cmake build system, we track generated files
# via generated_cpp.txt and generated_cpp.txt-cuda
#
# Sure would be nice to use gen.py to create this list dynamically
# instead of hardcoding, no? Well, we can't, as discussed in this
# thread:
# https://fb.facebook.com/groups/askbuck/permalink/1924258337622772/
GENERATED_H = [
"Functions.h",
"NativeFunctions.h",
"NativeMetaFunctions.h",
"FunctionalInverses.h",
"RedispatchFunctions.h",
"RegistrationDeclarations.h",
]
GENERATED_H_CORE = [
"Operators.h",
# CPUFunctions.h (and likely similar headers) need to be part of core because
# of the static dispatch build: TensorBody.h directly includes CPUFunctions.h.
# The disinction looks pretty arbitrary though; maybe will can kill core
# and merge the two?
"CPUFunctions.h",
"CPUFunctions_inl.h",
"CompositeExplicitAutogradFunctions.h",
"CompositeExplicitAutogradFunctions_inl.h",
"CompositeExplicitAutogradNonFunctionalFunctions.h",
"CompositeExplicitAutogradNonFunctionalFunctions_inl.h",
"CompositeImplicitAutogradFunctions.h",
"CompositeImplicitAutogradFunctions_inl.h",
"MetaFunctions.h",
"MetaFunctions_inl.h",
"core/TensorBody.h",
"MethodOperators.h",
"core/aten_interned_strings.h",
"core/enum_tag.h",
]
GENERATED_H_CUDA = [
"CUDAFunctions.h",
"CUDAFunctions_inl.h",
]
GENERATED_CPP_CUDA = [
"RegisterCUDA.cpp",
"RegisterNestedTensorCUDA.cpp",
"RegisterSparseCUDA.cpp",
"RegisterSparseCsrCUDA.cpp",
"RegisterQuantizedCUDA.cpp",
]
GENERATED_CPP = [
"Functions.cpp",
"RegisterBackendSelect.cpp",
"RegisterCPU.cpp",
"RegisterQuantizedCPU.cpp",
"RegisterNestedTensorCPU.cpp",
"RegisterSparseCPU.cpp",
"RegisterSparseCsrCPU.cpp",
"RegisterMkldnnCPU.cpp",
"RegisterCompositeImplicitAutograd.cpp",
"RegisterZeroTensor.cpp",
"RegisterMeta.cpp",
"RegisterCompositeExplicitAutograd.cpp",
"RegisterCompositeExplicitAutogradNonFunctional.cpp",
"CompositeViewCopyKernels.cpp",
"RegisterSchema.cpp",
"RegisterFunctionalization_0.cpp",
"RegisterFunctionalization_1.cpp",
"RegisterFunctionalization_2.cpp",
"RegisterFunctionalization_3.cpp",
]
GENERATED_CPP_CORE = [
"Operators_0.cpp",
"Operators_1.cpp",
"Operators_2.cpp",
"Operators_3.cpp",
"Operators_4.cpp",
"core/ATenOpList.cpp",
"core/TensorMethods.cpp",
]
# These lists are temporarily living in and exported from the shared
# structure so that an internal build that lives under a different
# root can access them. These could technically live in a separate
# file in the same directory but that would require extra work to
# ensure that file is synced to both Meta internal repositories and
# GitHub. This problem will go away when the targets downstream of
# generate-code that use these lists are moved into the shared
# structure as well.
_GENERATED_AUTOGRAD_PYTHON_HEADERS = [
"torch/csrc/autograd/generated/python_functions.h",
]
_GENERATED_AUTOGRAD_CPP_HEADERS = [
"torch/csrc/autograd/generated/Functions.h",
"torch/csrc/autograd/generated/VariableType.h",
"torch/csrc/autograd/generated/variable_factories.h",
]
GENERATED_TESTING_PY = [
"torch/testing/_internal/generated/annotated_fn_args.py",
]
GENERATED_LAZY_H = [
"torch/csrc/lazy/generated/LazyIr.h",
"torch/csrc/lazy/generated/LazyNonNativeIr.h",
"torch/csrc/lazy/generated/LazyNativeFunctions.h",
]
_GENERATED_AUTOGRAD_PYTHON_CPP = [
"torch/csrc/autograd/generated/python_functions_0.cpp",
"torch/csrc/autograd/generated/python_functions_1.cpp",
"torch/csrc/autograd/generated/python_functions_2.cpp",
"torch/csrc/autograd/generated/python_functions_3.cpp",
"torch/csrc/autograd/generated/python_functions_4.cpp",
"torch/csrc/autograd/generated/python_nn_functions.cpp",
"torch/csrc/autograd/generated/python_fft_functions.cpp",
"torch/csrc/autograd/generated/python_linalg_functions.cpp",
"torch/csrc/autograd/generated/python_return_types.cpp",
"torch/csrc/autograd/generated/python_enum_tag.cpp",
"torch/csrc/autograd/generated/python_sparse_functions.cpp",
"torch/csrc/autograd/generated/python_special_functions.cpp",
"torch/csrc/autograd/generated/python_torch_functions_0.cpp",
"torch/csrc/autograd/generated/python_torch_functions_1.cpp",
"torch/csrc/autograd/generated/python_torch_functions_2.cpp",
"torch/csrc/autograd/generated/python_variable_methods.cpp",
]
GENERATED_AUTOGRAD_PYTHON = _GENERATED_AUTOGRAD_PYTHON_HEADERS + _GENERATED_AUTOGRAD_PYTHON_CPP
GENERATED_AUTOGRAD_CPP = [
"torch/csrc/autograd/generated/Functions.cpp",
"torch/csrc/autograd/generated/VariableType_0.cpp",
"torch/csrc/autograd/generated/VariableType_1.cpp",
"torch/csrc/autograd/generated/VariableType_2.cpp",
"torch/csrc/autograd/generated/VariableType_3.cpp",
"torch/csrc/autograd/generated/VariableType_4.cpp",
"torch/csrc/autograd/generated/TraceType_0.cpp",
"torch/csrc/autograd/generated/TraceType_1.cpp",
"torch/csrc/autograd/generated/TraceType_2.cpp",
"torch/csrc/autograd/generated/TraceType_3.cpp",
"torch/csrc/autograd/generated/TraceType_4.cpp",
"torch/csrc/autograd/generated/ADInplaceOrViewType_0.cpp",
"torch/csrc/autograd/generated/ADInplaceOrViewType_1.cpp",
"torch/csrc/lazy/generated/LazyNativeFunctions.cpp",
"torch/csrc/lazy/generated/RegisterAutogradLazy.cpp",
"torch/csrc/lazy/generated/RegisterLazy.cpp",
] + _GENERATED_AUTOGRAD_CPP_HEADERS + GENERATED_LAZY_H