-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy path0001-Compile-BLIS-to-WebAssembly.patch
More file actions
348 lines (328 loc) · 13.1 KB
/
Copy path0001-Compile-BLIS-to-WebAssembly.patch
File metadata and controls
348 lines (328 loc) · 13.1 KB
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
From 85aa27abe96e988adc8fdfbf61844bfd3307ccbf Mon Sep 17 00:00:00 2001
From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Date: Tue, 30 Jun 2026 06:06:59 +0530
Subject: [PATCH 1/3] Compile BLIS to WebAssembly
This is a squashed patch from https://github.com/agriyakhetarpal/blis/pull/1
and applied on top of the v2.1 release of BLIS. See the release notes at:
https://github.com/flame/blis/releases/tag/2.1
The patch adds support for compiling BLIS to WebAssembly using Emscripten.
The following changes have been made:
* Treat Emscripten vendor as Clang
* Generate compile rule for `obj/wasm32/config/wasm32`
* Rename ref kernel init function after wasm32 config
* Include `WASM32` in `INSERT_GENTCONF`
* Declare BLIS_ARCH_WASM32
* Compile with PIC for Pyodide shared module
* Add family and kernel definitions headers
---
config/wasm32/bli_cntx_init_wasm32.c | 40 +++++++++++++
config/wasm32/bli_family_wasm32.h | 38 +++++++++++++
config/wasm32/bli_kernel_defs_wasm32.h | 38 +++++++++++++
config/wasm32/make_defs.mk | 74 +++++++++++++++++++++++++
config_registry | 1 +
configure | 6 ++
frame/base/bli_arch.c | 7 +++
frame/include/bli_gentconf_macro_defs.h | 12 +++-
frame/include/bli_type_defs.h | 3 +
9 files changed, 218 insertions(+), 1 deletion(-)
create mode 100644 config/wasm32/bli_cntx_init_wasm32.c
create mode 100644 config/wasm32/bli_family_wasm32.h
create mode 100644 config/wasm32/bli_kernel_defs_wasm32.h
create mode 100644 config/wasm32/make_defs.mk
diff --git a/config/wasm32/bli_cntx_init_wasm32.c b/config/wasm32/bli_cntx_init_wasm32.c
new file mode 100644
index 00000000..bc0f86b9
--- /dev/null
+++ b/config/wasm32/bli_cntx_init_wasm32.c
@@ -0,0 +1,40 @@
+/*
+
+ BLIS
+ An object-based framework for developing high-performance BLAS-like
+ libraries.
+
+ Copyright (C) 2014, The University of Texas at Austin
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name(s) of the copyright holder(s) nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+#include "blis.h"
+
+void bli_cntx_init_wasm32( cntx_t* cntx )
+{
+ bli_cntx_init_wasm32_ref( cntx );
+}
diff --git a/config/wasm32/bli_family_wasm32.h b/config/wasm32/bli_family_wasm32.h
new file mode 100644
index 00000000..74dbaf22
--- /dev/null
+++ b/config/wasm32/bli_family_wasm32.h
@@ -0,0 +1,38 @@
+/*
+
+ BLIS
+ An object-based framework for developing high-performance BLAS-like
+ libraries.
+
+ Copyright (C) 2014, The University of Texas at Austin
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ - Neither the name(s) of the copyright holder(s) nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+// This file is intentionally left blank.No family-specific configuration
+// is needed for wasm32. We still need to provide this file so that the
+// build system can find it and compile it, but it does not need to
+// contain any code.
diff --git a/config/wasm32/bli_kernel_defs_wasm32.h b/config/wasm32/bli_kernel_defs_wasm32.h
new file mode 100644
index 00000000..73f8d513
--- /dev/null
+++ b/config/wasm32/bli_kernel_defs_wasm32.h
@@ -0,0 +1,38 @@
+/*
+
+ BLIS
+ An object-based framework for developing high-performance BLAS-like
+ libraries.
+
+ Copyright (C) 2014, The University of Texas at Austin
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are
+ met:
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other statements provided with the distribution.
+ - Neither the name(s) of the copyright holder(s) nor the names of its
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+*/
+
+// This file is intentionally left blank. No kernel overrides are needed
+// because we have used generic reference kernels for wasm32. We still need
+// to provide this file so that the build system can find it and compile it,
+// but it does not need to contain any code.
diff --git a/config/wasm32/make_defs.mk b/config/wasm32/make_defs.mk
new file mode 100644
index 00000000..27020ccb
--- /dev/null
+++ b/config/wasm32/make_defs.mk
@@ -0,0 +1,74 @@
+#
+#
+# BLIS
+# An object-based framework for developing high-performance BLAS-like
+# libraries.
+#
+# Copyright (C) 2014, The University of Texas at Austin
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+# - Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# - Neither the name(s) of the copyright holder(s) nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#
+
+# Declare the name of the current configuration and add it to the
+# running list of configurations included by common.mk.
+THIS_CONFIG := wasm32
+#CONFIGS_INCL += $(THIS_CONFIG)
+
+#
+# --- Determine the C compiler and related flags ---
+#
+
+# NOTE: configure normalises emcc to cc_vendor=clang, so CC_VENDOR=clang here.
+CPPROCFLAGS :=
+CMISCFLAGS :=
+CPICFLAGS := -fPIC
+CWARNFLAGS :=
+
+ifneq ($(DEBUG_TYPE),off)
+CDBGFLAGS := -g
+endif
+
+ifeq ($(DEBUG_TYPE),noopt)
+COPTFLAGS := -O0
+else
+COPTFLAGS := -O2
+endif
+
+# Flags specific to optimized kernels.
+CKOPTFLAGS := $(COPTFLAGS) -O3
+CKVECFLAGS := -msimd128
+
+# Flags specific to reference kernels.
+CROPTFLAGS := $(CKOPTFLAGS)
+ifeq ($(CC_VENDOR),clang)
+CRVECFLAGS := $(CKVECFLAGS) -funsafe-math-optimizations -ffp-contract=fast
+else
+CRVECFLAGS := $(CKVECFLAGS)
+endif
+
+# Store all of the variables here to new variables containing the
+# configuration name.
+$(eval $(call store-make-defs,$(THIS_CONFIG)))
diff --git a/config_registry b/config_registry
index 8c1f6f25..a865e51c 100644
--- a/config_registry
+++ b/config_registry
@@ -66,3 +66,4 @@ sifive_x280: sifive_x280
# Generic architectures.
generic: generic
+wasm32: wasm32/generic
diff --git a/configure b/configure
index 34f71e36..2ac56b49 100755
--- a/configure
+++ b/configure
@@ -1685,6 +1685,12 @@ get_compiler_version()
| grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.?[0-9]*' \
| { read -r first rest ; echo "${first}"; })
+ elif [ "${cc_vendor}" = "emcc" ]; then
+ cc_vendor="clang"
+ cc_version=$(echo "${vendor_string}" \
+ | grep -oE '[0-9]+\.[0-9]+\.?[0-9]*' \
+ | { read -r first rest ; echo "${first}"; })
+
elif [ "${cc_vendor}" = "NVIDIA" ]; then
cc_version=$(echo "${vendor_string}" \
diff --git a/frame/base/bli_arch.c b/frame/base/bli_arch.c
index f7a6d693..198dad26 100644
--- a/frame/base/bli_arch.c
+++ b/frame/base/bli_arch.c
@@ -319,6 +319,11 @@ arch_t bli_arch_query_id_impl( void )
id = BLIS_ARCH_SIFIVE_X280;
#endif
+ // WebAssembly.
+ #ifdef BLIS_FAMILY_WASM32
+ id = BLIS_ARCH_WASM32;
+ #endif
+
// Generic microarchitecture.
#ifdef BLIS_FAMILY_GENERIC
id = BLIS_ARCH_GENERIC;
@@ -386,6 +391,8 @@ static const char* config_name[ BLIS_NUM_ARCHS ] =
"sifive_x280",
+ "wasm32",
+
"generic"
};
diff --git a/frame/include/bli_gentconf_macro_defs.h b/frame/include/bli_gentconf_macro_defs.h
index 70414fb4..818a159c 100644
--- a/frame/include/bli_gentconf_macro_defs.h
+++ b/frame/include/bli_gentconf_macro_defs.h
@@ -236,6 +236,14 @@
#define INSERT_GENTCONF_GENERIC
#endif
+// -- WebAssembly architectures ------------------------------------------------
+
+#ifdef BLIS_CONFIG_WASM32
+#define INSERT_GENTCONF_WASM32 GENTCONF( WASM32, wasm32 )
+#else
+#define INSERT_GENTCONF_WASM32
+#endif
+
// -- configuration-specific macro --
@@ -282,7 +290,9 @@ INSERT_GENTCONF_RV64IV \
\
INSERT_GENTCONF_SIFIVE_X280 \
\
-INSERT_GENTCONF_GENERIC
+INSERT_GENTCONF_GENERIC \
+\
+INSERT_GENTCONF_WASM32
#endif
diff --git a/frame/include/bli_type_defs.h b/frame/include/bli_type_defs.h
index 8fe8e5ed..a005bd97 100644
--- a/frame/include/bli_type_defs.h
+++ b/frame/include/bli_type_defs.h
@@ -1009,6 +1009,9 @@ typedef enum arch_e
// SiFive
BLIS_ARCH_SIFIVE_X280,
+ // WebAssembly
+ BLIS_ARCH_WASM32,
+
// Generic architecture/configuration
BLIS_ARCH_GENERIC,
--
2.50.1 (Apple Git-155)