pytorch

Форк
0
/
buckbuild.bzl 
2209 строк · 81.8 Кб
1
# NOTE: This file is shared by internal and OSS BUCK build.
2
# These load paths point to different files in internal and OSS environment
3

4
load("@bazel_skylib//lib:paths.bzl", "paths")
5
load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native")
6
load("//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library")
7
load("//tools/build_defs:fb_xplat_genrule.bzl", "fb_xplat_genrule")
8
load("//tools/build_defs:fbsource_utils.bzl", "is_arvr_mode")
9
load("//tools/build_defs:glob_defs.bzl", "subdir_glob")
10
load("//tools/build_defs:platform_defs.bzl", "APPLETVOS", "IOS", "MACOSX")
11
load("//tools/build_defs:type_defs.bzl", "is_list", "is_string")
12
load("//tools/build_defs/android:build_mode_defs.bzl", is_production_build_android = "is_production_build")
13
load("//tools/build_defs/apple:build_mode_defs.bzl", is_production_build_ios = "is_production_build")
14
load("//tools/build_defs/windows:windows_flag_map.bzl", "windows_convert_gcc_clang_flags")
15
load(
16
    ":build_variables.bzl",
17
    "aten_cpu_source_list",
18
    "aten_native_source_list",
19
    "core_sources_common",
20
    "core_sources_full_mobile_no_backend_interface_xplat",
21
    "core_trainer_sources",
22
    "jit_core_headers",
23
    "jit_core_sources",
24
    "libtorch_profiler_sources",
25
    "torch_cpp_srcs",
26
    "torch_mobile_tracer_sources",
27
)
28
load(
29
    ":pt_ops.bzl",
30
    "USED_PT_BACKENDS",
31
)
32
load(
33
    ":pt_template_srcs.bzl",
34
    "METAL_MASKRCNN_SOURCE_LIST",
35
    "METAL_SOURCE_LIST",
36
    "TEMPLATE_MASKRCNN_SOURCE_LIST",
37
    "TEMPLATE_SOURCE_LIST",
38
    "aten_ufunc_generated_all_cpu_sources",
39
    "get_gen_oplist_outs",
40
    "get_generate_code_bin_outs",
41
    "get_metal_registration_files_outs",
42
    "get_metal_registration_files_outs_windows",
43
    "get_metal_source_dict",
44
    "get_template_registration_file_rules",
45
    "get_template_registration_files_outs",
46
    "get_template_source_dict",
47
)
48
load(
49
    ":ufunc_defs.bzl",
50
    "aten_ufunc_generated_cpu_kernel_sources",
51
    "aten_ufunc_generated_cpu_sources",
52
    "aten_ufunc_generated_cuda_sources",
53
)
54

55
def read_bool(section, field, default, required = True):
56
    # @lint-ignore BUCKRESTRICTEDSYNTAX
57
    val = read_config(section, field)
58
    if val != None:
59
        if val in ["true", "True", "1"]:
60
            return True
61
        elif val in ["false", "False", "0"]:
62
            return False
63
        else:
64
            fail(
65
                "`{}:{}`: must be one of (0, 1, true, false, True, False), but was {}".format(section, field, val),
66
            )
67
    elif default != None:
68
        return default
69
    elif not required:
70
        return None
71
    else:
72
        fail("`{}:{}`: no value set".format(section, field))
73

74
def _is_build_mode_dev():
75
    if is_production_build_android():
76
        # Android Prod builds
77
        return False
78
    if is_production_build_ios():
79
        # iOS Prod builds
80
        return False
81

82
    return True
83

84
def _get_enable_lightweight_dispatch():
85
    return read_bool("pt", "enable_lightweight_dispatch", False)
86

87
def _get_enable_record_kernel_dtype():
88
    return read_bool("pt", "enable_record_kernel_dtype", False)
89

90
def get_enable_mobile_dispatch_keys_trimming():
91
    return read_bool("pt", "enable_mobile_dispatch_keys_trimming", False)
92

93
def get_disable_per_op_profiling():
94
    return read_bool("pt", "disable_per_op_profiling", True)
95

96
def get_strip_error_messages():
97
    if IS_OSS:
98
        return True  # always strip in OSS CI to expose potential issues
99
    return read_bool("pt", "strip_error_messages", not _is_build_mode_dev())
100

101
def get_disable_warn():
102
    return read_bool("pt", "disable_warn", False)
103

104
def get_enable_eager_symbolication():
105
    return read_bool("pt", "enable_eager_symbolication", default = False, required = False)
106

107
def get_static_dispatch_backend():
108
    static_dispatch_backend = native.read_config("pt", "static_dispatch_backend", None)
109
    if static_dispatch_backend == None:
110
        return []
111
    return static_dispatch_backend.split(";")
112

113
def get_glsl_image_format():
114
    if read_config("pt", "vulkan_full_precision", "0") == "0":
115
        return "rgba16f"
116
    return "rgba32f"
117

118
def get_glsl_paths():
119
    paths = [
120
        "//xplat/caffe2:aten_vulkan_glsl_src_path",
121
        "aten/src/ATen/native/vulkan/glsl",
122
    ] + [
123
        p
124
        for p in read_config("gen_vulkan_spv", "additional_glsl_paths", "").split(" ")
125
        if p
126
    ]
127

128
    if len(paths) % 2 != 0:
129
        fail(
130
            "gen_vulkan_spv.additional_glsl_paths must contain an even number of elements",
131
        )
132

133
    return " ".join(
134
        [
135
            "$(location {})/{}".format(
136
                paths[i],
137
                paths[i + 1],
138
            )
139
            for i in range(
140
                0,
141
                len(paths),
142
                2,
143
            )
144
        ],
145
    )
146

147
# @lint-ignore BUCKRESTRICTEDSYNTAX
148
IS_OSS = read_config("pt", "is_oss", "0") == "1"  # True for OSS BUCK build, and False for internal BUCK build
149

150
NOT_OSS = not IS_OSS
151

152
# for targets in caffe2 root path
153
ROOT = "//" if IS_OSS else "//xplat/caffe2"
154

155
# for targets in subfolders
156
ROOT_PATH = "//" if IS_OSS else "//xplat/caffe2/"
157

158
C10 = "//c10:c10" if IS_OSS else "//xplat/caffe2/c10:c10"
159

160
# a dictionary maps third party library name to fbsource and oss target
161
THIRD_PARTY_LIBS = {
162
    "FP16": ["//xplat/third-party/FP16:FP16", "//third_party:FP16"],
163
    "FXdiv": ["//xplat/third-party/FXdiv:FXdiv", "//third_party:FXdiv"],
164
    "XNNPACK": ["//xplat/third-party/XNNPACK:XNNPACK", "//third_party:XNNPACK"],
165
    "clog": ["//xplat/third-party/clog:clog", "//third_party:clog"],
166
    "cpuinfo": ["//third-party/cpuinfo:cpuinfo", "//third_party:cpuinfo"],
167
    "flatbuffers-api": ["//third-party/flatbuffers/fbsource_namespace:flatbuffers-api", "//third_party:flatbuffers-api"],
168
    "flatc": ["//third-party/flatbuffers/fbsource_namespace:flatc", "//third_party:flatc"],
169
    "fmt": ["//third-party/fmt:fmt", "//third_party:fmt"],
170
    "glog": ["//third-party/glog:glog", "//third_party:glog"],
171
    "gmock": ["//third-party/googletest:gmock_main", "//third_party:gmock"],
172
    "gtest": ["//third-party/googletest:gtest_main", "//third_party:gtest"],
173
    "kineto": ["//xplat/kineto/libkineto:libkineto", "//third_party:libkineto"],
174
    "libkineto_headers": ["//xplat/kineto/libkineto:libkineto_headers", "//third_party:libkineto_headers"],
175
    "omp": ["//xplat/third-party/linker_lib:omp", "//third_party:no-op"],
176
    "pocketfft": ["//third-party/pocket_fft:pocketfft", "//third_party:pocketfft_header"],
177
    "psimd": ["//xplat/third-party/psimd:psimd", "//third_party:psimd"],
178
    "pthreadpool": ["//xplat/third-party/pthreadpool:pthreadpool", "//third_party:pthreadpool"],
179
    "pthreadpool_header": ["//xplat/third-party/pthreadpool:pthreadpool_header", "//third_party:pthreadpool_header"],
180
    "pyyaml": ["//third-party/pyyaml:pyyaml", "//third_party:pyyaml"],
181
    "rt": ["//xplat/third-party/linker_lib:rt", "//third_party:rt"],
182
    "ruy": ["//third-party/ruy:ruy_xplat_lib", "//third_party:ruy_lib"],
183
    "sleef_arm": ["//third-party/sleef:sleef_arm", "//third_party:sleef_arm"],
184
    "typing-extensions": ["//third-party/typing-extensions:typing-extensions", "//third_party:typing-extensions"],
185
}
186

187
def third_party(name):
188
    if name not in THIRD_PARTY_LIBS:
189
        fail("Cannot find third party library " + name + ", please register it in THIRD_PARTY_LIBS first!")
190
    return THIRD_PARTY_LIBS[name][1] if IS_OSS else THIRD_PARTY_LIBS[name][0]
191

192
def get_pt_compiler_flags():
193
    return select({
194
        "DEFAULT": _PT_COMPILER_FLAGS,
195
        "ovr_config//compiler:cl": windows_convert_gcc_clang_flags(_PT_COMPILER_FLAGS),
196
    })
197

198
_PT_COMPILER_FLAGS = [
199
    "-fexceptions",
200
    "-frtti",
201
    "-Os",
202
    "-Wno-unknown-pragmas",
203
    "-Wno-write-strings",
204
    "-Wno-unused-variable",
205
    "-Wno-unused-function",
206
    "-Wno-deprecated-declarations",
207
    "-Wno-shadow",
208
    "-Wno-global-constructors",
209
    "-Wno-missing-prototypes",
210
]
211

212
ATEN_COMPILER_FLAGS = [
213
    "-fexceptions",
214
    "-frtti",
215
    "-fPIC",
216
    "-Os",
217
    "-Wno-absolute-value",
218
    "-Wno-deprecated-declarations",
219
    "-Wno-macro-redefined",
220
    "-Wno-tautological-constant-out-of-range-compare",
221
    "-Wno-unknown-pragmas",
222
    "-Wno-unknown-warning-option",
223
    "-Wno-unused-function",
224
    "-Wno-unused-variable",
225
    "-Wno-pass-failed",
226
    "-Wno-shadow",
227
]
228

229
def get_aten_compiler_flags():
230
    return ATEN_COMPILER_FLAGS
231

232
_COMMON_PREPROCESSOR_FLAGS = [
233
    "-DC10_MOBILE",
234
    "-DNO_EXPORT",
235
] + (
236
    ["-DC10_MOBILE_TRIM_DISPATCH_KEYS"] if get_enable_mobile_dispatch_keys_trimming() else []
237
) + (
238
    ["-DSTRIP_ERROR_MESSAGES"] if get_strip_error_messages() else []
239
) + (
240
    ["-DDISABLE_WARN"] if get_disable_warn() else []
241
)
242

243
def get_aten_preprocessor_flags():
244
    # read_config is not allowed outside of function in Starlark
245
    ATEN_PREPROCESSOR_FLAGS = _COMMON_PREPROCESSOR_FLAGS + [
246
        "-DCPU_CAPABILITY_DEFAULT",
247
        "-DCPU_CAPABILITY=DEFAULT",
248
        "-DCAFFE2_USE_LITE_PROTO",
249
        "-DATEN_CUDNN_ENABLED_FBXPLAT=0",
250
        "-DATEN_MKLDNN_ENABLED_FBXPLAT=0",
251
        "-DATEN_MKLDNN_ACL_ENABLED_FBXPLAT=0",
252
        "-DATEN_NNPACK_ENABLED_FBXPLAT=0",
253
        "-DATEN_MKL_ENABLED_FBXPLAT=0",
254
        "-DATEN_MKL_SEQUENTIAL_FBXPLAT=0",
255
        "-DUSE_PYTORCH_METAL",
256
        "-DUSE_PYTORCH_QNNPACK",
257
        "-DUSE_XNNPACK",
258
        "-DPYTORCH_QNNPACK_RUNTIME_QUANTIZATION",
259
        "-DAT_PARALLEL_OPENMP_FBXPLAT=0",
260
        "-DAT_PARALLEL_NATIVE_FBXPLAT=1",
261
        "-DAT_PARALLEL_NATIVE_TBB_FBXPLAT=0",
262
        "-DUSE_LAPACK_FBXPLAT=0",
263
        "-DAT_BLAS_F2C_FBXPLAT=0",
264
        "-DAT_BLAS_USE_CBLAS_DOT_FBXPLAT=0",
265
        "-DUSE_RUY_QMATMUL",
266
    ]
267
    if get_disable_per_op_profiling():
268
        ATEN_PREPROCESSOR_FLAGS.append("-DPYTORCH_DISABLE_PER_OP_PROFILING")
269
    if _get_enable_record_kernel_dtype():
270
        ATEN_PREPROCESSOR_FLAGS.append("-DENABLE_RECORD_KERNEL_FUNCTION_DTYPE")
271
    return ATEN_PREPROCESSOR_FLAGS
272

273
def get_pt_preprocessor_flags():
274
    # read_config is not allowed outside of function in Starlark
275
    PT_PREPROCESSOR_FLAGS = _COMMON_PREPROCESSOR_FLAGS + [
276
        "-D_THP_CORE",
277
        "-DUSE_SCALARS",
278
        "-DNO_CUDNN_DESTROY_HANDLE",
279
        "-DBUILD_CAFFE2",
280
    ]
281

282
    if _is_build_mode_dev():
283
        PT_PREPROCESSOR_FLAGS.append("-DENABLE_PYTORCH_NON_PRODUCTION_BUILDS")
284
    return PT_PREPROCESSOR_FLAGS
285

286
# This needs to be kept in sync with https://github.com/pytorch/pytorch/blob/release/1.9/torchgen/gen.py#L892
287
PT_BACKEND_HEADERS = [
288
    "CPU",
289
    "CUDA",
290
    "CompositeExplicitAutograd",
291
    "CompositeExplicitAutogradNonFunctional",
292
    "CompositeImplicitAutograd",
293
    "CompositeImplicitAutogradNestedTensor",
294
    "Meta",
295
]
296

297
def get_aten_static_dispatch_backend_headers(existing_headers):
298
    static_backends = get_static_dispatch_backend()
299
    for backend in static_backends:
300
        if backend != "CPU":
301
            existing_headers["{}Functions.h".format(backend)] = ":gen_aten[{}Functions.h]".format(backend)
302
            existing_headers["{}Functions_inl.h".format(backend)] = ":gen_aten[{}Functions_inl.h]".format(backend)
303
    return existing_headers
304

305
def get_aten_codegen_extra_params(backends):
306
    extra_params = {
307
        "force_schema_registration": True,
308
    }
309
    static_backends = get_static_dispatch_backend()
310
    if static_backends:
311
        extra_params["static_dispatch_backend"] = static_backends
312
        extra_params["enabled_backends"] = static_backends
313
    else:
314
        extra_params["enabled_backends"] = backends
315
    return extra_params
316

317
def get_jit_codegen_params():
318
    return []
319

320
def get_unboxing_generated_files():
321
    srcs = []
322
    if _get_enable_lightweight_dispatch():
323
        srcs = [
324
            "UnboxingFunctions.h",
325
            "UnboxingFunctions_0.cpp",
326
            "UnboxingFunctions_1.cpp",
327
            "UnboxingFunctions_2.cpp",
328
            "UnboxingFunctions_3.cpp",
329
            "UnboxingFunctions_4.cpp",
330
            "RegisterCodegenUnboxedKernels_0.cpp",
331
            "RegisterCodegenUnboxedKernels_1.cpp",
332
            "RegisterCodegenUnboxedKernels_2.cpp",
333
            "RegisterCodegenUnboxedKernels_3.cpp",
334
            "RegisterCodegenUnboxedKernels_4.cpp",
335
            "RegisterCodegenUnboxedKernels_5.cpp",
336
            "RegisterCodegenUnboxedKernels_6.cpp",
337
            "RegisterCodegenUnboxedKernels_7.cpp",
338
            "RegisterCodegenUnboxedKernels_8.cpp",
339
            "RegisterCodegenUnboxedKernels_9.cpp",
340
        ]
341
    res = {}
342
    for file_name in srcs:
343
        res[file_name] = [file_name]
344
    return res
345

346
def get_aten_generated_files(enabled_backends):
347
    # NB: RegisterMeta counts as an optionally enabled backend,
348
    # and is intentionally omitted from here
349
    src_files = [
350
        "RegisterBackendSelect.cpp",
351
        "RegisterCompositeImplicitAutograd.cpp",
352
        "RegisterCompositeImplicitAutogradNestedTensor.cpp",
353
        "RegisterCompositeExplicitAutograd.cpp",
354
        "RegisterCompositeExplicitAutogradNonFunctional.cpp",
355
        "CompositeViewCopyKernels.cpp",
356
        "RegisterSchema.cpp",
357
        "Declarations.yaml",
358
        "Functions.cpp",
359
        "Functions.h",
360
        "RedispatchFunctions.h",
361
        "NativeFunctions.h",
362
        "NativeMetaFunctions.h",
363
        "MethodOperators.h",
364
        "FunctionalInverses.h",
365
        "Operators.h",
366
        "Operators_0.cpp",
367
        "Operators_1.cpp",
368
        "Operators_2.cpp",
369
        "Operators_3.cpp",
370
        "Operators_4.cpp",
371
        "CompositeImplicitAutogradFunctions.h",
372
        "CompositeImplicitAutogradFunctions_inl.h",
373
        "CompositeImplicitAutogradNestedTensorFunctions.h",
374
        "CompositeImplicitAutogradNestedTensorFunctions_inl.h",
375
        "CompositeExplicitAutogradFunctions.h",
376
        "CompositeExplicitAutogradFunctions_inl.h",
377
        "CompositeExplicitAutogradNonFunctionalFunctions.h",
378
        "CompositeExplicitAutogradNonFunctionalFunctions_inl.h",
379
        "VmapGeneratedPlumbing.h",
380
        "core/ATenOpList.cpp",
381
        "core/TensorBody.h",
382
        "core/TensorMethods.cpp",
383
        "core/aten_interned_strings.h",
384
        "core/enum_tag.h",
385
    ] + get_aten_derived_type_srcs(enabled_backends)
386

387
    # This is tiresome.  A better strategy would be to unconditionally
388
    # generate these files, and then only actually COMPILE them depended
389
    # on the generated set.  C'est la vie...
390
    if "CPU" in enabled_backends:
391
        src_files.extend(aten_ufunc_generated_cpu_sources())
392
        src_files.extend(aten_ufunc_generated_cpu_kernel_sources())
393
    if "CUDA" in enabled_backends:
394
        # Cannot unconditionally include this, because in the Edge selective
395
        # build CUDA is not enabled and thus the ufunc codegen for CUDA gets
396
        # skipped
397
        src_files.extend(aten_ufunc_generated_cuda_sources())
398

399
    res = {}
400
    for file_name in src_files:
401
        res[file_name] = [file_name]
402
    return res
403

404
def get_aten_derived_type_src_rules(aten_rule_name, enabled_backends):
405
    return [
406
        ":{}[{}]".format(aten_rule_name, "Register" + backend + ".cpp")
407
        for backend in enabled_backends
408
    ]
409

410
def get_aten_selective_cpp_rules(aten_rule_name, enabled_backends):
411
    return [
412
        ":{}[{}]".format(aten_rule_name, f)
413
        for f in ["RegisterCompositeImplicitAutograd.cpp", "RegisterCompositeImplicitAutogradNestedTensor.cpp", "RegisterCompositeExplicitAutograd.cpp", "RegisterCompositeExplicitAutogradNonFunctional.cpp", "RegisterSchema.cpp", "RegisterBackendSelect.cpp", "CompositeViewCopyKernels.cpp"]
414
    ] + get_aten_derived_type_src_rules(aten_rule_name, enabled_backends)
415

416
def get_aten_derived_type_srcs(enabled_backends):
417
    return [
418
        "Register" + derived_type + ".cpp"
419
        for derived_type in enabled_backends
420
    ] + [
421
        derived_type + "Functions.h"
422
        for derived_type in enabled_backends
423
        if derived_type in PT_BACKEND_HEADERS or derived_type in get_static_dispatch_backend()
424
    ] + [
425
        derived_type + "Functions_inl.h"
426
        for derived_type in enabled_backends
427
        if derived_type in PT_BACKEND_HEADERS or derived_type in get_static_dispatch_backend()
428
    ]
429

430
def gen_aten_files(
431
        name,
432
        extra_flags = {},
433
        visibility = [],
434
        compatible_with = [],
435
        apple_sdks = None):
436
    extra_params = []
437
    force_schema_registration = extra_flags.get("force_schema_registration", False)
438
    op_registration_allowlist = extra_flags.get("op_registration_allowlist", None)
439
    op_selection_yaml_path = extra_flags.get("op_selection_yaml_path", None)
440
    enabled_backends = extra_flags.get("enabled_backends", None)
441
    static_dispatch_backend = extra_flags.get("static_dispatch_backend", None)
442

443
    if force_schema_registration:
444
        extra_params.append("--force_schema_registration")
445
    if op_registration_allowlist != None and is_string(op_registration_allowlist):
446
        extra_params.append("--op_registration_whitelist")
447
        extra_params.append(op_registration_allowlist)
448
    if op_selection_yaml_path != None and is_string(op_selection_yaml_path):
449
        extra_params.append("--op_selection_yaml_path")
450
        extra_params.append(op_selection_yaml_path)
451
    if enabled_backends != None and is_list(enabled_backends):
452
        extra_params.append("--backend_whitelist")
453
        extra_params.extend(enabled_backends)
454
    if _get_enable_lightweight_dispatch():
455
        extra_params.append("--skip_dispatcher_op_registration")
456
    if static_dispatch_backend:
457
        extra_params.append("--static_dispatch_backend")
458
        extra_params.extend(static_dispatch_backend)
459
        backends = static_dispatch_backend
460
    else:
461
        backends = enabled_backends
462
    fb_xplat_genrule(
463
        name = name,
464
        default_outs = ["."],
465
        outs = get_aten_generated_files(backends),
466
        cmd = "$(exe {}torchgen:gen) ".format(ROOT_PATH) + " ".join([
467
            "--source-path $(location {}:aten_src_path)/aten/src/ATen".format(ROOT),
468
            "--install_dir $OUT",
469
        ] + extra_params),
470
        visibility = visibility,
471
        compatible_with = compatible_with,
472
        apple_sdks = apple_sdks,
473
    )
474

475
def gen_aten_unboxing_files(
476
        genrule_name,
477
        extra_flags = {}):
478
    extra_params = []
479
    op_selection_yaml_path = extra_flags.get("op_selection_yaml_path", None)
480
    op_registration_allowlist = extra_flags.get("op_registration_allowlist", None)
481
    if op_selection_yaml_path != None and is_string(op_selection_yaml_path):
482
        extra_params.append("--op_selection_yaml_path")
483
        extra_params.append(op_selection_yaml_path)
484
    if op_registration_allowlist != None and is_string(op_registration_allowlist):
485
        extra_params.append("--op_registration_allowlist")
486
        extra_params.append(op_registration_allowlist)
487

488
    fb_xplat_genrule(
489
        name = genrule_name,
490
        default_outs = ["."],
491
        outs = get_unboxing_generated_files(),
492
        cmd = "$(exe {}tools:gen_unboxing_bin) ".format(ROOT_PATH) + " ".join([
493
            "--source-path $(location {}:aten_src_path)/aten/src/ATen".format(ROOT),
494
            "--install_dir $OUT",
495
        ] + extra_params),
496
        visibility = ["PUBLIC"],
497
    )
498

499
def copy_template_registration_files(name, apple_sdks = None):
500
    cmd = []
501
    cmd_exe = []
502

503
    template_source_dict = get_template_source_dict()
504

505
    # Ideally, we would run one copy command for a single source directory along
506
    # with all its child directories, but it's somewhat hard to know if a directory
507
    # is a child of another just bu looking at the metadata (directory relative
508
    # path) that we currently have since 1 directory could look like a parent of
509
    # another and yet come from a different filegroup() rule.
510
    #
511
    for (path_prefix, file_paths) in template_source_dict.items():
512
        cmd.append("mkdir -p $OUT/{}".format(path_prefix))
513
        cmd_exe.append("md $OUT/{}".format(path_prefix))
514

515
        # Adding *.cpp is a workaround to prevent cp from thrown an error when it
516
        # encounters a directory (since -r was not specified). If files with an
517
        # extension other than .cpp need to be copied, then the command below
518
        # will not work and will need to be updated.
519
        #
520
        cmd.append("cp -f $(location {0}:templated_selective_build_srcs)/{1}/*.cpp $OUT/{1}/".format(ROOT, path_prefix))
521
        cmd_exe.append("robocopy /E $(location {0}:templated_selective_build_srcs)/{1} $OUT/{1}".format(ROOT, path_prefix))
522

523
    if NOT_OSS:
524
        for file_path in TEMPLATE_MASKRCNN_SOURCE_LIST:
525
            maskrcnn_file = "$(location //xplat/caffe2/fb/custom_ops/maskrcnn:templated_selective_build_srcs)/" + file_path
526
            cmd.append("cp -f " + maskrcnn_file + " $OUT")
527
            cmd_exe.append("copy " + maskrcnn_file + " $OUT")
528

529
    cmd.append("mkdir -p $OUT/aten/src/ATen")
530
    cmd_exe.append("md $OUT/aten/src/ATen")
531

532
    # NB: CUDA is skipped here because this is selective build and CUDA is not
533
    # supported for selective build
534
    for ufunc_file in aten_ufunc_generated_all_cpu_sources("$(location " + ROOT + ":gen_aten[{}])"):
535
        cmd.append("cp -f " + ufunc_file + " $OUT/aten/src/ATen")
536
        cmd_exe.append("copy " + ufunc_file + " $OUT/aten/src/ATen")
537

538
    if NOT_OSS:
539
        pvd_batch_box_cox_file = "$(location //xplat/caffe2/fb/custom_ops/batch_box_cox:templated_selective_build_srcs)/register_batch_box_cox_ops.cpp"
540
        cmd.append("cp -f " + pvd_batch_box_cox_file + " $OUT")
541
        cmd_exe.append("copy " + pvd_batch_box_cox_file + " $OUT")
542

543
    fb_xplat_genrule(
544
        name = name,
545
        cmd = " && ".join(cmd),
546
        cmd_exe = "@powershell -Command " + ("; ".join(cmd_exe)),
547
        outs = get_template_registration_files_outs(IS_OSS),
548
        default_outs = ["."],
549
        apple_sdks = apple_sdks,
550
    )
551

552
def get_feature_tracer_source_list():
553
    """
554
    Return just the Feature specific handlers used in the model tracer.
555
    """
556
    sources = []
557
    for s in torch_mobile_tracer_sources:
558
        if s.endswith("Tracer.cpp"):
559
            sources.append(s)
560
    return sources
561

562
def pt_operator_query_codegen(
563
        name,
564
        deps = [],
565
        train = False,
566
        enforce_traced_op_list = False,
567
        pt_allow_forced_schema_registration = True,
568
        compatible_with = [],
569
        apple_sdks = None):
570
    oplist_dir_name = name + "_pt_oplist"
571

572
    # @lint-ignore BUCKLINT
573
    fb_native.genrule(
574
        name = oplist_dir_name,
575
        cmd = ("$(exe {}tools:gen_oplist) ".format(ROOT_PATH) +
576
               "--model_file_list_path $(@query_outputs 'attrfilter(labels, pt_operator_library, deps(set({deps})))') " +
577
               ("" if enforce_traced_op_list else "--allow_include_all_overloads ") +
578
               "--output_dir $OUT ").format(deps = " ".join(["\"{}\"".format(d) for d in deps])),
579
        outs = get_gen_oplist_outs(),
580
        default_outs = ["."],
581
        compatible_with = compatible_with,
582
    )
583

584
    # Aten files
585
    aten_genrule = name + "_aten"
586
    extra_flags = {
587
        "enabled_backends": USED_PT_BACKENDS,
588
        "op_selection_yaml_path": "$(location :{}[selected_operators.yaml])".format(oplist_dir_name),
589
    }
590

591
    if train and pt_allow_forced_schema_registration:
592
        extra_flags["force_schema_registration"] = True
593

594
    unboxing_genrule = name + "_unboxing"
595
    if _get_enable_lightweight_dispatch():
596
        gen_aten_unboxing_files(
597
            unboxing_genrule,
598
            extra_flags = extra_flags,
599
        )
600

601
    static_dispatch_backend = get_static_dispatch_backend()
602
    if static_dispatch_backend:
603
        extra_flags["static_dispatch_backend"] = static_dispatch_backend
604

605
    gen_aten_files(
606
        aten_genrule,
607
        extra_flags = extra_flags,
608
        compatible_with = compatible_with,
609
        apple_sdks = apple_sdks,
610
    )
611

612
    # unboxing_wrappers files
613
    extra_params = [
614
        "--operators_yaml_path",
615
        "$(location :" + oplist_dir_name + "[selected_operators.yaml])",
616
    ]
617
    unboxing_and_autograd_genrule = name + "_unboxing_and_autograd"
618
    gen_aten_libtorch_files(
619
        unboxing_and_autograd_genrule,
620
        extra_params,
621
        compatible_with,
622
        apple_sdks = apple_sdks,
623
    )
624

625
    # Template runtime files (prim ops, etc)
626
    template_registration_genrule = name + "_template_registration"
627
    copy_template_registration_files(template_registration_genrule, apple_sdks = apple_sdks)
628

629
    # Files needed for metal
630
    if NOT_OSS:
631
        metal_genrule = name + "_metal"
632
        copy_metal(metal_genrule, apple_sdks = apple_sdks)
633

634
    srcs = get_aten_selective_cpp_rules(
635
        aten_genrule,
636
        static_dispatch_backend if static_dispatch_backend else USED_PT_BACKENDS,
637
    ) + get_template_registration_file_rules(template_registration_genrule, IS_OSS) + ([
638
        ":{}[autograd/generated/VariableType_0.cpp]".format(unboxing_and_autograd_genrule),
639
        ":{}[autograd/generated/VariableType_1.cpp]".format(unboxing_and_autograd_genrule),
640
        ":{}[autograd/generated/VariableType_2.cpp]".format(unboxing_and_autograd_genrule),
641
        ":{}[autograd/generated/VariableType_3.cpp]".format(unboxing_and_autograd_genrule),
642
        ":{}[autograd/generated/VariableType_4.cpp]".format(unboxing_and_autograd_genrule),
643
        ":{}[autograd/generated/ADInplaceOrViewType_0.cpp]".format(unboxing_and_autograd_genrule),
644
        ":{}[autograd/generated/ADInplaceOrViewType_1.cpp]".format(unboxing_and_autograd_genrule),
645
    ] if train else []) + ([
646
        ":{}[SupportedMobileModelsRegistration.cpp]".format(oplist_dir_name),
647
    ] if NOT_OSS else [])
648

649
    headers = {
650
        "selected_mobile_ops.h": ":{}[selected_mobile_ops.h]".format(oplist_dir_name),
651
    }
652

653
    if _get_enable_lightweight_dispatch():
654
        srcs.extend([
655
            ":{}[UnboxingFunctions_0.cpp]".format(unboxing_genrule),
656
            ":{}[UnboxingFunctions_1.cpp]".format(unboxing_genrule),
657
            ":{}[UnboxingFunctions_2.cpp]".format(unboxing_genrule),
658
            ":{}[UnboxingFunctions_3.cpp]".format(unboxing_genrule),
659
            ":{}[UnboxingFunctions_4.cpp]".format(unboxing_genrule),
660
            ":{}[RegisterCodegenUnboxedKernels_0.cpp]".format(unboxing_genrule),
661
            ":{}[RegisterCodegenUnboxedKernels_1.cpp]".format(unboxing_genrule),
662
            ":{}[RegisterCodegenUnboxedKernels_2.cpp]".format(unboxing_genrule),
663
            ":{}[RegisterCodegenUnboxedKernels_3.cpp]".format(unboxing_genrule),
664
            ":{}[RegisterCodegenUnboxedKernels_4.cpp]".format(unboxing_genrule),
665
            ":{}[RegisterCodegenUnboxedKernels_5.cpp]".format(unboxing_genrule),
666
            ":{}[RegisterCodegenUnboxedKernels_6.cpp]".format(unboxing_genrule),
667
            ":{}[RegisterCodegenUnboxedKernels_7.cpp]".format(unboxing_genrule),
668
            ":{}[RegisterCodegenUnboxedKernels_8.cpp]".format(unboxing_genrule),
669
            ":{}[RegisterCodegenUnboxedKernels_9.cpp]".format(unboxing_genrule),
670
        ])
671
        headers["UnboxingFunctions.h"] = ":{}[UnboxingFunctions.h]".format(unboxing_genrule)
672
    return {"headers": headers, "srcs": srcs}
673

674
def gen_aten_libtorch_files(name, extra_params = [], compatible_with = [], apple_sdks = None):
675
    fb_xplat_genrule(
676
        name = name,
677
        outs = get_generate_code_bin_outs(),
678
        default_outs = ["."],
679
        bash = "mkdir -p tools && " +
680
               "$(exe {}tools:generate_code_bin) ".format(ROOT_PATH) + " ".join(
681
            # Mobile build only needs libtorch - skip python bindings for now, except
682
            # for ovrsource, which needs Python bindings.
683
            (["--subset libtorch"] if not is_arvr_mode() else []) + [
684
                "--native-functions-path $(location {}:aten_src_path)/aten/src/ATen/native/native_functions.yaml".format(ROOT),
685
                "--tags-path $(location {}:aten_src_path)/aten/src/ATen/native/tags.yaml".format(ROOT),
686
                "--install_dir $OUT",
687
            ] + extra_params,
688
        ),
689
        cmd_exe = "@powershell -Command New-Item -Path tools -ItemType Directory -Force; " +
690
                  "$(exe {}tools:generate_code_bin) ".format(ROOT_PATH) + " ".join(
691
            # Mobile build only needs libtorch - skip python bindings for now, except
692
            # for ovrsource, which needs Python bindings.
693
            (["--subset libtorch"] if not is_arvr_mode() else []) + [
694
                "--native-functions-path $(location {}:aten_src_path)/aten/src/ATen/native/native_functions.yaml".format(ROOT),
695
                "--tags-path $(location {}:aten_src_path)/aten/src/ATen/native/tags.yaml".format(ROOT),
696
                "--install_dir $OUT",
697
            ] + extra_params,
698
        ),
699
        compatible_with = compatible_with,
700
        apple_sdks = apple_sdks,
701
    )
702

703
def copy_metal(name, apple_sdks = None):
704
    cmd = []
705
    cmd_exe = []
706
    metal_source_dict = get_metal_source_dict()
707

708
    # Copy all source files over to bring them into the per app build
709
    for path_prefix in sorted(metal_source_dict.keys()):
710
        cmd.append("mkdir -p $OUT/{}".format(path_prefix))
711
        cmd_exe.append("mkdir -Force $OUT/{0}".format(path_prefix))
712

713
        # Not every directory has a mm or cpp file so '2>/dev/null || :' are tricks to suppress the error messages and codes.
714
        cmd.append("cp -f {0}/{1}/*.mm $OUT/{1}/ 2>/dev/null || :".format("$(location //xplat/caffe2:metal_build_srcs)", path_prefix))
715
        cmd.append("cp -f {0}/{1}/*.cpp $OUT/{1}/ 2>/dev/null || :".format("$(location //xplat/caffe2:metal_build_srcs)", path_prefix))
716

717
        # Robocopy has a default success code of 1 which buck treats as failure so the echo masks that problem
718
        cmd_exe.append("(robocopy /E /NFL /NDL /NJH /NJS {0}/{1} $OUT/{1}) || ECHO robocopy failed".format("$(location //xplat/caffe2:metal_build_srcs)", path_prefix))
719

720
    # Metal custom ops currently have to be brought into selective build because they directly reference metal ops instead of
721
    # going through the dispatcher. There is some weird issues with the genrule and these files locations on windows though, so
722
    # for now we simply skip building them for windows where they very likely arent needed anyway.
723
    # Metal MaskRCNN custom op
724
    for full_path in METAL_MASKRCNN_SOURCE_LIST:
725
        path_prefix = paths.dirname(full_path)
726
        cmd.append("mkdir -p $OUT/{}".format(path_prefix))
727
        cmd.append("cp -f {0}/{1}/*.mm $OUT/{1}/ 2>/dev/null || :".format("$(location //xplat/caffe2/fb/metal:metal_maskrcnn_sources)", path_prefix))
728

729
    # Unet Metal Prepack Custom op
730
    unet_metal_prepack_file = "$(location //xplat/caffe2/fb/custom_ops/unet_metal_prepack:unet_metal_prepack_sources)"
731
    cmd.append("cp -f " + unet_metal_prepack_file + "/unet_metal_prepack.cpp" + " $OUT")
732
    cmd.append("cp -f " + unet_metal_prepack_file + "/unet_metal_prepack.mm" + " $OUT")
733

734
    fb_xplat_genrule(
735
        name = name,
736
        cmd = " && ".join(cmd),
737
        cmd_exe = "@powershell -Command " + ("; ".join(cmd_exe)),
738
        # due to an obscure bug certain custom ops werent being copied correctly on windows. ARVR also sometimes builds android targets on windows,
739
        # so we just exclude those targets from being copied for those platforms (They end up uncompiled anyway).
740
        outs = select({
741
            "DEFAULT": get_metal_registration_files_outs(),
742
            "ovr_config//os:android": get_metal_registration_files_outs_windows(),
743
            "ovr_config//os:windows": get_metal_registration_files_outs_windows(),
744
        }),
745
        default_outs = ["."],
746
        apple_sdks = apple_sdks,
747
    )
748

749
def get_pt_operator_registry_dict(
750
        name,
751
        deps = [],
752
        train = False,
753
        labels = [],
754
        env = [],
755
        template_select = True,
756
        enforce_traced_op_list = False,
757
        pt_allow_forced_schema_registration = True,
758
        enable_flatbuffer = False,
759
        **kwargs):
760
    code_gen_files = pt_operator_query_codegen(
761
        name,
762
        deps = deps,
763
        train = train,
764
        enforce_traced_op_list = enforce_traced_op_list,
765
        pt_allow_forced_schema_registration = pt_allow_forced_schema_registration,
766
        compatible_with = kwargs.get("compatible_with", []),
767
        apple_sdks = kwargs.get("apple_sdks"),
768
    )
769

770
    return dict(
771
        srcs = code_gen_files["srcs"],
772
        linker_flags = [
773
            "-Wl,--no-as-needed",
774
        ],
775
        # @lint-ignore BUCKLINT link_whole
776
        link_whole = True,
777
        soname = "libtorch-code-gen.$(ext)",
778
        header_namespace = "ATen",
779
        compiler_flags = get_aten_compiler_flags(),
780
        exported_headers = code_gen_files["headers"],
781
        exported_preprocessor_flags = get_aten_preprocessor_flags() + (["-DTEMPLATE_SELECTIVE_BUILD"] if template_select else []),
782
        headers = kwargs.pop("headers", []),
783
        labels = kwargs.pop("labels", []) + [
784
            # This library has multiple sources with the same file name
785
            # and does not work with Buck filegroup used in bad practices.
786
            # Opt out of the bad practices check with the below label.
787
            "bad_practices_ignore_override",
788
            "pt_operator_registry",
789
        ],
790
        deps = [
791
            # need absolute path here
792
            ROOT + ":torch_mobile_core",
793
            ROOT + ":aten_cpu",
794
            ROOT + ":aten_metal_prepack_header",
795
            third_party("glog"),
796
            C10,
797
        ] + ([ROOT + ":torch_mobile_train"] if train else []),
798
        **kwargs
799
    )
800

801
# these targets are shared by internal and OSS BUCK
802
def define_buck_targets(
803
        aten_default_args = dict(),
804
        pt_xplat_cxx_library = fb_xplat_cxx_library,
805
        c2_fbandroid_xplat_compiler_flags = [],
806
        labels = []):
807
    # @lint-ignore BUCKLINT
808
    fb_native.filegroup(
809
        name = "metal_build_srcs",
810
        # @lint-ignore BUCKRESTRICTEDSYNTAX
811
        srcs = glob(METAL_SOURCE_LIST),
812
        visibility = [
813
            "PUBLIC",
814
        ],
815
    )
816

817
    # @lint-ignore BUCKLINT
818
    fb_native.filegroup(
819
        name = "templated_selective_build_srcs",
820
        # NB: no glob here, there are generated targets in this list!
821
        # @lint-ignore BUCKRESTRICTEDSYNTAX
822
        srcs = glob(TEMPLATE_SOURCE_LIST) + aten_ufunc_generated_all_cpu_sources(":gen_aten[{}]"),
823
        visibility = [
824
            "PUBLIC",
825
        ],
826
    )
827

828
    fb_xplat_cxx_library(
829
        name = "aten_header",
830
        header_namespace = "",
831
        exported_headers = subdir_glob([
832
            # ATen Core
833
            ("aten/src", "ATen/core/**/*.h"),
834
            ("aten/src", "ATen/ops/*.h"),
835
            # ATen Base
836
            ("aten/src", "ATen/*.h"),
837
            ("aten/src", "ATen/cpu/**/*.h"),
838
            ("aten/src", "ATen/detail/*.h"),
839
            ("aten/src", "ATen/functorch/**/*.h"),
840
            ("aten/src", "ATen/quantized/*.h"),
841
            ("aten/src", "ATen/vulkan/*.h"),
842
            ("aten/src", "ATen/metal/*.h"),
843
            ("aten/src", "ATen/nnapi/*.h"),
844
            # ATen Native
845
            ("aten/src", "ATen/native/*.h"),
846
            ("aten/src", "ATen/native/ao_sparse/quantized/cpu/*.h"),
847
            ("aten/src", "ATen/native/cpu/**/*.h"),
848
            ("aten/src", "ATen/native/sparse/*.h"),
849
            ("aten/src", "ATen/native/nested/*.h"),
850
            ("aten/src", "ATen/native/quantized/*.h"),
851
            ("aten/src", "ATen/native/quantized/cpu/*.h"),
852
            ("aten/src", "ATen/native/transformers/*.h"),
853
            ("aten/src", "ATen/native/ufunc/*.h"),
854
            ("aten/src", "ATen/native/utils/*.h"),
855
            ("aten/src", "ATen/native/vulkan/ops/*.h"),
856
            ("aten/src", "ATen/native/xnnpack/*.h"),
857
            ("aten/src", "ATen/mps/*.h"),
858
            ("aten/src", "ATen/native/mps/*.h"),
859
            # Remove the following after modifying codegen for mobile.
860
            ("aten/src", "ATen/mkl/*.h"),
861
            ("aten/src", "ATen/native/mkl/*.h"),
862
            ("aten/src", "ATen/native/mkldnn/*.h"),
863
        ]),
864
        visibility = ["PUBLIC"],
865
        labels = labels,
866
    )
867

868
    fb_xplat_cxx_library(
869
        name = "aten_vulkan_header",
870
        header_namespace = "",
871
        exported_headers = subdir_glob([
872
            ("aten/src", "ATen/native/vulkan/*.h"),
873
            ("aten/src", "ATen/native/vulkan/ops/*.h"),
874
            ("aten/src", "ATen/vulkan/*.h"),
875
        ]),
876
        labels = labels,
877
        visibility = ["PUBLIC"],
878
    )
879

880
    fb_xplat_cxx_library(
881
        name = "jit_core_headers",
882
        header_namespace = "",
883
        exported_headers = subdir_glob([("", x) for x in jit_core_headers]),
884
        labels = labels,
885
    )
886

887
    fb_xplat_cxx_library(
888
        name = "torch_headers",
889
        header_namespace = "",
890
        exported_headers = subdir_glob(
891
            [
892
                ("torch/csrc/api/include", "torch/**/*.h"),
893
                ("", "torch/csrc/**/*.h"),
894
                ("", "torch/script.h"),
895
                ("", "torch/library.h"),
896
                ("", "torch/custom_class.h"),
897
                ("", "torch/custom_class_detail.h"),
898
                # Add again due to namespace difference from aten_header.
899
                ("", "aten/src/ATen/*.h"),
900
                ("", "aten/src/ATen/functorch/**/*.h"),
901
                ("", "aten/src/ATen/quantized/*.h"),
902
            ],
903
            exclude = [
904
                # Don't need on mobile.
905
                "torch/csrc/Exceptions.h",
906
                "torch/csrc/python_headers.h",
907
                "torch/csrc/jit/serialization/mobile_bytecode_generated.h",
908
            ],
909
        ),
910
        labels = labels,
911
        visibility = ["PUBLIC"],
912
        deps = [
913
            ":generated-version-header",
914
        ],
915
    )
916

917
    fb_xplat_cxx_library(
918
        name = "aten_test_header",
919
        header_namespace = "",
920
        exported_headers = subdir_glob([
921
            ("aten/src", "ATen/test/*.h"),
922
        ]),
923
    )
924

925
    fb_xplat_cxx_library(
926
        name = "aten_metal_prepack_header",
927
        header_namespace = "",
928
        exported_headers = subdir_glob([
929
            ("aten/src", "ATen/native/metal/MetalPrepackOpContext.h"),
930
        ]),
931
        labels = labels,
932
        visibility = ["PUBLIC"],
933
    )
934

935
    fb_xplat_cxx_library(
936
        name = "torch_mobile_headers",
937
        header_namespace = "",
938
        exported_headers = subdir_glob(
939
            [
940
                ("", "torch/csrc/jit/mobile/*.h"),
941
            ],
942
        ),
943
        labels = labels,
944
        visibility = ["PUBLIC"],
945
    )
946

947
    fb_xplat_cxx_library(
948
        name = "generated_aten_config_header",
949
        header_namespace = "ATen",
950
        exported_headers = {
951
            "Config.h": ":generate_aten_config[Config.h]",
952
        },
953
        labels = labels,
954
    )
955

956
    fb_xplat_cxx_library(
957
        name = "generated-autograd-headers",
958
        header_namespace = "torch/csrc/autograd/generated",
959
        exported_headers = {
960
            "Functions.h": ":gen_aten_libtorch[autograd/generated/Functions.h]",
961
            "VariableType.h": ":gen_aten_libtorch[autograd/generated/VariableType.h]",
962
            "variable_factories.h": ":gen_aten_libtorch[autograd/generated/variable_factories.h]",
963
            "ViewFuncs.h": ":gen_aten_libtorch[autograd/generated/ViewFuncs.h]",
964
            # Don't build python bindings on mobile.
965
            #"python_functions.h",
966
        },
967
        labels = labels,
968
        visibility = ["PUBLIC"],
969
    )
970

971
    fb_xplat_cxx_library(
972
        name = "generated-version-header",
973
        header_namespace = "torch",
974
        exported_headers = {
975
            "version.h": ":generate-version-header[version.h]",
976
        },
977
        labels = labels,
978
    )
979

980
    # @lint-ignore BUCKLINT
981
    fb_native.genrule(
982
        name = "generate-version-header",
983
        srcs = [
984
            "torch/csrc/api/include/torch/version.h.in",
985
            "version.txt",
986
        ],
987
        cmd = "$(exe {}tools:gen-version-header) ".format(ROOT_PATH) + " ".join([
988
            "--template-path",
989
            "torch/csrc/api/include/torch/version.h.in",
990
            "--version-path",
991
            "version.txt",
992
            "--output-path",
993
            "$OUT/version.h",
994
        ]),
995
        outs = {
996
            "version.h": ["version.h"],
997
        },
998
        default_outs = ["."],
999
    )
1000

1001
    # @lint-ignore BUCKLINT
1002
    fb_native.filegroup(
1003
        name = "aten_src_path",
1004
        srcs = [
1005
            "aten/src/ATen/native/native_functions.yaml",
1006
            "aten/src/ATen/native/tags.yaml",
1007
            # @lint-ignore BUCKRESTRICTEDSYNTAX
1008
        ] + glob(["aten/src/ATen/templates/*"]),
1009
        visibility = [
1010
            "PUBLIC",
1011
        ],
1012
    )
1013

1014
    fb_xplat_cxx_library(
1015
        name = "common_core",
1016
        srcs = [
1017
            "caffe2/core/common.cc",
1018
        ],
1019
        apple_sdks = (IOS, MACOSX, APPLETVOS),
1020
        compiler_flags = get_pt_compiler_flags(),
1021
        labels = labels,
1022
        # @lint-ignore BUCKLINT link_whole
1023
        link_whole = True,
1024
        visibility = ["PUBLIC"],
1025
        windows_preferred_linkage = "static" if is_arvr_mode() else None,
1026
        deps = [
1027
            ":caffe2_headers",
1028
            C10,
1029
        ],
1030
    )
1031

1032
    # @lint-ignore BUCKLINT
1033
    fb_native.genrule(
1034
        name = "generate_aten_config",
1035
        srcs = [
1036
            "aten/src/ATen/Config.h.in",
1037
        ],
1038
        cmd = "$(exe {}tools:substitute) ".format(ROOT_PATH) + " ".join([
1039
            "--install_dir",
1040
            "$OUT",
1041
            "--input-file",
1042
            "aten/src/ATen/Config.h.in",
1043
            "--output-file",
1044
            "Config.h",
1045
            "--replace",
1046
            "@AT_MKLDNN_ENABLED@",
1047
            "ATEN_MKLDNN_ENABLED_FBXPLAT",
1048
            "--replace",
1049
            "@AT_MKLDNN_ACL_ENABLED@",
1050
            "ATEN_MKLDNN_ACL_ENABLED_FBXPLAT",
1051
            "--replace",
1052
            "@AT_MKL_ENABLED@",
1053
            "ATEN_MKL_ENABLED_FBXPLAT",
1054
            "--replace",
1055
            "@AT_MKL_SEQUENTIAL@",
1056
            "ATEN_MKL_SEQUENTIAL_FBXPLAT",
1057
            "--replace",
1058
            "@AT_POCKETFFT_ENABLED@",
1059
            "1",
1060
            "--replace",
1061
            "@AT_NNPACK_ENABLED@",
1062
            "ATEN_NNPACK_ENABLED_FBXPLAT",
1063
            "--replace",
1064
            "@CAFFE2_STATIC_LINK_CUDA_INT@",
1065
            "CAFFE2_STATIC_LINK_CUDA_FBXPLAT",
1066
            "--replace",
1067
            "@AT_BUILD_WITH_BLAS@",
1068
            "USE_BLAS_FBXPLAT",
1069
            "--replace",
1070
            "@AT_PARALLEL_OPENMP@",
1071
            "AT_PARALLEL_OPENMP_FBXPLAT",
1072
            "--replace",
1073
            "@AT_PARALLEL_NATIVE@",
1074
            "AT_PARALLEL_NATIVE_FBXPLAT",
1075
            "--replace",
1076
            "@AT_PARALLEL_NATIVE_TBB@",
1077
            "AT_PARALLEL_NATIVE_TBB_FBXPLAT",
1078
            "--replace",
1079
            "@AT_BUILD_WITH_LAPACK@",
1080
            "USE_LAPACK_FBXPLAT",
1081
            "--replace",
1082
            "@AT_BLAS_F2C@",
1083
            "AT_BLAS_F2C_FBXPLAT",
1084
            "--replace",
1085
            "@AT_BLAS_USE_CBLAS_DOT@",
1086
            "AT_BLAS_USE_CBLAS_DOT_FBXPLAT",
1087
        ]),
1088
        outs = {
1089
            "Config.h": ["Config.h"],
1090
        },
1091
        default_outs = ["."],
1092
    )
1093

1094
    gen_aten_files(
1095
        name = "gen_aten",
1096
        extra_flags = get_aten_codegen_extra_params(USED_PT_BACKENDS),
1097
        visibility = ["PUBLIC"],
1098
    )
1099

1100
    gen_aten_libtorch_files(name = "gen_aten_libtorch")
1101

1102
    gen_aten_libtorch_files(
1103
        name = "gen_aten_libtorch_lite",
1104
        extra_params = get_jit_codegen_params(),
1105
    )
1106

1107
    fb_xplat_cxx_library(
1108
        name = "generated_aten_headers_cpu",
1109
        header_namespace = "ATen",
1110
        exported_headers = get_aten_static_dispatch_backend_headers({
1111
            "CPUFunctions.h": ":gen_aten[CPUFunctions.h]",
1112
            "CPUFunctions_inl.h": ":gen_aten[CPUFunctions_inl.h]",
1113
            "CompositeExplicitAutogradFunctions.h": ":gen_aten[CompositeExplicitAutogradFunctions.h]",
1114
            "CompositeExplicitAutogradFunctions_inl.h": ":gen_aten[CompositeExplicitAutogradFunctions_inl.h]",
1115
            "CompositeExplicitAutogradNonFunctionalFunctions.h": ":gen_aten[CompositeExplicitAutogradNonFunctionalFunctions.h]",
1116
            "CompositeExplicitAutogradNonFunctionalFunctions_inl.h": ":gen_aten[CompositeExplicitAutogradNonFunctionalFunctions_inl.h]",
1117
            "CompositeImplicitAutogradFunctions.h": ":gen_aten[CompositeImplicitAutogradFunctions.h]",
1118
            "CompositeImplicitAutogradFunctions_inl.h": ":gen_aten[CompositeImplicitAutogradFunctions_inl.h]",
1119
            "CompositeImplicitAutogradNestedTensorFunctions.h": ":gen_aten[CompositeImplicitAutogradNestedTensorFunctions.h]",
1120
            "CompositeImplicitAutogradNestedTensorFunctions_inl.h": ":gen_aten[CompositeImplicitAutogradNestedTensorFunctions_inl.h]",
1121
            "FunctionalInverses.h": ":gen_aten[FunctionalInverses.h]",
1122
            "Functions.h": ":gen_aten[Functions.h]",
1123
            "MethodOperators.h": ":gen_aten[MethodOperators.h]",
1124
            "NativeFunctions.h": ":gen_aten[NativeFunctions.h]",
1125
            "NativeMetaFunctions.h": ":gen_aten[NativeMetaFunctions.h]",
1126
            "Operators.h": ":gen_aten[Operators.h]",
1127
            "RedispatchFunctions.h": ":gen_aten[RedispatchFunctions.h]",
1128
            "core/TensorBody.h": ":gen_aten[core/TensorBody.h]",
1129
            "core/aten_interned_strings.h": ":gen_aten[core/aten_interned_strings.h]",
1130
            "core/enum_tag.h": ":gen_aten[core/enum_tag.h]",
1131
        }),
1132
        labels = labels,
1133
    )
1134

1135
    fb_xplat_cxx_library(
1136
        name = "torch_mobile_observer",
1137
        srcs = [
1138
            "torch/csrc/jit/mobile/observer.cpp",
1139
        ] + ([] if IS_OSS else ["torch/fb/observers/MobileObserverUtil.cpp"]),
1140
        compiler_flags = ["-fexceptions"],
1141
        header_namespace = "",
1142
        exported_headers = subdir_glob(
1143
            [
1144
                ("", "torch/csrc/jit/mobile/observer.h"),
1145
            ] + ([] if IS_OSS else [
1146
                ("", "torch/fb/observers/ObserverUtil.h"),
1147
                ("", "torch/fb/observers/MobileObserverUtil.h"),
1148
            ]),
1149
        ),
1150
        fbobjc_compiler_flags = [
1151
            "-Wno-missing-prototypes",
1152
        ],
1153
        labels = labels,
1154
        visibility = ["PUBLIC"],
1155
        deps = [
1156
            C10,
1157
        ],
1158
    )
1159

1160
    # Base library shared by lite-interpreter and full-jit.
1161
    pt_xplat_cxx_library(
1162
        name = "torch_common",
1163
        srcs = core_sources_common,
1164
        compiler_flags = get_pt_compiler_flags(),
1165
        exported_preprocessor_flags = get_pt_preprocessor_flags(),
1166
        # @lint-ignore BUCKLINT link_whole
1167
        link_whole = True,
1168
        visibility = ["PUBLIC"],
1169
        deps = [
1170
            ":aten_cpu",
1171
            ":generated-autograd-headers",
1172
            ":torch_headers",
1173
            C10,
1174
            third_party("libkineto_headers"),
1175
        ],
1176
    )
1177

1178
    pt_xplat_cxx_library(
1179
        name = "torch_mobile_deserialize_common",
1180
        srcs = [
1181
            "torch/csrc/jit/mobile/parse_bytecode.cpp",
1182
            "torch/csrc/jit/mobile/parse_operators.cpp",
1183
            "torch/csrc/jit/mobile/upgrader_mobile.cpp",
1184
            "torch/csrc/jit/serialization/import_read.cpp",
1185
            "torch/csrc/jit/serialization/unpickler.cpp",
1186
        ],
1187
        header_namespace = "",
1188
        exported_headers = [
1189
            "torch/csrc/jit/serialization/import_read.h",
1190
            "torch/csrc/jit/serialization/unpickler.h",
1191
        ],
1192
        compiler_flags = get_pt_compiler_flags(),
1193
        exported_preprocessor_flags = get_pt_preprocessor_flags(),
1194
        extra_flags = {
1195
            "fbandroid_compiler_flags": ["-frtti"],
1196
        },
1197
        # torch_mobile_deserialize brings in sources neccessary to read a module
1198
        # which depends on mobile module definition
1199
        # link_whole is enable so that all symbols neccessary for mobile module are compiled
1200
        # instead of only symbols used while loading; this prevents symbol
1201
        # found definied in runtime
1202
        # @lint-ignore BUCKLINT link_whole
1203
        link_whole = True,
1204
        linker_flags = ["-Wl,--no-as-needed"],
1205
        visibility = ["PUBLIC"],
1206
        exported_deps = [
1207
            ":aten_cpu",
1208
            ":caffe2_headers",
1209
            ":caffe2_serialize",
1210
            ":torch_common",
1211
            ":torch_headers",
1212
            ":torch_mobile_headers",
1213
            ":torch_mobile_module",
1214
            ":torch_mobile_observer",
1215
            C10,
1216
        ],
1217
    )
1218

1219
    pt_xplat_cxx_library(
1220
        name = "torch_mobile_module",
1221
        srcs = [
1222
            "torch/csrc/jit/mobile/function.cpp",
1223
            "torch/csrc/jit/mobile/interpreter.cpp",
1224
            "torch/csrc/jit/mobile/module.cpp",
1225
        ],
1226
        header_namespace = "",
1227
        exported_headers = [
1228
        ],
1229
        compiler_flags = get_pt_compiler_flags(),
1230
        exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []),
1231
        extra_flags = {
1232
            "fbandroid_compiler_flags": ["-frtti"],
1233
        },
1234
        # @lint-ignore BUCKLINT link_whole
1235
        link_whole = True,
1236
        linker_flags = [
1237
            "-Wl,--no-as-needed",
1238
        ],
1239
        visibility = ["PUBLIC"],
1240
        exported_deps = [
1241
            ":aten_cpu",
1242
            ":caffe2_headers",
1243
            ":torch_common",
1244
            ":torch_headers",
1245
            ":torch_mobile_headers",
1246
            ":torch_mobile_observer",
1247
            C10,
1248
        ],
1249
    )
1250

1251
    pt_xplat_cxx_library(
1252
        name = "torch_mobile_debug_symbolication",
1253
        srcs = [
1254
            # included in aten_cpu "torch/csrc/jit/frontend/source_range.cpp",
1255
            "torch/csrc/jit/ir/scope.cpp",
1256
            "torch/csrc/jit/mobile/debug_info.cpp",
1257
            "torch/csrc/jit/serialization/callstack_debug_info_serialization.cpp",
1258
            "torch/csrc/jit/serialization/source_range_serialization.cpp",
1259
            "torch/csrc/jit/serialization/pickle.cpp",
1260
            # pickler.cpp doesn't seem to be needed.
1261
            # "torch/csrc/jit/serialization/pickler.cpp",
1262
            # included in core_sources_common "torch/csrc/jit/serialization/unpickler.cpp",
1263
        ],
1264
        compiler_flags = get_pt_compiler_flags(),
1265
        exported_preprocessor_flags = get_pt_preprocessor_flags(),
1266
        header_namespace = "",
1267
        # @lint-ignore BUCKLINT link_whole
1268
        link_whole = True,
1269
        linker_flags = [
1270
            "-Wl,--no-as-needed",
1271
        ],
1272
        visibility = ["PUBLIC"],
1273
        deps = [
1274
            ":torch_mobile_deserialize",
1275
        ],
1276
        exported_deps = [
1277
            ":torch_common",
1278
        ],
1279
    )
1280

1281
    pt_xplat_cxx_library(
1282
        name = "torch_model_tracer",
1283
        srcs = [
1284
            "torch/csrc/jit/mobile/model_tracer/TracerRunner.cpp",
1285
        ] + get_feature_tracer_source_list(),
1286
        header_namespace = "",
1287
        compiler_flags = get_pt_compiler_flags(),
1288
        exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []),
1289
        # @lint-ignore BUCKLINT link_whole
1290
        link_whole = True,
1291
        linker_flags = [
1292
            "-Wl,--no-as-needed",
1293
        ],
1294
        visibility = ["PUBLIC"],
1295
        deps = [
1296
            ":generated-autograd-headers",
1297
            ":torch_mobile_deserialize",
1298
            ":torch_mobile_headers",
1299
            ":torch_mobile_observer",
1300
        ] + ([] if IS_OSS else ["//xplat/folly:molly"]),
1301
        exported_deps = [
1302
            ":aten_cpu",
1303
            ":torch_common",
1304
        ] + ([] if IS_OSS else [
1305
            "//xplat/caffe2/fb/custom_ops/batch_box_cox:batch_box_cox",
1306
            "//xplat/caffe2/fb/custom_ops/maskrcnn:maskrcnn",
1307
        ]),
1308
    )
1309

1310
    pt_xplat_cxx_library(
1311
        name = "torch_mobile_deserialize",
1312
        srcs = [
1313
            "torch/csrc/jit/mobile/import.cpp",
1314
            "torch/csrc/jit/mobile/flatbuffer_loader.cpp",
1315
        ],
1316
        compiler_flags = get_pt_compiler_flags(),
1317
        exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DFB_XPLAT_BUILD"] if not IS_OSS else []),
1318
        header_namespace = "",
1319
        exported_headers = [
1320
            "torch/csrc/jit/mobile/import.h",
1321
            "torch/csrc/jit/mobile/flatbuffer_loader.h",
1322
        ],
1323
        # torch_mobile_deserialize brings in sources neccessary to read a module
1324
        # which depends on mobile module definition
1325
        # link_whole is enable so that all symbols neccessary for mobile module are compiled
1326
        # instead of only symbols used while loading; this prevents symbol
1327
        # found definied in runtime
1328
        # @lint-ignore BUCKLINT link_whole
1329
        link_whole = True,
1330
        linker_flags = [
1331
            "-Wl,--no-as-needed",
1332
        ],
1333
        visibility = ["PUBLIC"],
1334
        exported_deps = [
1335
            ":aten_cpu",
1336
            ":caffe2_headers",
1337
            ":caffe2_serialize",
1338
            ":torch_common",
1339
            ":torch_headers",
1340
            ":torch_mobile_headers",
1341
            ":torch_mobile_module",
1342
            ":torch_mobile_observer",
1343
            ":torch_mobile_deserialize_common",
1344
            ":mobile_bytecode",
1345
            C10,
1346
        ],
1347
    )
1348

1349
    pt_xplat_cxx_library(
1350
        name = "torch_mobile_core",
1351
        srcs = [],
1352
        header_namespace = "",
1353
        exported_headers = [],
1354
        compiler_flags = get_pt_compiler_flags(),
1355
        exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []),
1356
        # torch_mobile_core brings in sources neccessary to read and run a module
1357
        # link_whole is enabled so that all symbols linked
1358
        # operators, registerations and other few symbols are need in runtime
1359
        # @lint-ignore BUCKLINT link_whole
1360
        link_whole = True,
1361
        linker_flags = [
1362
            "-Wl,--no-as-needed",
1363
        ],
1364
        visibility = ["PUBLIC"],
1365
        deps = [
1366
            ":generated-autograd-headers",
1367
            ":torch_mobile_headers",
1368
            ":torch_mobile_observer",
1369
        ],
1370
        exported_deps = [
1371
            ":aten_cpu",
1372
            ":torch_common",
1373
            ":torch_mobile_deserialize",
1374
            ":torch_supported_mobile_models",
1375
        ],
1376
    )
1377

1378
    pt_xplat_cxx_library(
1379
        name = "torch_mobile_core_pickle_and_flatbuffer",
1380
        compiler_flags = get_pt_compiler_flags(),
1381
        exported_preprocessor_flags = get_pt_preprocessor_flags(),
1382
        visibility = ["PUBLIC"],
1383
        exported_deps = [
1384
            ":flatbuffers_mobile",
1385
            ":torch_mobile_core",
1386
        ],
1387
    )
1388

1389
    pt_xplat_cxx_library(
1390
        name = "torch_cpp_cpu",
1391
        srcs = torch_cpp_srcs,
1392
        headers = native.glob(["torch/csrc/api/include/**/*.h"]) + ["torch/script.h"],
1393
        compiler_flags = get_pt_compiler_flags(),
1394
        exported_preprocessor_flags = get_pt_preprocessor_flags(),
1395
        visibility = ["PUBLIC"],
1396
        exported_deps = [
1397
            ":torch",
1398
            ":torch_mobile_deserialize_common",  # for torch/csrc/api/src/serialize/input-archive.cpp
1399
        ],
1400
    )
1401

1402
    pt_xplat_cxx_library(
1403
        name = "torch_core",
1404
        srcs = core_sources_full_mobile_no_backend_interface_xplat,
1405
        compiler_flags = get_pt_compiler_flags(),
1406
        exported_preprocessor_flags = get_pt_preprocessor_flags(),
1407
        visibility = [
1408
            "//xplat/caffe2/android/...",
1409
            "//xplat/caffe2/fb/...",
1410
            "//xplat/caffe2/fb/model_tracer/...",
1411
        ],
1412
        deps = [
1413
            ":aten_cpu",
1414
            ":backend_interface_lib",
1415
            ":generated-autograd-headers",
1416
            ":torch_headers",
1417
            ":torch_mobile_deserialize",
1418
            third_party("glog"),
1419
            third_party("rt"),
1420
            C10,
1421
        ] + ([] if IS_OSS else [
1422
            "//xplat/caffe2/fb/custom_ops/batch_box_cox:batch_box_cox",
1423
            "//xplat/caffe2/fb/custom_ops/maskrcnn:maskrcnn",
1424
        ]),
1425
        exported_deps = [
1426
            ":torch_common",
1427
            ":torch_mobile_train",
1428
        ],
1429
    )
1430

1431
    pt_xplat_cxx_library(
1432
        name = "torch_train",
1433
        srcs = [
1434
            "torch/csrc/api/src/data/samplers/random.cpp",
1435
            "torch/csrc/api/src/data/samplers/sequential.cpp",
1436
            "torch/csrc/api/src/optim/optimizer.cpp",
1437
            "torch/csrc/api/src/optim/serialize.cpp",
1438
            "torch/csrc/api/src/optim/sgd.cpp",
1439
            "torch/csrc/api/src/serialize/input-archive.cpp",
1440
            "torch/csrc/api/src/serialize/output-archive.cpp",
1441
            "torch/csrc/jit/api/module_save.cpp",
1442
        ],
1443
        compiler_flags = get_pt_compiler_flags(),
1444
        exported_preprocessor_flags = get_pt_preprocessor_flags(),
1445
        visibility = ["PUBLIC"],
1446
        deps = [
1447
            ":aten_cpu",
1448
            ":torch_headers",
1449
            ":torch",
1450
            ":torch_core",
1451
            ":torch_mobile_deserialize",
1452
            ":torch_mobile_train",
1453
            ":jit_module_saving",
1454
            C10,
1455
        ],
1456
    )
1457

1458
    pt_xplat_cxx_library(
1459
        name = "torch_mobile_train",
1460
        srcs = core_trainer_sources + [
1461
            "torch/csrc/autograd/VariableTypeManual.cpp",
1462
            "torch/csrc/autograd/FunctionsManual.cpp",
1463
            "torch/csrc/api/src/data/datasets/mnist.cpp",
1464
            "torch/csrc/jit/mobile/quantization.cpp",
1465
            "torch/csrc/jit/mobile/train/export_data.cpp",
1466
            "torch/csrc/jit/mobile/train/optim/sgd.cpp",
1467
            "torch/csrc/jit/mobile/train/random.cpp",
1468
            "torch/csrc/jit/mobile/train/sequential.cpp",
1469
            ":gen_aten_libtorch[autograd/generated/Functions.cpp]",
1470
            ":gen_aten_libtorch[autograd/generated/ViewFuncs.cpp]",
1471
        ],
1472
        compiler_flags = get_pt_compiler_flags(),
1473
        exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DUSE_MOBILE_CLASSTYPE"],
1474
        # torch_mobile_train brings in sources neccessary to read and run a mobile
1475
        # and save and load mobile params along with autograd
1476
        # link_whole is enabled so that all symbols linked
1477
        # operators, registerations and autograd related symbols are need in runtime
1478
        # @lint-ignore BUCKLINT link_whole
1479
        link_whole = True,
1480
        visibility = ["PUBLIC"],
1481
        deps = [
1482
            ":aten_cpu",
1483
            ":generated-autograd-headers",
1484
            ":torch_headers",
1485
            ":torch_mobile_deserialize",
1486
            ":flatbuffers_serializer_mobile",
1487
            C10,
1488
        ],
1489
    )
1490

1491
    pt_xplat_cxx_library(
1492
        name = "torch",
1493
        srcs = [
1494
            "torch/csrc/jit/runtime/register_c10_ops.cpp",
1495
            "torch/csrc/jit/runtime/register_prim_ops_fulljit.cpp",
1496
        ],
1497
        compiler_flags = get_pt_compiler_flags(),
1498
        exported_preprocessor_flags = get_pt_preprocessor_flags(),
1499
        # torch brings in all sources neccessary to read and run a mobile module/jit module
1500
        # link_whole is enabled so that all symbols linked
1501
        # operators, registerations and other few symbols are need in runtime
1502
        # @lint-ignore BUCKLINT link_whole
1503
        link_whole = True,
1504
        visibility = ["PUBLIC"],
1505
        deps = [
1506
            # This is to have autograd profiler available
1507
            # in xplat/caffe2:torch which some builds are using
1508
            # notable xplate/facegen:testsAndroid
1509
            ":torch_headers",
1510
            ":torch_kineto_profiling",
1511
        ],
1512
        exported_deps = [
1513
            ":aten_cpu",
1514
            ":torch_core",
1515
            C10,
1516
        ],
1517
    )
1518

1519
    pt_xplat_cxx_library(
1520
        name = "torch_mobile_train_import_data",
1521
        srcs = [
1522
            "torch/csrc/jit/mobile/import_data.cpp",
1523
        ],
1524
        compiler_flags = get_pt_compiler_flags(),
1525
        exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DUSE_MOBILE_CLASSTYPE"],
1526
        # torch_mobile_train_import_data brings in sources neccessary to read a mobile module
1527
        # link_whole is enabled so that all symbols linked
1528
        # operators other few symbols are need in runtime
1529
        # @lint-ignore BUCKLINT link_whole
1530
        link_whole = True,
1531
        visibility = ["PUBLIC"],
1532
        deps = [
1533
            ":torch_headers",
1534
            ":torch_mobile_observer",
1535
            ":torch_mobile_core",
1536
            ":torch_mobile_train",
1537
        ],
1538
    )
1539

1540
    fb_xplat_cxx_library(
1541
        name = "torch_mobile_compatibility",
1542
        srcs = [
1543
            # These .cpp brought in through core_sources_common
1544
            # "torch/csrc/jit/mobile/compatibility/runtime_compatibility.cpp",
1545
            # "torch/csrc/jit/serialization/unpickler.cpp",
1546
            "torch/csrc/jit/mobile/compatibility/model_compatibility.cpp",
1547
        ],
1548
        header_namespace = "",
1549
        exported_headers = [
1550
            "torch/csrc/jit/mobile/compatibility/backport.h",
1551
            "torch/csrc/jit/mobile/compatibility/backport_manager.h",
1552
            "torch/csrc/jit/mobile/compatibility/model_compatibility.h",
1553
            "torch/csrc/jit/mobile/compatibility/runtime_compatibility.h",
1554
        ],
1555
        compiler_flags = [
1556
            "-fexceptions",
1557
            "-frtti",
1558
            "-Wno-deprecated-declarations",
1559
            "-Wno-global-constructors",
1560
        ],
1561
        labels = labels,
1562
        visibility = ["PUBLIC"],
1563
        deps = [
1564
            ":torch_mobile_deserialize",
1565
        ],
1566
    )
1567

1568
    pt_xplat_cxx_library(
1569
        name = "jit_module_saving",
1570
        srcs = [
1571
            "torch/csrc/jit/api/module_save.cpp",
1572
            "torch/csrc/jit/serialization/export_bytecode.cpp",
1573
            "torch/csrc/jit/serialization/export_module.cpp",
1574
        ],
1575
        compiler_flags = get_pt_compiler_flags(),
1576
        exported_preprocessor_flags = get_pt_preprocessor_flags() +
1577
                                      (["-DFB_XPLAT_BUILD"] if not IS_OSS else []),
1578
        exported_headers = [
1579
            "torch/csrc/jit/serialization/export.h",
1580
        ],
1581
        visibility = ["PUBLIC"],
1582
        deps = [
1583
            ":torch",
1584
            ":torch_mobile_core",
1585
            ":flatbuffers_serializer_mobile",
1586
        ],
1587
    )
1588

1589
    pt_xplat_cxx_library(
1590
        name = "torch_mobile_model_tracer",
1591
        srcs = [
1592
            "torch/csrc/jit/mobile/model_tracer/MobileModelRunner.cpp",
1593
            "torch/csrc/jit/mobile/model_tracer/TensorUtils.cpp",
1594
        ],
1595
        headers = [
1596
            "torch/csrc/jit/mobile/model_tracer/MobileModelRunner.h",
1597
            "torch/csrc/jit/mobile/model_tracer/TensorUtils.h",
1598
        ],
1599
        header_namespace = "",
1600
        exported_headers = [
1601
            "torch/csrc/jit/mobile/model_tracer/MobileModelRunner.h",
1602
        ],
1603
        compiler_flags = get_pt_compiler_flags(),
1604
        exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []),
1605
        # torch_mobile_model_tracer brings in sources neccessary to read and run a jit module
1606
        # and trace the ops
1607
        # link_whole is enabled so that all symbols linked
1608
        # operators, registerations and other few symbols are need in runtime
1609
        # @lint-ignore BUCKLINT link_whole
1610
        link_whole = True,
1611
        linker_flags = [
1612
            "-Wl,--no-as-needed",
1613
        ],
1614
        visibility = ["PUBLIC"],
1615
        deps = [
1616
            ":caffe2_serialize",
1617
            ":generated-autograd-headers",
1618
            ":torch_mobile_headers",
1619
            ":torch_mobile_observer",
1620
            ":torch_mobile_core",
1621
        ] + ([] if IS_OSS else ["//xplat/folly:molly"]),
1622
        exported_deps = [
1623
            ":aten_cpu",
1624
            ":torch_common",
1625
        ] + ([] if IS_OSS else [
1626
            "//xplat/caffe2/fb/custom_ops/batch_box_cox:batch_box_cox",
1627
            "//xplat/caffe2/fb/custom_ops/maskrcnn:maskrcnn",
1628
            "//xplat/caffe2/fb/custom_ops/sparsenn:sparsenn-all",
1629
        ]),
1630
    )
1631

1632
    #TODO(qihan) delete
1633
    pt_xplat_cxx_library(
1634
        name = "torch_mobile_core_flatbuffer",
1635
        srcs = [],
1636
        header_namespace = "",
1637
        exported_headers = [],
1638
        compiler_flags = get_pt_compiler_flags(),
1639
        exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []),
1640
        # @lint-ignore BUCKLINT link_whole
1641
        link_whole = True,
1642
        linker_flags = [
1643
            "-Wl,--no-as-needed",
1644
        ],
1645
        visibility = ["PUBLIC"],
1646
        deps = [
1647
            ":generated-autograd-headers",
1648
            ":torch_mobile_headers",
1649
            ":torch_mobile_observer",
1650
        ],
1651
        exported_deps = [
1652
            ":aten_cpu",
1653
            ":torch_common",
1654
        ],
1655
    )
1656

1657
    fb_xplat_cxx_library(
1658
        name = "backend_interface_lib",
1659
        srcs = [
1660
            "torch/csrc/jit/backends/backend_debug_info.cpp",
1661
            "torch/csrc/jit/backends/backend_interface.cpp",
1662
        ],
1663
        compiler_flags = get_pt_compiler_flags(),
1664
        fbandroid_compiler_flags = c2_fbandroid_xplat_compiler_flags,
1665
        # @lint-ignore BUCKLINT link_whole
1666
        link_whole = True,
1667
        linker_flags = [
1668
            "-Wl,--no-as-needed",
1669
        ],
1670
        visibility = ["PUBLIC"],
1671
        exported_deps = [
1672
            ":aten_cpu",
1673
            ":torch_common",
1674
        ],
1675
    )
1676

1677
    pt_xplat_cxx_library(
1678
        name = "torch_kineto_profiling",
1679
        srcs = libtorch_profiler_sources,
1680
        compiler_flags = get_pt_compiler_flags() + ["-Wno-error"],
1681
        exported_preprocessor_flags = get_pt_preprocessor_flags() + [
1682
            "-DUSE_KINETO",
1683
            # Need this otherwise USE_KINETO is undefed
1684
            # for mobile
1685
            "-DEDGE_PROFILER_USE_KINETO",
1686
        ],
1687
        # @lint-ignore BUCKLINT link_whole
1688
        link_whole = True,
1689
        linker_flags = [
1690
            "-Wl,--no-as-needed",
1691
        ],
1692
        visibility = ["PUBLIC"],
1693
        deps = [
1694
            third_party("glog"),
1695
            third_party("kineto"),
1696
        ],
1697
        exported_deps = [
1698
            ":aten_cpu",
1699
            ":torch_common",
1700
        ],
1701
    )
1702

1703
    pt_xplat_cxx_library(
1704
        name = "torch_edge_profiling",
1705
        srcs = ["torch/csrc/jit/mobile/profiler_edge.cpp"],
1706
        compiler_flags = get_pt_compiler_flags() + ["-Wno-error"],
1707
        exported_preprocessor_flags = get_pt_preprocessor_flags() + [
1708
            "-DUSE_KINETO",
1709
            "-DEDGE_PROFILER_USE_KINETO",
1710
        ],
1711
        # @lint-ignore BUCKLINT link_whole
1712
        link_whole = True,
1713
        linker_flags = [
1714
            "-Wl,--no-as-needed",
1715
        ],
1716
        visibility = ["PUBLIC"],
1717
        exported_deps = [
1718
            ":torch_common",
1719
            ":torch_kineto_profiling",
1720
            ":torch_mobile_core",
1721
        ],
1722
    )
1723

1724
    fb_xplat_genrule(
1725
        name = "mobile_bytecode_header",
1726
        srcs = [
1727
            "torch/csrc/jit/serialization/mobile_bytecode.fbs",
1728
        ],
1729
        outs = {
1730
            "mobile_bytecode_generated_fbsource.h": ["mobile_bytecode_generated.h"],
1731
        },
1732
        cmd = "$(exe {})".format(third_party("flatc")) +
1733
              " --cpp --gen-mutable --scoped-enums -o ${OUT} ${SRCS}",
1734
        default_outs = ["."],
1735
        visibility = [
1736
            "{}:mobile_bytecode".format(ROOT),
1737
        ],
1738
    )
1739

1740
    # Users of this target will need to add third_party("flatbuffers-api") as a
1741
    # dep.
1742
    fb_xplat_cxx_library(
1743
        name = "mobile_bytecode",
1744
        header_namespace = "",
1745
        exported_headers = {
1746
            ("torch/csrc/jit/serialization/mobile_bytecode_generated.h" if IS_OSS else "torch/csrc/jit/serialization/mobile_bytecode_generated_fbsource.h"): ":mobile_bytecode_header[mobile_bytecode_generated_fbsource.h]",
1747
        },
1748
        # Avoid leaking implementation details by only exposing this header to
1749
        # the internals of the loader/serializer layer.
1750
        visibility = [
1751
            "{}:flatbuffer_loader".format(ROOT),
1752
            "{}:flatbuffers_serializer_mobile".format(ROOT),
1753
        ],
1754
        exported_deps = [
1755
            third_party("flatbuffers-api"),
1756
        ],
1757
    )
1758

1759
    fb_xplat_cxx_library(
1760
        name = "flatbuffers_serializer_mobile",
1761
        srcs = ["torch/csrc/jit/serialization/flatbuffer_serializer.cpp"],
1762
        exported_headers = [
1763
            "torch/csrc/jit/serialization/flatbuffer_serializer.h",
1764
        ],
1765
        compiler_flags = [
1766
            "-g0",
1767
            "-O3",
1768
            "-fexceptions",
1769
            "-frtti",
1770
            "-Wno-deprecated-declarations",
1771
        ] + (["-DFB_XPLAT_BUILD"] if not IS_OSS else []),
1772
        visibility = ["PUBLIC"],
1773
        deps = [
1774
            ":mobile_bytecode",
1775
            ":torch_mobile_module",
1776
            C10,
1777
        ],
1778
        exported_deps = [
1779
            ":torch_mobile_deserialize",
1780
            ":mobile_bytecode",
1781
        ],
1782
    )
1783

1784
    # TODO (qihan) delete
1785
    pt_xplat_cxx_library(
1786
        name = "flatbuffer_loader",
1787
        srcs = [
1788
        ],
1789
        exported_headers = [
1790
            "torch/csrc/jit/mobile/flatbuffer_loader.h",
1791
        ],
1792
        compiler_flags = get_pt_compiler_flags() + ["-Wno-error"],
1793
        exported_preprocessor_flags = get_pt_preprocessor_flags() + [
1794
            "-DUSE_KINETO",
1795
            # Need this otherwise USE_KINETO is undefed
1796
            # for mobile
1797
            "-DEDGE_PROFILER_USE_KINETO",
1798
        ] + (["-DFB_XPLAT_BUILD"] if not IS_OSS else []),
1799
        extra_flags = {
1800
            "fbandroid_compiler_flags": ["-frtti"],
1801
        },
1802
        # torch_mobile_deserialize brings in sources neccessary to read a module
1803
        # which depends on mobile module definition
1804
        # link_whole is enable so that all symbols neccessary for mobile module are compiled
1805
        # instead of only symbols used while loading; this prevents symbol
1806
        # found definied in runtime
1807
        # @lint-ignore BUCKLINT link_whole
1808
        link_whole = True,
1809
        linker_flags = [
1810
            "-Wl,--no-as-needed",
1811
        ],
1812
        visibility = ["PUBLIC"],
1813
        deps = [
1814
            ":mobile_bytecode",
1815
        ],
1816
        exported_deps = [
1817
            C10,
1818
        ],
1819
    )
1820

1821
    # TODO(qihan) delete
1822
    fb_xplat_cxx_library(
1823
        name = "flatbuffers_serializer_jit",
1824
        compiler_flags = [
1825
            "-g0",
1826
            "-O3",
1827
            "-fexceptions",
1828
            "-frtti",
1829
            "-Wno-deprecated-declarations",
1830
        ],
1831
        headers = [
1832
            "torch/csrc/jit/serialization/flatbuffer_serializer_jit.h",
1833
        ],
1834
        srcs = [
1835
            "torch/csrc/jit/serialization/flatbuffer_serializer_jit.cpp",
1836
        ],
1837
        linker_flags = [
1838
            "-Wl,--no-as-needed",
1839
        ],
1840
        visibility = ["PUBLIC"],
1841
        deps = [
1842
            ":flatbuffer_loader",
1843
            ":flatbuffers_serializer_mobile",
1844
            ":torch_core",
1845
            ":torch_mobile_module",
1846
            C10,
1847
        ],
1848
    )
1849

1850
    fb_xplat_cxx_library(
1851
        name = "flatbuffers_jit",
1852
        visibility = ["PUBLIC"],
1853
        exported_deps = [
1854
            ":flatbuffer_loader",
1855
            ":flatbuffers_serializer_mobile",
1856
            ":flatbuffers_serializer_jit",
1857
        ],
1858
    )
1859

1860
    fb_xplat_cxx_library(
1861
        name = "flatbuffers_mobile",
1862
        visibility = ["PUBLIC"],
1863
        exported_deps = [
1864
            ":flatbuffer_loader",
1865
            ":flatbuffers_serializer_mobile",
1866
            ":torch_mobile_train",
1867
        ],
1868
    )
1869

1870
    pt_xplat_cxx_library(
1871
        name = "torch_supported_mobile_models",
1872
        srcs = [
1873
            "fb/supported_mobile_models/SupportedMobileModels.cpp",
1874
        ] if NOT_OSS else [],
1875
        header_namespace = "",
1876
        exported_headers = ["fb/supported_mobile_models/SupportedMobileModels.h"] if NOT_OSS else [],
1877
        compiler_flags = get_pt_compiler_flags() + ["-Wno-error"],
1878
        exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []),
1879
        # @lint-ignore BUCKLINT link_whole
1880
        link_whole = True,
1881
        linker_flags = [
1882
            "-Wl,--no-as-needed",
1883
        ],
1884
        visibility = ["PUBLIC"],
1885
        deps = [],
1886
        exported_deps = [
1887
            "//xplat/caffe2/fb/custom_ops/batch_box_cox:batch_box_cox",
1888
            "//xplat/caffe2/fb/custom_ops/maskrcnn:maskrcnn",
1889
        ] if NOT_OSS else [],
1890
    )
1891

1892
    fb_xplat_cxx_library(
1893
        name = "static_runtime",
1894
        srcs = [
1895
            "torch/csrc/jit/runtime/static/fusion.cpp",
1896
            "torch/csrc/jit/runtime/static/generated_ops.cpp",
1897
            "torch/csrc/jit/runtime/static/impl.cpp",
1898
            "torch/csrc/jit/runtime/static/memory_planner.cpp",
1899
            "torch/csrc/jit/runtime/static/native_ops.cpp",
1900
            "torch/csrc/jit/runtime/static/ops.cpp",
1901
            "torch/csrc/jit/runtime/static/passes.cpp",
1902
            "torch/csrc/jit/runtime/static/te_wrapper.cpp",
1903
        ],
1904
        compiler_flags = ["-fexceptions"],
1905
        labels = labels,
1906
        # @lint-ignore BUCKLINT link_whole
1907
        link_whole = True,
1908
        visibility = ["PUBLIC"],
1909
        windows_preferred_linkage = "static" if is_arvr_mode() else None,
1910
        deps = [
1911
            ":aten_cpu",
1912
            ":caffe2_headers",
1913
            ":torch_core",
1914
            C10,
1915
        ],
1916
    )
1917

1918
    # aten_cpu and aten_native_cpu
1919
    for name, srcs in [
1920
        ("aten_cpu", jit_core_sources + aten_cpu_source_list + [
1921
            # Generated
1922
            ":gen_aten[Functions.cpp]",
1923
            ":gen_aten[Operators_0.cpp]",
1924
            ":gen_aten[Operators_1.cpp]",
1925
            ":gen_aten[Operators_2.cpp]",
1926
            ":gen_aten[Operators_3.cpp]",
1927
            ":gen_aten[Operators_4.cpp]",
1928
            ":gen_aten[core/ATenOpList.cpp]",
1929
            ":gen_aten[core/TensorMethods.cpp]",
1930
            # Needed by ATen/native/EmbeddingBag.cpp
1931
            "caffe2/perfkernels/embedding_lookup_idx.cc",
1932
        ]),
1933
        ("aten_native_cpu", aten_native_source_list),
1934
    ]:
1935
        fb_xplat_cxx_library(
1936
            name = name,
1937
            srcs = srcs,
1938
            header_namespace = "",
1939
            # @lint-ignore BUCKLINT
1940
            link_whole = True,
1941
            visibility = ["PUBLIC"],
1942
            deps = [
1943
                third_party("omp"),
1944
                third_party("cpuinfo"),
1945
                third_party("glog"),
1946
                third_party("XNNPACK"),
1947
                third_party("pocketfft"),
1948
            ] + select({
1949
                "DEFAULT": [],
1950
                "ovr_config//runtime:fbcode-arm64": [
1951
                    third_party("sleef_arm"),
1952
                ],
1953
            }),
1954
            compiler_flags = get_aten_compiler_flags(),
1955
            exported_preprocessor_flags = get_aten_preprocessor_flags(),
1956
            exported_deps = [
1957
                ":aten_header",
1958
                ":caffe2_headers",
1959
                ":common_core",
1960
                ":generated_aten_config_header",
1961
                ":generated_aten_headers_cpu",
1962
                ":jit_core_headers",
1963
                ":pthreadpool",
1964
                third_party("fmt"),
1965
                third_party("ruy"),
1966
                C10,
1967
                ROOT_PATH + "aten/src/ATen/native/quantized/cpu/qnnpack:pytorch_qnnpack",
1968
            ],
1969
            labels = labels,
1970
            **aten_default_args
1971
        )
1972

1973
    fb_xplat_cxx_library(
1974
        name = "lean_runtime_with_flatbuffer",
1975
        srcs = [
1976
            "aten/src/ATen/core/DeprecatedTypePropertiesRegistry.cpp",
1977
            "torch/csrc/jit/mobile/import.cpp",
1978
            "torch/csrc/jit/mobile/module.cpp",
1979
            "torch/csrc/jit/mobile/observer.cpp",
1980
            "torch/csrc/jit/serialization/import_read.cpp",
1981
        ],
1982
        header_namespace = "",
1983
        exported_headers = subdir_glob(
1984
            [
1985
                ("", "torch/csrc/jit/ir/*.h"),
1986
                ("", "caffe2/serialize/*.h"),
1987
                ("", "caffe2/utils/*.h"),
1988
                ("", "caffe2/core/*.h"),
1989
                ("", "torch/csrc/*.h"),
1990
                ("", "torch/csrc/api/include/torch/*.h"),
1991
                ("", "torch/csrc/autograd/*.h"),
1992
                ("", "torch/csrc/autograd/*/*.h"),
1993
                ("", "torch/csrc/jit/api/*.h"),
1994
                ("", "torch/csrc/jit/backends/*.h"),
1995
                ("", "torch/csrc/jit/mobile/*.h"),
1996
                ("", "torch/csrc/jit/runtime/*.h"),
1997
                ("", "torch/csrc/jit/passes/*.h"),
1998
                ("", "torch/csrc/jit/python/*.h"),
1999
                ("", "torch/csrc/jit/frontend/*.h"),
2000
                ("", "torch/csrc/jit/serialization/*.h"),
2001
                ("", "torch/csrc/profiler/**/*.h"),
2002
                ("", "torch/csrc/utils/*.h"),
2003
                ("", "aten/src/ATen/quantized/*.h"),
2004
            ] + ([
2005
                ("third_party/miniz-2.1.0", "*.h"),
2006
            ] if NOT_OSS else []),
2007
            exclude = [
2008
                "torch/csrc/jit/serialization/mobile_bytecode_generated.h",
2009
            ],
2010
        ),
2011
        compiler_flags = get_pt_compiler_flags() + select({
2012
            "DEFAULT": [],
2013
            "ovr_config//os:xtensa-xos": [
2014
                "-fdata-sections",
2015
                "-ffunction-sections",
2016
            ],
2017
        }),
2018
        exported_preprocessor_flags = get_pt_preprocessor_flags() + [
2019
            "-DMIN_EDGE_RUNTIME",
2020
        ],
2021
        linker_flags = [
2022
            "-Wl,--no-as-needed",
2023
        ] + select({
2024
            "DEFAULT": [],
2025
            "ovr_config//os:macos": [
2026
                "-dead_strip",
2027
            ],
2028
            "ovr_config//os:xtensa-xos": [
2029
                "-Wl,--gc-sections",
2030
            ],
2031
        }),
2032
        visibility = ["PUBLIC"],
2033
        exported_deps = [
2034
            ":lean_runtime_with_tensor",
2035
        ],
2036
    )
2037

2038
    pt_xplat_cxx_library(
2039
        name = "lean_runtime_with_tensor",
2040
        srcs = [
2041
            "aten/src/ATen/Context.cpp",
2042
            "aten/src/ATen/EmptyTensor.cpp",
2043
            "aten/src/ATen/Utils.cpp",
2044
            "aten/src/ATen/detail/CUDAHooksInterface.cpp",
2045
            "aten/src/ATen/detail/PrivateUse1HooksInterface.cpp",
2046
            ":gen_aten[Operators_0.cpp]",
2047
            ":gen_aten[Operators_1.cpp]",
2048
            ":gen_aten[Operators_2.cpp]",
2049
            ":gen_aten[Operators_3.cpp]",
2050
            ":gen_aten[Operators_4.cpp]",
2051
            ":gen_aten[core/TensorMethods.cpp]",
2052
        ],
2053
        header_namespace = "",
2054
        exported_headers = [
2055
            "torch/csrc/jit/runtime/custom_operator.h",
2056
            ":gen_aten[core/TensorBody.h]",
2057
        ],
2058
        compiler_flags = get_pt_compiler_flags() + select({
2059
            "DEFAULT": [],
2060
            "ovr_config//os:xtensa-xos": [
2061
                "-fdata-sections",
2062
                "-ffunction-sections",
2063
            ],
2064
        }),
2065
        exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DMIN_EDGE_RUNTIME"] + select({
2066
            "DEFAULT": [],
2067
            "ovr_config//os:xtensa-xos": [
2068
                "-Dthread_local=",
2069
            ],
2070
        }),
2071
        # @lint-ignore BUCKLINT link_whole
2072
        link_whole = True,
2073
        linker_flags = [
2074
            "-Wl,--no-as-needed",
2075
        ],
2076
        visibility = ["PUBLIC"],
2077
        exported_deps = [
2078
            ":generated_aten_config_header",
2079
            ":lean_runtime_with_op",
2080
            ":aten_header",
2081
            C10,
2082
        ] + (["//xplat/caffe2/fb/embedded:experimental"] if NOT_OSS else []),
2083
    )
2084

2085
    pt_xplat_cxx_library(
2086
        name = "lean_runtime_with_op",
2087
        srcs = [
2088
            "aten/src/ATen/SequenceNumber.cpp",
2089
            "aten/src/ATen/core/boxing/KernelFunction.cpp",
2090
            "aten/src/ATen/core/custom_class.cpp",
2091
            "aten/src/ATen/core/dispatch/DispatchKeyExtractor.cpp",
2092
            "aten/src/ATen/core/dispatch/Dispatcher.cpp",
2093
            "aten/src/ATen/core/dispatch/ObservedOperators.cpp",
2094
            "aten/src/ATen/core/dispatch/OperatorEntry.cpp",
2095
            "aten/src/ATen/core/PythonOpRegistrationTrampoline.cpp",
2096
            "aten/src/ATen/core/interned_strings.cpp",
2097
            "aten/src/ATen/core/library.cpp",
2098
            "aten/src/ATen/core/op_registration/infer_schema.cpp",
2099
            "aten/src/ATen/core/function_schema.cpp",
2100
            "aten/src/ATen/core/operator_name.cpp",
2101
            "aten/src/ATen/core/register_symbols.cpp",
2102
            "aten/src/ATen/core/tensor_type.cpp",
2103
            "aten/src/ATen/core/union_type.cpp",
2104
            "aten/src/ATen/record_function.cpp",
2105
            "torch/csrc/jit/frontend/edit_distance.cpp",
2106
            "torch/csrc/jit/frontend/error_report.cpp",
2107
            "torch/csrc/jit/frontend/function_schema_parser.cpp",
2108
            "torch/csrc/jit/frontend/lexer.cpp",
2109
            "torch/csrc/jit/frontend/schema_type_parser.cpp",
2110
            "torch/csrc/jit/frontend/source_range.cpp",
2111
            "torch/csrc/jit/frontend/strtod.cpp",
2112
            "torch/csrc/jit/mobile/parse_operators.cpp",
2113
            "torch/csrc/jit/mobile/prim_ops_registery.cpp",
2114
            "torch/csrc/jit/runtime/operator.cpp",
2115
            "torch/csrc/jit/runtime/slice_indices_adjust.cpp",
2116
        ],
2117
        header_namespace = "",
2118
        exported_headers = [
2119
            "torch/csrc/jit/frontend/edit_distance.h",
2120
            "torch/csrc/jit/runtime/slice_indices_adjust.h",
2121
        ],
2122
        compiler_flags = get_pt_compiler_flags() + select({
2123
            "DEFAULT": [],
2124
            "ovr_config//os:xtensa-xos": [
2125
                "-fdata-sections",
2126
                "-ffunction-sections",
2127
            ],
2128
        }),
2129
        exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DMIN_EDGE_RUNTIME"] + select({
2130
            "DEFAULT": [],
2131
            "ovr_config//os:xtensa-xos": [
2132
                "-Dthread_local=",
2133
            ],
2134
        }),
2135
        # @lint-ignore BUCKLINT link_whole
2136
        link_whole = True,
2137
        linker_flags = [
2138
            "-Wl,--no-as-needed",
2139
        ],
2140
        visibility = ["PUBLIC"],
2141
        exported_deps = [
2142
            ":min_runtime_lib",
2143
            C10,
2144
        ],
2145
    )
2146

2147
    pt_xplat_cxx_library(
2148
        name = "min_runtime_lib",
2149
        srcs = [
2150
            "aten/src/ATen/ScalarOps.cpp",
2151
            "aten/src/ATen/core/Dict.cpp",
2152
            "aten/src/ATen/core/List.cpp",
2153
            "aten/src/ATen/core/class_type.cpp",
2154
            "aten/src/ATen/core/dynamic_type.cpp",
2155
            "aten/src/ATen/core/ivalue.cpp",
2156
            "aten/src/ATen/core/type.cpp",
2157
            "aten/src/ATen/core/type_factory.cpp",
2158
            "aten/src/ATen/native/prim_native_functions.cpp",
2159
            "torch/csrc/jit/mobile/function.cpp",
2160
            "torch/csrc/jit/mobile/interpreter.cpp",
2161
            "torch/csrc/jit/mobile/parse_bytecode.cpp",
2162
            "torch/csrc/jit/mobile/promoted_prim_ops.cpp",
2163
            "torch/csrc/jit/mobile/register_ops_common_utils.cpp",
2164
            "torch/csrc/jit/mobile/type_parser.cpp",
2165
            "torch/csrc/jit/runtime/instruction.cpp",
2166
            "torch/csrc/jit/runtime/jit_exception.cpp",
2167
            "torch/csrc/jit/runtime/vararg_functions.cpp",
2168
        ],
2169
        header_namespace = "",
2170
        exported_headers = [
2171
            "caffe2/serialize/versions.h",
2172
            "torch/csrc/jit/backends/backend_exception.h",
2173
            "torch/csrc/jit/mobile/register_ops_common_utils.h",
2174
            "torch/csrc/jit/runtime/instruction.h",
2175
            "torch/csrc/jit/runtime/jit_exception.h",
2176
            "torch/csrc/jit/runtime/operator.h",
2177
            "torch/csrc/jit/runtime/operator_options.h",
2178
            "torch/csrc/jit/runtime/vararg_functions.h",
2179
            "torch/csrc/jit/serialization/import_export_constants.h",
2180
            "torch/csrc/jit/serialization/import_export_functions.h",
2181
        ],
2182
        compiler_flags = get_pt_compiler_flags() + select({
2183
            "DEFAULT": [],
2184
            "ovr_config//os:xtensa-xos": [
2185
                "-fexceptions",
2186
                "-fdata-sections",
2187
                "-ffunction-sections",
2188
            ],
2189
        }),
2190
        exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DMIN_EDGE_RUNTIME"] + select({
2191
            "DEFAULT": [],
2192
            "ovr_config//os:xtensa-xos": [
2193
                "-Dthread_local=",
2194
            ],
2195
        }),
2196
        # @lint-ignore BUCKLINT link_whole
2197
        link_whole = True,
2198
        linker_flags = [
2199
            "-Wl,--no-as-needed",
2200
        ],
2201
        visibility = ["PUBLIC"],
2202
        exported_deps = [
2203
            ":aten_header",
2204
            ":generated_aten_headers_cpu",
2205
            ":jit_core_headers",
2206
            ":torch_mobile_headers",
2207
            C10,
2208
        ],
2209
    )
2210

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.