===== SKEPU code in FastFlow =====
The code should be compiled with CUDA, using **nvcc** compiler:
nvcc -I fastflowFfDirPath -I skepuIncludeDirPath -o pipemap pipemap.cu -lpthread
#include
#include
#include
#define SKEPU_CUDA
// #define SKEPU_OPENMP
#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);
#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 3-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;
}