From: gburri Date: Wed, 1 Oct 2014 20:51:52 +0000 (+0200) Subject: Implémentation de RipplingMOO (entralecement + auto-for). X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=1ad82fc988adf2f8837584ec26873953a83dc7b8;p=GPU.git Implémentation de RipplingMOO (entralecement + auto-for). --- diff --git a/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp b/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp index 94d1656..18f672d 100755 --- a/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp +++ b/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.cpp @@ -1,100 +1,124 @@ -#include -#include - -#include "RipplingMOO.h" -#include "OmpTools.h" - -#include "RipplingMath.h" - -using std::cout; -using std::endl; -using std::string; - -/*----------------------------------------------------------------------*\ - |* Declaration *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -/*--------------------------------------*\ - |* Private *| - \*-------------------------------------*/ - -/*----------------------------------------------------------------------*\ - |* Implementation *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -RipplingMOO::RipplingMOO(unsigned int w, unsigned int h, float dt) - { - this->t=0; - this->dt=dt; - } - -RipplingMOO::~RipplingMOO(void) - { - // rien - } - - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -void RipplingMOO::process(uchar4* ptrTabPixels, int w, int h) - { - if (isEntrelacement) - { - entrelacementOMP(ptrTabPixels); // Plus lent - } - else - { - forAutoOMP(ptrTabPixels); // Plus rapide - } - - isEntrelacement=!isEntrelacement;// Pour tester que les deux implementations fonctionnent - } - - -void RipplingMOO::animationStep() - { - t+=dt; - } - -/*--------------*\ - |* get *| - \*-------------*/ - -float RipplingMOO::getT() - { - return t; - } - -/*--------------------------------------*\ - |* Private *| - \*-------------------------------------*/ - -/** - * Code entrainement Cuda - */ -void RipplingMOO::entrelacementOMP(uchar4* ptrTabPixels) - { - // TODO - } - -/** - * Code naturel et direct OMP - */ -void RipplingMOO::forAutoOMP(uchar4* ptrTabPixels) - { - // TODO - } - -/*----------------------------------------------------------------------*\ - |* End *| - \*---------------------------------------------------------------------*/ +#include +#include + +#include "RipplingMOO.h" +#include "RipplingMath.h" + +#include "OmpTools.h" +#include "IndiceTools.h" + + +using std::cout; +using std::endl; +using std::string; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +RipplingMOO::RipplingMOO(unsigned int w, unsigned int h, float dt) + : w(w), h(h), t(0), dt(dt), isEntrelacement(false) + { + } + +RipplingMOO::~RipplingMOO(void) + { + // rien + } + + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void RipplingMOO::process(uchar4* ptrTabPixels, int w, int h) // Pourquoi w et h ne sont pas utilisé?? + { + if (this->isEntrelacement)x + this->entrelacementOMP(ptrTabPixels); // Plus lent + else + this->forAutoOMP(ptrTabPixels); // Plus rapide + + this->isEntrelacement = ! this->isEntrelacement; // Pour tester que les deux implementations fonctionnent + } + + +void RipplingMOO::animationStep() + { + this->t += this->dt; + } + +/*--------------*\ + |* get *| + \*-------------*/ + +float RipplingMOO::getT() + { + return this->t; + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/** + * Code entrainement Cuda + */ +void RipplingMOO::entrelacementOMP(uchar4* ptrTabPixels) + { + RipplingMath ripplingMath(w,h); // ici pour preparer cuda + const int WH = w * h; + +#pragma omp parallel + { + const int NB_THREAD = OmpTools::getNbThread(); + const int TID = OmpTools::getTid(); + int s = TID; + + int i, j; + while (s < WH) + { + IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[ + ripplingMath.colorIJ(&ptrTabPixels[s], i, j,t); + s += NB_THREAD; + } + } + } + +/** + * Code naturel et direct OMP + */ +void RipplingMOO::forAutoOMP(uchar4* ptrTabPixels) + { + RipplingMath ripplingMath(w,h); // ici pour preparer cuda + +#pragma omp parallel for + for (int i = 0; i < h; i++) + { + for (int j = 0; j < w; j++) + { + // int s = i * W + j; + const int s = IndiceTools::toS(w, i, j); // i[0,H[ j[0,W[ --> s[0,W*H[ + ripplingMath.colorIJ(&ptrTabPixels[s], i, j,t); + } + } + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ diff --git a/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.h b/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.h index 6e26b26..001faf7 100755 --- a/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.h +++ b/WCudaMSE/Student_OMP_Image/src/cpp/core/01_Rippling/b_moo/RipplingMOO.h @@ -1,60 +1,61 @@ -#ifndef RIPPLING_MOO_H_ -#define RIPPLING_MOO_H_ - -#include "cudaType.h" - -/*----------------------------------------------------------------------*\ - |* Declaration *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -class RipplingMOO - { - - /*--------------------------------------*\ - |* Constructeur *| - \*-------------------------------------*/ - - public: - - RipplingMOO(unsigned int w, unsigned int h, float dt); - virtual ~RipplingMOO(void); - - /*--------------------------------------*\ - |* Methode *| - \*-------------------------------------*/ - - public: - - void process(uchar4* ptrTabPixels, int w, int h); - void animationStep(); - float getT(); - - private: - - void entrelacementOMP(uchar4* ptrTabPixels); // Code entrainement Cuda - void forAutoOMP(uchar4* ptrTabPixels); // Code naturel et direct OMP, plus performsnt - - /*--------------------------------------*\ - |* Attribut *| - \*-------------------------------------*/ - - private: - - // Inputs - double dt; - - // Tools - double t; - bool isEntrelacement; - - }; - -#endif - -/*----------------------------------------------------------------------*\ - |* End *| - \*---------------------------------------------------------------------*/ +#ifndef RIPPLING_MOO_H_ +#define RIPPLING_MOO_H_ + +#include "cudaType.h" + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +class RipplingMOO + { + + /*--------------------------------------*\ + |* Constructeur *| + \*-------------------------------------*/ + + public: + + RipplingMOO(unsigned int w, unsigned int h, float dt); + virtual ~RipplingMOO(void); + + /*--------------------------------------*\ + |* Methode *| + \*-------------------------------------*/ + + public: + + void process(uchar4* ptrTabPixels, int w, int h); + void animationStep(); + float getT(); + + private: + + void entrelacementOMP(uchar4* ptrTabPixels); // Code entrainement Cuda + void forAutoOMP(uchar4* ptrTabPixels); // Code naturel et direct OMP, plus performsnt + + /*--------------------------------------*\ + |* Attribut *| + \*-------------------------------------*/ + + private: + const unsigned int w; + const unsigned int h; + + // Inputs + const double dt; + + // Tools + double t; + bool isEntrelacement; + }; + +#endif + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ diff --git a/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp b/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp index 7a1e633..47e7198 100755 --- a/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp +++ b/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.cpp @@ -1,150 +1,148 @@ -#include -#include -#include - -#include "VagueMOO.h" -#include "VagueMath.h" - -#include "OmpTools.h" -#include "IndiceTools.h" - -using std::cout; -using std::endl; - -/*----------------------------------------------------------------------*\ - |* Declaration *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -/*--------------------------------------*\ - |* Private *| - \*-------------------------------------*/ - -/*----------------------------------------------------------------------*\ - |* Implementation *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -VagueMOO::VagueMOO(unsigned int w, unsigned int h, float dt) - { - // Input - this->dt = dt; - this->w=w; - - - // Tools - this->t = 0; - this->isEntrelacement=true; - - - // OMP (facultatif) - const int NB_THREADS = OmpTools::setAndGetNaturalGranularity(); - cout << "\n[VAGUE] nbThread = " << NB_THREADS << endl; - } - -VagueMOO::~VagueMOO(void) - { - // rien - } - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -void VagueMOO::process(uchar4* ptrTabPixels, int w, int h) - { - if (isEntrelacement) - { - entrelacementOMP(ptrTabPixels, w, h); // Plus lent - } - else - { - forAutoOMP(ptrTabPixels, w, h); // Plus rapide - } - - isEntrelacement = !isEntrelacement; // Pour tester que les deux implementations fonctionnent - } - -void VagueMOO::animationStep() - { - t+=dt; - } - -/*--------------*\ - |* get *| - \*-------------*/ - -float VagueMOO::getT() - { - return t; - } - -float VagueMOO::getDT() - { - return dt; - } - -/*--------------------------------------*\ - |* Private *| - \*-------------------------------------*/ - -/** - * Code naturel et direct OMP - */ -void VagueMOO::forAutoOMP(uchar4* ptrTabPixels, int w, int h) - { - VagueMath vagueMath(w,h); // ici pour preparer cuda - -#pragma omp parallel for - for (int i = 0; i < h; i++) - { - for (int j = 0; j < w; j++) - { - // int s = i * W + j; - int s = IndiceTools::toS(w, i, j); // i[0,H[ j[0,W[ --> s[0,W*H[ - - vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); - } - } - } - -/** - * Code entrainement Cuda - */ -void VagueMOO::entrelacementOMP(uchar4* ptrTabPixels, int w, int h) - { - VagueMath vagueMath(w,h); // ici pour preparer cuda - - const int WH = w * h; - - -#pragma omp parallel - { - const int NB_THREAD = OmpTools::getNbThread();// dans region parallel - const int TID = OmpTools::getTid(); - int s = TID; // in [0,... - - int i; - int j; - while (s < WH) - { - IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[ - - vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); - - s += NB_THREAD; - } - } - } - - -/*----------------------------------------------------------------------*\ - |* End *| - \*---------------------------------------------------------------------*/ - +#include +#include +#include + +#include "VagueMOO.h" +#include "VagueMath.h" + +#include "OmpTools.h" +#include "IndiceTools.h" + +using std::cout; +using std::endl; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +VagueMOO::VagueMOO(unsigned int w, unsigned int h, float dt) + { + // Input + this->dt = dt; + this->w=w; + + + // Tools + this->t = 0; + this->isEntrelacement=true; + + + // OMP (facultatif) + const int NB_THREADS = OmpTools::setAndGetNaturalGranularity(); + cout << "\n[VAGUE] nbThread = " << NB_THREADS << endl; + } + +VagueMOO::~VagueMOO(void) + { + // rien + } + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +void VagueMOO::process(uchar4* ptrTabPixels, int w, int h) + { + if (isEntrelacement) + { + entrelacementOMP(ptrTabPixels, w, h); // Plus lent + } + else + { + forAutoOMP(ptrTabPixels, w, h); // Plus rapide + } + + isEntrelacement = !isEntrelacement; // Pour tester que les deux implementations fonctionnent + } + +void VagueMOO::animationStep() + { + t+=dt; + } + +/*--------------*\ + |* get *| + \*-------------*/ + +float VagueMOO::getT() + { + return t; + } + +float VagueMOO::getDT() + { + return dt; + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + + +/** + * Code entrainement Cuda + */ +void VagueMOO::entrelacementOMP(uchar4* ptrTabPixels, int w, int h) + { + VagueMath vagueMath(w,h); // ici pour preparer cuda + + const int WH = w * h; + +#pragma omp parallel + { + const int NB_THREAD = OmpTools::getNbThread();// dans region parallel + const int TID = OmpTools::getTid(); + int s = TID; // in [0,... + + int i; + int j; + while (s < WH) + { + IndiceTools::toIJ(s, w, &i, &j); // s[0,W*H[ --> i[0,H[ j[0,W[ + + vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); + + s += NB_THREAD; + } + } + } + +/** + * Code naturel et direct OMP + */ +void VagueMOO::forAutoOMP(uchar4* ptrTabPixels, int w, int h) + { + VagueMath vagueMath(w,h); // ici pour preparer cuda + +#pragma omp parallel for + for (int i = 0; i < h; i++) + { + for (int j = 0; j < w; j++) + { + // int s = i * W + j; + int s = IndiceTools::toS(w, i, j); // i[0,H[ j[0,W[ --> s[0,W*H[ + + vagueMath.colorIJ(&ptrTabPixels[s], i, j,t); + } + } + } +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ + diff --git a/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.h b/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.h index b0b862a..b13a900 100755 --- a/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.h +++ b/WCudaMSE/Tuto_Image/src/cpp/core/01_Vague/b_moo/VagueMOO.h @@ -1,63 +1,63 @@ -#ifndef VAGUE_MOO_H_ -#define VAGUE_MOO_H_ - -#include "cudaType.h" - - -/*----------------------------------------------------------------------*\ - |* Declaration *| - \*---------------------------------------------------------------------*/ - -/*--------------------------------------*\ - |* Public *| - \*-------------------------------------*/ - -class VagueMOO - { - - /*--------------------------------------*\ - |* Constructeur *| - \*-------------------------------------*/ - - public: - - VagueMOO(unsigned int w, unsigned int h, float dt); - virtual ~VagueMOO(void); - - /*--------------------------------------*\ - |* Methode *| - \*-------------------------------------*/ - - public: - - void process(uchar4* ptrTabPixels, int w, int h); - void animationStep(); - float getT(); - float getDT(); - - private: - - // Balayage image - void entrelacementOMP(uchar4* ptrTabPixels,int w, int h); - void forAutoOMP(uchar4* ptrTabPixels,int w, int h); - - /*--------------------------------------*\ - |* Attribut *| - \*-------------------------------------*/ - - private: - - // Inputs - double dt; - unsigned char w; - - // Tools - double t; - bool isEntrelacement; - }; - -#endif - -/*----------------------------------------------------------------------*\ - |* End *| - /*----------------------------------------------------------------------*/ +#ifndef VAGUE_MOO_H_ +#define VAGUE_MOO_H_ + +#include "cudaType.h" + + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +class VagueMOO + { + + /*--------------------------------------*\ + |* Constructeur *| + \*-------------------------------------*/ + + public: + + VagueMOO(unsigned int w, unsigned int h, float dt); + virtual ~VagueMOO(void); + + /*--------------------------------------*\ + |* Methode *| + \*-------------------------------------*/ + + public: + + void process(uchar4* ptrTabPixels, int w, int h); + void animationStep(); + float getT(); + float getDT(); + + private: + + // Balayage image + void entrelacementOMP(uchar4* ptrTabPixels,int w, int h); + void forAutoOMP(uchar4* ptrTabPixels,int w, int h); + + /*--------------------------------------*\ + |* Attribut *| + \*-------------------------------------*/ + + private: + + // Inputs + double dt; + unsigned char w; + + // Tools + double t; + bool isEntrelacement; + }; + +#endif + +/*----------------------------------------------------------------------*\ + |* End *| + /*----------------------------------------------------------------------*/