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