magistraleinformaticanetworking:spm:skepu_sample
Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Entrambe le parti precedenti la revisioneRevisione precedenteProssima revisione | Revisione precedente | ||
| magistraleinformaticanetworking:spm:skepu_sample [11/05/2012 alle 12:55 (14 anni fa)] – Marco Danelutto | magistraleinformaticanetworking:spm:skepu_sample [11/05/2012 alle 13:00 (14 anni fa)] (versione attuale) – Marco Danelutto | ||
|---|---|---|---|
| Linea 7: | Linea 7: | ||
| <code lang=" | <code lang=" | ||
| #include < | #include < | ||
| + | |||
| + | //#define SKEPU_CUDA | ||
| #include " | #include " | ||
| Linea 40: | Linea 42: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | === Sample map === | ||
| + | |||
| + | <code lang=" | ||
| + | #include < | ||
| + | |||
| + | |||
| + | #define SKEPU_CUDA | ||
| + | |||
| + | #include " | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | // definition of functions to be used in the map and reduce | ||
| + | |||
| + | UNARY_FUNC(inc, | ||
| + | UNARY_FUNC(dec, | ||
| + | UNARY_FUNC(sq, | ||
| + | BINARY_FUNC(add, | ||
| + | BINARY_FUNC(sub, | ||
| + | BINARY_FUNC(mul, | ||
| + | BINARY_FUNC(div, | ||
| + | |||
| + | #define N 4 | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | // declare vectors | ||
| + | skepu:: | ||
| + | skepu:: | ||
| + | skepu:: | ||
| + | | ||
| + | // initialize the vector(s) to some meaningful value | ||
| + | for(int i=0; i<N;i++) { | ||
| + | v0[i]=i+1; | ||
| + | v1[i]=-(i+1); | ||
| + | } | ||
| + | cout << " | ||
| + | | ||
| + | // one input map: forall i compute f(v0[i]) | ||
| + | skepu:: | ||
| + | sqmap(v0, | ||
| + | cout << "After sqmap: | ||
| + | |||
| + | // two input map: forall i compute f(v0[i], | ||
| + | // same as: alpha(f) o zip | ||
| + | skepu:: | ||
| + | mapzip(v0, | ||
| + | cout << "After mapzip: | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Sample reduce ==== | ||
| + | <code lang=" | ||
| + | #include < | ||
| + | |||
| + | #include " | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | // definition of functions to be used in the map and reduce | ||
| + | |||
| + | UNARY_FUNC(inc, | ||
| + | UNARY_FUNC(dec, | ||
| + | UNARY_FUNC(sq, | ||
| + | BINARY_FUNC(add, | ||
| + | BINARY_FUNC(sub, | ||
| + | BINARY_FUNC(mul, | ||
| + | BINARY_FUNC(div, | ||
| + | |||
| + | #define N 4 | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | // declare vectors | ||
| + | skepu:: | ||
| + | skepu:: | ||
| + | | ||
| + | // initialize the vector(s) to some meaningful value | ||
| + | for(int i=0; i<N;i++) { | ||
| + | v0[i]=i+1; | ||
| + | } | ||
| + | cout << " | ||
| + | for(int i=0; i<N; i++) | ||
| + | for(int j=0; j<N; j++) | ||
| + | m(i,j) = (i*N)+j; | ||
| + | cout << " | ||
| + | | ||
| + | skepu:: | ||
| + | int i = reduceadd(v0); | ||
| + | cout << "After reduceadd : " << i << endl; | ||
| + | |||
| + | skepu:: | ||
| + | i = reduceaddmat(m); | ||
| + | cout << "After reduceaddmat : " << i << endl; | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Sample stencil (mapoverlap) ==== | ||
| + | <code lang=" | ||
| + | #include < | ||
| + | |||
| + | #include " | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | OVERLAP_FUNC(avg, | ||
| + | |||
| + | #define N 8 | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | // declare vectors | ||
| + | skepu:: | ||
| + | skepu:: | ||
| + | | ||
| + | // initialize the vector(s) to some meaningful value | ||
| + | for(int i=0; i<N;i++) { | ||
| + | v0[i]=i; | ||
| + | } | ||
| + | cout << " | ||
| + | | ||
| + | // compute things in stencil map mode | ||
| + | skepu:: | ||
| + | // in vecs, missing boundary filled with 1 (CONSTANT) | ||
| + | average(v0, | ||
| + | cout << "After average (boundary = 1): " << v2 << endl; | ||
| + | // consider the vector as a torus | ||
| + | average(v0, | ||
| + | cout << "After average (cyclic): | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Sample maparray ==== | ||
| + | <code lang=" | ||
| + | #include < | ||
| + | |||
| + | #include " | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | // definition of functions to be used in the map and reduce | ||
| + | |||
| + | #define N 4 | ||
| + | |||
| + | ARRAY_FUNC(f, | ||
| + | { int s = 0; \ | ||
| + | | ||
| + | s += a[i]; \ | ||
| + | } \ | ||
| + | | ||
| + | | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | // declare vectors | ||
| + | skepu:: | ||
| + | skepu:: | ||
| + | skepu:: | ||
| + | | ||
| + | // initialize the vector(s) to some meaningful value | ||
| + | for(int i=0; i<N;i++) { | ||
| + | v0[i]=i+1; | ||
| + | v1[i]=i; | ||
| + | } | ||
| + | cout << " | ||
| + | cout << " | ||
| + | | ||
| + | skepu:: | ||
| + | ff(v0, | ||
| + | cout << "After ff: " << v2 << endl; | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Sample scan ==== | ||
| + | <code lang=" | ||
| + | #include < | ||
| + | |||
| + | #include " | ||
| + | #include " | ||
| + | #include " | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | // definition of functions to be used in the map and reduce | ||
| + | |||
| + | BINARY_FUNC(add, | ||
| + | BINARY_FUNC(mul, | ||
| + | |||
| + | #define N 4 | ||
| + | |||
| + | int main() | ||
| + | { | ||
| + | // declare vectors | ||
| + | skepu:: | ||
| + | skepu:: | ||
| + | skepu:: | ||
| + | | ||
| + | // initialize the vector(s) to some meaningful value | ||
| + | for(int i=0; i<N;i++) { | ||
| + | v0[i]=i+1; | ||
| + | v1[i]=-(i+1); | ||
| + | } | ||
| + | cout << " | ||
| + | | ||
| + | // one input map: forall i compute f(v0[i]) | ||
| + | skepu:: | ||
| + | // at pos i sum of items up to (i) | ||
| + | scanadd(v0, | ||
| + | cout << "After scanadd: " << v2 << endl; | ||
| + | // at pos i sum of items up to (i-1) | ||
| + | scanadd(v0, | ||
| + | cout << "After scanadd: " << v2 << endl; | ||
| + | |||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | |||
magistraleinformaticanetworking/spm/skepu_sample.1336740958.txt.gz · Ultima modifica: 11/05/2012 alle 12:55 (14 anni fa) da Marco Danelutto
