blob: afb8bd5e76c8b7edcd3310e2ed82fbbafc2d0298 [file] [log] [blame]
Michael Andreas Dagitseseb5751d2022-06-15 11:08:48 -07001load(
2 ":ufunc_defs.bzl",
3 "aten_ufunc_generated_cpu_kernel_sources",
4 "aten_ufunc_generated_cpu_sources",
5 "aten_ufunc_generated_cuda_sources",
6)
7
Sergii Dymchenkoa5b48392022-04-15 17:25:29 +00008def define_targets(rules):
9 rules.cc_library(
10 name = "caffe2_serialize",
11 srcs = [
12 "caffe2/serialize/file_adapter.cc",
13 "caffe2/serialize/inline_container.cc",
14 "caffe2/serialize/istream_adapter.cc",
15 "caffe2/serialize/read_adapter_interface.cc",
16 ],
Richard Howell51cc6142022-07-14 20:03:17 +000017 copts = ["-fexceptions"],
Sergii Dymchenkoa5b48392022-04-15 17:25:29 +000018 tags = [
19 "supermodule:android/default/pytorch",
20 "supermodule:ios/default/public.pytorch",
mikey dagitses8b1cf8e2022-04-26 05:00:03 -070021 "-fbcode",
mikey dagitsesf4200602022-04-25 10:45:10 -070022 "xplat",
Sergii Dymchenkoa5b48392022-04-15 17:25:29 +000023 ],
24 visibility = ["//visibility:public"],
25 deps = [
26 ":caffe2_headers",
mikey dagitsesd78dd822022-04-25 09:04:57 -070027 "@com_github_glog//:glog",
28 "//c10",
Md Aamir Raihan7ea723b2022-06-22 15:02:16 +000029 "//third_party/miniz-2.1.0:miniz",
Sergii Dymchenkoa5b48392022-04-15 17:25:29 +000030 ],
Sergii Dymchenkoa5b48392022-04-15 17:25:29 +000031 )
mikey dagitsesf4200602022-04-25 10:45:10 -070032
Michael Andreas Dagitseseb5751d2022-06-15 11:08:48 -070033 #
34 # ATen generated code
35 # You need to keep this is sync with the files written out
36 # by gen.py (in the cmake build system, we track generated files
37 # via generated_cpp.txt and generated_cpp.txt-cuda
38 #
39 # Sure would be nice to use gen.py to create this list dynamically
40 # instead of hardcoding, no? Well, we can't, as discussed in this
41 # thread:
42 # https://fb.facebook.com/groups/askbuck/permalink/1924258337622772/
43
44 gen_aten_srcs = [
45 "aten/src/ATen/native/native_functions.yaml",
46 "aten/src/ATen/native/tags.yaml",
47 ] + rules.glob(["aten/src/ATen/templates/*"])
48
49 gen_aten_cmd = " ".join([
Michael Andreas Dagitsese21c0ac2022-06-15 17:36:32 -070050 "$(execpath //torchgen:gen)",
Michael Andreas Dagitseseb5751d2022-06-15 11:08:48 -070051 "--install_dir=$(RULEDIR)",
52 "--source-path aten/src/ATen",
53 ] + (["--static_dispatch_backend CPU"] if rules.is_cpu_static_dispatch_build() else []))
54
55 gen_aten_outs_cuda = (
56 GENERATED_H_CUDA + GENERATED_CPP_CUDA +
57 aten_ufunc_generated_cuda_sources()
58 )
59
60 gen_aten_outs = (
61 GENERATED_H + GENERATED_H_CORE +
62 GENERATED_CPP + GENERATED_CPP_CORE +
63 aten_ufunc_generated_cpu_sources() +
64 aten_ufunc_generated_cpu_kernel_sources() + [
65 "Declarations.yaml",
66 ] + gen_aten_outs_cuda
67 )
68
69 rules.genrule(
70 name = "gen_aten",
71 srcs = gen_aten_srcs,
72 tools = ["//torchgen:gen"],
73 outs = gen_aten_outs,
74 cmd = gen_aten_cmd,
75 )
76
77 rules.genrule(
78 name = "gen_aten_hip",
79 srcs = gen_aten_srcs,
80 tools = ["//torchgen:gen"],
81 outs = gen_aten_outs_cuda,
82 cmd = gen_aten_cmd + " --rocm",
83 features = ["-create_bazel_outputs"],
84 tags = ["-bazel"],
85 )
86
mikey dagitsesf4200602022-04-25 10:45:10 -070087 rules.genrule(
mikey dagitseseb27c852022-05-03 02:48:27 -070088 name = "generate-code",
89 srcs = [
mikey dagitses37fb6362022-05-05 16:31:35 -070090 ":DispatchKeyNativeFunctions.cpp",
91 ":DispatchKeyNativeFunctions.h",
92 ":LazyIr.h",
Antonio Kim02c4d8772022-05-24 19:29:23 +000093 ":LazyNonNativeIr.h",
mikey dagitses37fb6362022-05-05 16:31:35 -070094 ":RegisterDispatchKey.cpp",
mikey dagitseseb27c852022-05-03 02:48:27 -070095 ":native_functions.yaml",
mikey dagitses37fb6362022-05-05 16:31:35 -070096 ":shape_inference.h",
mikey dagitseseb27c852022-05-03 02:48:27 -070097 ":tags.yaml",
mikey dagitses37fb6362022-05-05 16:31:35 -070098 ":ts_native_functions.cpp",
99 ":ts_native_functions.yaml",
mikey dagitseseb27c852022-05-03 02:48:27 -0700100 ],
101 tools = ["//tools/setup_helpers:generate_code"],
Michael Andreas Dagitsese517fc82022-05-16 14:40:31 -0700102 outs = GENERATED_AUTOGRAD_CPP + GENERATED_AUTOGRAD_PYTHON + GENERATED_TESTING_PY,
Michael Andreas Dagitses86606fb2022-06-15 17:36:30 -0700103 cmd = "$(execpath //tools/setup_helpers:generate_code) " +
mikey dagitses096ff0e2022-05-04 06:48:20 -0700104 "--gen-dir=$(RULEDIR) " +
mikey dagitseseb27c852022-05-03 02:48:27 -0700105 "--native-functions-path $(location :native_functions.yaml) " +
106 "--tags-path=$(location :tags.yaml) " +
107 "--gen_lazy_ts_backend",
108 )
109
Michael Andreas Dagitsesc2ff4132022-05-18 11:28:43 -0700110 rules.cc_library(
111 name = "generated-autograd-headers",
112 hdrs = [":{}".format(h) for h in _GENERATED_AUTOGRAD_CPP_HEADERS + _GENERATED_AUTOGRAD_PYTHON_HEADERS],
113 visibility = ["//visibility:public"],
114 )
115
mikey dagitseseb27c852022-05-03 02:48:27 -0700116 rules.genrule(
mikey dagitsesf4200602022-04-25 10:45:10 -0700117 name = "version_h",
118 srcs = [
119 ":torch/csrc/api/include/torch/version.h.in",
120 ":version.txt",
121 ],
122 outs = ["torch/csrc/api/include/torch/version.h"],
Michael Andreas Dagitsese21c0ac2022-06-15 17:36:32 -0700123 cmd = "$(execpath //tools/setup_helpers:gen_version_header) " +
mikey dagitsesf4200602022-04-25 10:45:10 -0700124 "--template-path $(location :torch/csrc/api/include/torch/version.h.in) " +
125 "--version-path $(location :version.txt) --output-path $@ ",
126 tools = ["//tools/setup_helpers:gen_version_header"],
127 )
mikey dagitseseb27c852022-05-03 02:48:27 -0700128
Michael Andreas Dagitses7dc5b5b2022-06-01 08:02:21 -0700129#
130# ATen generated code
131# You need to keep this is sync with the files written out
132# by gen.py (in the cmake build system, we track generated files
133# via generated_cpp.txt and generated_cpp.txt-cuda
134#
135# Sure would be nice to use gen.py to create this list dynamically
136# instead of hardcoding, no? Well, we can't, as discussed in this
137# thread:
138# https://fb.facebook.com/groups/askbuck/permalink/1924258337622772/
139
140GENERATED_H = [
141 "Functions.h",
142 "NativeFunctions.h",
143 "NativeMetaFunctions.h",
144 "FunctionalInverses.h",
145 "RedispatchFunctions.h",
146 "RegistrationDeclarations.h",
147]
148
149GENERATED_H_CORE = [
150 "Operators.h",
151 # CPUFunctions.h (and likely similar headers) need to be part of core because
152 # of the static dispatch build: TensorBody.h directly includes CPUFunctions.h.
153 # The disinction looks pretty arbitrary though; maybe will can kill core
154 # and merge the two?
155 "CPUFunctions.h",
156 "CPUFunctions_inl.h",
157 "CompositeExplicitAutogradFunctions.h",
158 "CompositeExplicitAutogradFunctions_inl.h",
Brian Hirshadf80602022-06-15 08:34:00 -0700159 "CompositeExplicitAutogradNonFunctionalFunctions.h",
160 "CompositeExplicitAutogradNonFunctionalFunctions_inl.h",
Michael Andreas Dagitses7dc5b5b2022-06-01 08:02:21 -0700161 "CompositeImplicitAutogradFunctions.h",
162 "CompositeImplicitAutogradFunctions_inl.h",
163 "MetaFunctions.h",
164 "MetaFunctions_inl.h",
165 "core/TensorBody.h",
166 "MethodOperators.h",
167 "core/aten_interned_strings.h",
anjali41138350ac2022-06-10 21:48:56 +0000168 "core/enum_tag.h",
Michael Andreas Dagitses7dc5b5b2022-06-01 08:02:21 -0700169]
170
171GENERATED_H_CUDA = [
172 "CUDAFunctions.h",
173 "CUDAFunctions_inl.h",
174]
175
Michael Andreas Dagitses7d12eec2022-06-02 03:39:40 -0700176GENERATED_CPP_CUDA = [
177 "RegisterCUDA.cpp",
178 "RegisterNestedTensorCUDA.cpp",
179 "RegisterSparseCUDA.cpp",
180 "RegisterSparseCsrCUDA.cpp",
181 "RegisterQuantizedCUDA.cpp",
182]
183
Michael Andreas Dagitses7dc5b5b2022-06-01 08:02:21 -0700184GENERATED_CPP = [
185 "Functions.cpp",
186 "RegisterBackendSelect.cpp",
187 "RegisterCPU.cpp",
188 "RegisterQuantizedCPU.cpp",
189 "RegisterNestedTensorCPU.cpp",
190 "RegisterSparseCPU.cpp",
191 "RegisterSparseCsrCPU.cpp",
192 "RegisterMkldnnCPU.cpp",
193 "RegisterCompositeImplicitAutograd.cpp",
194 "RegisterZeroTensor.cpp",
195 "RegisterMeta.cpp",
196 "RegisterCompositeExplicitAutograd.cpp",
Brian Hirshadf80602022-06-15 08:34:00 -0700197 "RegisterCompositeExplicitAutogradNonFunctional.cpp",
Michael Andreas Dagitses7dc5b5b2022-06-01 08:02:21 -0700198 "CompositeViewCopyKernels.cpp",
199 "RegisterSchema.cpp",
200 "RegisterFunctionalization_0.cpp",
201 "RegisterFunctionalization_1.cpp",
202 "RegisterFunctionalization_2.cpp",
203 "RegisterFunctionalization_3.cpp",
204]
205
206GENERATED_CPP_CORE = [
207 "Operators_0.cpp",
208 "Operators_1.cpp",
209 "Operators_2.cpp",
210 "Operators_3.cpp",
211 "Operators_4.cpp",
212 "core/ATenOpList.cpp",
213 "core/TensorMethods.cpp",
214]
215
mikey dagitseseb27c852022-05-03 02:48:27 -0700216# These lists are temporarily living in and exported from the shared
217# structure so that an internal build that lives under a different
218# root can access them. These could technically live in a separate
219# file in the same directory but that would require extra work to
220# ensure that file is synced to both Meta internal repositories and
221# GitHub. This problem will go away when the targets downstream of
222# generate-code that use these lists are moved into the shared
223# structure as well.
224
Michael Andreas Dagitsese517fc82022-05-16 14:40:31 -0700225_GENERATED_AUTOGRAD_PYTHON_HEADERS = [
Michael Andreas Dagitsesa013d832022-05-16 14:40:29 -0700226 "torch/csrc/autograd/generated/python_functions.h",
227]
228
Michael Andreas Dagitsese517fc82022-05-16 14:40:31 -0700229_GENERATED_AUTOGRAD_CPP_HEADERS = [
mikey dagitses096ff0e2022-05-04 06:48:20 -0700230 "torch/csrc/autograd/generated/Functions.h",
231 "torch/csrc/autograd/generated/VariableType.h",
mikey dagitses096ff0e2022-05-04 06:48:20 -0700232 "torch/csrc/autograd/generated/variable_factories.h",
Michael Andreas Dagitsese517fc82022-05-16 14:40:31 -0700233]
234
mikey dagitseseb27c852022-05-03 02:48:27 -0700235GENERATED_TESTING_PY = [
mikey dagitses096ff0e2022-05-04 06:48:20 -0700236 "torch/testing/_internal/generated/annotated_fn_args.py",
mikey dagitseseb27c852022-05-03 02:48:27 -0700237]
238
239GENERATED_LAZY_H = [
mikey dagitses096ff0e2022-05-04 06:48:20 -0700240 "torch/csrc/lazy/generated/LazyIr.h",
Antonio Kim02c4d8772022-05-24 19:29:23 +0000241 "torch/csrc/lazy/generated/LazyNonNativeIr.h",
mikey dagitses096ff0e2022-05-04 06:48:20 -0700242 "torch/csrc/lazy/generated/LazyNativeFunctions.h",
mikey dagitseseb27c852022-05-03 02:48:27 -0700243]
244
Michael Andreas Dagitsesa013d832022-05-16 14:40:29 -0700245_GENERATED_AUTOGRAD_PYTHON_CPP = [
mikey dagitses096ff0e2022-05-04 06:48:20 -0700246 "torch/csrc/autograd/generated/python_functions_0.cpp",
247 "torch/csrc/autograd/generated/python_functions_1.cpp",
248 "torch/csrc/autograd/generated/python_functions_2.cpp",
249 "torch/csrc/autograd/generated/python_functions_3.cpp",
250 "torch/csrc/autograd/generated/python_functions_4.cpp",
251 "torch/csrc/autograd/generated/python_nn_functions.cpp",
252 "torch/csrc/autograd/generated/python_fft_functions.cpp",
253 "torch/csrc/autograd/generated/python_linalg_functions.cpp",
254 "torch/csrc/autograd/generated/python_return_types.cpp",
anjali41138350ac2022-06-10 21:48:56 +0000255 "torch/csrc/autograd/generated/python_enum_tag.cpp",
mikey dagitses096ff0e2022-05-04 06:48:20 -0700256 "torch/csrc/autograd/generated/python_sparse_functions.cpp",
257 "torch/csrc/autograd/generated/python_special_functions.cpp",
258 "torch/csrc/autograd/generated/python_torch_functions_0.cpp",
259 "torch/csrc/autograd/generated/python_torch_functions_1.cpp",
260 "torch/csrc/autograd/generated/python_torch_functions_2.cpp",
261 "torch/csrc/autograd/generated/python_variable_methods.cpp",
Michael Andreas Dagitsesa013d832022-05-16 14:40:29 -0700262]
263
Michael Andreas Dagitsese517fc82022-05-16 14:40:31 -0700264GENERATED_AUTOGRAD_PYTHON = _GENERATED_AUTOGRAD_PYTHON_HEADERS + _GENERATED_AUTOGRAD_PYTHON_CPP
Michael Andreas Dagitsesa013d832022-05-16 14:40:29 -0700265
Michael Andreas Dagitsese517fc82022-05-16 14:40:31 -0700266GENERATED_AUTOGRAD_CPP = [
Michael Andreas Dagitsesa013d832022-05-16 14:40:29 -0700267 "torch/csrc/autograd/generated/Functions.cpp",
268 "torch/csrc/autograd/generated/VariableType_0.cpp",
269 "torch/csrc/autograd/generated/VariableType_1.cpp",
270 "torch/csrc/autograd/generated/VariableType_2.cpp",
271 "torch/csrc/autograd/generated/VariableType_3.cpp",
272 "torch/csrc/autograd/generated/VariableType_4.cpp",
273 "torch/csrc/autograd/generated/TraceType_0.cpp",
274 "torch/csrc/autograd/generated/TraceType_1.cpp",
275 "torch/csrc/autograd/generated/TraceType_2.cpp",
276 "torch/csrc/autograd/generated/TraceType_3.cpp",
277 "torch/csrc/autograd/generated/TraceType_4.cpp",
278 "torch/csrc/autograd/generated/ADInplaceOrViewType_0.cpp",
279 "torch/csrc/autograd/generated/ADInplaceOrViewType_1.cpp",
mikey dagitsesac45fb92022-05-04 06:48:20 -0700280 "torch/csrc/lazy/generated/LazyNativeFunctions.cpp",
281 "torch/csrc/lazy/generated/RegisterAutogradLazy.cpp",
282 "torch/csrc/lazy/generated/RegisterLazy.cpp",
Michael Andreas Dagitsese517fc82022-05-16 14:40:31 -0700283] + _GENERATED_AUTOGRAD_CPP_HEADERS + GENERATED_LAZY_H