Skip to content

Commit

Permalink
move generate-code into shared build structure (pytorch#75699)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#75699

ghstack-source-id: 155255334

Test Plan: Rely on CI.

Reviewed By: dreiss

Differential Revision: D35587412

fbshipit-source-id: 5ab79c07029de279a1fae36519654a73bb61d430
(cherry picked from commit 4896b72)
  • Loading branch information
mikey dagitses authored and pytorchmergebot committed May 3, 2022
1 parent 28dfed9 commit eb27c85
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 33 deletions.
14 changes: 14 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1919,3 +1919,17 @@ test_suite(
"//c10/test:tests",
],
)

# An internal genrule that we are converging with refers to these file
# as if they are from this package, so we alias them for
# compatibility.

alias(
name = "native_functions.yaml",
actual = "aten/src/ATen/native/native_functions.yaml",
)

alias(
name = "tags.yaml",
actual = "aten/src/ATen/native/tags.yaml",
)
84 changes: 84 additions & 0 deletions build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ def define_targets(rules):
],
)

rules.genrule(
name = "generate-code",
srcs = [
"aten/src/ATen/native/ts_native_functions.yaml",
"aten/src/ATen/templates/DispatchKeyNativeFunctions.cpp",
"aten/src/ATen/templates/DispatchKeyNativeFunctions.h",
"aten/src/ATen/templates/LazyIr.h",
"aten/src/ATen/templates/RegisterDispatchKey.cpp",
"torch/csrc/lazy/core/shape_inference.h",
"torch/csrc/lazy/ts_backend/ts_native_functions.cpp",
":native_functions.yaml",
":tags.yaml",
],
tools = ["//tools/setup_helpers:generate_code"],
outs = _GENERATED_CPP + GENERATED_AUTOGRAD_H + GENERATED_LAZY_H + GENERATED_TESTING_PY,
cmd = "$(location //tools/setup_helpers:generate_code) " +
"--install_dir $(RULEDIR) " +
"--native-functions-path $(location :native_functions.yaml) " +
"--tags-path=$(location :tags.yaml) " +
"--gen_lazy_ts_backend",
)

rules.genrule(
name = "version_h",
srcs = [
Expand All @@ -34,3 +56,65 @@ def define_targets(rules):
"--version-path $(location :version.txt) --output-path $@ ",
tools = ["//tools/setup_helpers:gen_version_header"],
)

# These lists are temporarily living in and exported from the shared
# structure so that an internal build that lives under a different
# root can access them. These could technically live in a separate
# file in the same directory but that would require extra work to
# ensure that file is synced to both Meta internal repositories and
# GitHub. This problem will go away when the targets downstream of
# generate-code that use these lists are moved into the shared
# structure as well.

# In the open-source build, these are generated into
# torch/csrc/autograd/generated
GENERATED_AUTOGRAD_H = [
"autograd/generated/Functions.h",
"autograd/generated/VariableType.h",
"autograd/generated/python_functions.h",
"autograd/generated/variable_factories.h",
]

# In the open-source build, these are generated into
# torch/testing/_internal/generated
GENERATED_TESTING_PY = [
"annotated_fn_args.py",
]

GENERATED_LAZY_H = [
"lazy/generated/LazyIr.h",
"lazy/generated/LazyNativeFunctions.h",
]

# In both open-source and fbcode builds, these are generated into
# torch/csrc/{autograd,jit}/generated.i
_GENERATED_CPP = [
"autograd/generated/Functions.cpp",
"autograd/generated/VariableType_0.cpp",
"autograd/generated/VariableType_1.cpp",
"autograd/generated/VariableType_2.cpp",
"autograd/generated/VariableType_3.cpp",
"autograd/generated/VariableType_4.cpp",
"autograd/generated/TraceType_0.cpp",
"autograd/generated/TraceType_1.cpp",
"autograd/generated/TraceType_2.cpp",
"autograd/generated/TraceType_3.cpp",
"autograd/generated/TraceType_4.cpp",
"autograd/generated/ADInplaceOrViewType_0.cpp",
"autograd/generated/ADInplaceOrViewType_1.cpp",
"autograd/generated/python_functions_0.cpp",
"autograd/generated/python_functions_1.cpp",
"autograd/generated/python_functions_2.cpp",
"autograd/generated/python_functions_3.cpp",
"autograd/generated/python_functions_4.cpp",
"autograd/generated/python_nn_functions.cpp",
"autograd/generated/python_fft_functions.cpp",
"autograd/generated/python_linalg_functions.cpp",
"autograd/generated/python_return_types.cpp",
"autograd/generated/python_sparse_functions.cpp",
"autograd/generated/python_special_functions.cpp",
"autograd/generated/python_torch_functions_0.cpp",
"autograd/generated/python_torch_functions_1.cpp",
"autograd/generated/python_torch_functions_2.cpp",
"autograd/generated/python_variable_methods.cpp",
]
33 changes: 0 additions & 33 deletions tools/build_variables.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,6 @@
# bzl files are not exported via ShipIt by default, so you may also need to
# update PyTorch's ShipIt config)

# In both open-source and fbcode builds, these are generated into
# torch/csrc/{autograd,jit}/generated.i
GENERATED_CPP = [
"autograd/generated/Functions.cpp",
"autograd/generated/VariableType_0.cpp",
"autograd/generated/VariableType_1.cpp",
"autograd/generated/VariableType_2.cpp",
"autograd/generated/VariableType_3.cpp",
"autograd/generated/VariableType_4.cpp",
"autograd/generated/TraceType_0.cpp",
"autograd/generated/TraceType_1.cpp",
"autograd/generated/TraceType_2.cpp",
"autograd/generated/TraceType_3.cpp",
"autograd/generated/TraceType_4.cpp",
"autograd/generated/ADInplaceOrViewType_0.cpp",
"autograd/generated/ADInplaceOrViewType_1.cpp",
"autograd/generated/python_functions_0.cpp",
"autograd/generated/python_functions_1.cpp",
"autograd/generated/python_functions_2.cpp",
"autograd/generated/python_functions_3.cpp",
"autograd/generated/python_functions_4.cpp",
"autograd/generated/python_nn_functions.cpp",
"autograd/generated/python_fft_functions.cpp",
"autograd/generated/python_linalg_functions.cpp",
"autograd/generated/python_return_types.cpp",
"autograd/generated/python_sparse_functions.cpp",
"autograd/generated/python_special_functions.cpp",
"autograd/generated/python_torch_functions_0.cpp",
"autograd/generated/python_torch_functions_1.cpp",
"autograd/generated/python_torch_functions_2.cpp",
"autograd/generated/python_variable_methods.cpp",
]

# This is duplicated in caffe2/CMakeLists.txt for now and not yet used in buck
GENERATED_LAZY_TS_CPP = [
"lazy/generated/LazyNativeFunctions.cpp",
Expand Down

0 comments on commit eb27c85

Please sign in to comment.