forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleef.BUILD
488 lines (450 loc) · 12.2 KB
/
sleef.BUILD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@//third_party:sleef.bzl", "sleef_cc_library")
SLEEF_COPTS = [
"-DHAVE_MALLOC_USABLE_SIZE=1",
"-DHAVE_MMAP=1",
"-DHAVE_SHM_OPEN=1",
"-DHAVE_SHM_UNLINK=1",
"-DIDEEP_USE_MKL",
"-DDNNL_CPU_RUNTIME=TBB",
"-DONNX_ML=1",
"-DONNX_NAMESPACE=onnx",
"-D_FILE_OFFSET_BITS=64",
"-ffp-contract=off",
"-fno-math-errno",
"-fno-trapping-math",
"-DCAFFE2_USE_GLOO",
"-std=gnu99",
]
SLEEF_COMMON_TARGET_COPTS = [
"-DSLEEF_STATIC_LIBS=1",
"-DENABLE_ALIAS=1",
]
SLEEF_PRIVATE_HEADERS = glob([
"build/include/*.h",
"src/arch/*.h",
"src/common/*.h",
"src/libm/*.h",
"src/libm/include/*.h",
])
SLEEF_PUBLIC_HEADERS = [
":sleef_h",
]
SLEEF_PRIVATE_INCLUDES = [
"-Iexternal/sleef/src/arch",
"-Iexternal/sleef/src/common",
]
SLEEF_PUBLIC_INCLUDES = [
"build/include",
]
SLEEF_VISIBILITY = [
"//visibility:public",
]
cc_binary(
name = "mkalias",
srcs = [
"src/libm/funcproto.h",
"src/libm/mkalias.c",
],
)
genrule(
name = "alias_avx512f_h",
outs = ["alias_avx512f.h"],
cmd = "{ " + "; ".join([
"$(location :mkalias) -16 __m512 __m512i e avx512f",
"$(location :mkalias) 8 __m512d __m256i e avx512f",
]) + "; } > $@",
tools = [":mkalias"],
)
cc_binary(
name = "mkdisp",
srcs = [
"src/libm/funcproto.h",
"src/libm/mkdisp.c",
],
copts = SLEEF_COPTS,
)
genrule(
name = "dispavx_c",
srcs = ["src/libm/dispavx.c.org"],
outs = ["dispavx.c"],
cmd = "{ cat $(location src/libm/dispavx.c.org); $(location :mkdisp) 4 8 __m256d __m256 __m128i avx fma4 avx2; } > $@",
tools = [":mkdisp"],
)
genrule(
name = "dispsse_c",
srcs = ["src/libm/dispsse.c.org"],
outs = ["dispsse.c"],
cmd = "{ cat $(location src/libm/dispsse.c.org); $(location :mkdisp) 2 4 __m128d __m128 __m128i sse2 sse4 avx2128; } > $@",
tools = [":mkdisp"],
)
cc_binary(
name = "mkrename",
srcs = [
"src/libm/funcproto.h",
"src/libm/mkrename.c",
],
)
genrule(
name = "renameavx_h",
outs = ["renameavx.h"],
cmd = "$(location :mkrename) cinz_ 4 8 avx > $@",
tools = [":mkrename"],
)
genrule(
name = "renameavx2_h",
outs = ["renameavx2.h"],
cmd = "$(location :mkrename) finz_ 4 8 avx2 > $@",
tools = [":mkrename"],
)
genrule(
name = "renameavx2128_h",
outs = ["renameavx2128.h"],
cmd = "$(location :mkrename) finz_ 2 4 avx2128 > $@",
tools = [":mkrename"],
)
genrule(
name = "renameavx512f_h",
outs = ["renameavx512f.h"],
cmd = "$(location :mkrename) finz_ 8 16 avx512f > $@",
tools = [":mkrename"],
)
genrule(
name = "renameavx512fnofma_h",
outs = ["renameavx512fnofma.h"],
cmd = "$(location :mkrename) cinz_ 8 16 avx512fnofma > $@",
tools = [":mkrename"],
)
genrule(
name = "renamefma4_h",
outs = ["renamefma4.h"],
cmd = "$(location :mkrename) finz_ 4 8 fma4 > $@",
tools = [":mkrename"],
)
genrule(
name = "renamepurec_scalar_h",
outs = ["renamepurec_scalar.h"],
cmd = "$(location :mkrename) cinz_ 1 1 purec > $@",
tools = [":mkrename"],
)
genrule(
name = "renamepurecfma_scalar_h",
outs = ["renamepurecfma_scalar.h"],
cmd = "$(location :mkrename) finz_ 1 1 purecfma > $@",
tools = [":mkrename"],
)
genrule(
name = "renamesse2_h",
outs = ["renamesse2.h"],
cmd = "$(location :mkrename) cinz_ 2 4 sse2 > $@",
tools = [":mkrename"],
)
genrule(
name = "renamesse4_h",
outs = ["renamesse4.h"],
cmd = "$(location :mkrename) cinz_ 2 4 sse4 > $@",
tools = [":mkrename"],
)
genrule(
name = "sleef_h",
srcs = [
"src/libm/sleeflibm_header.h.org.in",
"src/libm/sleeflibm_footer.h.org",
],
outs = ["build/include/sleef.h"],
cmd = "{ " + "; ".join([
"cat $(location src/libm/sleeflibm_header.h.org.in)",
"$(location :mkrename) cinz_ 2 4 __m128d __m128 __m128i __m128i __SSE2__",
"$(location :mkrename) cinz_ 2 4 __m128d __m128 __m128i __m128i __SSE2__ sse2",
"$(location :mkrename) cinz_ 2 4 __m128d __m128 __m128i __m128i __SSE2__ sse4",
"$(location :mkrename) cinz_ 4 8 __m256d __m256 __m128i \"struct { __m128i x, y; }\" __AVX__",
"$(location :mkrename) cinz_ 4 8 __m256d __m256 __m128i \"struct { __m128i x, y; }\" __AVX__ avx",
"$(location :mkrename) finz_ 4 8 __m256d __m256 __m128i \"struct { __m128i x, y; }\" __AVX__ fma4",
"$(location :mkrename) finz_ 4 8 __m256d __m256 __m128i __m256i __AVX__ avx2",
"$(location :mkrename) finz_ 2 4 __m128d __m128 __m128i __m128i __SSE2__ avx2128",
"$(location :mkrename) finz_ 8 16 __m512d __m512 __m256i __m512i __AVX512F__",
"$(location :mkrename) finz_ 8 16 __m512d __m512 __m256i __m512i __AVX512F__ avx512f",
"$(location :mkrename) cinz_ 8 16 __m512d __m512 __m256i __m512i __AVX512F__ avx512fnofma",
"$(location :mkrename) cinz_ 1 1 double float int32_t int32_t __STDC__ purec",
"$(location :mkrename) finz_ 1 1 double float int32_t int32_t FP_FAST_FMA purecfma",
"cat $(location src/libm/sleeflibm_footer.h.org)",
]) + "; } > $@",
tools = [":mkrename"],
)
cc_library(
name = "sleef",
srcs = [
"src/libm/rempitab.c",
"src/libm/sleefdp.c",
"src/libm/sleefld.c",
"src/libm/sleefqp.c",
"src/libm/sleefsp.c",
],
hdrs = SLEEF_PUBLIC_HEADERS,
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLEFLOAT128=1",
"-Wno-unused-result",
],
includes = SLEEF_PUBLIC_INCLUDES,
# -lgcc resolves
# U __addtf3
# U __eqtf2
# U __fixtfdi
# U __floatditf
# U __gttf2
# U __lttf2
# U __multf3
# U __subtf3
# in bazel-bin/external/sleef/_objs/sleef/sleefqp.pic.o
linkopts = [
"-lgcc",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
# The purpose of the lists in deps is to keep related pairs of
# libraries together. In particular, each pair that contains a *det*
# library originates with a sleef_cc_library().
deps = [
":common",
":dispavx",
":dispsse",
] + [
":sleefavx",
":sleefdetavx",
] + [
":sleefavx2",
":sleefdetavx2",
] + [
":sleefavx2128",
":sleefdetavx2128",
] + [
":sleefavx512f",
":sleefdetavx512f",
] + [
":sleefavx512fnofma",
":sleefdetavx512fnofma",
] + [
":sleeffma4",
":sleefdetfma4",
] + [
":sleefsse2",
":sleefdetsse2",
] + [
":sleefsse4",
":sleefdetsse4",
] + [
":sleefpurec_scalar",
":sleefdetpurec_scalar",
] + [
":sleefpurecfma_scalar",
":sleefdetpurecfma_scalar",
],
alwayslink = True,
)
cc_library(
name = "common",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/common/common.c",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + [
"-Wno-unused-result",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
cc_library(
name = "dispavx",
srcs = SLEEF_PRIVATE_HEADERS + SLEEF_PUBLIC_HEADERS + [
":dispavx_c",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DENABLE_AVX2=1",
"-DENABLE_FMA4=1",
"-mavx",
],
includes = SLEEF_PUBLIC_INCLUDES,
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
cc_library(
name = "dispsse",
srcs = SLEEF_PRIVATE_HEADERS + SLEEF_PUBLIC_HEADERS + [
":dispsse_c",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DENABLE_AVX2=1",
"-DENABLE_FMA4=1",
"-msse2",
],
includes = SLEEF_PUBLIC_INCLUDES,
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefavx512f",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":alias_avx512f_h",
":renameavx512f_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DALIAS_NO_EXT_SUFFIX=\\\"alias_avx512f.h\\\"",
"-DENABLE_AVX512F=1",
"-mavx512f",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefavx512fnofma",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renameavx512fnofma_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_AVX512FNOFMA=1",
"-mavx512f",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefavx",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renameavx_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_AVX=1",
"-mavx",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefavx2",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renameavx2_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_AVX2=1",
"-mavx2",
"-mfma",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefavx2128",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renameavx2128_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_AVX2128=1",
"-mavx2",
"-mfma",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleeffma4",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renamefma4_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_FMA4=1",
"-mfma4",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefsse2",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renamesse2_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_SSE2=1",
"-msse2",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefsse4",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renamesse4_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_SSE4=1",
"-msse4.1",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefpurec_scalar",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renamepurec_scalar_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_PUREC_SCALAR=1",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)
sleef_cc_library(
name = "sleefpurecfma_scalar",
srcs = SLEEF_PRIVATE_HEADERS + [
"src/libm/sleefsimddp.c",
"src/libm/sleefsimdsp.c",
":renamepurecfma_scalar_h",
],
copts = SLEEF_PRIVATE_INCLUDES + SLEEF_COPTS + SLEEF_COMMON_TARGET_COPTS + [
"-DDORENAME=1",
"-DENABLE_PURECFMA_SCALAR=1",
"-mavx2",
"-mfma",
],
linkstatic = True,
visibility = SLEEF_VISIBILITY,
alwayslink = True,
)