Download Autotuning Tutorials - ROSE compiler infrastructure

Transcript
As a result, the .so file contains all unrolled versions.
A configuration file is needed for Active Harmony to know the parameters
to be tuned and their corresponding ranges. The following file is used to specify
a tunable parameter named unroll with a range from 1 to 32. obsGoodness
(observed Goodness - or performance) and predGoodness (predicted goodness)
are related to a GUI window showing during the execution. They do not impact
the performance tuning and the workings of the search algorithm.
harmonyApp smg2000Unroll {
{ harmonyBundle unroll {
int {1 32 1}
}
}
{ obsGoodness 1 5000}
{ predGoodness 1 5000}
}
We don’t use BLCR since an online tuning method is used for Active Harmony. The code transformation to work with Active Harmony
is shown below.
The basic idea is to call a set of Harmony interface functions to startup communication with the server (harmony startup()),
send a configuration file ( harmony application setup file () ), define a parameter to be tuned (harmony add variable()), report performance feedback
(harmony peformance update()), and finally request the next set of values of the
tunable parameters (harmony request all()).
#include ” h c l i e n t . h”
#include ” h s o c k u t i l . h”
static int h a r r e g i s t r a t i o n = 0 ;
s t a t i c i n t ∗ u n r o l l =NULL ;
int
hypre SMGResidual ( . . )
{
// i n i t i a l i z e t h e s e a r c h e n g i n e f o r t h e f i r s t c a l l
i f ( h a r r e g i s t r a t i o n == 0 )
{
p r i n t f ( ” S t a r t i n g Harmony . . . \ n” ) ;
harmony startup ( 0 ) ;
p r i n t f ( ” S e n d i n g s e t u p f i l e ! \ n” ) ;
h a r m o n y a p p l i c a t i o n s e t u p f i l e ( ” harmony . t c l ” ) ;
p r i n t f ( ” Adding a harmony v a r i a b l e . . . . ” ) ;
u n r o l l =( i n t ∗ ) h a r m o n y a d d v a r i a b l e ( ” s m g 2 0 0 0 U n r o l l ” , ” u n r o l l ” ,VAR INT ) ;
h a r r e g i s t r a t i o n ++;
}
//Load t h e . so f i l e s
char n e x t U n r o l l [ 2 5 5 ] ;
i f ( g e x e c u t i o n f l a g == 0 )
{
/∗ Only l o a d t h e l i b f o r t h e f i r s t time , r e u s e i t l a t e r on ∗/
p r i n t f ( ” Opening t h e . s o f i l e . . . \ n” ) ;
F u n c t i o n L i b = d l o p e n ( ” . / u n r o l l e d v e r s i o n s . s o ” ,RTLD LAZY ) ;
dlError = dlerror ( ) ;
i f ( dlError ) {
p r i n t f ( ” c a n n o t open . s o f i l e ! \ n” ) ;
exit (1);
}
} // end i f ( f l a g ==0)
//Use t h e v a l u e p r o v i d e d Harmony t o f i n d a k e r n e l v a r i a n t
s p r i n t f ( n e x t U n r o l l , ” O U T 1 6 7 5 5 %d” , ∗ u n r o l l ) ;
p r i n t f ( ” T r y i n g t o f i n d : %s . . . \ n” , n e x t U n r o l l ) ;
OUT 1 6755
= ( void ( ∗ ) ( void ∗ ∗ ) ) dlsym ( F u n c t i o n L i b , n e x t U n r o l l ) ;
// t i m i n g t h e e x e c u t i o n o f a v a r i a n t
t i m e 1=t i m e s t a m p ( ) ;
// . . parameter wrapping i s o m i t t e d h e r e
21
FIXME: This is
not an ideal way
to tune the
application, we
will explore
better
alternatives.