Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 00_Rippling_warmup / rippling0FreeGL.cpp
1 #include <iostream>
2 #include "cudaTools.h"
3 #include "Device.h"
4 #include "MathTools.h"
5
6 #include "Chronos.h"
7
8 using std::cout;
9 using std::endl;
10
11 /*----------------------------------------------------------------------*\
12 |* Declaration *|
13 \*---------------------------------------------------------------------*/
14
15 /*--------------------------------------*\
16 |* Imported *|
17 \*-------------------------------------*/
18
19 extern void launchKernelRippling0(uchar4* ptrDevPixels, int w, int h, float t);
20
21 /*--------------------------------------*\
22 |* Public *|
23 \*-------------------------------------*/
24
25 int rippling0FreeGL(int itmax);
26
27 /*--------------------------------------*\
28 |* Private *|
29 \*-------------------------------------*/
30
31 /*----------------------------------------------------------------------*\
32 |* Implementation *|
33 \*---------------------------------------------------------------------*/
34
35 /*--------------------------------------*\
36 |* Public *|
37 \*-------------------------------------*/
38
39 /**
40 * Hyp: itmax suffisamment grand pour que timeElapse soit significatif
41 */
42 int rippling0FreeGL(int itmax)
43 {
44 cout<<"\n[Rippling0] : FreeGL running ..."<<endl;
45
46 int h = 16 * 60;
47 int w = h;
48
49 uchar4* ptrDevImage;
50 size_t size = w * h * sizeof(uchar4);
51 HANDLE_ERROR(cudaMalloc((void**) &ptrDevImage, size));
52 HANDLE_ERROR(cudaMemset(ptrDevImage, 0, size));
53
54 int i = 0;
55 float t = 0;
56 float dt = 2 * PI / 10;
57 Chronos chrono;
58
59 while (i < itmax)
60 {
61 launchKernelRippling0(ptrDevImage, w, h, t);
62 Device::checkKernelError("Rippling0");
63 Device::synchronize();
64
65 t += dt;
66 i++;
67 }
68
69 chrono.stop();
70 HANDLE_ERROR(cudaFree(ptrDevImage));
71
72 double timeElapseS = chrono.getDeltaTime();
73 int fps = itmax / timeElapseS;
74
75 cout << "fps : "<<fps<<endl;
76
77 return fps;
78 }
79
80 /*--------------------------------------*\
81 |* Private *|
82 \*-------------------------------------*/
83
84 /*----------------------------------------------------------------------*\
85 |* End *|
86 \*---------------------------------------------------------------------*/
87