8000 switch Bazel to common aten codegen by dagitses · Pull Request #79783 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

switch Bazel to common aten codegen #79783

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("//third_party:substitution.bzl", "header_template_rule")
load("//:tools/bazel.bzl", "rules")
load("//tools/rules:cu.bzl", "cu_library")
load("//tools/config:defs.bzl", "if_cuda")
load("//:aten.bzl", "intern_build_aten_ops", "generate_aten")
load("//:aten.bzl", "intern_build_aten_ops")
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")
Expand All @@ -22,16 +22,13 @@ COMMON_COPTS = [
"-DTH_HAVE_THREAD",
"-DUSE_FBGEMM",
"-DUSE_DISTRIBUTED",
"-DAT_PER_OPERATOR_HEADERS",
"-DATEN_THREADING=NATIVE",
"-DNO_CUDNN_DESTROY_HANDLE",
] + if_cuda([
"-DUSE_CUDA",
"-D 8000 USE_CUDNN",
])

aten_generation_srcs = ["aten/src/ATen/native/native_functions.yaml"] + ["aten/src/ATen/native/tags.yaml"] + glob(["aten/src/ATen/templates/**"])

generated_cpu_cpp = [
"aten/src/ATen/RegisterBackendSelect.cpp",
"aten/src/ATen/RegisterCPU.cpp",
Expand Down Expand Up @@ -93,20 +90,6 @@ generated_cuda_cpp = [
"aten/src/ATen/RegisterSparseCsrCUDA.cpp",
]

generate_aten(
name = "generated_aten_cpp",
srcs = aten_generation_srcs,
outs = (
generated_cpu_cpp +
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"]
),
generator = "//torchgen:gen",
)

filegroup(
name = "cpp_generated_code",
data = [":generate-code"],
Expand Down Expand Up @@ -291,7 +274,7 @@ cc_library(
],
) + [
":aten_src_ATen_config",
":generated_aten_cpp",
":gen_aten",
],
includes = [
"aten/src",
Expand Down
40 changes: 0 additions & 40 deletions aten.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@rules_cc//cc:defs.bzl", "cc_library")

CPU_CAPABILITY_NAMES = ["DEFAULT", "AVX2"]
Expand Down Expand Up @@ -55,42 +54,3 @@ def intern_build_aten_ops(copts, deps, extra_impls):
deps = [":ATen_CPU_" + cpu_capability for cpu_capability in CPU_CAPABILITY_NAMES],
linkstatic = 1,
)

def generate_aten_impl(ctx):
# Declare the entire ATen/ops/ directory as an output
ops_dir = ctx.actions.declare_directory("aten/src/ATen/ops")
outputs = [ops_dir] + ctx.outputs.outs

install_dir = paths.dirname(ops_dir.path)
tool_inputs, tool_inputs_manifest = ctx.resolve_tools(tools = [ctx.attr.generator])
ctx.actions.run_shell(
outputs = outputs,
inputs = ctx.files.srcs,
command = ctx.executable.generator.path + " $@",
arguments = [
"--source-path",
"aten/src/ATen",
"--per-operator-headers",
"--install_dir",
install_dir,
],
tools = tool_inputs,
input_manifests = tool_inputs_manifest,
use_default_shell_env = True,
mnemonic = "GenerateAten",
)
return [DefaultInfo(files = depset(outputs))]

generate_aten = rule(
implementation = generate_aten_impl,
attrs = {
"generator": attr.label(
executable = True,
allow_files = True,
mandatory = True,
cfg = "exec",
),
"outs": attr.output_list(),
"srcs": attr.label_list(allow_files = True),
},
)
3 changes: 0 additions & 3 deletions build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ def define_targets(rules):
tools = ["//torchgen:gen"],
outs = ["aten/src/ATen/" + out for out in gen_aten_outs],
cmd = gen_aten_cmd,
# This currently clashes with the existing Bazel generated
# files.
tags = ["-bazel"],
)

rules.genrule(
Expand Down
0