• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Build file for OpenMP library that is part of llvm
2
3load(
4    "@org_tensorflow//tensorflow:tensorflow.bzl",
5    "if_linux_x86_64",
6    "if_macos",
7    "if_windows",
8)
9load(
10    "@org_tensorflow//third_party/llvm_openmp:cmake_vars.bzl",
11    "cmake_var_string",
12    "expand_cmake_vars",
13)
14load(
15    "@org_tensorflow//third_party/llvm_openmp:openmp.bzl",
16    "dict_add",
17    "libiomp5_cc_binary",
18)
19load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
20
21package(
22    default_visibility = [
23        "//visibility:public",
24    ],
25)
26
27exports_files(["LICENSE.txt"])
28
29py_binary(
30    name = "expand_cmake_vars",
31    srcs = ["expand_cmake_vars.py"],
32    srcs_version = "PY3",
33    visibility = [
34        "@llvm_openmp//:__subpackages__",
35    ],
36)
37
38kmp_i18n_os_type = select({
39    "@org_tensorflow//tensorflow:windows": "win",
40    "//conditions:default": "lin",
41})
42
43genrule(
44    name = "kmp_i18n_id",
45    srcs = [
46        "runtime/tools/message-converter.pl",
47        "runtime/tools/lib/tools.pm",
48        "runtime/src/i18n/en_US.txt",
49    ],
50    outs = ["include/kmp_i18n_id.inc"],
51    cmd = "perl $(location runtime/tools/message-converter.pl) --os=" + kmp_i18n_os_type + " --prefix=kmp_i18n --enum=$@  $(location runtime/src/i18n/en_US.txt)",
52)
53
54genrule(
55    name = "kmp_i18n_default",
56    srcs = [
57        "runtime/tools/message-converter.pl",
58        "runtime/tools/lib/tools.pm",
59        "runtime/src/i18n/en_US.txt",
60    ],
61    outs = ["include/kmp_i18n_default.inc"],
62    cmd = "perl $(location runtime/tools/message-converter.pl) --os=" + kmp_i18n_os_type + " --prefix=kmp_i18n --default=$@ $(location runtime/src/i18n/en_US.txt)",
63)
64
65genrule(
66    name = "generate_def",
67    srcs = [
68        "runtime/tools/generate-def.pl",
69    ],
70    outs = ["omp_dll.def"],
71    cmd = "perl $(location runtime/tools/generate-def.pl) -D arch_32e -D msvc_compat -D norm -o omp_dll.tmp external/llvm_openmp/runtime/src/dllexports; mv omp_dll.tmp $@",
72)
73
74# Bazel doesn't accept .txt as an input, rename the ldscript to .inc to workaround.
75genrule(
76    name = "ldscript",
77    srcs = ["runtime/src/exports_so.txt"],
78    outs = ["exports_so.inc"],
79    cmd = "cp $(location runtime/src/exports_so.txt) $@",
80)
81
82genrule(
83    name = "openmp_asm",
84    srcs = [
85        "runtime/src/z_Windows_NT-586_asm.asm",
86    ],
87    outs = [
88        "z_Windows_NT-586_asm.S",
89    ],
90    cmd = "cp $(location runtime/src/z_Windows_NT-586_asm.asm) $@",
91    visibility = ["//visibility:public"],
92)
93
94# Common Cmake vars to expand.
95omp_vars = {
96    "LIBOMP_ENABLE_SHARED": 1,
97    "LIBOMP_LEGAL_ARCH": "Intel(R) 64",
98    "LIBOMP_LIB_FILE": "libiomp5",
99    "LIBOMP_VERSION_MAJOR": 5,
100    "LIBOMP_VERSION_MINOR": 0,
101}
102
103# Linux Cmake vars to expand.
104omp_vars_linux = {
105    "LIBOMP_USE_VERSION_SYMBOLS": 1,
106    "LIBOMP_HAVE_WEAK_ATTRIBUTE": 1,
107    "LIBOMP_USE_ADAPTIVE_LOCKS": 1,
108    "LIBOMP_ENABLE_ASSERTIONS": 1,
109}
110
111# Windows Cmake vars to expand.
112omp_vars_win = {
113    "MSVC": 1,
114}
115
116omp_all_cmake_vars = select({
117    "@org_tensorflow//tensorflow:windows": cmake_var_string(
118        dict_add(
119            omp_vars,
120            omp_vars_win,
121        ),
122    ),
123    "//conditions:default": cmake_var_string(
124        dict_add(
125            omp_vars,
126            omp_vars_linux,
127        ),
128    ),
129})
130
131expand_cmake_vars(
132    name = "config_kmp",
133    src = "runtime/src/kmp_config.h.cmake",
134    cmake_vars = omp_all_cmake_vars,
135    dst = "include/kmp_config.h",
136)
137
138expand_cmake_vars(
139    name = "config_omp",
140    src = "runtime/src/include/omp.h.var",
141    cmake_vars = omp_all_cmake_vars,
142    dst = "include/omp.h",
143)
144
145headers = [
146    "runtime/src/kmp_affinity.h",
147    "runtime/src/kmp_atomic.h",
148    "runtime/src/kmp_debug.h",
149    "runtime/src/kmp_dispatch_hier.h",
150    "runtime/src/kmp_dispatch.h",
151    "runtime/src/kmp_environment.h",
152    "runtime/src/kmp_error.h",
153    "runtime/src/kmp_ftn_entry.h",
154    "runtime/src/kmp_ftn_os.h",
155    "runtime/src/kmp_i18n.h",
156    "runtime/src/kmp_io.h",
157    "runtime/src/kmp_itt.h",
158    "runtime/src/kmp_itt.inl",
159    "runtime/src/kmp_lock.h",
160    "runtime/src/kmp_os.h",
161    "runtime/src/kmp_platform.h",
162    "runtime/src/kmp_safe_c_api.h",
163    "runtime/src/kmp_settings.h",
164    "runtime/src/kmp_stats.h",
165    "runtime/src/kmp_str.h",
166    "runtime/src/kmp_taskdeps.h",
167    "runtime/src/kmp_version.h",
168    "runtime/src/kmp_wait_release.h",
169    "runtime/src/kmp_wrapper_getpid.h",
170    "runtime/src/kmp_wrapper_malloc.h",
171    "runtime/src/kmp.h",
172    "runtime/src/ompt-specific.h",
173    "runtime/src/tsan_annotations.h",
174]
175
176cppsources = [
177    "runtime/src/kmp_alloc.cpp",
178    "runtime/src/kmp_atomic.cpp",
179    "runtime/src/kmp_csupport.cpp",
180    "runtime/src/kmp_debug.cpp",
181    "runtime/src/kmp_itt.cpp",
182    "runtime/src/kmp_environment.cpp",
183    "runtime/src/kmp_error.cpp",
184    "runtime/src/kmp_global.cpp",
185    "runtime/src/kmp_i18n.cpp",
186    "runtime/src/kmp_io.cpp",
187    "runtime/src/kmp_runtime.cpp",
188    "runtime/src/kmp_settings.cpp",
189    "runtime/src/kmp_str.cpp",
190    "runtime/src/kmp_tasking.cpp",
191    "runtime/src/kmp_threadprivate.cpp",
192    "runtime/src/kmp_utility.cpp",
193    "runtime/src/kmp_barrier.cpp",
194    "runtime/src/kmp_wait_release.cpp",
195    "runtime/src/kmp_affinity.cpp",
196    "runtime/src/kmp_dispatch.cpp",
197    "runtime/src/kmp_lock.cpp",
198    "runtime/src/kmp_sched.cpp",
199    "runtime/src/kmp_taskdeps.cpp",
200    "runtime/src/kmp_cancel.cpp",
201    "runtime/src/kmp_ftn_cdecl.cpp",
202    "runtime/src/kmp_ftn_extra.cpp",
203    "runtime/src/kmp_version.cpp",
204]
205
206srcdeps = [
207    ":config_kmp",
208    ":config_omp",
209    ":kmp_i18n_id",
210    ":kmp_i18n_default",
211]
212
213common_includes = [
214    "runtime/src/",
215    "include/",
216]
217
218# Expand libiomp build rule based on platform.
219if_linux_x86_64(a = libiomp5_cc_binary(
220    "libiomp5.so",
221    cppsources,
222    srcdeps + headers,
223    common_includes,
224))
225
226if_macos(a = libiomp5_cc_binary(
227    "libiomp5.dylib",
228    cppsources,
229    srcdeps + headers,
230    common_includes,
231))
232
233if_windows(a = libiomp5_cc_binary(
234    "libiomp5md.dll",
235    cppsources,
236    srcdeps + headers,
237    common_includes,
238))
239
240bzl_library(
241    name = "openmp_bzl",
242    srcs = ["openmp.bzl"],
243)
244