Compile with
g++ -DSKEPU_CUDA -DSKEPU_OPENMP_THREADS=4
-fopenmp -o cpu -I . -I include pipemap.cpp -lpthread
to target CPU cores via OpenMP SKEPU backend or
nvcc -o cuda -I. -Iinclude pipemap.cu
to target GPU via CUDA backend.
#include
#include
#include
#include
#include
using namespace ff;
int N = 10;
class Source: public ff_node {
public:
Source(unsigned int streamlen):streamlen(streamlen) {}
void * svc(void * task) {
if(streamlen != 0) {
skepu::Vector * v = new skepu::Vector(N,(float)streamlen);
streamlen--;
task = (void *) v;
#ifdef DEBUG
std::cout << "Source delivering:" << *v << std::endl;
#endif
} else {
task = NULL;
}
return task;
}
private:
unsigned int streamlen;
};
class Drain: public ff_node {
void * svc(void * task) {
skepu::Vector * v = (skepu::Vector *) task;
#ifdef DEBUG
std::cout << "Drain got " << *v << std::endl;
#endif
return(GO_ON);
}
};
#define ITERNO 800000
UNARY_FUNC(iters, float, a,
for(int _i=0; _i * v = (skepu::Vector *) task;
#ifdef DEBUG
std::cout << "MapStage got: " << *v << std::endl;
#endif
skepu::Vector * r = new skepu::Vector(NN);
skepu::Map skepumap(new iters);
skepumap(*v, *r);n
#ifdef DEBUG
std::cout << "MapStage delivering: " << *r << std::endl;
#endif
return((void *) r);
}
};
int main(int argc, char * argv[]) {
if (argc!=3) {
std::cerr << "use: " << argv[0] << " streamlen veclen\n";
return -1;
}
N = atoi(argv[2]);
// bild a 2-stage pipeline
ff_pipeline pipe;
pipe.add_stage(new Source(atoi(argv[1])));
pipe.add_stage(new MapStage());
pipe.add_stage(new Drain());
ffTime(START_TIME);
if (pipe.run_and_wait_end()<0) {
error("running pipeline\n");
return -1;
}
ffTime(STOP_TIME);
std::cerr << "DONE, pipe time= " << pipe.ffTime() << " (ms)\n";
std::cerr << "DONE, total time= " << ffTime(GET_TIME) << " (ms)\n";
pipe.ffStats(std::cerr);
return 0;
}