Retour vers le futur des biblioth`
eques de
squelettes algorithmiques et DSL
Sylvain Jubertie [email protected]
Squelettes algorithmiques
Objectifs
Approche de haut-niveau pour la programmation parall`ele. Masquer la complexit´e de la programmation parall`ele. Synchronisation/communication.
Composition de squelettes.
Squelettes algorithmiques
R´eduction optimis´ee en CUDA (M. Harris) :
t e m p l a t e < u n s i g n e d int b l o c k S i z e >
_ _ d e v i c e _ _ v o i d w a r p R e d u c e ( v o l a t i l e int * sdata , u n s i g n e d int tid ) { if ( b l o c k S i z e >= 64) s d a t a [ tid ] += s d a t a [ tid + 3 2 ] ; if ( b l o c k S i z e >= 32) s d a t a [ tid ] += s d a t a [ tid + 1 6 ] ; if ( b l o c k S i z e >= 16) s d a t a [ tid ] += s d a t a [ tid + 8]; if ( b l o c k S i z e >= 8) s d a t a [ tid ] += s d a t a [ tid + 4]; if ( b l o c k S i z e >= 4) s d a t a [ tid ] += s d a t a [ tid + 2]; if ( b l o c k S i z e >= 2) s d a t a [ tid ] += s d a t a [ tid + 1]; } t e m p l a t e < u n s i g n e d int b l o c k S i z e >
_ _ g l o b a l _ _ v o i d r e d u c e 6 ( int * g_idata , int * g_odata , u n s i g n e d int n ) { e x t e r n _ _ s h a r e d _ _ int s d a t a []; u n s i g n e d int tid = t h r e a d I d x . x ; u n s i g n e d int i = b l o c k I d x . x *( b l o c k S i z e *2) + tid ; u n s i g n e d int g r i d S i z e = b l o c k S i z e *2* g r i d D i m . x ; s d a t a [ tid ] = 0; w h i l e ( i < n ) { s d a t a [ tid ] += g _ i d a t a [ i ] + g _ i d a t a [ i + b l o c k S i z e ]; i += g r i d S i z e ; } _ _ s y n c t h r e a d s ();
if ( b l o c k S i z e >= 5 1 2 ) { if ( tid < 2 5 6 ) { s d a t a [ tid ] += s d a t a [ tid + 2 5 6 ] ; } _ _ s y n c t h r e a d s (); } if ( b l o c k S i z e >= 2 5 6 ) { if ( tid < 1 2 8 ) { s d a t a [ tid ] += s d a t a [ tid + 1 2 8 ] ; } _ _ s y n c t h r e a d s (); } if ( b l o c k S i z e >= 1 2 8 ) { if ( tid < 6 4 ) { s d a t a [ tid ] += s d a t a [ tid + 6 4 ] ; } _ _ s y n c t h r e a d s (); }
Squelettes algorithmiques
Implantations Muesli SkePU QUAFF SkeTo SkelGIS OSL . . .Squelettes algorithmiques
Limitations
jeu de squelettes + structures de donn´ees fix´es. limitations `a un domaine.
optimisations logicielles : fusion de squelettes. optimisations mat´erielles : support des architectures. conception.
Squelettes algorithmiques
Muesli :
v o i d msl :: I n i t S k e l e t o n s ( int argc , c h a r ** argv ,
b o o l s e r i a l i z a t i o n ) { M P I _ I n i t (& argc , & a r g v );
M P I _ C o m m _ s i z e ( M P I _ C O M M _ W O R L D , & M u e s l i :: M S L _ n u m O f T o t a l P r o c s ); M P I _ C o m m _ r a n k ( M P I _ C O M M _ W O R L D , & M u e s l i :: M S L _ m y I d ); ... }
Squelettes algorithmiques
SkeTo : v o i d m a k e _ e d g e s () c o n s t { ... M P I _ B a r r i e r ( M P I _ C O M M _ W O R L D ); }Squelettes algorithmiques
SkePU :
// unary transpose operator
i n l i n e Matrix < T >& o p e r a t o r ~() { ... # if d e f i n e d ( S K E P U _ C U D A ) t r a n s p o s e _ C U ( E n v i r o n m e n t < int >:: g e t I n s t a n c e () - >... # e l i f d e f i n e d ( S K E P U _ O P E N C L ) t r a n s p o s e _ C L ( 0 ) ; # e l i f d e f i n e d ( S K E P U _ O P E N M P ) t r a n s p o s e _ O M P (); # e l s e t r a n s p o s e _ C P U (); # e n d i f ... }
Squelettes algorithmiques
Remarques
Difficiles `a maintenir/´etendre. S´eparer les aspects :
Squelettes fournis Optimisations (fusion) Support des architectures.
Domain Specific Languages
Objectifs
Fournir aux utilisateurs des langages adapt´es `a leurs domaines. Op´erateurs/fonctions + structures de donn´ees.
V e c t o r v1 (...) , v2 ( . . . ) ;
a u t o v3 = map ( plus , v1 , v2 ); // squelettes. a u t o v3 = v1 + v2 ; // DSL
Domain Specific Languages
Implantations LateX SQL HTML VHDL Matlab . . .Domain Specific Languages
DSL pour le HPC
NT2
Delite : OptiML, OptiQL, OptiGraph, OptiMesh . . .
Domain Specific Languages
NT2
syntaxe Matlab.
C++, m´eta-programmation.
squelettes algorithmiques : transform, fold, scan. m´emoire partag´ee : multithreading, vectorisation. acc´el´erateurs.
Domain Specific Languages
Delite
Scala
Squelettes algorithmiques. M´emoire partag´ee, acc´el´erateurs.
M´emoire distribu´ee : Apache Mesos, Google Protocol Buffers. Forge : m´eta-DSL.
Architecture g´
en´
erale
DSL Signal LinAlg Graphe Image
FFTW BLAS OpenCV Squelettes Structures CuBLAS CuFFT OpenMP MPI Transformations CUDA Utilisateur Architecture SIMD Implantations
Probl`
emes `
a r´
esoudre
Donn´ees
G´en´eration de structures de donn´ees optimis´ees. Transformation des donn´ees AoS - SoA.
Choix localit´e des donn´ees (NUMA, acc´el´erateurs, distribu´e). Solution : tags, mod`ele de coˆut ?
I m a g e i m a g e ( . . . ) ; // conversion AoS -> SoA ?
a u t o g r a y = g r a y s c a l e ( i m a g e ); // RGBRGB. -> RR. GG. BB. M a t r i x m1 (...) , m2 ( . . . ) ;
Probl`
emes `
a r´
esoudre
Aspects distribu´es
Distribution des donn´ees. Bordures.
G´en´eration des synchronisations/communications. Recouvrement calcul/communication.
Solution : allocation dynamique des bordures.
I m a g e i m a g e ( . . . ) ; // info sur les bordures ici ?
i m a g e . a p p l y ( /* s t e n c i l 3 x 3 */ ); // allocation retard´ee ? i m a g e . a p p l y ( /* s t e n c i l 5 x 5 */ ); // reallocation ?
Probl`
emes `
a r´
esoudre
Autres
Interfaces des biblioth`eques: allocation interne, type des param`etres, . . . Portabilit´e : libnuma. Chaˆınes de compilation (nvcc), . . . cv :: Mat m = cv :: i m r e a d ( " i m a g e . png " , cv :: I M R E A D _ U N C H A N G E D ); // allocation interne a u t o * p o i n t e r = m . d a t a ; // pointeur align´e ?
Travaux en cours
G´en´eration de structures de donn´ees optimis´ees
J. Falcou, I. Masliah, S. Jubertie - LRI
DSL pour la g´eologie, . . .
G´
en´
eration de structures de donn´
ees optimis´
ees
Id´ee
1 Repr´esentation utilisateur : AoS Image 2D pixels RGB 2 Repr´esentation interm´ediaire : SoA 3 tableaux 2D 3 Repr´esentation m´emoire : segment m´emoire 1D
Allocateurs - Buffers - Conteneurs
Allocateurs : alignement, NUMA, huge pages, acc´el´erateurs. Conteneurs : localit´e, dimensions, . . .
Optimisation vectorisation : SoA.
Transferts m´emoire centrale - acc´el´erateurs. Distribution/communication.
G´
en´
eration de structures de donn´
ees optimis´
ees
Allocators
malloc, aligned, NUMA, CUDA, . . . adaptateur allocateurs C++. retourne un Block.
Block
G´
en´
eration de structures de donn´
ees optimis´
ees
Buffer capacit´e. iterateurs. redimensionnement. copie.G´
en´
eration de structures de donn´
ees optimis´
ees
AoS - SoA
Fournir une vision AoS `a une structure de donn´ees SoA.
vectors < int , float , int > v e c s ; v e c s . add ( 3 , 4.0 f , 5 ); v e c s . add ( 6 , 7.3 f , 8 ); v e c s . add ( 9 , 1 0 . 2 f , 11 ); ... u s i n g i m a g e R G B = vectors < u n s i g n e d char , u n s i g n e d char , u n s i g n e d c h a r >;
Conclusion
Existant
Beaucoup d’approches diff´erentes/similaires. Pas de factorisation.
Limitations li´ees `a la conception (squelettes). Beaucoup de DSL ad hoc.
Conclusion
Travaux en cours
Reconstruction par le bas : 1 bloc m´emoire,
2 structure de donn´ees interne,
3 distribution,
4 structure de donn´ees expos´ee `a l’utilisateur. Ce n’est que le d´ebut !