X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;ds=sidebyside;f=WCudaMSE%2FBilatTools_Cuda_Image%2Fsrc%2Fcore%2FcudaImageTools%2Fbitmap%2Fcpp%2FAnimateurFreeGL.cpp;fp=WCudaMSE%2FBilatTools_Cuda_Image%2Fsrc%2Fcore%2FcudaImageTools%2Fbitmap%2Fcpp%2FAnimateurFreeGL.cpp;h=6d2a14cc6f84964c185e6c7291e1851f819dfc9c;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/BilatTools_Cuda_Image/src/core/cudaImageTools/bitmap/cpp/AnimateurFreeGL.cpp b/WCudaMSE/BilatTools_Cuda_Image/src/core/cudaImageTools/bitmap/cpp/AnimateurFreeGL.cpp new file mode 100755 index 0000000..6d2a14c --- /dev/null +++ b/WCudaMSE/BilatTools_Cuda_Image/src/core/cudaImageTools/bitmap/cpp/AnimateurFreeGL.cpp @@ -0,0 +1,114 @@ +#include + +#include "cudaTools.h" +#include "Device.h" +#include "MathTools.h" + +#include "Chronos.h" + +#include "AnimateurFreeGL.h" + +using std::cout; +using std::endl; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +AnimateurFreeGL::AnimateurFreeGL(Animable_I* ptrAnimable, int nbIteration) + { + // Input + this->nbIteration = nbIteration; + this->ptrAnimable = ptrAnimable; + + // Outputs + this->fps = -1; + this->timeElapseS = -1; + + start(); + printStat(); + } + +AnimateurFreeGL::~AnimateurFreeGL() + { + delete ptrAnimable; // discutable! + } + +int AnimateurFreeGL::getFps(void) + { + return fps; + } + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +int AnimateurFreeGL::start() + { + cout << "\n[AnimateurFreeGL] : started : " << ptrAnimable->getTitle() << endl; + + int w = ptrAnimable->getW(); + int h = ptrAnimable->getH(); + size_t size = w * h * sizeof(uchar4); + + uchar4* ptrDevImage; + HANDLE_ERROR(cudaMalloc((void**) &ptrDevImage, size)); + HANDLE_ERROR(cudaMemset(ptrDevImage, 0, size)); + + int i = 0; + Chronos chrono; + const char* messageError=ptrAnimable->getTitle().c_str(); + while (i < nbIteration) + { + ptrAnimable->runGPU(ptrDevImage); + + Device::checkKernelError(messageError); + Device::synchronize(); // Important! + + ptrAnimable->animationStep(); + + i++; + } + + chrono.stop(); + HANDLE_ERROR(cudaFree(ptrDevImage)); + + this->timeElapseS = chrono.getDeltaTime(); + this->fps = nbIteration / timeElapseS; + + return fps; + } + +void AnimateurFreeGL::printStat() + { + cout << endl; + cout << "Benchmark : [" << ptrAnimable->getTitle()<<"]" << endl; + cout << "#Iteration : " << nbIteration << endl; + cout << "#secondes : " << timeElapseS << " (s)" << endl; + cout << "#fps : " << fps << endl; + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +