diff --git a/BUCK.oss b/BUCK.oss index 8ba89590c458..62868fbb08a5 100644 --- a/BUCK.oss +++ b/BUCK.oss @@ -1,35 +1,14 @@ load("//tools/build_defs:glob_defs.bzl", "subdir_glob") -load( - ":build_variables.bzl", - "aten_cpu_source_list", - "aten_native_source_list", - "core_sources_common", - "jit_core_headers", - "jit_core_sources", - "libtorch_profiler_sources", -) load( ":pt_defs.oss.bzl", - "USED_PT_BACKENDS", - "build_aten_cpu", - "gen_aten_files", - "gen_aten_libtorch_files", - "get_aten_codegen_extra_params", - "get_pt_compiler_flags", - "get_pt_preprocessor_flags", "pt_operator_library", "get_pt_ops_deps", - "aten_ufunc_generated_all_cpu_sources", - "pt_xplat_cxx_library", - "TEMPLATE_SOURCE_LIST", ) load(":buckbuild.bzl", "define_buck_targets", ) -define_buck_targets( - pt_xplat_cxx_library = pt_xplat_cxx_library, -) +define_buck_targets() cxx_library( name = "pthreadpool", @@ -78,59 +57,6 @@ cxx_library( visibility = ['PUBLIC'], ) -build_aten_cpu( - name = "aten_cpu", - srcs = jit_core_sources + - aten_cpu_source_list + [ - # Generated - ":gen_aten[Functions.cpp]", - ":gen_aten[Operators_0.cpp]", - ":gen_aten[Operators_1.cpp]", - ":gen_aten[Operators_2.cpp]", - ":gen_aten[Operators_3.cpp]", - ":gen_aten[Operators_4.cpp]", - ":gen_aten[core/ATenOpList.cpp]", - ":gen_aten[core/TensorMethods.cpp]", - ] + [ - # Needed by ATen/native/EmbeddingBag.cpp - "caffe2/perfkernels/embedding_lookup_idx.cc", - ], -) - -gen_aten_files( - name = "gen_aten", - extra_flags = get_aten_codegen_extra_params(USED_PT_BACKENDS), - visibility = ["PUBLIC"], -) - -ATEN_EXPORTED_HEADERS = { - "CPUFunctions.h": ":gen_aten[CPUFunctions.h]", - "CPUFunctions_inl.h": ":gen_aten[CPUFunctions_inl.h]", - "CompositeExplicitAutogradFunctions.h": ":gen_aten[CompositeExplicitAutogradFunctions.h]", - "CompositeExplicitAutogradFunctions_inl.h": ":gen_aten[CompositeExplicitAutogradFunctions_inl.h]", - "CompositeExplicitAutogradNonFunctionalFunctions.h": ":gen_aten[CompositeExplicitAutogradNonFunctionalFunctions.h]", - "CompositeExplicitAutogradNonFunctionalFunctions_inl.h": ":gen_aten[CompositeExplicitAutogradNonFunctionalFunctions_inl.h]", - "CompositeImplicitAutogradFunctions.h": ":gen_aten[CompositeImplicitAutogradFunctions.h]", - "CompositeImplicitAutogradFunctions_inl.h": ":gen_aten[CompositeImplicitAutogradFunctions_inl.h]", - "FunctionalInverses.h": ":gen_aten[FunctionalInverses.h]", - "Functions.h": ":gen_aten[Functions.h]", - "MethodOperators.h": ":gen_aten[MethodOperators.h]", - "NativeFunctions.h": ":gen_aten[NativeFunctions.h]", - "NativeMetaFunctions.h": ":gen_aten[NativeMetaFunctions.h]", - "Operators.h": ":gen_aten[Operators.h]", - "RedispatchFunctions.h": ":gen_aten[RedispatchFunctions.h]", - "core/TensorBody.h": ":gen_aten[core/TensorBody.h]", - "core/aten_interned_strings.h": ":gen_aten[core/aten_interned_strings.h]", - "core/enum_tag.h": ":gen_aten[core/enum_tag.h]", -} - -cxx_library( - name = "generated_aten_headers_cpu", - header_namespace = "ATen", - exported_headers = ATEN_EXPORTED_HEADERS, -) -gen_aten_libtorch_files(name = "gen_aten_libtorch") - cxx_library( name = "caffe2_serialize", srcs = [ @@ -196,12 +122,3 @@ cxx_binary( "//c10:c10", ], ) - -filegroup( - name = "templated_selective_build_srcs", - # NB: no glob here, there are generated targets in this list! - srcs = glob(TEMPLATE_SOURCE_LIST) + aten_ufunc_generated_all_cpu_sources(":gen_aten[{}]"), - visibility = [ - "PUBLIC", - ], -) diff --git a/buckbuild.bzl b/buckbuild.bzl index 4e4d28dfd3c8..55e22851d48d 100644 --- a/buckbuild.bzl +++ b/buckbuild.bzl @@ -1,6 +1,7 @@ # NOTE: This file is shared by internal and OSS BUCK build. # These load paths point to different files in internal and OSS environment +load("@bazel_skylib//lib:paths.bzl", "paths") load("//tools/build_defs:fb_native_wrapper.bzl", "fb_native") load("//tools/build_defs:fb_python_binary.bzl", "fb_python_binary") load("//tools/build_defs:fb_python_library.bzl", "fb_python_library") @@ -9,15 +10,43 @@ load("//tools/build_defs:fb_xplat_genrule.bzl", "fb_xplat_genrule") load("//tools/build_defs:fbsource_utils.bzl", "is_arvr_mode") load("//tools/build_defs:glob_defs.bzl", "subdir_glob") load("//tools/build_defs:platform_defs.bzl", "APPLETVOS", "IOS", "MACOSX") +load("//tools/build_defs:type_defs.bzl", "is_list", "is_string") +load("//tools/build_defs/android:build_mode_defs.bzl", is_production_build_android = "is_production_build") +load("//tools/build_defs/apple:build_mode_defs.bzl", is_production_build_ios = "is_production_build") load("//tools/build_defs/windows:windows_flag_map.bzl", "windows_convert_gcc_clang_flags") load( ":build_variables.bzl", + "aten_cpu_source_list", + "aten_native_source_list", "core_sources_common", "core_sources_full_mobile_no_backend_interface", "core_trainer_sources", "jit_core_headers", + "jit_core_sources", "libtorch_profiler_sources", ) +load( + ":pt_template_srcs.bzl", + "METAL_MASKRCNN_SOURCE_LIST", + "METAL_SOURCE_LIST", + "TEMPLATE_MASKRCNN_SOURCE_LIST", + "TEMPLATE_SOURCE_LIST", + "aten_ufunc_generated_all_cpu_sources", + "get_gen_oplist_outs", + "get_generate_code_bin_outs", + "get_metal_registration_files_outs", + "get_metal_registration_files_outs_windows", + "get_metal_source_dict", + "get_template_registration_file_rules", + "get_template_registration_files_outs", + "get_template_source_dict", +) +load( + ":ufunc_defs.bzl", + "aten_ufunc_generated_cpu_kernel_sources", + "aten_ufunc_generated_cpu_sources", + "aten_ufunc_generated_cuda_sources", +) def read_bool(section, field, default, required = True): # @lint-ignore BUCKRESTRICTEDSYNTAX @@ -38,9 +67,42 @@ def read_bool(section, field, default, required = True): else: fail("`{}:{}`: no value set".format(section, field)) +def _is_build_mode_dev(): + if is_production_build_android(): + # Android Prod builds + return False + if is_production_build_ios(): + # iOS Prod builds + return False + + return True + +def _get_enable_lightweight_dispatch(): + return read_bool("pt", "enable_lightweight_dispatch", False) + +def _get_enable_record_kernel_dtype(): + return read_bool("pt", "enable_record_kernel_dtype", False) + +def get_enable_mobile_dispatch_keys_trimming(): + return read_bool("pt", "enable_mobile_dispatch_keys_trimming", False) + +def get_disable_per_op_profiling(): + return read_bool("pt", "disable_per_op_profiling", True) + +def get_strip_error_messages(): + if IS_OSS: + return True # always strip in OSS CI to expose potential issues + return read_bool("pt", "strip_error_messages", not _is_build_mode_dev()) + def get_enable_eager_symbolication(): return read_bool("pt", "enable_eager_symbolication", default = False, required = False) +def get_static_dispatch_backend(): + static_dispatch_backend = native.read_config("pt", "static_dispatch_backend", None) + if static_dispatch_backend == None: + return [] + return static_dispatch_backend.split(";") + # @lint-ignore BUCKRESTRICTEDSYNTAX IS_OSS = read_config("pt", "is_oss", "0") == "1" # True for OSS BUCK build, and False for internal BUCK build @@ -66,10 +128,12 @@ THIRD_PARTY_LIBS = { "fmt": ["//third-party/fmt:fmt", "//third_party:fmt"], "glog": ["//third-party/glog:glog", "//third_party:glog"], "kineto": ["//xplat/kineto/libkineto:libkineto", "//third_party:libkineto"], + "omp": ["//xplat/third-party/linker_lib:omp", "//third_party:no-op"], "psimd": ["//third-party/psimd:psimd", "//third_party:psimd"], "pthreadpool": ["//third-party/pthreadpool:pthreadpool", "//third_party:pthreadpool"], "pthreadpool_header": ["//third-party/pthreadpool:pthreadpool_header", "//third_party:pthreadpool_header"], "pyyaml": ["//third-party/pyyaml:pyyaml", "//third_party:pyyaml"], + "rt": ["//xplat/third-party/linker_lib:rt", "//third_party:rt"], "ruy": ["//third-party/ruy:ruy_xplat_lib", "//third_party:ruy_lib"], "typing-extensions": ["//third-party/typing-extensions:typing-extensions", "//third_party:typing-extensions"], } @@ -100,11 +164,611 @@ _PT_COMPILER_FLAGS = [ "-Wno-missing-prototypes", ] +ATEN_COMPILER_FLAGS = [ + "-fexceptions", + "-frtti", + "-fPIC", + "-Os", + "-Wno-absolute-value", + "-Wno-deprecated-declarations", + "-Wno-macro-redefined", + "-Wno-tautological-constant-out-of-range-compare", + "-Wno-unknown-pragmas", + "-Wno-unknown-warning-option", + "-Wno-unused-function", + "-Wno-unused-variable", + "-Wno-pass-failed", + "-Wno-shadow", +] + +def get_aten_compiler_flags(): + return ATEN_COMPILER_FLAGS + +_COMMON_PREPROCESSOR_FLAGS = [ + "-DC10_MOBILE", + "-DNO_EXPORT", +] + ( + ["-DC10_MOBILE_TRIM_DISPATCH_KEYS"] if get_enable_mobile_dispatch_keys_trimming() else [] +) + ( + ["-DSTRIP_ERROR_MESSAGES"] if get_strip_error_messages() else [] +) + +def get_aten_preprocessor_flags(): + # read_config is not allowed outside of function in Starlark + ATEN_PREPROCESSOR_FLAGS = _COMMON_PREPROCESSOR_FLAGS + [ + "-DCPU_CAPABILITY_DEFAULT", + "-DCPU_CAPABILITY=DEFAULT", + "-DCAFFE2_USE_LITE_PROTO", + "-DATEN_CUDNN_ENABLED_FBXPLAT=0", + "-DATEN_MKLDNN_ENABLED_FBXPLAT=0", + "-DATEN_NNPACK_ENABLED_FBXPLAT=0", + "-DATEN_MKL_ENABLED_FBXPLAT=0", + "-DATEN_MKL_SEQUENTIAL_FBXPLAT=0", + "-DUSE_PYTORCH_METAL", + "-DUSE_PYTORCH_QNNPACK", + "-DUSE_XNNPACK", + "-DPYTORCH_QNNPACK_RUNTIME_QUANTIZATION", + "-DAT_PARALLEL_OPENMP_FBXPLAT=0", + "-DAT_PARALLEL_NATIVE_FBXPLAT=1", + "-DAT_PARALLEL_NATIVE_TBB_FBXPLAT=0", + "-DUSE_LAPACK_FBXPLAT=0", + "-DAT_BLAS_F2C_FBXPLAT=0", + "-DAT_BLAS_USE_CBLAS_DOT_FBXPLAT=0", + "-DUSE_RUY_QMATMUL", + ] + if get_disable_per_op_profiling(): + ATEN_PREPROCESSOR_FLAGS.append("-DPYTORCH_DISABLE_PER_OP_PROFILING") + if _get_enable_record_kernel_dtype(): + ATEN_PREPROCESSOR_FLAGS.append("-DENABLE_RECORD_KERNEL_FUNCTION_DTYPE") + return ATEN_PREPROCESSOR_FLAGS + +def get_pt_preprocessor_flags(): + # read_config is not allowed outside of function in Starlark + PT_PREPROCESSOR_FLAGS = _COMMON_PREPROCESSOR_FLAGS + [ + "-D_THP_CORE", + "-DUSE_SCALARS", + "-DNO_CUDNN_DESTROY_HANDLE", + "-DBUILD_CAFFE2", + ] + + if _is_build_mode_dev(): + PT_PREPROCESSOR_FLAGS.append("-DENABLE_PYTORCH_NON_PRODUCTION_BUILDS") + return PT_PREPROCESSOR_FLAGS + +USED_PT_BACKENDS = [ + "CPU", + "QuantizedCPU", + "SparseCPU", # brings ~20 kb size regression +] + +# This needs to be kept in sync with https://github.com/pytorch/pytorch/blob/release/1.9/torchgen/gen.py#L892 +PT_BACKEND_HEADERS = [ + "CPU", + "CUDA", + "CompositeExplicitAutograd", + "CompositeExplicitAutogradNonFunctional", + "CompositeImplicitAutograd", + "Meta", +] + +def get_aten_static_dispatch_backend_headers(existing_headers): + static_backends = get_static_dispatch_backend() + for backend in static_backends: + if backend != "CPU": + existing_headers["{}Functions.h".format(backend)] = ":gen_aten[{}Functions.h]".format(backend) + existing_headers["{}Functions_inl.h".format(backend)] = ":gen_aten[{}Functions_inl.h]".format(backend) + return existing_headers + +def get_aten_codegen_extra_params(backends): + extra_params = { + "force_schema_registration": True, + } + static_backends = get_static_dispatch_backend() + if static_backends: + extra_params["static_dispatch_backend"] = static_backends + extra_params["enabled_backends"] = static_backends + else: + extra_params["enabled_backends"] = backends + return extra_params + +def get_jit_codegen_params(): + return [] + +def get_unboxing_generated_files(): + srcs = [] + if _get_enable_lightweight_dispatch(): + srcs = [ + "UnboxingFunctions.h", + "UnboxingFunctions_0.cpp", + "UnboxingFunctions_1.cpp", + "UnboxingFunctions_2.cpp", + "UnboxingFunctions_3.cpp", + "UnboxingFunctions_4.cpp", + "RegisterCodegenUnboxedKernels_0.cpp", + "RegisterCodegenUnboxedKernels_1.cpp", + "RegisterCodegenUnboxedKernels_2.cpp", + "RegisterCodegenUnboxedKernels_3.cpp", + "RegisterCodegenUnboxedKernels_4.cpp", + "RegisterCodegenUnboxedKernels_5.cpp", + "RegisterCodegenUnboxedKernels_6.cpp", + "RegisterCodegenUnboxedKernels_7.cpp", + "RegisterCodegenUnboxedKernels_8.cpp", + "RegisterCodegenUnboxedKernels_9.cpp", + ] + res = {} + for file_name in srcs: + res[file_name] = [file_name] + return res + +def get_aten_generated_files(enabled_backends): + # NB: RegisterMeta counts as an optionally enabled backend, + # and is intentionally omitted from here + src_files = [ + "RegisterBackendSelect.cpp", + "RegisterCompositeImplicitAutograd.cpp", + "RegisterCompositeExplicitAutograd.cpp", + "RegisterCompositeExplicitAutogradNonFunctional.cpp", + "CompositeViewCopyKernels.cpp", + "RegisterSchema.cpp", + "Declarations.yaml", + "Functions.cpp", + "Functions.h", + "RedispatchFunctions.h", + "NativeFunctions.h", + "NativeMetaFunctions.h", + "MethodOperators.h", + "FunctionalInverses.h", + "Operators.h", + "Operators_0.cpp", + "Operators_1.cpp", + "Operators_2.cpp", + "Operators_3.cpp", + "Operators_4.cpp", + "CompositeImplicitAutogradFunctions.h", + "CompositeImplicitAutogradFunctions_inl.h", + "CompositeExplicitAutogradFunctions.h", + "CompositeExplicitAutogradFunctions_inl.h", + "CompositeExplicitAutogradNonFunctionalFunctions.h", + "CompositeExplicitAutogradNonFunctionalFunctions_inl.h", + "core/ATenOpList.cpp", + "core/TensorBody.h", + "core/TensorMethods.cpp", + "core/aten_interned_strings.h", + "core/enum_tag.h", + ] + get_aten_derived_type_srcs(enabled_backends) + + # This is tiresome. A better strategy would be to unconditionally + # generate these files, and then only actually COMPILE them depended + # on the generated set. C'est la vie... + if "CPU" in enabled_backends: + src_files.extend(aten_ufunc_generated_cpu_sources()) + src_files.extend(aten_ufunc_generated_cpu_kernel_sources()) + if "CUDA" in enabled_backends: + # Cannot unconditionally include this, because in the Edge selective + # build CUDA is not enabled and thus the ufunc codegen for CUDA gets + # skipped + src_files.extend(aten_ufunc_generated_cuda_sources()) + + res = {} + for file_name in src_files: + res[file_name] = [file_name] + return res + +def get_aten_derived_type_src_rules(aten_rule_name, enabled_backends): + return [ + ":{}[{}]".format(aten_rule_name, "Register" + backend + ".cpp") + for backend in enabled_backends + ] + +def get_aten_selective_cpp_rules(aten_rule_name, enabled_backends): + return [ + ":{}[{}]".format(aten_rule_name, f) + for f in ["RegisterCompositeImplicitAutograd.cpp", "RegisterCompositeExplicitAutograd.cpp", "RegisterCompositeExplicitAutogradNonFunctional.cpp", "RegisterSchema.cpp", "RegisterBackendSelect.cpp", "CompositeViewCopyKernels.cpp"] + ] + get_aten_derived_type_src_rules(aten_rule_name, enabled_backends) + +def get_aten_derived_type_srcs(enabled_backends): + return [ + "Register" + derived_type + ".cpp" + for derived_type in enabled_backends + ] + [ + derived_type + "Functions.h" + for derived_type in enabled_backends + if derived_type in PT_BACKEND_HEADERS or derived_type in get_static_dispatch_backend() + ] + [ + derived_type + "Functions_inl.h" + for derived_type in enabled_backends + if derived_type in PT_BACKEND_HEADERS or derived_type in get_static_dispatch_backend() + ] + +def gen_aten_files( + name, + extra_flags = {}, + visibility = [], + compatible_with = [], + apple_sdks = None): + extra_params = [] + force_schema_registration = extra_flags.get("force_schema_registration", False) + op_registration_allowlist = extra_flags.get("op_registration_allowlist", None) + op_selection_yaml_path = extra_flags.get("op_selection_yaml_path", None) + enabled_backends = extra_flags.get("enabled_backends", None) + static_dispatch_backend = extra_flags.get("static_dispatch_backend", None) + + if force_schema_registration: + extra_params.append("--force_schema_registration") + if op_registration_allowlist != None and is_string(op_registration_allowlist): + extra_params.append("--op_registration_whitelist") + extra_params.append(op_registration_allowlist) + if op_selection_yaml_path != None and is_string(op_selection_yaml_path): + extra_params.append("--op_selection_yaml_path") + extra_params.append(op_selection_yaml_path) + if enabled_backends != None and is_list(enabled_backends): + extra_params.append("--backend_whitelist") + extra_params.extend(enabled_backends) + if _get_enable_lightweight_dispatch(): + extra_params.append("--skip_dispatcher_op_registration") + if static_dispatch_backend: + extra_params.append("--static_dispatch_backend") + extra_params.extend(static_dispatch_backend) + backends = static_dispatch_backend + else: + backends = enabled_backends + fb_xplat_genrule( + name = name, + default_outs = ["."], + outs = get_aten_generated_files(backends), + cmd = "$(exe {}:gen_aten_bin) ".format(ROOT) + " ".join([ + "--source-path $(location {}:aten_src_path)/aten/src/ATen".format(ROOT), + "--install_dir $OUT", + ] + extra_params), + visibility = visibility, + compatible_with = compatible_with, + apple_sdks = apple_sdks, + ) + +def gen_aten_unboxing_files( + genrule_name, + extra_flags = {}): + extra_params = [] + op_selection_yaml_path = extra_flags.get("op_selection_yaml_path", None) + op_registration_allowlist = extra_flags.get("op_registration_allowlist", None) + if op_selection_yaml_path != None and is_string(op_selection_yaml_path): + extra_params.append("--op_selection_yaml_path") + extra_params.append(op_selection_yaml_path) + if op_registration_allowlist != None and is_string(op_registration_allowlist): + extra_params.append("--op_registration_allowlist") + extra_params.append(op_registration_allowlist) + + fb_xplat_genrule( + name = genrule_name, + default_outs = ["."], + outs = get_unboxing_generated_files(), + cmd = "$(exe {}:gen_unboxing_bin) ".format(ROOT) + " ".join([ + "--source-path $(location {}:aten_src_path)/aten/src/ATen".format(ROOT), + "--install_dir $OUT", + ] + extra_params), + visibility = ["PUBLIC"], + ) + +def copy_template_registration_files(name, apple_sdks = None): + cmd = [] + cmd_exe = [] + + template_source_dict = get_template_source_dict() + + # Ideally, we would run one copy command for a single source directory along + # with all its child directories, but it's somewhat hard to know if a directory + # is a child of another just bu looking at the metadata (directory relative + # path) that we currently have since 1 directory could look like a parent of + # another and yet come from a different filegroup() rule. + # + for (path_prefix, file_paths) in template_source_dict.items(): + cmd.append("mkdir -p $OUT/{}".format(path_prefix)) + cmd_exe.append("md $OUT/{}".format(path_prefix)) + + # Adding *.cpp is a workaround to prevent cp from thrown an error when it + # encounters a directory (since -r was not specified). If files with an + # extension other than .cpp need to be copied, then the command below + # will not work and will need to be updated. + # + cmd.append("cp -f $(location {0}:templated_selective_build_srcs)/{1}/*.cpp $OUT/{1}/".format(ROOT, path_prefix)) + cmd_exe.append("robocopy /E $(location {0}:templated_selective_build_srcs)/{1} $OUT/{1}".format(ROOT, path_prefix)) + + if NOT_OSS: + for file_path in TEMPLATE_MASKRCNN_SOURCE_LIST: + maskrcnn_file = "$(location //xplat/caffe2/fb/custom_ops/maskrcnn:templated_selective_build_srcs)/" + file_path + cmd.append("cp -f " + maskrcnn_file + " $OUT") + cmd_exe.append("copy " + maskrcnn_file + " $OUT") + + cmd.append("mkdir -p $OUT/aten/src/ATen") + cmd_exe.append("md $OUT/aten/src/ATen") + + # NB: CUDA is skipped here because this is selective build and CUDA is not + # supported for selective build + for ufunc_file in aten_ufunc_generated_all_cpu_sources("$(location " + ROOT + ":gen_aten[{}])"): + cmd.append("cp -f " + ufunc_file + " $OUT/aten/src/ATen") + cmd_exe.append("copy " + ufunc_file + " $OUT/aten/src/ATen") + + if NOT_OSS: + pvd_batch_box_cox_file = "$(location //xplat/caffe2/fb/custom_ops/batch_box_cox:templated_selective_build_srcs)/register_batch_box_cox_ops.cpp" + cmd.append("cp -f " + pvd_batch_box_cox_file + " $OUT") + cmd_exe.append("copy " + pvd_batch_box_cox_file + " $OUT") + + fb_xplat_genrule( + name = name, + cmd = " && ".join(cmd), + cmd_exe = "@powershell -Command " + ("; ".join(cmd_exe)), + outs = get_template_registration_files_outs(IS_OSS), + default_outs = ["."], + apple_sdks = apple_sdks, + ) + +def pt_operator_query_codegen( + name, + deps = [], + train = False, + enforce_traced_op_list = False, + pt_allow_forced_schema_registration = True, + compatible_with = [], + apple_sdks = None): + oplist_dir_name = name + "_pt_oplist" + + # @lint-ignore BUCKLINT + fb_native.genrule( + name = oplist_dir_name, + cmd = ("$(exe {}:gen_oplist) ".format(ROOT) + + "--model_file_list_path $(@query_outputs 'attrfilter(labels, pt_operator_library, deps(set({deps})))') " + + ("" if enforce_traced_op_list else "--allow_include_all_overloads ") + + "--output_dir $OUT ").format(deps = " ".join(["\"{}\"".format(d) for d in deps])), + outs = get_gen_oplist_outs(), + default_outs = ["."], + compatible_with = compatible_with, + ) + + # Aten files + aten_genrule = name + "_aten" + extra_flags = { + "enabled_backends": USED_PT_BACKENDS, + "op_selection_yaml_path": "$(location :{}[selected_operators.yaml])".format(oplist_dir_name), + } + + if train and pt_allow_forced_schema_registration: + extra_flags["force_schema_registration"] = True + + unboxing_genrule = name + "_unboxing" + if _get_enable_lightweight_dispatch(): + gen_aten_unboxing_files( + unboxing_genrule, + extra_flags = extra_flags, + ) + + static_dispatch_backend = get_static_dispatch_backend() + if static_dispatch_backend: + extra_flags["static_dispatch_backend"] = static_dispatch_backend + + gen_aten_files( + aten_genrule, + extra_flags = extra_flags, + compatible_with = compatible_with, + apple_sdks = apple_sdks, + ) + + # unboxing_wrappers files + extra_params = [ + "--operators_yaml_path", + "$(location :" + oplist_dir_name + "[selected_operators.yaml])", + ] + unboxing_and_autograd_genrule = name + "_unboxing_and_autograd" + gen_aten_libtorch_files( + unboxing_and_autograd_genrule, + extra_params, + compatible_with, + apple_sdks = apple_sdks, + ) + + # Template runtime files (prim ops, etc) + template_registration_genrule = name + "_template_registration" + copy_template_registration_files(template_registration_genrule, apple_sdks = apple_sdks) + + # Files needed for metal + if NOT_OSS: + metal_genrule = name + "_metal" + copy_metal(metal_genrule, apple_sdks = apple_sdks) + + srcs = get_aten_selective_cpp_rules( + aten_genrule, + static_dispatch_backend if static_dispatch_backend else USED_PT_BACKENDS, + ) + get_template_registration_file_rules(template_registration_genrule, IS_OSS) + ([ + ":{}[autograd/generated/VariableType_0.cpp]".format(unboxing_and_autograd_genrule), + ":{}[autograd/generated/VariableType_1.cpp]".format(unboxing_and_autograd_genrule), + ":{}[autograd/generated/VariableType_2.cpp]".format(unboxing_and_autograd_genrule), + ":{}[autograd/generated/VariableType_3.cpp]".format(unboxing_and_autograd_genrule), + ":{}[autograd/generated/VariableType_4.cpp]".format(unboxing_and_autograd_genrule), + ":{}[autograd/generated/ADInplaceOrViewType_0.cpp]".format(unboxing_and_autograd_genrule), + ":{}[autograd/generated/ADInplaceOrViewType_1.cpp]".format(unboxing_and_autograd_genrule), + ] if train else []) + ([ + ":{}[SupportedMobileModelsRegistration.cpp]".format(oplist_dir_name), + ] if NOT_OSS else []) + + headers = { + "selected_mobile_ops.h": ":{}[selected_mobile_ops.h]".format(oplist_dir_name), + } + + if _get_enable_lightweight_dispatch(): + srcs.extend([ + ":{}[UnboxingFunctions_0.cpp]".format(unboxing_genrule), + ":{}[UnboxingFunctions_1.cpp]".format(unboxing_genrule), + ":{}[UnboxingFunctions_2.cpp]".format(unboxing_genrule), + ":{}[UnboxingFunctions_3.cpp]".format(unboxing_genrule), + ":{}[UnboxingFunctions_4.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_0.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_1.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_2.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_3.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_4.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_5.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_6.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_7.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_8.cpp]".format(unboxing_genrule), + ":{}[RegisterCodegenUnboxedKernels_9.cpp]".format(unboxing_genrule), + ]) + headers["UnboxingFunctions.h"] = ":{}[UnboxingFunctions.h]".format(unboxing_genrule) + return {"headers": headers, "srcs": srcs} + +def gen_aten_libtorch_files(name, extra_params = [], compatible_with = [], apple_sdks = None): + fb_xplat_genrule( + name = name, + outs = get_generate_code_bin_outs(), + default_outs = ["."], + bash = "mkdir -p tools && " + + "$(exe {}tools/setup_helpers:generate_code_bin) ".format(ROOT_PATH) + " ".join( + # Mobile build only needs libtorch - skip python bindings for now, except + # for ovrsource, which needs Python bindings. + (["--subset libtorch"] if not is_arvr_mode() else []) + [ + "--native-functions-path $(location {}:aten_src_path)/aten/src/ATen/native/native_functions.yaml".format(ROOT), + "--tags-path $(location {}:aten_src_path)/aten/src/ATen/native/tags.yaml".format(ROOT), + "--install_dir $OUT", + ] + extra_params, + ), + cmd_exe = "@powershell -Command New-Item -Path tools -ItemType Directory -Force; " + + "$(exe {}tools/setup_helpers:generate_code_bin) ".format(ROOT_PATH) + " ".join( + # Mobile build only needs libtorch - skip python bindings for now, except + # for ovrsource, which needs Python bindings. + (["--subset libtorch"] if not is_arvr_mode() else []) + [ + "--native-functions-path $(location {}:aten_src_path)/aten/src/ATen/native/native_functions.yaml".format(ROOT), + "--tags-path $(location {}:aten_src_path)/aten/src/ATen/native/tags.yaml".format(ROOT), + "--install_dir $OUT", + ] + extra_params, + ), + compatible_with = compatible_with, + apple_sdks = apple_sdks, + ) + +def copy_metal(name, apple_sdks = None): + cmd = [] + cmd_exe = [] + metal_source_dict = get_metal_source_dict() + + # Copy all source files over to bring them into the per app build + for path_prefix in sorted(metal_source_dict.keys()): + cmd.append("mkdir -p $OUT/{}".format(path_prefix)) + cmd_exe.append("mkdir -Force $OUT/{0}".format(path_prefix)) + + # Not every directory has a mm or cpp file so '2>/dev/null || :' are tricks to suppress the error messages and codes. + cmd.append("cp -f {0}/{1}/*.mm $OUT/{1}/ 2>/dev/null || :".format("$(location //xplat/caffe2:metal_build_srcs)", path_prefix)) + cmd.append("cp -f {0}/{1}/*.cpp $OUT/{1}/ 2>/dev/null || :".format("$(location //xplat/caffe2:metal_build_srcs)", path_prefix)) + + # Robocopy has a default success code of 1 which buck treats as failure so the echo masks that problem + 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)) + + # Metal custom ops currently have to be brought into selective build because they directly reference metal ops instead of + # going through the dispatcher. There is some weird issues with the genrule and these files locations on windows though, so + # for now we simply skip building them for windows where they very likely arent needed anyway. + # Metal MaskRCNN custom op + for full_path in METAL_MASKRCNN_SOURCE_LIST: + path_prefix = paths.dirname(full_path) + cmd.append("mkdir -p $OUT/{}".format(path_prefix)) + cmd.append("cp -f {0}/{1}/*.mm $OUT/{1}/ 2>/dev/null || :".format("$(location //xplat/caffe2/fb/metal:metal_maskrcnn_sources)", path_prefix)) + + # Unet Metal Prepack Custom op + unet_metal_prepack_file = "$(location //xplat/caffe2/fb/custom_ops/unet_metal_prepack:unet_metal_prepack_sources)" + cmd.append("cp -f " + unet_metal_prepack_file + "/unet_metal_prepack.cpp" + " $OUT") + cmd.append("cp -f " + unet_metal_prepack_file + "/unet_metal_prepack.mm" + " $OUT") + + fb_xplat_genrule( + name = name, + cmd = " && ".join(cmd), + cmd_exe = "@powershell -Command " + ("; ".join(cmd_exe)), + # due to an obscure bug certain custom ops werent being copied correctly on windows. ARVR also sometimes builds android targets on windows, + # so we just exclude those targets from being copied for those platforms (They end up uncompiled anyway). + outs = select({ + "DEFAULT": get_metal_registration_files_outs(), + "ovr_config//os:android": get_metal_registration_files_outs_windows(), + "ovr_config//os:windows": get_metal_registration_files_outs_windows(), + }), + default_outs = ["."], + apple_sdks = apple_sdks, + ) + +def get_pt_operator_registry_dict( + name, + deps = [], + train = False, + labels = [], + env = [], + template_select = True, + enforce_traced_op_list = False, + pt_allow_forced_schema_registration = True, + enable_flatbuffer = False, + **kwargs): + code_gen_files = pt_operator_query_codegen( + name, + deps = deps, + train = train, + enforce_traced_op_list = enforce_traced_op_list, + pt_allow_forced_schema_registration = pt_allow_forced_schema_registration, + compatible_with = kwargs.get("compatible_with", []), + apple_sdks = kwargs.get("apple_sdks"), + ) + + return dict( + srcs = code_gen_files["srcs"], + linker_flags = [ + "-Wl,--no-as-needed", + ], + # @lint-ignore BUCKLINT link_whole + link_whole = True, + soname = "libtorch-code-gen.$(ext)", + header_namespace = "ATen", + compiler_flags = get_aten_compiler_flags(), + exported_headers = code_gen_files["headers"], + exported_preprocessor_flags = get_aten_preprocessor_flags() + (["-DTEMPLATE_SELECTIVE_BUILD"] if template_select else []), + headers = kwargs.pop("headers", []), + labels = kwargs.pop("labels", []) + [ + # This library has multiple sources with the same file name + # and does not work with Buck filegroup used in bad practices. + # Opt out of the bad practices check with the below label. + "bad_practices_ignore_override", + "pt_operator_registry", + ], + deps = [ + # need absolute path here + ROOT + ":torch_mobile_core", + ROOT + ":aten_cpu", + ROOT + ":aten_metal_prepack_header", + third_party("glog"), + C10, + ] + ([ROOT + ":torch_mobile_train"] if train else []) + + ([ROOT + ":torch_flatbuffer_all"] if enable_flatbuffer else []), + **kwargs + ) + # these targets are shared by internal and OSS BUCK def define_buck_targets( - pt_xplat_cxx_library, + aten_default_args = dict(), + pt_xplat_cxx_library = fb_xplat_cxx_library, c2_fbandroid_xplat_compiler_flags = [], labels = []): + # @lint-ignore BUCKLINT + fb_native.filegroup( + name = "metal_build_srcs", + # @lint-ignore BUCKRESTRICTEDSYNTAX + srcs = glob(METAL_SOURCE_LIST), + visibility = [ + "PUBLIC", + ], + ) + + # @lint-ignore BUCKLINT + fb_native.filegroup( + name = "templated_selective_build_srcs", + # NB: no glob here, there are generated targets in this list! + # @lint-ignore BUCKRESTRICTEDSYNTAX + srcs = glob(TEMPLATE_SOURCE_LIST) + aten_ufunc_generated_all_cpu_sources(":gen_aten[{}]"), + visibility = [ + "PUBLIC", + ], + ) + fb_xplat_cxx_library( name = "th_header", header_namespace = "", @@ -225,6 +889,16 @@ def define_buck_targets( ]), ) + fb_xplat_cxx_library( + name = "aten_metal_prepack_header", + header_namespace = "", + exported_headers = subdir_glob([ + ("aten/src", "ATen/native/metal/MetalPrepackOpContext.h"), + ]), + labels = labels, + visibility = ["PUBLIC"], + ) + fb_xplat_cxx_library( name = "torch_mobile_headers", header_namespace = "", @@ -453,28 +1127,6 @@ def define_buck_targets( ], ) - fb_python_binary( - name = "gen_aten_vulkan_spv_bin", - main_module = "aten.src.ATen.gen_vulkan_spv", - visibility = [ - "PUBLIC", - ], - deps = [ - ":gen_aten_vulkan_spv_lib", - ], - ) - - fb_python_library( - name = "gen_aten_vulkan_spv_lib", - srcs = [ - "aten/src/ATen/gen_vulkan_spv.py", - ], - base_module = "", - deps = [ - ROOT_PATH + "torchgen:torchgen", - ], - ) - fb_python_binary( name = "gen_oplist", main_module = "gen_oplist", @@ -493,6 +1145,45 @@ def define_buck_targets( ], ) + gen_aten_files( + name = "gen_aten", + extra_flags = get_aten_codegen_extra_params(USED_PT_BACKENDS), + visibility = ["PUBLIC"], + ) + + gen_aten_libtorch_files(name = "gen_aten_libtorch") + + gen_aten_libtorch_files( + name = "gen_aten_libtorch_lite", + extra_params = get_jit_codegen_params(), + ) + + fb_xplat_cxx_library( + name = "generated_aten_headers_cpu", + header_namespace = "ATen", + exported_headers = get_aten_static_dispatch_backend_headers({ + "CPUFunctions.h": ":gen_aten[CPUFunctions.h]", + "CPUFunctions_inl.h": ":gen_aten[CPUFunctions_inl.h]", + "CompositeExplicitAutogradFunctions.h": ":gen_aten[CompositeExplicitAutogradFunctions.h]", + "CompositeExplicitAutogradFunctions_inl.h": ":gen_aten[CompositeExplicitAutogradFunctions_inl.h]", + "CompositeExplicitAutogradNonFunctionalFunctions.h": ":gen_aten[CompositeExplicitAutogradNonFunctionalFunctions.h]", + "CompositeExplicitAutogradNonFunctionalFunctions_inl.h": ":gen_aten[CompositeExplicitAutogradNonFunctionalFunctions_inl.h]", + "CompositeImplicitAutogradFunctions.h": ":gen_aten[CompositeImplicitAutogradFunctions.h]", + "CompositeImplicitAutogradFunctions_inl.h": ":gen_aten[CompositeImplicitAutogradFunctions_inl.h]", + "FunctionalInverses.h": ":gen_aten[FunctionalInverses.h]", + "Functions.h": ":gen_aten[Functions.h]", + "MethodOperators.h": ":gen_aten[MethodOperators.h]", + "NativeFunctions.h": ":gen_aten[NativeFunctions.h]", + "NativeMetaFunctions.h": ":gen_aten[NativeMetaFunctions.h]", + "Operators.h": ":gen_aten[Operators.h]", + "RedispatchFunctions.h": ":gen_aten[RedispatchFunctions.h]", + "core/TensorBody.h": ":gen_aten[core/TensorBody.h]", + "core/aten_interned_strings.h": ":gen_aten[core/aten_interned_strings.h]", + "core/enum_tag.h": ":gen_aten[core/enum_tag.h]", + }), + labels = labels, + ) + fb_xplat_cxx_library( name = "torch_mobile_observer", srcs = [ @@ -521,6 +1212,8 @@ def define_buck_targets( pt_xplat_cxx_library( name = "torch_common", srcs = core_sources_common, + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), # @lint-ignore BUCKLINT link_whole link_whole = True, visibility = ["PUBLIC"], @@ -546,6 +1239,8 @@ def define_buck_targets( "torch/csrc/jit/serialization/import_read.h", "torch/csrc/jit/serialization/unpickler.h", ], + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), extra_flags = { "fbandroid_compiler_flags": ["-frtti"], }, @@ -581,6 +1276,8 @@ def define_buck_targets( header_namespace = "", exported_headers = [ ], + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), extra_flags = { "fbandroid_compiler_flags": ["-frtti"], }, @@ -614,6 +1311,8 @@ def define_buck_targets( # "torch/csrc/jit/serialization/pickler.cpp", # included in core_sources_common "torch/csrc/jit/serialization/unpickler.cpp", ], + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), header_namespace = "", # @lint-ignore BUCKLINT link_whole link_whole = True, @@ -639,9 +1338,8 @@ def define_buck_targets( "torch/csrc/jit/mobile/model_tracer/TracerRunner.cpp", ], header_namespace = "", - extra_flags = { - "exported_preprocessor_flags": ["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else [], - }, + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []), # @lint-ignore BUCKLINT link_whole link_whole = True, linker_flags = [ @@ -668,6 +1366,8 @@ def define_buck_targets( srcs = [ "torch/csrc/jit/mobile/import.cpp", ], + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), header_namespace = "", exported_headers = [ "torch/csrc/jit/mobile/import.h", @@ -702,9 +1402,8 @@ def define_buck_targets( srcs = [], header_namespace = "", exported_headers = [], - extra_flags = { - "exported_preprocessor_flags": (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []), - }, + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []), # torch_mobile_core brings in sources neccessary to read and run a module # link_whole is enabled so that all symbols linked # operators, registerations and other few symbols are need in runtime @@ -729,6 +1428,8 @@ def define_buck_targets( pt_xplat_cxx_library( name = "torch_mobile_core_pickle_and_flatbuffer", + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), visibility = ["PUBLIC"], exported_deps = [ ":torch_flatbuffer_all", @@ -743,6 +1444,8 @@ def define_buck_targets( "torch/csrc/jit/serialization/export_bytecode.cpp", "torch/csrc/jit/serialization/export_module.cpp", ], + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), visibility = [ "//xplat/caffe2/android/...", "//xplat/caffe2/fb/...", @@ -755,11 +1458,11 @@ def define_buck_targets( ":torch_headers", ":torch_mobile_deserialize", third_party("glog"), + third_party("rt"), C10, ] + ([] if IS_OSS else [ "//xplat/caffe2/fb/custom_ops/batch_box_cox:batch_box_cox", "//xplat/caffe2/fb/custom_ops/maskrcnn:maskrcnn", - "//xplat/third-party/linker_lib:rt", ]), exported_deps = [ ":torch_common", @@ -779,6 +1482,8 @@ def define_buck_targets( "torch/csrc/api/src/serialize/output-archive.cpp", "torch/csrc/jit/api/module_save.cpp", ], + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), visibility = ["PUBLIC"], deps = [ ":aten_cpu", @@ -803,9 +1508,8 @@ def define_buck_targets( "torch/csrc/jit/mobile/train/sequential.cpp", ":gen_aten_libtorch[autograd/generated/Functions.cpp]", ], - extra_flags = { - "exported_preprocessor_flags": ["-DUSE_MOBILE_CLASSTYPE"], - }, + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DUSE_MOBILE_CLASSTYPE"], # torch_mobile_train brings in sources neccessary to read and run a mobile # and save and load mobile params along with autograd # link_whole is enabled so that all symbols linked @@ -828,6 +1532,8 @@ def define_buck_targets( "torch/csrc/jit/runtime/register_c10_ops.cpp", "torch/csrc/jit/runtime/register_prim_ops_fulljit.cpp", ], + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), # torch brings in all sources neccessary to read and run a mobile module/jit module # link_whole is enabled so that all symbols linked # operators, registerations and other few symbols are need in runtime @@ -853,9 +1559,8 @@ def define_buck_targets( srcs = [ "torch/csrc/jit/mobile/import_data.cpp", ], - extra_flags = { - "exported_preprocessor_flags": ["-DUSE_MOBILE_CLASSTYPE"], - }, + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DUSE_MOBILE_CLASSTYPE"], # torch_mobile_train_import_data brings in sources neccessary to read a mobile module # link_whole is enabled so that all symbols linked # operators other few symbols are need in runtime @@ -907,6 +1612,8 @@ def define_buck_targets( "torch/csrc/jit/serialization/export_bytecode.cpp", "torch/csrc/jit/serialization/export_module.cpp", ], + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags(), exported_headers = [ "torch/csrc/jit/serialization/export.h", "torch/csrc/jit/serialization/flatbuffer_serializer_jit.h", @@ -932,9 +1639,8 @@ def define_buck_targets( exported_headers = [ "torch/csrc/jit/mobile/model_tracer/MobileModelRunner.h", ], - extra_flags = { - "exported_preprocessor_flags": (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []), - }, + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags() + (["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else []), # torch_mobile_model_tracer brings in sources neccessary to read and run a jit module # and trace the ops # link_whole is enabled so that all symbols linked @@ -967,9 +1673,8 @@ def define_buck_targets( srcs = [], header_namespace = "", exported_headers = [], - extra_flags = { - "exported_preprocessor_flags": ["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else [], - }, + compiler_flags = get_pt_compiler_flags(), + exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else [], # @lint-ignore BUCKLINT link_whole link_whole = True, linker_flags = [ @@ -1012,16 +1717,14 @@ def define_buck_targets( pt_xplat_cxx_library( name = "torch_kineto_profiling", srcs = libtorch_profiler_sources, - extra_flags = { - "compiler_flags": ["-Wno-error"], - "exported_preprocessor_flags": [ - "-DUSE_KINETO", - "-DUSE_KINETO_UPDATED", - # Need this otherwise USE_KINETO is undefed - # for mobile - "-DEDGE_PROFILER_USE_KINETO", - ], - }, + compiler_flags = get_pt_compiler_flags() + ["-Wno-error"], + exported_preprocessor_flags = get_pt_preprocessor_flags() + [ + "-DUSE_KINETO", + "-DUSE_KINETO_UPDATED", + # Need this otherwise USE_KINETO is undefed + # for mobile + "-DEDGE_PROFILER_USE_KINETO", + ], # @lint-ignore BUCKLINT link_whole link_whole = True, linker_flags = [ @@ -1041,13 +1744,12 @@ def define_buck_targets( pt_xplat_cxx_library( name = "torch_edge_profiling", srcs = ["torch/csrc/jit/mobile/profiler_edge.cpp"], - extra_flags = { - "exported_preprocessor_flags": [ - "-DUSE_KINETO", - "-DUSE_KINETO_UPDATED", - "-DEDGE_PROFILER_USE_KINETO", - ], - }, + compiler_flags = get_pt_compiler_flags() + ["-Wno-error"], + exported_preprocessor_flags = get_pt_preprocessor_flags() + [ + "-DUSE_KINETO", + "-DUSE_KINETO_UPDATED", + "-DEDGE_PROFILER_USE_KINETO", + ], # @lint-ignore BUCKLINT link_whole link_whole = True, linker_flags = [ @@ -1119,6 +1821,14 @@ def define_buck_targets( exported_headers = [ "torch/csrc/jit/mobile/flatbuffer_loader.h", ], + compiler_flags = get_pt_compiler_flags() + ["-Wno-error"], + exported_preprocessor_flags = get_pt_preprocessor_flags() + [ + "-DUSE_KINETO", + "-DUSE_KINETO_UPDATED", + # Need this otherwise USE_KINETO is undefed + # for mobile + "-DEDGE_PROFILER_USE_KINETO", + ], extra_flags = { "fbandroid_compiler_flags": ["-frtti"], }, @@ -1186,9 +1896,8 @@ def define_buck_targets( ] if NOT_OSS else [], header_namespace = "", exported_headers = ["fb/supported_mobile_models/SupportedMobileModels.h"] if NOT_OSS else [], - extra_flags = { - "exported_preprocessor_flags": ["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else [], - }, + compiler_flags = get_pt_compiler_flags() + ["-Wno-error"], + exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DSYMBOLICATE_MOBILE_DEBUG_HANDLE"] if get_enable_eager_symbolication() else [], # @lint-ignore BUCKLINT link_whole link_whole = True, linker_flags = [ @@ -1226,3 +1935,285 @@ def define_buck_targets( C10, ], ) + + # aten_cpu and aten_native_cpu + for name, srcs in [ + ("aten_cpu", jit_core_sources + aten_cpu_source_list + [ + # Generated + ":gen_aten[Functions.cpp]", + ":gen_aten[Operators_0.cpp]", + ":gen_aten[Operators_1.cpp]", + ":gen_aten[Operators_2.cpp]", + ":gen_aten[Operators_3.cpp]", + ":gen_aten[Operators_4.cpp]", + ":gen_aten[core/ATenOpList.cpp]", + ":gen_aten[core/TensorMethods.cpp]", + # Needed by ATen/native/EmbeddingBag.cpp + "caffe2/perfkernels/embedding_lookup_idx.cc", + ]), + ("aten_native_cpu", aten_native_source_list), + ]: + fb_xplat_cxx_library( + name = name, + srcs = srcs, + header_namespace = "", + # @lint-ignore BUCKLINT + link_whole = True, + visibility = ["PUBLIC"], + deps = [ + third_party("omp"), + third_party("cpuinfo"), + third_party("glog"), + third_party("XNNPACK"), + ], + compiler_flags = get_aten_compiler_flags(), + exported_preprocessor_flags = get_aten_preprocessor_flags(), + exported_deps = [ + ":aten_header", + ":caffe2_headers", + ":common_core", + ":generated_aten_config_header", + ":generated_aten_headers_cpu", + ":jit_core_headers", + ":pthreadpool", + third_party("fmt"), + third_party("ruy"), + C10, + ROOT_PATH + "aten/src/ATen/native/quantized/cpu/qnnpack:pytorch_qnnpack", + ], + labels = labels, + **aten_default_args + ) + + fb_xplat_cxx_library( + name = "lean_runtime_with_flatbuffer", + srcs = [ + "aten/src/ATen/core/DeprecatedTypePropertiesRegistry.cpp", + "torch/csrc/jit/mobile/import.cpp", + "torch/csrc/jit/mobile/module.cpp", + "torch/csrc/jit/mobile/observer.cpp", + "torch/csrc/jit/serialization/import_read.cpp", + ], + header_namespace = "", + exported_headers = subdir_glob( + [ + ("", "torch/csrc/jit/ir/*.h"), + ("", "caffe2/serialize/*.h"), + ("", "caffe2/utils/*.h"), + ("", "caffe2/core/*.h"), + ("", "torch/csrc/*.h"), + ("", "torch/csrc/api/include/torch/*.h"), + ("", "torch/csrc/autograd/*.h"), + ("", "torch/csrc/autograd/*/*.h"), + ("", "torch/csrc/jit/api/*.h"), + ("", "torch/csrc/jit/backends/*.h"), + ("", "torch/csrc/jit/mobile/*.h"), + ("", "torch/csrc/jit/runtime/*.h"), + ("", "torch/csrc/jit/passes/*.h"), + ("", "torch/csrc/jit/python/*.h"), + ("", "torch/csrc/jit/frontend/*.h"), + ("", "torch/csrc/jit/serialization/*.h"), + ("", "torch/csrc/utils/*.h"), + ("", "aten/src/ATen/quantized/*.h"), + ("third_party/miniz-2.0.8", "*.h") if NOT_OSS else ("third-party/miniz-2.0.8", "*.h"), + ], + exclude = [ + "torch/csrc/jit/serialization/mobile_bytecode_generated.h", + ], + ), + compiler_flags = get_pt_compiler_flags() + select({ + "DEFAULT": [], + "ovr_config//os:xtensa-xos": [ + "-fdata-sections", + "-ffunction-sections", + ], + }), + exported_preprocessor_flags = get_pt_preprocessor_flags() + [ + "-DMIN_EDGE_RUNTIME", + ], + linker_flags = [ + "-Wl,--no-as-needed", + ] + select({ + "DEFAULT": [], + "ovr_config//os:macos": [ + "-dead_strip", + ], + "ovr_config//os:xtensa-xos": [ + "-Wl,--gc-sections", + ], + }), + visibility = ["PUBLIC"], + exported_deps = [ + ":lean_runtime_with_tensor", + ], + ) + + pt_xplat_cxx_library( + name = "lean_runtime_with_tensor", + srcs = [ + "aten/src/ATen/Context.cpp", + "aten/src/ATen/EmptyTensor.cpp", + "aten/src/ATen/Utils.cpp", + "aten/src/ATen/detail/CUDAHooksInterface.cpp", + ":gen_aten[Operators_0.cpp]", + ":gen_aten[Operators_1.cpp]", + ":gen_aten[Operators_2.cpp]", + ":gen_aten[Operators_3.cpp]", + ":gen_aten[Operators_4.cpp]", + ":gen_aten[core/TensorMethods.cpp]", + ], + header_namespace = "", + exported_headers = [ + "torch/csrc/jit/runtime/custom_operator.h", + ":gen_aten[core/TensorBody.h]", + ], + compiler_flags = get_pt_compiler_flags() + select({ + "DEFAULT": [], + "ovr_config//os:xtensa-xos": [ + "-fdata-sections", + "-ffunction-sections", + ], + }), + exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DMIN_EDGE_RUNTIME"] + select({ + "DEFAULT": [], + "ovr_config//os:xtensa-xos": [ + "-Dthread_local=", + ], + }), + # @lint-ignore BUCKLINT link_whole + link_whole = True, + linker_flags = [ + "-Wl,--no-as-needed", + ], + visibility = ["PUBLIC"], + exported_deps = [ + ":generated_aten_config_header", + ":lean_runtime_with_op", + ":aten_header", + C10, + ] + (["//xplat/caffe2/fb/embedded:experimental"] if NOT_OSS else []), + ) + + pt_xplat_cxx_library( + name = "lean_runtime_with_op", + srcs = [ + "aten/src/ATen/SequenceNumber.cpp", + "aten/src/ATen/core/boxing/KernelFunction.cpp", + "aten/src/ATen/core/custom_class.cpp", + "aten/src/ATen/core/dispatch/DispatchKeyExtractor.cpp", + "aten/src/ATen/core/dispatch/Dispatcher.cpp", + "aten/src/ATen/core/dispatch/ObservedOperators.cpp", + "aten/src/ATen/core/dispatch/OperatorEntry.cpp", + "aten/src/ATen/core/interned_strings.cpp", + "aten/src/ATen/core/library.cpp", + "aten/src/ATen/core/op_registration/infer_schema.cpp", + "aten/src/ATen/core/operator_name.cpp", + "aten/src/ATen/core/register_symbols.cpp", + "aten/src/ATen/core/tensor_type.cpp", + "aten/src/ATen/core/union_type.cpp", + "aten/src/ATen/record_function.cpp", + "torch/csrc/jit/frontend/edit_distance.cpp", + "torch/csrc/jit/frontend/error_report.cpp", + "torch/csrc/jit/frontend/function_schema_parser.cpp", + "torch/csrc/jit/frontend/lexer.cpp", + "torch/csrc/jit/frontend/schema_type_parser.cpp", + "torch/csrc/jit/frontend/source_range.cpp", + "torch/csrc/jit/frontend/strtod.cpp", + "torch/csrc/jit/mobile/parse_operators.cpp", + "torch/csrc/jit/mobile/prim_ops_registery.cpp", + "torch/csrc/jit/runtime/operator.cpp", + "torch/csrc/jit/runtime/slice_indices_adjust.cpp", + ], + header_namespace = "", + exported_headers = [ + "torch/csrc/jit/frontend/edit_distance.h", + "torch/csrc/jit/runtime/slice_indices_adjust.h", + ], + compiler_flags = get_pt_compiler_flags() + select({ + "DEFAULT": [], + "ovr_config//os:xtensa-xos": [ + "-fdata-sections", + "-ffunction-sections", + ], + }), + exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DMIN_EDGE_RUNTIME"] + select({ + "DEFAULT": [], + "ovr_config//os:xtensa-xos": [ + "-Dthread_local=", + ], + }), + # @lint-ignore BUCKLINT link_whole + link_whole = True, + linker_flags = [ + "-Wl,--no-as-needed", + ], + visibility = ["PUBLIC"], + exported_deps = [ + ":min_runtime_lib", + C10, + ], + ) + + pt_xplat_cxx_library( + name = "min_runtime_lib", + srcs = [ + "aten/src/ATen/ScalarOps.cpp", + "aten/src/ATen/core/Dict.cpp", + "aten/src/ATen/core/List.cpp", + "aten/src/ATen/core/class_type.cpp", + "aten/src/ATen/core/dynamic_type.cpp", + "aten/src/ATen/core/ivalue.cpp", + "aten/src/ATen/core/type.cpp", + "aten/src/ATen/core/type_factory.cpp", + "aten/src/ATen/native/prim_native_functions.cpp", + "torch/csrc/jit/mobile/function.cpp", + "torch/csrc/jit/mobile/interpreter.cpp", + "torch/csrc/jit/mobile/parse_bytecode.cpp", + "torch/csrc/jit/mobile/promoted_prim_ops.cpp", + "torch/csrc/jit/mobile/register_ops_common_utils.cpp", + "torch/csrc/jit/mobile/type_parser.cpp", + "torch/csrc/jit/runtime/instruction.cpp", + "torch/csrc/jit/runtime/jit_exception.cpp", + "torch/csrc/jit/runtime/vararg_functions.cpp", + ], + header_namespace = "", + exported_headers = [ + "caffe2/serialize/versions.h", + "torch/csrc/jit/backends/backend_exception.h", + "torch/csrc/jit/mobile/register_ops_common_utils.h", + "torch/csrc/jit/runtime/instruction.h", + "torch/csrc/jit/runtime/jit_exception.h", + "torch/csrc/jit/runtime/operator.h", + "torch/csrc/jit/runtime/operator_options.h", + "torch/csrc/jit/runtime/vararg_functions.h", + "torch/csrc/jit/serialization/import_export_constants.h", + "torch/csrc/jit/serialization/import_export_functions.h", + ], + compiler_flags = get_pt_compiler_flags() + select({ + "DEFAULT": [], + "ovr_config//os:xtensa-xos": [ + "-fexceptions", + "-fdata-sections", + "-ffunction-sections", + ], + }), + exported_preprocessor_flags = get_pt_preprocessor_flags() + ["-DMIN_EDGE_RUNTIME"] + select({ + "DEFAULT": [], + "ovr_config//os:xtensa-xos": [ + "-Dthread_local=", + ], + }), + # @lint-ignore BUCKLINT link_whole + link_whole = True, + linker_flags = [ + "-Wl,--no-as-needed", + ], + visibility = ["PUBLIC"], + exported_deps = [ + ":aten_header", + ":generated_aten_headers_cpu", + ":jit_core_headers", + ":torch_mobile_headers", + C10, + ], + ) diff --git a/pt_defs.oss.bzl b/pt_defs.oss.bzl index e1cedf0035bb..8710b1bd7c30 100644 --- a/pt_defs.oss.bzl +++ b/pt_defs.oss.bzl @@ -1,31 +1,10 @@ -load("@bazel_skylib//lib:paths.bzl", "paths") load("//tools/build_defs:fb_xplat_cxx_library.bzl", "fb_xplat_cxx_library") load("//tools/build_defs:fb_xplat_genrule.bzl", "fb_xplat_genrule") -load("//tools/build_defs:type_defs.bzl", "is_list", "is_string") -load(":build_variables.bzl", "aten_native_source_list") load( - ":ufunc_defs.bzl", - "aten_ufunc_generated_cpu_kernel_sources", - "aten_ufunc_generated_cpu_sources", - "aten_ufunc_generated_cuda_sources", + ":buckbuild.bzl", + "get_pt_operator_registry_dict", ) -USED_PT_BACKENDS = [ - "CPU", - "QuantizedCPU", - "SparseCPU", # brings ~20 kb size regression -] - -# This needs to be kept in sync with https://github.com/pytorch/pytorch/blob/release/1.9/torchgen/gen.py#L892 -PT_BACKEND_HEADERS = [ - "CPU", - "CUDA", - "CompositeExplicitAutograd", - "CompositeExplicitAutogradNonFunctional", - "CompositeImplicitAutograd", - "Meta", -] - PT_BASE_OPS = [ "aten::_coalesced_", "aten::_copy_from", @@ -104,375 +83,8 @@ PT_BASE_OPS = [ "aten::zeros_like", ] -def get_aten_compiler_flags(): - return ATEN_COMPILER_FLAGS - -def get_generate_code_bin_outs(): - return { - "autograd/generated/ADInplaceOrViewTypeEverything.cpp": ["autograd/generated/ADInplaceOrViewTypeEverything.cpp"], - "autograd/generated/ADInplaceOrViewType_0.cpp": ["autograd/generated/ADInplaceOrViewType_0.cpp"], - "autograd/generated/ADInplaceOrViewType_1.cpp": ["autograd/generated/ADInplaceOrViewType_1.cpp"], - "autograd/generated/Functions.cpp": ["autograd/generated/Functions.cpp"], - "autograd/generated/Functions.h": ["autograd/generated/Functions.h"], - "autograd/generated/TraceTypeEverything.cpp": ["autograd/generated/TraceTypeEverything.cpp"], - "autograd/generated/TraceType_0.cpp": ["autograd/generated/TraceType_0.cpp"], - "autograd/generated/TraceType_1.cpp": ["autograd/generated/TraceType_1.cpp"], - "autograd/generated/TraceType_2.cpp": ["autograd/generated/TraceType_2.cpp"], - "autograd/generated/TraceType_3.cpp": ["autograd/generated/TraceType_3.cpp"], - "autograd/generated/TraceType_4.cpp": ["autograd/generated/TraceType_4.cpp"], - "autograd/generated/VariableType.h": ["autograd/generated/VariableType.h"], - "autograd/generated/VariableTypeEverything.cpp": ["autograd/generated/VariableTypeEverything.cpp"], - "autograd/generated/VariableType_0.cpp": ["autograd/generated/VariableType_0.cpp"], - "autograd/generated/VariableType_1.cpp": ["autograd/generated/VariableType_1.cpp"], - "autograd/generated/VariableType_2.cpp": ["autograd/generated/VariableType_2.cpp"], - "autograd/generated/VariableType_3.cpp": ["autograd/generated/VariableType_3.cpp"], - "autograd/generated/VariableType_4.cpp": ["autograd/generated/VariableType_4.cpp"], - "autograd/generated/variable_factories.h": ["autograd/generated/variable_factories.h"], - } - -ATEN_COMPILER_FLAGS = [ - "-fexceptions", - "-frtti", - "-fPIC", - "-Os", - "-Wno-absolute-value", - "-Wno-deprecated-declarations", - "-Wno-macro-redefined", - "-Wno-tautological-constant-out-of-range-compare", - "-Wno-unknown-pragmas", - "-Wno-unknown-warning-option", - "-Wno-unused-function", - "-Wno-unused-variable", - "-Wno-pass-failed", - "-Wno-shadow", -] - -PT_COMPILER_FLAGS = [ - "-frtti", - "-Os", - "-Wno-unknown-pragmas", - "-Wno-write-strings", - "-Wno-unused-variable", - "-Wno-unused-function", - "-Wno-deprecated-declarations", - "-Wno-shadow", - "-Wno-global-constructors", - "-Wno-missing-prototypes", - "-std=gnu++17", # to accommodate Eigen -] - -def get_template_source_dict(): - ret = {} - for file_path in TEMPLATE_SOURCE_LIST: - path_prefix = paths.dirname(file_path) - if path_prefix not in ret: - ret[path_prefix] = [] - ret[path_prefix].append(file_path) - return ret - -def get_gen_oplist_outs(): - return { - #"SupportedMobileModelsRegistration.cpp": [ - # "SupportedMobileModelsRegistration.cpp", - #], - "selected_mobile_ops.h": [ - "selected_mobile_ops.h", - ], - "selected_operators.yaml": [ - "selected_operators.yaml", - ], - } - -def get_pt_compiler_flags(): - return PT_COMPILER_FLAGS - -def get_aten_preprocessor_flags(): - # read_config is not allowed outside of function in Starlark - ATEN_PREPROCESSOR_FLAGS = [ - "-DC10_MOBILE", - "-DCPU_CAPABILITY_DEFAULT", - "-DCPU_CAPABILITY=DEFAULT", - "-DCAFFE2_USE_LITE_PROTO", - "-DATEN_CUDNN_ENABLED_FBXPLAT=0", - "-DATEN_MKLDNN_ENABLED_FBXPLAT=0", - "-DATEN_NNPACK_ENABLED_FBXPLAT=0", - "-DATEN_MKL_ENABLED_FBXPLAT=0", - "-DATEN_MKL_SEQUENTIAL_FBXPLAT=0", - "-DUSE_PYTORCH_METAL", - "-DUSE_PYTORCH_QNNPACK", - "-DUSE_XNNPACK", - "-DNO_EXPORT", - "-DPYTORCH_QNNPACK_RUNTIME_QUANTIZATION", - "-DAT_PARALLEL_OPENMP_FBXPLAT=0", - "-DAT_PARALLEL_NATIVE_FBXPLAT=1", - "-DAT_PARALLEL_NATIVE_TBB_FBXPLAT=0", - "-DUSE_LAPACK_FBXPLAT=0", - "-DAT_BLAS_F2C_FBXPLAT=0", - "-DAT_BLAS_USE_CBLAS_DOT_FBXPLAT=0", - "-DUSE_RUY_QMATMUL", # need third_party:ruy - ] - - # if get_disable_per_op_profiling(): - ATEN_PREPROCESSOR_FLAGS.append("-DPYTORCH_DISABLE_PER_OP_PROFILING") - return ATEN_PREPROCESSOR_FLAGS - -TEMPLATE_SOURCE_LIST = [ - "torch/csrc/jit/runtime/register_prim_ops.cpp", - "torch/csrc/jit/runtime/register_special_ops.cpp", -] + aten_native_source_list - -# the basic xplat library for OSS build -def pt_xplat_cxx_library(extra_flags = {}, **kwargs): - fb_xplat_cxx_library( - compiler_flags = get_pt_compiler_flags() + extra_flags.get("compiler_flags", []), - exported_preprocessor_flags = get_pt_preprocessor_flags() + extra_flags.get("exported_preprocessor_flags", []), - **kwargs - ) - -def get_aten_default_args(): - return dict( - compiler_flags = get_aten_compiler_flags(), - exported_preprocessor_flags = get_aten_preprocessor_flags(), - ) - -# For selective build, we can lump the CPU and CPU kernel sources altogether -# because there is only ever one vectorization variant that is compiled -def aten_ufunc_generated_all_cpu_sources(gencode_pattern = "{}"): - return ( - aten_ufunc_generated_cpu_sources(gencode_pattern) + - aten_ufunc_generated_cpu_kernel_sources(gencode_pattern) - ) - -def get_template_registration_files_outs(): - outs = {} - - for file_path in TEMPLATE_SOURCE_LIST: - outs[file_path] = [file_path] - - for base_name in aten_ufunc_generated_all_cpu_sources(): - file_path = "aten/src/ATen/{}".format(base_name) - outs[file_path] = [file_path] - - return outs - -def get_pt_preprocessor_flags(): - # read_config is not allowed outside of function in Starlark - PT_PREPROCESSOR_FLAGS = [ - "-D_THP_CORE", - "-DC10_MOBILE", - "-DUSE_SCALARS", - "-DNO_CUDNN_DESTROY_HANDLE", - "-DNO_EXPORT", - "-DBUILD_CAFFE2", - ] - return PT_PREPROCESSOR_FLAGS - -def is_arvr_mode(): - return False - -def get_build_from_deps_query(): - build_from_query = native.read_config("pt", "build_from_deps_query", "1") - return bool(int(build_from_query)) - -def get_enable_lightweight_dispatch(): - enable_lightweight_dispatch = native.read_config("pt", "enable_lightweight_dispatch", "0") - return bool(int(enable_lightweight_dispatch)) - -def get_static_dispatch_backend(): - static_dispatch_backend = native.read_config("pt", "static_dispatch_backend", None) - if static_dispatch_backend == None: - return [] - return static_dispatch_backend.split(";") - -def get_aten_codegen_extra_params(backends): - if get_build_from_deps_query(): - extra_params = { - "force_schema_registration": True, - } - static_backends = get_static_dispatch_backend() - if static_backends: - extra_params["static_dispatch_backend"] = static_backends - extra_params["enabled_backends"] = static_backends - else: - extra_params["enabled_backends"] = backends - return extra_params - else: - return {} - -def gen_aten_files( - name, - extra_flags = {}, - visibility = [], - compatible_with = []): - extra_params = [] - force_schema_registration = extra_flags.get("force_schema_registration", False) - op_registration_allowlist = extra_flags.get("op_registration_allowlist", None) - op_selection_yaml_path = extra_flags.get("op_selection_yaml_path", None) - enabled_backends = extra_flags.get("enabled_backends", None) - static_dispatch_backend = extra_flags.get("static_dispatch_backend", None) - - if force_schema_registration: - extra_params.append("--force_schema_registration") - if op_registration_allowlist != None and is_string(op_registration_allowlist): - extra_params.append("--op_registration_whitelist") - extra_params.append(op_registration_allowlist) - if op_selection_yaml_path != None and is_string(op_selection_yaml_path): - extra_params.append("--op_selection_yaml_path") - extra_params.append(op_selection_yaml_path) - if enabled_backends != None and is_list(enabled_backends): - extra_params.append("--backend_whitelist") - extra_params.extend(enabled_backends) - if get_enable_lightweight_dispatch(): - extra_params.append("--skip_dispatcher_op_registration") - if static_dispatch_backend: - extra_params.append("--static_dispatch_backend") - extra_params.extend(static_dispatch_backend) - backends = static_dispatch_backend - else: - backends = enabled_backends - fb_xplat_genrule( - name = name, - default_outs = ["."], - outs = get_aten_generated_files(backends), - cmd = "$(exe //torchgen:gen) " + " ".join([ - "--source-path $(location //:aten_src_path)/aten/src/ATen", - "--install_dir $OUT", - ] + extra_params), - visibility = visibility, - compatible_with = compatible_with, - ) - -def get_aten_generated_files(enabled_backends): - # NB: RegisterMeta counts as an optionally enabled backend, - # and is intentionally omitted from here - src_files = [ - "RegisterBackendSelect.cpp", - "RegisterCompositeImplicitAutograd.cpp", - "RegisterCompositeExplicitAutograd.cpp", - "RegisterCompositeExplicitAutogradNonFunctional.cpp", - "CompositeViewCopyKernels.cpp", - "RegisterSchema.cpp", - "Declarations.yaml", - "Functions.cpp", - "Functions.h", - "RedispatchFunctions.h", - "NativeFunctions.h", - "NativeMetaFunctions.h", - "MethodOperators.h", - "FunctionalInverses.h", - "Operators.h", - "Operators_0.cpp", - "Operators_1.cpp", - "Operators_2.cpp", - "Operators_3.cpp", - "Operators_4.cpp", - "CompositeImplicitAutogradFunctions.h", - "CompositeImplicitAutogradFunctions_inl.h", - "CompositeExplicitAutogradFunctions.h", - "CompositeExplicitAutogradFunctions_inl.h", - "CompositeExplicitAutogradNonFunctionalFunctions.h", - "CompositeExplicitAutogradNonFunctionalFunctions_inl.h", - "core/ATenOpList.cpp", - "core/TensorBody.h", - "core/TensorMethods.cpp", - "core/aten_interned_strings.h", - "core/enum_tag.h", - ] + get_aten_derived_type_srcs(enabled_backends) - - # This is tiresome. A better strategy would be to unconditionally - # generate these files, and then only actually COMPILE them depended - # on the generated set. C'est la vie... - if "CPU" in enabled_backends: - src_files.extend(aten_ufunc_generated_cpu_sources()) - src_files.extend(aten_ufunc_generated_cpu_kernel_sources()) - if "CUDA" in enabled_backends: - # Cannot unconditionally include this, because in the Edge selective - # build CUDA is not enabled and thus the ufunc codegen for CUDA gets - # skipped - src_files.extend(aten_ufunc_generated_cuda_sources()) - - res = {} - for file_name in src_files: - res[file_name] = [file_name] - return res - -def get_template_registration_file_rules(rule_name): - rules = [] - for file_path in TEMPLATE_SOURCE_LIST: - rules.append(":{}[{}]".format(rule_name, file_path)) - for file_path in aten_ufunc_generated_all_cpu_sources(): - rules.append(":{}[aten/src/ATen/{}]".format(rule_name, file_path)) - - return rules - -# Originally, there were two sets of codes in caffe2:aten_cpu, native codes and non-native. -# Now we have only non-naitve sources in aten_cpu. However, there are some aten related -# tests that may require both native and non-native codes. This rule is used to generate -# both aten_cpu and aten_native_cpu. They are using the same compilation setups. -def build_aten_cpu(name, srcs, deps = []): - cxx_library( - name = name, - srcs = srcs, - header_namespace = "", - compiler_flags = get_pt_compiler_flags(), - exported_preprocessor_flags = get_aten_preprocessor_flags(), - link_whole = True, - linker_flags = ["-Wl,--no-as-needed", "-ldl"], - visibility = ["PUBLIC"], - deps = [ - "//third_party:cpuinfo", - "//third_party:glog", - "//third_party:XNNPACK", - #"//third_party/linker_lib:omp", - ], - exported_deps = [ - "//third_party:fmt", - "//aten/src/ATen/native/quantized/cpu/qnnpack:pytorch_qnnpack", - "//c10:c10", - ":aten_header", - ":caffe2_headers", - ":common_core", - ":generated_aten_config_header", - ":generated_aten_headers_cpu", - ":jit_core_headers", - ":pthreadpool", - "//third_party:ruy_lib", - ], - ) - ######### selective build ######### -def get_pt_ops_deps(name, deps, train = False, enforce_traced_op_list = False, enable_flatbuffer = False, **kwargs): - if not get_build_from_deps_query(): - return deps - pt_operator_registry( - name, - deps, - train = train, - enforce_traced_op_list = enforce_traced_op_list, - enable_flatbuffer = enable_flatbuffer, - **kwargs - ) - return deps + [":" + name] - -# pt_operator_registry is the method that defines the fb_xplat_cxx_library that contains -# code for all selected PyTorch Operators and kernel functions. This also includes -# operator registration into the dispatcher. -# -# template_select: bool: Indicates if template based selective build is enabled. -# -# enforce_traced_op_list: bool: Enforces that only new-style operator -# lists based on the all_mobile_model_configs.yaml file and tracing based selective -# build are used in this library. -# -# train: bool: Build this library for training (True) or inference only (False). -# If built for training, codegen for VariableType is also included. -# -# pt_allow_forced_schema_registration: Manually disables forced schema registration when set to false, Default is true. -# Only does anything when train=True and the app requires full jit then force_schema_registration needs to occur. -# As Federated Learning migrates to lite interpreter -# we can slowly turn off forced schema registration as it is useless space and floods the compatibility api -# def pt_operator_registry( name, deps = [], @@ -484,245 +96,34 @@ def pt_operator_registry( pt_allow_forced_schema_registration = True, enable_flatbuffer = False, **kwargs): - compatible_with = kwargs.get("compatible_with", []) - code_gen_files = pt_operator_query_codegen(name, deps = deps, train = train, enforce_traced_op_list = enforce_traced_op_list, pt_allow_forced_schema_registration = pt_allow_forced_schema_registration, compatible_with = compatible_with) - code_gen_srcs = code_gen_files["srcs"] - - lib_deps = [ - ":aten_cpu", - ":torch_mobile_core", - "//c10:c10", - "//third_party:glog", - ] - - #if train: - # lib_deps = lib_deps + ["fbsource//xplat/caffe2:torch_mobile_train"] - - exported_preprocessor_flags = get_aten_preprocessor_flags() - exported_preprocessor_flags += kwargs.pop("exported_preprocessor_flags", []) - if template_select: - # In addition to the - # original code-gen select, this option further filter more operators based on - # compile-time calculation. Examples include prim ops and any other ops that were - # not filtered out before. The purpose of this option is to reduce the production - # size further. However, it may have less flexibility, especially for tests from - # python, where the used operator list is not explicitly generated. If the tests - # are for functionality but not for size, and it's difficult to maintain an explicit - # operator list, it's suggested to turn this option off. - exported_preprocessor_flags.append("-DTEMPLATE_SELECTIVE_BUILD") - kwargs.pop("exported_headers", []) - cxx_library( - name = name, - srcs = code_gen_srcs, - linker_flags = [ - "-Wl,--no-as-needed", - "-ldl", - ], - link_whole = True, - soname = "libtorch-code-gen.$(ext)", - compiler_flags = get_aten_compiler_flags(), - platform_compiler_flags = get_cpukernel_avx2_flags(), - platform_deps = get_cpukernel_avx2_deps(), - header_namespace = "ATen", - exported_headers = code_gen_files["headers"], - exported_preprocessor_flags = exported_preprocessor_flags, - headers = kwargs.pop("headers", []), - deps = lib_deps + [ - "//third_party:XNNPACK", - ], + args = get_pt_operator_registry_dict( + name, + deps, + train, + labels, + env, + template_select, + enforce_traced_op_list, + pt_allow_forced_schema_registration, + enable_flatbuffer = True, **kwargs ) -def get_aten_derived_type_src_rules(aten_rule_name, enabled_backends): - return [ - ":{}[{}]".format(aten_rule_name, "Register" + backend + ".cpp") - for backend in enabled_backends - ] - -def get_aten_selective_cpp_rules(aten_rule_name, enabled_backends): - return [ - ":{}[{}]".format(aten_rule_name, f) - for f in ["RegisterCompositeImplicitAutograd.cpp", "RegisterCompositeExplicitAutograd.cpp", "RegisterCompositeExplicitAutogradNonFunctional.cpp", "RegisterSchema.cpp", "RegisterBackendSelect.cpp", "CompositeViewCopyKernels.cpp"] - ] + get_aten_derived_type_src_rules(aten_rule_name, enabled_backends) - -def get_aten_derived_type_srcs(enabled_backends): - return [ - "Register" + derived_type + ".cpp" - for derived_type in enabled_backends - ] + [ - derived_type + "Functions.h" - for derived_type in enabled_backends - if derived_type in PT_BACKEND_HEADERS or derived_type in get_static_dispatch_backend() - ] + [ - derived_type + "Functions_inl.h" - for derived_type in enabled_backends - if derived_type in PT_BACKEND_HEADERS or derived_type in get_static_dispatch_backend() - ] - -def pt_operator_query_codegen(name, deps = [], train = False, enforce_traced_op_list = False, pt_allow_forced_schema_registration = True, compatible_with = []): - oplist_dir_name = name + "_pt_oplist" - - # @lint-ignore BUCKLINT - fb_xplat_genrule( - name = oplist_dir_name, - cmd = ("$(exe //:gen_oplist) " + - "--model_file_list_path $(@query_outputs 'attrfilter(labels, pt_operator_library, deps(set({deps})))') " + - ("" if enforce_traced_op_list else "--allow_include_all_overloads ") + - "--output_dir $OUT ").format(deps = " ".join(["\"{}\"".format(d) for d in deps])), - outs = get_gen_oplist_outs(), - default_outs = ["."], - compatible_with = compatible_with, - ) - - # Aten files - aten_genrule = name + "_aten" - extra_flags = { - "enabled_backends": USED_PT_BACKENDS, - "op_selection_yaml_path": "$(location :{}[selected_operators.yaml])".format(oplist_dir_name), - } - - if train and pt_allow_forced_schema_registration: - extra_flags["force_schema_registration"] = True - - # if get_enable_lightweight_dispatch(): - # unboxing_genrule = name + "_unboxing" - # gen_aten_unboxing_files( - # unboxing_genrule, - # extra_flags = extra_flags, - # ) - - static_dispatch_backend = get_static_dispatch_backend() - if static_dispatch_backend: - extra_flags["static_dispatch_backend"] = static_dispatch_backend - - gen_aten_files( - aten_genrule, - extra_flags = extra_flags, - compatible_with = compatible_with, - ) - - # unboxing_wrappers files - extra_params = [ - "--operators_yaml_path", - "$(location :" + oplist_dir_name + "[selected_operators.yaml])", - ] - unboxing_and_autograd_genrule = name + "_unboxing_and_autograd" - gen_aten_libtorch_files(unboxing_and_autograd_genrule, extra_params, compatible_with) - - # Template runtime files (prim ops, etc) - template_registration_genrule = name + "_template_registration" - copy_template_registration_files(template_registration_genrule) - - srcs = get_aten_selective_cpp_rules( - aten_genrule, - static_dispatch_backend if static_dispatch_backend else USED_PT_BACKENDS, - ) + get_template_registration_file_rules( - template_registration_genrule, - ) + ([ - ":{}[autograd/generated/VariableType_0.cpp]".format(unboxing_and_autograd_genrule), - ":{}[autograd/generated/VariableType_1.cpp]".format(unboxing_and_autograd_genrule), - ":{}[autograd/generated/VariableType_2.cpp]".format(unboxing_and_autograd_genrule), - ":{}[autograd/generated/VariableType_3.cpp]".format(unboxing_and_autograd_genrule), - ":{}[autograd/generated/VariableType_4.cpp]".format(unboxing_and_autograd_genrule), - ":{}[autograd/generated/ADInplaceOrViewType_0.cpp]".format(unboxing_and_autograd_genrule), - ":{}[autograd/generated/ADInplaceOrViewType_1.cpp]".format(unboxing_and_autograd_genrule), - ] if train else []) + ([ - #":{}[SupportedMobileModelsRegistration.cpp]".format(oplist_dir_name), - ]) - - headers = { - "selected_mobile_ops.h": ":{}[selected_mobile_ops.h]".format(oplist_dir_name), - } - - # if get_enable_lightweight_dispatch(): - # srcs.extend([ - # ":{}[UnboxingFunctions_0.cpp]".format(unboxing_genrule), - # ":{}[UnboxingFunctions_1.cpp]".format(unboxing_genrule), - # ":{}[UnboxingFunctions_2.cpp]".format(unboxing_genrule), - # ":{}[UnboxingFunctions_3.cpp]".format(unboxing_genrule), - # ":{}[UnboxingFunctions_4.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_0.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_1.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_2.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_3.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_4.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_5.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_6.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_7.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_8.cpp]".format(unboxing_genrule), - # ":{}[RegisterCodegenUnboxedKernels_9.cpp]".format(unboxing_genrule), - # ]) - # headers["UnboxingFunctions.h"] = ":{}[UnboxingFunctions.h]".format(unboxing_genrule) - return {"headers": headers, "srcs": srcs} - -def gen_aten_libtorch_files(name, extra_params = [], compatible_with = []): - fb_xplat_genrule( + fb_xplat_cxx_library( name = name, - outs = get_generate_code_bin_outs(), - default_outs = ["."], - cmd = "mkdir -p tools && " + - "$(exe //tools/setup_helpers:generate_code_bin) " + " ".join( - # Mobile build only needs libtorch - skip python bindings for now, except - # for ovrsource, which needs Python bindings. - (["--subset libtorch"] if not is_arvr_mode() else []) + [ - "--native-functions-path $(location :aten_src_path)/aten/src/ATen/native/native_functions.yaml", - "--tags-path $(location :aten_src_path)/aten/src/ATen/native/tags.yaml", # todo D35992309 - "--install_dir $OUT", - ] + extra_params, - ), - cmd_exe = "@powershell -Command New-Item -Path tools -ItemType Directory -Force; " + - "$(exe //tools/setup_helpers:generate_code_bin) " + " ".join( - # Mobile build only needs libtorch - skip python bindings for now, except - # for ovrsource, which needs Python bindings. - (["--subset libtorch"] if not is_arvr_mode() else []) + [ - "--native-functions-path $(location :aten_src_path)/aten/src/ATen/native/native_functions.yaml", - "--tags-path $(location :aten_src_path)/aten/src/ATen/native/tags.yaml", - "--install_dir $OUT", - ] + extra_params, - ), - compatible_with = compatible_with, + **args ) -def copy_template_registration_files(name): - cmd = [] - cmd_exe = [] - - template_source_dict = get_template_source_dict() - - # Ideally, we would run one copy command for a single source directory along - # with all its child directories, but it's somewhat hard to know if a directory - # is a child of another just bu looking at the metadata (directory relative - # path) that we currently have since 1 directory could look like a parent of - # another and yet come from a different filegroup() rule. - # - for (path_prefix, file_paths) in template_source_dict.items(): - cmd.append("mkdir -p $OUT/{}".format(path_prefix)) - cmd_exe.append("md $OUT/{}".format(path_prefix)) - - # Adding *.cpp is a workaround to prevent cp from thrown an error when it - # encounters a directory (since -r was not specified). If files with an - # extension other than .cpp need to be copied, then the command below - # will not work and will need to be updated. - # - cmd.append("cp -f {0}/{1}/*.cpp $OUT/{1}/".format("$(location :templated_selective_build_srcs)", path_prefix)) - cmd_exe.append("robocopy /E {0}/{1} $OUT/{1}".format("$(location :templated_selective_build_srcs)", path_prefix)) - - cmd.append("mkdir -p $OUT/aten/src/ATen") - cmd_exe.append("md $OUT/aten/src/ATen") - - # NB: CUDA is skipped here because this is selective build and CUDA is not - # supported for selective build - for ufunc_file in aten_ufunc_generated_all_cpu_sources("$(location :gen_aten[{}])"): - cmd.append("cp -f " + ufunc_file + " $OUT/aten/src/ATen") - cmd_exe.append("copy " + ufunc_file + " $OUT/aten/src/ATen") - - fb_xplat_genrule( - name = name, - cmd = " && ".join(cmd), - cmd_exe = "@powershell -Command " + ("; ".join(cmd_exe)), - outs = get_template_registration_files_outs(), - default_outs = ["."], +def get_pt_ops_deps(name, deps, train = False, enforce_traced_op_list = False, enable_flatbuffer = False, **kwargs): + pt_operator_registry( + name, + deps, + train = train, + enforce_traced_op_list = enforce_traced_op_list, + enable_flatbuffer = enable_flatbuffer, + **kwargs ) + return deps + [":" + name] def pt_operator_library( name, @@ -735,91 +136,42 @@ def pt_operator_library( **kwargs): model_name = name - if get_build_from_deps_query(): - ops = [op.strip() for op in ops] + ops = [op.strip() for op in ops] - # If ops are specified, then we are in static selective build mode, so we append - # base ops to this list to avoid additional special case logic in subsequent code. - if len(ops) > 0: - ops.extend(PT_BASE_OPS) + # If ops are specified, then we are in static selective build mode, so we append + # base ops to this list to avoid additional special case logic in subsequent code. + if len(ops) > 0: + ops.extend(PT_BASE_OPS) - visibility = kwargs.pop("visibility", ["PUBLIC"]) + visibility = kwargs.pop("visibility", ["PUBLIC"]) - fb_xplat_genrule( - name = name, - out = "model_operators.yaml", - cmd = ( - "$(exe :gen_operators_yaml) " + - "{optionally_root_ops} " + - "{optionally_training_root_ops} " + - "--rule_name {rule_name} " + - "--output_path \"${{OUT}}\" " + - "--model_name {model_name} " + - "--dep_graph_yaml_path pytorch_op_deps.yaml " + - "--models_yaml_path all_mobile_model_configs.yaml " + - #"{optionally_model_versions} " + - #"{optionally_model_assets} " + - #"{optionally_model_traced_backends} " + - "{optionally_include_all_operators}" - ).format( - rule_name = name, - model_name = model_name, - optionally_root_ops = "--root_ops " + (",".join(ops)) if len(ops) > 0 else "", - optionally_training_root_ops = "--training_root_ops " + (",".join(ops)) if len(ops) > 0 and train else "", - #optionally_model_versions = "--model_versions " + (",".join(model_versions)) if model_versions != None else "", - #optionally_model_assets = "--model_assets " + (",".join(model_assets)) if model_assets != None else "", - #optionally_model_traced_backends = "--model_traced_backends " + (",".join(model_traced_backends)) if model_traced_backends != None else "", - optionally_include_all_operators = "--include_all_operators " if include_all_operators else "", - ), - labels = ["pt_operator_library"], # for pt_operator_query_codegen query - visibility = visibility, - **kwargs - ) - else: - if check_decl: - pass - # ensure_ops_are_declared(ops) - - cxx_library( - name = name, - compiler_flags = get_pt_compiler_flags(), - cxx_platform_compiler_flags = get_cpukernel_avx2_flags(), - exported_deps = exported_deps, - **kwargs - ) - -def compose_platform_setting_list(settings): - """Settings object: - os/cpu pair: should be valid key, or at most one part can be wildcard. - flags: the values added to the compiler flags - """ - result = [] - for setting in settings: - result = result.append([ - "^{}-{}$".format(setting["os"], setting["cpu"]), - setting["flags"], - ]) - return result - -def get_cpukernel_avx2_flags(): - # flags = compose_platform_setting_list([ - # { - # "cpu": "x86_64", - # "flags": ["-DHAVE_AVX2_CPU_DEFINITION"], - # "os": "macosx", - # }, - # ]) if build_cpukernel_avx2() else [] - return [] - -def build_cpukernel_avx2(): - return not is_arvr_mode() - -def get_cpukernel_avx2_deps(): - # flags = compose_platform_setting_list([ - # { - # "cpu": "x86_64", - # "flags": ["fbsource//xplat/caffe2:cpukernel_avx2"], - # "os": "macosx", - # }, - # ]) if build_cpukernel_avx2() else [] - return [] + fb_xplat_genrule( + name = name, + out = "model_operators.yaml", + cmd = ( + "$(exe :gen_operators_yaml) " + + "{optionally_root_ops} " + + "{optionally_training_root_ops} " + + "--rule_name {rule_name} " + + "--output_path \"${{OUT}}\" " + + "--model_name {model_name} " + + "--dep_graph_yaml_path pytorch_op_deps.yaml " + + "--models_yaml_path all_mobile_model_configs.yaml " + + #"{optionally_model_versions} " + + #"{optionally_model_assets} " + + #"{optionally_model_traced_backends} " + + "{optionally_include_all_operators}" + ).format( + rule_name = name, + model_name = model_name, + optionally_root_ops = "--root_ops " + (",".join(ops)) if len(ops) > 0 else "", + optionally_training_root_ops = "--training_root_ops " + (",".join(ops)) if len(ops) > 0 and train else "", + #optionally_model_versions = "--model_versions " + (",".join(model_versions)) if model_versions != None else "", + #optionally_model_assets = "--model_assets " + (",".join(model_assets)) if model_assets != None else "", + #optionally_model_traced_backends = "--model_traced_backends " + (",".join(model_traced_backends)) if model_traced_backends != None else "", + optionally_include_all_operators = "--include_all_operators " if include_all_operators else "", + ), + labels = ["pt_operator_library"], # for pt_operator_query_codegen query + visibility = visibility, + **kwargs + ) diff --git a/pt_template_srcs.bzl b/pt_template_srcs.bzl index 8f1499268aaf..58a65c13d69e 100644 --- a/pt_template_srcs.bzl +++ b/pt_template_srcs.bzl @@ -3,7 +3,7 @@ # being built load("@bazel_skylib//lib:paths.bzl", "paths") -load("@fbsource//tools/build_defs:fbsource_utils.bzl", "is_arvr_mode") +load("//tools/build_defs:fbsource_utils.bzl", "is_arvr_mode") load(":build_variables.bzl", "aten_native_source_list") load( ":ufunc_defs.bzl", @@ -154,13 +154,14 @@ def get_generate_code_bin_outs(): }) return outs -def get_template_registration_files_outs(): +def get_template_registration_files_outs(is_oss = False): outs = {} - for file_path in TEMPLATE_MASKRCNN_SOURCE_LIST: - outs[file_path] = [file_path] + if not is_oss: + for file_path in TEMPLATE_MASKRCNN_SOURCE_LIST: + outs[file_path] = [file_path] - for file_path in TEMPLATE_BATCH_BOX_COX_SOURCE_LIST: - outs[file_path] = [file_path] + for file_path in TEMPLATE_BATCH_BOX_COX_SOURCE_LIST: + outs[file_path] = [file_path] for file_path in TEMPLATE_SOURCE_LIST: outs[file_path] = [file_path] @@ -171,9 +172,9 @@ def get_template_registration_files_outs(): return outs -def get_template_registration_file_rules(rule_name): +def get_template_registration_file_rules(rule_name, is_oss = False): rules = [] - for file_path in TEMPLATE_SOURCE_LIST + TEMPLATE_MASKRCNN_SOURCE_LIST + TEMPLATE_BATCH_BOX_COX_SOURCE_LIST: + for file_path in TEMPLATE_SOURCE_LIST if is_oss else (TEMPLATE_SOURCE_LIST + TEMPLATE_MASKRCNN_SOURCE_LIST + TEMPLATE_BATCH_BOX_COX_SOURCE_LIST): rules.append(":{}[{}]".format(rule_name, file_path)) for file_path in aten_ufunc_generated_all_cpu_sources(): rules.append(":{}[aten/src/ATen/{}]".format(rule_name, file_path)) diff --git a/third_party/BUCK.oss b/third_party/BUCK.oss index 214e97b32aee..6360b605d143 100644 --- a/third_party/BUCK.oss +++ b/third_party/BUCK.oss @@ -8,6 +8,20 @@ define_xnnpack() define_kineto() +# a placeholder for libraries that are not implemented in OSS +cxx_library( + name = "no-op", + visibility = ['PUBLIC'], +) + +cxx_library( + name = "rt", + exported_platform_linker_flags = [ + ("^linux-.*$", ["-lrt"]), + ], + visibility = ['PUBLIC'], +) + cxx_library( name = "fmt", srcs = ['fmt/src/format.cc'], diff --git a/tools/build_defs/android/build_mode_defs.bzl b/tools/build_defs/android/build_mode_defs.bzl new file mode 100644 index 000000000000..2bf307f09c41 --- /dev/null +++ b/tools/build_defs/android/build_mode_defs.bzl @@ -0,0 +1,5 @@ +# @lint-ignore-every BUCKRESTRICTEDSYNTAX +def is_production_build(): + if read_config("pt", "is_oss", "0") == "0": + fail("This file is for open source pytorch build. Do not use it in fbsource!") + return False diff --git a/tools/build_defs/apple/build_mode_defs.bzl b/tools/build_defs/apple/build_mode_defs.bzl new file mode 100644 index 000000000000..2bf307f09c41 --- /dev/null +++ b/tools/build_defs/apple/build_mode_defs.bzl @@ -0,0 +1,5 @@ +# @lint-ignore-every BUCKRESTRICTEDSYNTAX +def is_production_build(): + if read_config("pt", "is_oss", "0") == "0": + fail("This file is for open source pytorch build. Do not use it in fbsource!") + return False diff --git a/tools/build_defs/fb_xplat_cxx_library.bzl b/tools/build_defs/fb_xplat_cxx_library.bzl index c73fa500a984..025a3bc4d229 100644 --- a/tools/build_defs/fb_xplat_cxx_library.bzl +++ b/tools/build_defs/fb_xplat_cxx_library.bzl @@ -8,6 +8,7 @@ load( def fb_xplat_cxx_library( name, + extra_flags = {}, **kwgs): if read_config("pt", "is_oss", "0") == "0": fail("This file is for open source pytorch build. Do not use it in fbsource!") diff --git a/tools/build_defs/fb_xplat_genrule.bzl b/tools/build_defs/fb_xplat_genrule.bzl index 8d61967cdb41..f1e09617888c 100644 --- a/tools/build_defs/fb_xplat_genrule.bzl +++ b/tools/build_defs/fb_xplat_genrule.bzl @@ -1,7 +1,7 @@ # Only used for PyTorch open source BUCK build # @lint-ignore-every BUCKRESTRICTEDSYNTAX -def fb_xplat_genrule(default_outs = ["."], **kwargs): +def fb_xplat_genrule(default_outs = ["."], apple_sdks = None, **kwargs): if read_config("pt", "is_oss", "0") == "0": fail("This file is for open source pytorch build. Do not use it in fbsource!")