ad90374ad0d5e175ec452e29f06f12f6d933605e
[GPU.git] / AnimateurFonctionelFreeGL.cpp
1 #include <iostream>
2
3 #include "cudaTools.h"
4 #include "Device.h"
5 #include "MathTools.h"
6 #include "StringTools.h"
7
8 #include "Chronos.h"
9
10 #include "AnimateurFonctionelFreeGL.h"
11
12 using std::cout;
13 using std::endl;
14
15 /*----------------------------------------------------------------------*\
16 |* Declaration *|
17 \*---------------------------------------------------------------------*/
18
19 /*--------------------------------------*\
20 |* Imported *|
21 \*-------------------------------------*/
22
23 /*--------------------------------------*\
24 |* Public *|
25 \*-------------------------------------*/
26
27 /*--------------------------------------*\
28 |* Private *|
29 \*-------------------------------------*/
30
31 /*----------------------------------------------------------------------*\
32 |* Implementation *|
33 \*---------------------------------------------------------------------*/
34
35 /*--------------------------------------*\
36 |* Public *|
37 \*-------------------------------------*/
38
39 AnimateurFonctionelFreeGL::AnimateurFonctionelFreeGL(AnimableFonctionel_I* ptrAnimable, int nbIteration)
40 {
41 // Input
42 this->nbIteration = nbIteration;
43 this->ptrAnimable = ptrAnimable;
44
45 // Outputs
46 this->fps = -1;
47 this->timeElapseS = -1;
48
49 start();
50 printStat();
51 }
52
53 AnimateurFonctionelFreeGL::~AnimateurFonctionelFreeGL()
54 {
55 delete ptrAnimable; // discutable!
56 }
57
58 int AnimateurFonctionelFreeGL::getFps(void)
59 {
60 return fps;
61 }
62
63 /*--------------------------------------*\
64 |* Private *|
65 \*-------------------------------------*/
66
67 int AnimateurFonctionelFreeGL::start()
68 {
69 cout << "\n[AnimateurFreeGL] : started : " << ptrAnimable->getTitle() << endl;
70
71 int w = ptrAnimable->getW();
72 int h = ptrAnimable->getH();
73 size_t size = w * h * sizeof(uchar4);
74
75 uchar4* ptrDevImage;
76 HANDLE_ERROR(cudaMalloc((void**) &ptrDevImage, size));
77 HANDLE_ERROR(cudaMemset(ptrDevImage, 0, size));
78
79 int i = 0;
80 Chronos chrono;
81
82 DomaineMath* ptrDomaineMath=ptrAnimable->getDomaineMathInit();
83 const char* messageError=ptrAnimable->getTitle().c_str();
84 while (i < nbIteration)
85 {
86 ptrAnimable->runGPU(ptrDevImage,*ptrDomaineMath);
87
88 Device::checkKernelError(messageError);
89 Device::synchronize(); // Important!
90
91 ptrAnimable->animationStep();
92
93 i++;
94 }
95
96 chrono.stop();
97 HANDLE_ERROR(cudaFree(ptrDevImage));
98
99 this->timeElapseS = chrono.getDeltaTime();
100 this->fps = nbIteration / timeElapseS;
101
102 return fps;
103 }
104
105 void AnimateurFonctionelFreeGL::printStat()
106 {
107 cout << endl;
108 cout << "Benchmark : [" << ptrAnimable->getTitle()<<"]" << endl;
109 cout << "#Iteration : " << nbIteration << endl;
110 cout << "#secondes : " << timeElapseS << " (s)" << endl;
111 cout << "#fps : " << fps << endl;
112 }
113
114 /*----------------------------------------------------------------------*\
115 |* End *|
116 \*---------------------------------------------------------------------*/
117