diff --git a/BUILD.bazel b/BUILD.bazel index d858c4d6412..b3c50fb3970 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -6,10 +6,10 @@ load("@pytorch//third_party:substitution.bzl", "header_template_rule") load("@pytorch//:tools/bazel.bzl", "rules") load("@pytorch//tools/rules:cu.bzl", "cu_library") load("@pytorch//tools/config:defs.bzl", "if_cuda") -load("@pytorch//:aten.bzl", "intern_build_aten_ops", "generate_aten") -load(":build.bzl", "define_targets", "GENERATED_AUTOGRAD_CPP", "GENERATED_AUTOGRAD_PYTHON") -load(":build_variables.bzl", "jit_core_sources", "libtorch_core_sources", "libtorch_cuda_sources", "libtorch_distributed_sources", "libtorch_extra_sources", "libtorch_nvfuser_generated_headers", "libtorch_nvfuser_runtime_sources", "libtorch_python_core_sources", "torch_cpp_srcs", "lazy_tensor_ts_sources") -load(":ufunc_defs.bzl", "aten_ufunc_generated_cpu_sources", "aten_ufunc_generated_cpu_kernel_sources", "aten_ufunc_generated_cuda_sources") +load("@pytorch//:aten.bzl", "generate_aten", "intern_build_aten_ops") +load(":build.bzl", "GENERATED_AUTOGRAD_CPP", "GENERATED_AUTOGRAD_PYTHON", "define_targets") +load(":build_variables.bzl", "jit_core_sources", "lazy_tensor_ts_sources", "libtorch_core_sources", "libtorch_cuda_sources", "libtorch_distributed_sources", "libtorch_extra_sources", "libtorch_nvfuser_generated_headers", "libtorch_nvfuser_runtime_sources", "libtorch_python_core_sources", "torch_cpp_srcs") +load(":ufunc_defs.bzl", "aten_ufunc_generated_cpu_kernel_sources", "aten_ufunc_generated_cpu_sources", "aten_ufunc_generated_cuda_sources") define_targets(rules = rules) @@ -112,16 +112,17 @@ generate_aten( generated_cuda_cpp + aten_ufunc_generated_cpu_sources("aten/src/ATen/{}") + aten_ufunc_generated_cpu_kernel_sources("aten/src/ATen/{}") + - aten_ufunc_generated_cuda_sources("aten/src/ATen/{}") + - ["aten/src/ATen/Declarations.yaml"] + aten_ufunc_generated_cuda_sources("aten/src/ATen/{}") + [ + "aten/src/ATen/Declarations.yaml", + ] ), generator = "//torchgen:gen", ) filegroup( name = "cpp_generated_code", - data = [":generate-code"], srcs = GENERATED_AUTOGRAD_CPP, + data = [":generate-code"], ) exports_files( @@ -183,7 +184,10 @@ filegroup( filegroup( name = "aten_native_mkl_cpp", - srcs = glob(["aten/src/ATen/native/mkl/*.cpp", "aten/src/ATen/mkl/*.cpp"]), + srcs = glob([ + "aten/src/ATen/native/mkl/*.cpp", + "aten/src/ATen/mkl/*.cpp", + ]), ) filegroup( @@ -294,13 +298,14 @@ cc_library( hdrs = [ "torch/csrc/Export.h", "torch/csrc/jit/frontend/function_schema_parser.h", - ] + glob([ - "aten/src/**/*.h", - "aten/src/**/*.hpp", - "aten/src/ATen/cuda/**/*.cuh", - "aten/src/ATen/native/**/*.cuh", - "aten/src/THC/*.cuh", - ], + ] + glob( + [ + "aten/src/**/*.h", + "aten/src/**/*.hpp", + "aten/src/ATen/cuda/**/*.cuh", + "aten/src/ATen/native/**/*.cuh", + "aten/src/THC/*.cuh", + ], ) + [ ":aten_src_ATen_config", ":generated_aten_cpp", @@ -324,13 +329,13 @@ ATEN_COPTS = COMMON_COPTS + [ intern_build_aten_ops( copts = ATEN_COPTS, + extra_impls = aten_ufunc_generated_cpu_kernel_sources("aten/src/ATen/{}"), deps = [ ":aten_headers", - "@sleef", "@fbgemm", "@mkl", + "@sleef", ], - extra_impls = aten_ufunc_generated_cpu_kernel_sources("aten/src/ATen/{}"), ) cc_library( @@ -344,9 +349,9 @@ cc_library( ":aten_native_cpp", ":aten_native_mkl_cpp", ":aten_native_mkldnn_cpp", + ":aten_native_nested_cpp", ":aten_native_quantized_cpp", ":aten_native_sparse_cpp", - ":aten_native_nested_cpp", ":aten_native_transformers_cpp", ":aten_native_xnnpack", ":aten_src_ATen_config", @@ -378,10 +383,10 @@ cc_library( visibility = ["//visibility:public"], deps = [ ":aten_headers", + "//c10:headers", "@cuda", "@cuda//:cuda_driver", "@cuda//:nvrtc", - "//c10:headers", ], alwayslink = True, ) @@ -1284,8 +1289,8 @@ cc_library( "caffe2/perfkernels/common.h", "caffe2/perfkernels/embedding_lookup.h", "caffe2/perfkernels/embedding_lookup_idx.h", - "caffe2/utils/fixed_divisor.h", "caffe2/utils/cpuid.h", + "caffe2/utils/fixed_divisor.h", ] + glob([ "caffe2/utils/threadpool/*.h", "caffe2/proto/*.h", @@ -1293,8 +1298,8 @@ cc_library( copts = CAFFE2_COPTS, visibility = ["//visibility:public"], deps = [ - ":caffe2_protos", ":caffe2_core_macros_h", + ":caffe2_protos", "//c10:headers", ], ) @@ -1427,8 +1432,8 @@ cc_library( linkstatic = 1, visibility = ["//visibility:public"], deps = [ - ":caffe2_headers", ":caffe2_dnnlowp_avx2_ops", + ":caffe2_headers", ":caffe2_perfkernels_avx", ":caffe2_perfkernels_avx2", ":caffe2_perfkernels_avx512", @@ -1437,10 +1442,10 @@ cc_library( "@com_google_protobuf//:protobuf", "@eigen", "@fbgemm//:fbgemm_src_headers", + "@fmt", "@foxi", "@gloo", "@onnx", - "@fmt", ] + if_cuda( [ ":caffe2_cuda_cpp", @@ -1587,12 +1592,12 @@ cc_library( ] + torch_cuda_headers, ) + GENERATED_AUTOGRAD_CPP + [":version_h"], includes = [ + "third_party/kineto/libkineto/include", "torch/csrc", "torch/csrc/api/include", "torch/csrc/distributed", "torch/lib", "torch/lib/libshm", - "third_party/kineto/libkineto/include", ], visibility = ["//visibility:public"], deps = [ @@ -1622,16 +1627,18 @@ cu_library( deps = [":torch_headers"], ) -torch_sources = ({ - k: "" for k in ( - libtorch_core_sources + - libtorch_distributed_sources + - torch_cpp_srcs + - libtorch_extra_sources + - jit_core_sources + - lazy_tensor_ts_sources + - GENERATED_AUTOGRAD_CPP) -}).keys() +torch_sources = { + k: "" + for k in ( + libtorch_core_sources + + libtorch_distributed_sources + + torch_cpp_srcs + + libtorch_extra_sources + + jit_core_sources + + lazy_tensor_ts_sources + + GENERATED_AUTOGRAD_CPP + ) +}.keys() cc_library( name = "torch", @@ -1677,7 +1684,7 @@ cc_library( # We need the filegroup here because the raw list causes Bazel # to see duplicate files. It knows how to deduplicate with the # filegroup. - ":cpp_generated_code" + ":cpp_generated_code", ], includes = [ "torch/csrc/api/include", @@ -1695,8 +1702,8 @@ cc_library( name = "torch_python", srcs = libtorch_python_core_sources + GENERATED_AUTOGRAD_PYTHON, deps = [ - ":torch", ":shm", + ":torch", "@pybind11", ], ) @@ -1705,7 +1712,7 @@ pybind_extension( name = "_C", srcs = ["torch/csrc/stub.c"], deps = [ - ":torch_python" + ":torch_python", ], ) @@ -1740,31 +1747,32 @@ cpp_api_tests = glob( ) cc_test( - name = "integration_test", - size = "medium", - srcs = ["test/cpp/api/integration.cpp"], - deps = [ - ":test_support", - "@com_google_googletest//:gtest_main", - ], - tags = [ - "gpu-required", - ], - data = [ + name = "integration_test", + size = "medium", + srcs = ["test/cpp/api/integration.cpp"], + data = [ ":download_mnist", - ], + ], + tags = [ + "gpu-required", + ], + deps = [ + ":test_support", + "@com_google_googletest//:gtest_main", + ], ) [ - cc_test( - name = paths.split_extension(paths.basename(filename))[0].replace("-","_") + "_test", - size = "medium", - srcs = [filename], - deps = [ - ":test_support", - "@com_google_googletest//:gtest_main", - ], - ) for filename in cpp_api_tests + cc_test( + name = paths.split_extension(paths.basename(filename))[0].replace("-", "_") + "_test", + size = "medium", + srcs = [filename], + deps = [ + ":test_support", + "@com_google_googletest//:gtest_main", + ], + ) + for filename in cpp_api_tests ] test_suite( @@ -1818,15 +1826,18 @@ cc_test( cc_test( name = "jit_tests", size = "small", - srcs = glob([ - "test/cpp/jit/*.cpp", - "test/cpp/jit/*.h", - "test/cpp/tensorexpr/*.cpp", - "test/cpp/tensorexpr/*.h", - ], exclude=[ - # skip this since is not found in OSS build - "test/cpp/jit/test_exception.cpp", - ]), + srcs = glob( + [ + "test/cpp/jit/*.cpp", + "test/cpp/jit/*.h", + "test/cpp/tensorexpr/*.cpp", + "test/cpp/tensorexpr/*.h", + ], + exclude = [ + # skip this since is not found in OSS build + "test/cpp/jit/test_exception.cpp", + ], + ), linkstatic = True, tags = [ "exclusive", @@ -1841,15 +1852,18 @@ cc_test( cc_test( name = "lazy_tests", size = "small", - srcs = glob([ - "test/cpp/lazy/*.cpp", - "test/cpp/lazy/*.h", - ], exclude=[ - # skip these since they depend on generated LazyIr.h which isn't available in bazel yet - "test/cpp/lazy/test_ir.cpp", - "test/cpp/lazy/test_lazy_ops.cpp", - "test/cpp/lazy/test_lazy_ops_util.cpp", - ]), + srcs = glob( + [ + "test/cpp/lazy/*.cpp", + "test/cpp/lazy/*.h", + ], + exclude = [ + # skip these since they depend on generated LazyIr.h which isn't available in bazel yet + "test/cpp/lazy/test_ir.cpp", + "test/cpp/lazy/test_lazy_ops.cpp", + "test/cpp/lazy/test_lazy_ops_util.cpp", + ], + ), linkstatic = True, tags = [ "exclusive",