Skip to content

Commit 0384780

Browse files
committed
Add all bzl files per D36874458
1 parent 1f53d03 commit 0384780

34 files changed

+3888
-0
lines changed

android/build_defs.bzl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("@fbsource//tools/build_defs:fb_xplat_cxx_test.bzl", "fb_xplat_cxx_test")
2+
load("@fbsource//xplat/caffe2:pt_defs.bzl", "get_build_from_deps_query", "pt_operator_registry")
3+
4+
DEFAULT_PT_OP_DEPS = [
5+
"fbsource//xplat/caffe2:torch_mobile_ops_full_dev",
6+
]
7+
8+
def pt_xplat_cxx_test(name, deps = [], pt_op_deps = DEFAULT_PT_OP_DEPS, **kwargs):
9+
code_gen_lib = []
10+
if get_build_from_deps_query():
11+
lib_name = name + "_lib"
12+
pt_operator_registry(lib_name, preferred_linkage = "static", template_select = False, deps = pt_op_deps)
13+
code_gen_lib = [":" + lib_name]
14+
deps = deps + code_gen_lib
15+
fb_xplat_cxx_test(
16+
name = name,
17+
deps = deps,
18+
**kwargs
19+
)

c10/c10_defs.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
load("@fbsource//tools/build_defs:expect.bzl", "expect")
2+
load(
3+
"@fbsource//tools/build_defs/apple:build_mode_defs.bzl",
4+
"is_production_build",
5+
)
6+
7+
###############################################################################
8+
# Check if we need to strip glog.
9+
def _get_strip_glog_config():
10+
c2_strip_glog = native.read_config("caffe2", "strip_glog", "1")
11+
expect(
12+
c2_strip_glog in ("0", "1"),
13+
c2_strip_glog,
14+
)
15+
return bool(int(c2_strip_glog))
16+
17+
# For iOS production builds (and all Android builds), strip GLOG logging to
18+
# save size. We can disable by setting caffe2.strip_glog=0 in .buckconfig.local.
19+
def get_fbobjc_strip_glog_flags():
20+
if is_production_build() or _get_strip_glog_config():
21+
return ["-UGOOGLE_STRIP_LOG", "-DGOOGLE_STRIP_LOG=3"]
22+
else:
23+
return ["-UGOOGLE_STRIP_LOG"]
24+
25+
def get_fbandroid_strip_glog_flags():
26+
if _get_strip_glog_config():
27+
return ["-UGOOGLE_STRIP_LOG", "-DGOOGLE_STRIP_LOG=1"]
28+
else:
29+
return []

c10/defs_hip.bzl

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
load("@bazel_skylib//lib:paths.bzl", "paths")
2+
load("//caffe2:defs_hip.bzl", "get_hip_file_path")
3+
4+
gpu_file_extensions = [".cu", ".c", ".cc", ".cpp"]
5+
gpu_header_extensions = [".cuh", ".h", ".hpp"]
6+
7+
def is_test_files(filepath):
8+
if filepath.startswith("test"):
9+
return True
10+
else:
11+
return False
12+
13+
def get_c10_hip_srcs():
14+
gpu_file_pattern = [
15+
base + suffix
16+
for base in c10_includes
17+
for suffix in gpu_file_extensions
18+
]
19+
native_gpu_files = native.glob(gpu_file_pattern)
20+
21+
gpu_files = []
22+
hip_files = []
23+
for name in native_gpu_files:
24+
# exclude the test folder
25+
if is_test_files(name):
26+
continue
27+
28+
gpu_files.append(name)
29+
hip_file_name = get_hip_file_path(paths.join("cuda/", name))
30+
hip_files.append(hip_file_name)
31+
32+
# there will be some native hip files that needs suffix changed
33+
native_hip_pattern = [
34+
"hip/**/*.hip",
35+
]
36+
native_hip_files = native.glob(native_hip_pattern)
37+
38+
gpu_files += native_hip_files
39+
hip_files += native_hip_files
40+
41+
# we run hipify script under the caffe2 folder; therefore we need to
42+
# prepend c10 to the path so that buck can find the hipified file
43+
real_hip_files = []
44+
for filename in hip_files:
45+
real_hip_files.append(paths.join("c10", filename))
46+
47+
# return the src and output_gen files
48+
return gpu_files, real_hip_files
49+
50+
def get_c10_hip_headers():
51+
gpu_file_pattern = [
52+
base + suffix
53+
for base in c10_includes
54+
for suffix in gpu_header_extensions
55+
]
56+
native_gpu_files = native.glob(gpu_file_pattern)
57+
58+
# store the original
59+
gpu_files = []
60+
hip_files = []
61+
for name in native_gpu_files:
62+
if is_test_files(name):
63+
continue
64+
65+
gpu_files.append(name)
66+
hip_file_name = get_hip_file_path(paths.join("cuda/", name))
67+
hip_files.append(hip_file_name)
68+
69+
# there will be some native hip files that needs suffix changed
70+
native_hip_pattern = [
71+
"hip/**/*" + suffix
72+
for suffix in gpu_header_extensions
73+
]
74+
native_hip_files = native.glob(native_hip_pattern)
75+
76+
gpu_files += native_hip_files
77+
hip_files += native_hip_files
78+
79+
# we run hipify script under the caffe2 folder; therefore we need to
80+
# prepend c10 to the path so that buck can find the hipified file
81+
real_hip_files = []
82+
for filename in hip_files:
83+
real_hip_files.append(paths.join("c10", filename))
84+
85+
# return the src and output_gen files
86+
return gpu_files, real_hip_files
87+
88+
def get_c10_hip_test_files():
89+
gpu_file_pattern = [
90+
base + suffix
91+
for base in c10_includes
92+
for suffix in gpu_file_extensions
93+
]
94+
native_gpu_files = native.glob(gpu_file_pattern)
95+
96+
# store the original
97+
gpu_files = []
98+
hip_files = []
99+
for name in native_gpu_files:
100+
if not is_test_files(name):
101+
continue
102+
103+
gpu_files.append(name)
104+
hip_file_name = get_hip_file_path(paths.join("cuda/", name))
105+
hip_files.append(hip_file_name)
106+
107+
# there will be some native hip files that needs suffix changed
108+
native_hip_pattern = [
109+
"hip/test/**/*" + suffix
110+
for suffix in gpu_header_extensions
111+
]
112+
native_hip_files = native.glob(native_hip_pattern)
113+
114+
gpu_files += native_hip_files
115+
hip_files += native_hip_files
116+
117+
# we run hipify script under the caffe2 folder; therefore we need to
118+
# prepend c10 to the path so that buck can find the hipified file
119+
real_hip_files = []
120+
for filename in hip_files:
121+
real_hip_files.append(paths.join("c10", filename))
122+
123+
# return the src and output_gen files
124+
return gpu_files, real_hip_files
125+
126+
c10_includes = ["**/*"]

0 commit comments

Comments
 (0)