The code should be compiled with CUDA, using nvcc compiler:
nvcc -I fastflowFfDirPath -I skepuIncludeDirPath -o pipemap pipemap.cu -lpthread
#include <iostream> #include <ff/pipeline.hpp> #include <math.h> #define SKEPU_CUDA // #define SKEPU_OPENMP #include <skepu/vector.h> #include <skepu/map.h> 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<float> * v = new skepu::Vector<float>(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<float> * v = (skepu::Vector<float> *) 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<ITERNO; _i++) a = sin(a); return(a); ) int NN = 10; UNARY_FUNC(f, float, a, return(a+1); ) class MapStage:public ff_node { void *svc(void * task) { skepu::Vector<float> * v = (skepu::Vector<float> *) task; #ifdef DEBUG std::cout << "MapStage got: " << *v << std::endl; #endif skepu::Vector<float> * r = new skepu::Vector<float>(NN); skepu::Map<iters> 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; }