mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
move XNNPACK buck build to shared build file (#77941)
Summary: This diff moved the XNNPACK buck build to a shared build file in xplat/caffe2/third_party, so it can be reused by OSS buck CI in the future. There's no functionality change. **Background**: as we are moving to github-first, we want community to receive more signals from our internal build. XNNPACK is part of pytorch mobile build so we want to add it to OSS BUCK CI. **How it works**: all XNNPACK targets are defined in xplat/caffe2/third_party/xnnpack_defs.bzl. When we build it internally, the XNNPACK source is still at xplat/third-party/XNNPACK and we will load that bzl file in xplat/third-party/XNNPACK/BUCK. Everything should work as before. In OSS build, XNNPACK is a submodule in xplat/caffe2/third_party and we will load the same bzl file in pytorch/third_party/BUILD.buck. **Wrapper Generation**: the wrapper generation script is moved to xplat/caffe2/third_party/generate-xnnpack-wrappers.py. It will take an optional argument for the path of XNNPACK (they are different in internal build and OSS build). The wrapper files will always be generated at the parent folder of XNNPACK source. But the src_defs.bzl and wrapper_defs.bzl will always be in xplat/caffe2/third_party/ (they are now called xnnpack_src_defs.bzl and xnnpack_wrapper_defs.bzl). For OSS build this script will only be used in CI, and the generated files will not be committed. **Next Steps:** Once landed, I will try to build XNNPACK in OSS BUCK using xnnpack_defs.bzl. Meta-specific symbols need to be resolved, so there will be some refactors to the build file. Test Plan: buck build xplat/third-party/XNNPACK:XNNPACK Differential Revision: D36529332 Pull Request resolved: https://github.com/pytorch/pytorch/pull/77941 Approved by: https://github.com/malfet, https://github.com/seemethere
This commit is contained in:
committed by
PyTorch MergeBot
parent
18273c39da
commit
b8b46f932b
45
third_party/generate-xnnpack-wrappers.py
vendored
45
third_party/generate-xnnpack-wrappers.py
vendored
@ -3,6 +3,7 @@
|
||||
from __future__ import print_function
|
||||
import collections
|
||||
import os
|
||||
import sys
|
||||
|
||||
BANNER = "Auto-generated by generate-wrappers.py script. Do not modify"
|
||||
WRAPPER_SRC_NAMES = {
|
||||
@ -53,9 +54,9 @@ SRC_NAMES = [
|
||||
"PROD_AVX512SKX_MICROKERNEL_SRCS",
|
||||
]
|
||||
|
||||
def update_sources():
|
||||
def update_sources(xnnpack_path):
|
||||
sources = collections.defaultdict(list)
|
||||
with open("./XNNPACK/CMakeLists.txt") as cmake:
|
||||
with open(os.path.join(xnnpack_path, "XNNPACK/CMakeLists.txt")) as cmake:
|
||||
lines = cmake.readlines()
|
||||
i = 0
|
||||
while i < len(lines):
|
||||
@ -74,17 +75,16 @@ def update_sources():
|
||||
sources[name].append(value[4:])
|
||||
else:
|
||||
i += 1
|
||||
print(sources)
|
||||
return sources
|
||||
|
||||
if __name__ == "__main__":
|
||||
def gen_wrappers(xnnpack_path):
|
||||
xnnpack_sources = collections.defaultdict(list)
|
||||
sources = update_sources()
|
||||
sources = update_sources(xnnpack_path)
|
||||
for name in WRAPPER_SRC_NAMES:
|
||||
xnnpack_sources[WRAPPER_SRC_NAMES[name]].extend(sources[name])
|
||||
for condition, filenames in xnnpack_sources.items():
|
||||
for filename in filenames:
|
||||
filepath = os.path.join("XNNPACK/wrappers", filename)
|
||||
filepath = os.path.join(xnnpack_path, "xnnpack_wrappers", filename)
|
||||
if not os.path.isdir(os.path.dirname(filepath)):
|
||||
os.makedirs(os.path.dirname(filepath))
|
||||
with open(filepath, "w") as wrapper:
|
||||
@ -102,3 +102,36 @@ if __name__ == "__main__":
|
||||
print("#if %s" % condition, file=wrapper)
|
||||
print("#include <%s>" % filename, file=wrapper)
|
||||
print("#endif /* %s */" % condition, file=wrapper)
|
||||
|
||||
# update xnnpack_wrapper_defs.bzl file under the same folder
|
||||
with open(os.path.join(os.path.dirname(__file__), "xnnpack_wrapper_defs.bzl"), 'w') as wrapper_defs:
|
||||
print('"""', file=wrapper_defs)
|
||||
print(BANNER, file=wrapper_defs)
|
||||
print('"""', file=wrapper_defs)
|
||||
for name in WRAPPER_SRC_NAMES:
|
||||
print(name + ' = [', file=wrapper_defs)
|
||||
for file_name in sources[name]:
|
||||
print(' "xnnpack_wrappers/{}",'.format(file_name), file=wrapper_defs)
|
||||
print(']\n', file=wrapper_defs)
|
||||
|
||||
# update xnnpack_src_defs.bzl file under the same folder
|
||||
with open(os.path.join(os.path.dirname(__file__), "xnnpack_src_defs.bzl"), 'w') as src_defs:
|
||||
print('"""', file=src_defs)
|
||||
print(BANNER, file=src_defs)
|
||||
print('"""', file=src_defs)
|
||||
for name in SRC_NAMES:
|
||||
print(name + ' = [', file=src_defs)
|
||||
for file_name in sources[name]:
|
||||
print(' "XNNPACK/src/{}",'.format(file_name), file=src_defs)
|
||||
print(']\n', file=src_defs)
|
||||
|
||||
|
||||
def main(argv):
|
||||
if argv is None or len(argv) == 0:
|
||||
gen_wrappers(".")
|
||||
else:
|
||||
gen_wrappers(argv[0])
|
||||
|
||||
# the first argument is the path of XNNPACK's parent folder
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv[1:])
|
||||
|
Reference in New Issue
Block a user