-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpresentation.txt
287 lines (182 loc) · 7.9 KB
/
presentation.txt
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
____ __ ________ ______ ___
/ __ )/ /___ _____ ___ / ____/ / / / __ \/ |
/ __ / / __ `/_ / / _ \ / / / / / / / / / /| |
/ /_/ / / /_/ / / /_/ __/ / /___/ /_/ / /_/ / ___ |
/_____/_/\__,_/ /___/\___/ \____/\____/_____/_/ |_|
Jules Pénuchot
- Intern @ Stellar Group (LSU, Baton Rouge, LA, USA) with Dr. Hartmut Kaiser
* Blaze CUDA (https://github.com/stellar-group/blaze_cuda)
- Intern @ Parallel Systems (LRI, Orsay, France) with Dr. Joel Falcou
* 2017 - Generic programming: SIMD optimization
* 2018 - Abstraction on parallel runtimes (StarPU)
.01/13
____ __ ________ ______ ___ ___
/ __ )/ /___ _____ ___ / ____/ / / / __ \/ |/__ \
/ __ / / __ `/_ / / _ \ / / / / / / / / / /| | / _/
/ /_/ / / /_/ / / /_/ __/ / /___/ /_/ / /_/ / ___ |/_/
/_____/_/\__,_/ /___/\___/ \____/\____/_____/_/ |_(_)
What is Blaze CUDA?
X Not a fork
X Not a replacement
→ An extension
→ Interoperable with Blaze
→ Provides drop-in replacement container types
& assignment strategies for CUDA computation
.02/13
____ __ ___
/ __ \__ __/ /_/ (_)___ ___
/ / / / / / / __/ / / __ \/ _ \
/ /_/ / /_/ / /_/ / / / / / __/
\____/\__,_/\__/_/_/_/ /_/\___/
- Blaze:
* Brief introduction
* Types - Expression templates: Compile-time representation of expressions
* Functions - assign() overloads: Evaluation strategies
- Blaze CUDA:
* Types - Extending: CUDA-compatible data containers
* Functions - cudaAssign() overloads: CUDA evaluation strategies
* Plumbery - CUDA compatibility: Attributes & typetraits
.03/13
____ __
/ __ )/ /___ _____ ___
/ __ / / __ `/_ / / _ \
/ /_/ / / /_/ / / /_/ __/
/_____/_/\__,_/ /___/\___/
Implementation of Smart Expression Templates (SET)
Expression Templates:
- Types that represent expressions
- Element-wise computation
Smart Expression Templates:
- Expression templates
- More than just element-wise computations (BLAS, LAPACK, ...)
→ High level code, high performance assembly
.04/13
____ __ __
/ __ )/ /___ _____ ___ / /___ ______ ___ _____
/ __ / / __ `/_ / / _ \ / __/ / / / __ \/ _ \/ ___/
/ /_/ / / /_/ / / /_/ __/ / /_/ /_/ / /_/ / __(__ )
/_____/_/\__,_/ /___/\___/ \__/\__, / .___/\___/____/
/____/_/
- Abstract types: DenseVector, DenseMatrix, ...
- Data containers: DynamicMatrix, DynamicVector, CompressedVector, ...
- Expressions: DMatDMatMultExpr, DMatDMatAddExpr, DMatDVecMultExpr, ...
Blaze operators only build expression types:
DyVec + DyVec
-> DVecDVecAddExpr<DyVec,DyVec>
DVecDVecAddExpr<DyVec,DyVec> * DyVec
-> DVecDVecMultExpr<DVecDVecAddExpr<DyVec,DyVec>,DyVec>
.05/13
____ __ __
/ __ )/ /___ _____ ___ / /___ ______ ___ _____
/ __ / / __ `/_ / / _ \ / __/ / / / __ \/ _ \/ ___/
/ /_/ / / /_/ / / /_/ __/ / /_/ /_/ / /_/ / __(__ )
/_____/_/\__,_/ /___/\___/ \__/\__, / .___/\___/____/
/____/_/
Blaze types provide:
- Subscript operators (element access & computations)
- Iterators (element access & computations)
- Compile-time attributes (Storage order, SMP-assignable, ...)
→ Types alone implement Expression Templates
.06/13
____ __ __
/ __ )/ /___ _____ ___ / /___ ______ ___ _____
/ __ / / __ `/_ / / _ \ / __/ / / / __ \/ _ \/ ___/
/ /_/ / / /_/ / / /_/ __/ / /_/ /_/ / /_/ / __(__ )
/_____/_/\__,_/ /___/\___/ \__/\__, / .___/\___/____/
/____/_/
Type hierarchy:
- Vector
* DenseVector
- DynamicVector
- StaticVector
- DVecDVecAddExpr
- DVecDVecSubExpr
- ...
* SparseVector
- CompressedVector
- Matrix
...
.07/13
____ __ __
/ __ )/ /___ _____ ___ / /___ ______ ___ _____
/ __ / / __ `/_ / / _ \ / __/ / / / __ \/ _ \/ ___/
/ /_/ / / /_/ / / /_/ __/ / /_/ /_/ / /_/ / __(__ )
/_____/_/\__,_/ /___/\___/ \__/\__, / .___/\___/____/
/____/_/
Use of Curiously Recurring Template Pattern (CRTP):
struct Concrete: Abstract<Concrete> {};
DynamicVector<...>: DenseVector<DynamicVector<...>>: Vector<DenseVector<...>>
template<typename VT>
void do_stuff( DenseVector<VT> const& v ); // v can be casted into a VT
→ Semantically lossless abstraction, resolvable at compile-time by overloading
(unlike virtual inheritance)
.08/13
______ __ _
/ ____/_ ______ _____/ /_(_)___ ____ _____
/ /_ / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
/ __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__ )
/_/ \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/
Types allow for easy computation with a
universal element-wise assignment function.
Pros: cheap, easy, performant in various complex cases
Cons: terrible in many simple cases
DVecDVecAddExpr ? Cache-friendly, generates better assembly
DMatDMatMultExpr? Terrybly cache-unfriendly!
→ We need better strategies...
Why not combine them?
.09/13
______ __ _
/ ____/_ ______ _____/ /_(_)___ ____ _____
/ /_ / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
/ __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__ )
/_/ \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/
How? By overloading assign()! assign( DenseVector<VT> &lhs, ... const& rhs )
General case (DenseVector<VT>): Element-wise assignment
Specific cases (DMatDMatMultExpr & others): Own assign() implementations
Specific implementations can use:
- BLAS
- LAPACK
DMatDMatMultExpr can use GEMM!
→ SMART Expression Templates: selective strategies
.10/13
____ __ ________ ______ ___
/ __ )/ /___ _____ ___ / ____/ / / / __ \/ |
/ __ / / __ `/_ / / _ \ / / / / / / / / / /| |
/ /_/ / / /_/ / / /_/ __/ / /___/ /_/ / /_/ / ___ |
/_____/_/\__,_/ /___/\___/ \____/\____/_____/_/ |_|
How to reuse Blaze's code?
- Reuse strategies implemented for CPUs on GPUs? Sadly not.
- Reuse the types? Sure we do!
→ Adding CUDA-compatible containers, build expressions on top of them,
and implement new assignment strategies with cudaAssign() overloads.
.11/13
______
/_ __/_ ______ ___ _____
/ / / / / / __ \/ _ \/ ___/
/ / / /_/ / /_/ / __(__ )
/_/ \__, / .___/\___/____/
/____/_/
Only CUDA-allocated container types are required:
- CUDADynamicMatrix: DenseMatrix<...>: ...
- CUDADynamicVector: DenseVector<...>: ...
Inheriting from DenseMatrix/DenseVector makes the reuse of
expression templates possible, along with their features:
iterators, typetraits, ...
→ (Almost) Free code! (Minor modifications to Blaze were required)
Totally conflict-free
.12/13
______ __ _
/ ____/_ ______ _____/ /_(_)___ ____ _____
/ /_ / / / / __ \/ ___/ __/ / __ \/ __ \/ ___/
/ __/ / /_/ / / / / /__/ /_/ / /_/ / / / (__ )
/_/ \__,_/_/ /_/\___/\__/_/\____/_/ /_/____/
- assign() is designed for CPUs
- Adding more overloads to assign() *will* cause conflicts...
→ New "class" of assign function, cudaAssign(), based on
Thrust & cuBLAS
.13/13
__ __ _ ___ _
/ / ___ / /( )_____ ____/ (_) _____ (_)___
/ / / _ \/ __/// ___/ / __ / / | / / _ \ / / __ \
/ /___/ __/ /_ (__ ) / /_/ / /| |/ / __/ / / / / /
/_____/\___/\__/ /____/ \__,_/_/ |___/\___/ /_/_/ /_/