Skip to content

Commit 8a45ef2

Browse files
linbinyupytorchmergebot
authored andcommitted
[5] move XNNPACK to shared BUCK build (pytorch#80209)
Summary: Reland D36529332 (pytorch@b8b46f9) with shared buck build structure. Test Plan: buck build //xplat/third-party/XNNPACK:XNNPACK Sandcastle Differential Revision: D37407609 Pull Request resolved: pytorch#80209 Approved by: https://github.com/kimishpatel
1 parent 17ee5de commit 8a45ef2

7 files changed

+3391
-460
lines changed

.buckconfig.oss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
[cxx]
1616
cxxflags = -std=c++17
1717
should_remap_host_platform = true
18+
cpp = /usr/bin/clang
19+
cc = /usr/bin/clang
20+
cxx = /usr/bin/clang++
21+
cxxpp = /usr/bin/clang++
22+
ld = /usr/bin/clang++
1823

1924
[project]
2025
default_flavors_mode=all

buckbuild.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ C10 = "//c10:c10" if IS_OSS else "//xplat/caffe2/c10:c10"
122122

123123
# a dictionary maps third party library name to fbsource and oss target
124124
THIRD_PARTY_LIBS = {
125-
"FP16": ["//third-party/FP16:FP16", "//third_party:FP16"],
126-
"FXdiv": ["//third-party/FXdiv:FXdiv", "//third_party:FXdiv"],
125+
"FP16": ["//xplat/third-party/FP16:FP16", "//third_party:FP16"],
126+
"FXdiv": ["//xplat/third-party/FXdiv:FXdiv", "//third_party:FXdiv"],
127127
"XNNPACK": ["//xplat/third-party/XNNPACK:XNNPACK", "//third_party:XNNPACK"],
128-
"clog": ["//third-party/clog:clog", "//third_party:clog"],
128+
"clog": ["//xplat/third-party/clog:clog", "//third_party:clog"],
129129
"cpuinfo": ["//third-party/cpuinfo:cpuinfo", "//third_party:cpuinfo"],
130130
"flatbuffers-api": ["//third-party/flatbuffers:flatbuffers-api", "//third_party:flatbuffers-api"],
131131
"flatc": ["//third-party/flatbuffers:flatc", "//third_party:flatc"],
@@ -134,8 +134,8 @@ THIRD_PARTY_LIBS = {
134134
"kineto": ["//xplat/kineto/libkineto:libkineto", "//third_party:libkineto"],
135135
"omp": ["//xplat/third-party/linker_lib:omp", "//third_party:no-op"],
136136
"psimd": ["//third-party/psimd:psimd", "//third_party:psimd"],
137-
"pthreadpool": ["//third-party/pthreadpool:pthreadpool", "//third_party:pthreadpool"],
138-
"pthreadpool_header": ["//third-party/pthreadpool:pthreadpool_header", "//third_party:pthreadpool_header"],
137+
"pthreadpool": ["//xplat/third-party/pthreadpool:pthreadpool", "//third_party:pthreadpool"],
138+
"pthreadpool_header": ["//xplat/third-party/pthreadpool:pthreadpool_header", "//third_party:pthreadpool_header"],
139139
"pyyaml": ["//third-party/pyyaml:pyyaml", "//third_party:pyyaml"],
140140
"rt": ["//xplat/third-party/linker_lib:rt", "//third_party:rt"],
141141
"ruy": ["//third-party/ruy:ruy_xplat_lib", "//third_party:ruy_lib"],

third_party/BUCK.oss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
load("//third_party:glog.buck.bzl", "define_glog")
22
load("//third_party:xnnpack.buck.bzl", "define_xnnpack")
33
load("//third_party:kineto.buck.bzl", "define_kineto")
4+
load("//:buckbuild.bzl", "third_party")
45

56
define_glog()
67

7-
define_xnnpack()
8+
define_xnnpack(third_party)
89

910
define_kineto()
1011

third_party/generate-xnnpack-wrappers.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import print_function
44
import collections
55
import os
6+
import sys
67

78
BANNER = "Auto-generated by generate-wrappers.py script. Do not modify"
89
WRAPPER_SRC_NAMES = {
@@ -53,9 +54,9 @@
5354
"PROD_AVX512SKX_MICROKERNEL_SRCS",
5455
]
5556

56-
def update_sources():
57+
def update_sources(xnnpack_path):
5758
sources = collections.defaultdict(list)
58-
with open("./XNNPACK/CMakeLists.txt") as cmake:
59+
with open(os.path.join(xnnpack_path, "XNNPACK/CMakeLists.txt")) as cmake:
5960
lines = cmake.readlines()
6061
i = 0
6162
while i < len(lines):
@@ -74,17 +75,16 @@ def update_sources():
7475
sources[name].append(value[4:])
7576
else:
7677
i += 1
77-
print(sources)
7878
return sources
7979

80-
if __name__ == "__main__":
80+
def gen_wrappers(xnnpack_path):
8181
xnnpack_sources = collections.defaultdict(list)
82-
sources = update_sources()
82+
sources = update_sources(xnnpack_path)
8383
for name in WRAPPER_SRC_NAMES:
8484
xnnpack_sources[WRAPPER_SRC_NAMES[name]].extend(sources[name])
8585
for condition, filenames in xnnpack_sources.items():
8686
for filename in filenames:
87-
filepath = os.path.join("XNNPACK/wrappers", filename)
87+
filepath = os.path.join(xnnpack_path, "xnnpack_wrappers", filename)
8888
if not os.path.isdir(os.path.dirname(filepath)):
8989
os.makedirs(os.path.dirname(filepath))
9090
with open(filepath, "w") as wrapper:
@@ -102,3 +102,38 @@ def update_sources():
102102
print("#if %s" % condition, file=wrapper)
103103
print("#include <%s>" % filename, file=wrapper)
104104
print("#endif /* %s */" % condition, file=wrapper)
105+
106+
# update xnnpack_wrapper_defs.bzl file under the same folder
107+
with open(os.path.join(os.path.dirname(__file__), "xnnpack_wrapper_defs.bzl"), 'w') as wrapper_defs:
108+
print('"""', file=wrapper_defs)
109+
print(BANNER, file=wrapper_defs)
110+
print('"""', file=wrapper_defs)
111+
for name in WRAPPER_SRC_NAMES:
112+
print('\n' + name + ' = [', file=wrapper_defs)
113+
for file_name in sources[name]:
114+
print(' "xnnpack_wrappers/{}",'.format(file_name), file=wrapper_defs)
115+
print(']', file=wrapper_defs)
116+
117+
# update xnnpack_src_defs.bzl file under the same folder
118+
with open(os.path.join(os.path.dirname(__file__), "xnnpack_src_defs.bzl"), 'w') as src_defs:
119+
print('"""', file=src_defs)
120+
print(BANNER, file=src_defs)
121+
print('"""', file=src_defs)
122+
for name in SRC_NAMES:
123+
print('\n' + name + ' = [', file=src_defs)
124+
for file_name in sources[name]:
125+
print(' "XNNPACK/src/{}",'.format(file_name), file=src_defs)
126+
print(']', file=src_defs)
127+
128+
129+
def main(argv):
130+
if argv is None or len(argv) == 0:
131+
gen_wrappers(".")
132+
else:
133+
gen_wrappers(argv[0])
134+
135+
# The first argument is the place where the "xnnpack_wrappers" folder will be created.
136+
# Run it without arguments will generate "xnnpack_wrappers" in the current path.
137+
# The two .bzl files will always be generated in the current path.
138+
if __name__ == "__main__":
139+
main(sys.argv[1:])

0 commit comments

Comments
 (0)