Rippling CUDA Warmup et Smart.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 00_Rippling_warmup / 02_cuda / rippling0.cu
1 #include <iostream>\r
2 #include <stdlib.h>\r
3 \r
4 #include "Indice2D.h"\r
5 #include "IndiceTools.h"\r
6 #include "cudaTools.h"\r
7 #include "Device.h"\r
8 \r
9 #include "Rippling0Math.h"\r
10 \r
11 using std::cout;\r
12 using std::endl;\r
13 \r
14 /*----------------------------------------------------------------------*\\r
15  |*                     Declaration                                     *|\r
16  \*---------------------------------------------------------------------*/\r
17 \r
18 /*--------------------------------------*\\r
19  |*             Imported                *|\r
20  \*-------------------------------------*/\r
21 \r
22 /*--------------------------------------*\\r
23  |*             Public                  *|\r
24  \*-------------------------------------*/\r
25 \r
26 \r
27 \r
28 /*--------------------------------------*\\r
29  |*             Private                 *|\r
30  \*-------------------------------------*/\r
31 \r
32 static __global__ void rippling0(uchar4* ptrDevPixels,int w, int h,float t);\r
33 \r
34 /*----------------------------------------------------------------------*\\r
35  |*                     Implementation                                  *|\r
36  \*---------------------------------------------------------------------*/\r
37 \r
38 /*--------------------------------------*\\r
39  |*             Public                  *|\r
40  \*-------------------------------------*/\r
41 \r
42 void launchKernelRippling0(uchar4* ptrDevPixels, int w, int h, float t)\r
43     {\r
44     dim3 dg = dim3(4, 4, 1); // disons, a optimiser\r
45     dim3 db = dim3(8, 8, 1); // disons, a optimiser\r
46 \r
47     //Device::print(dg, db);\r
48     Device::checkDimError(dg,db);\r
49 \r
50     rippling0<<<dg,db>>>(ptrDevPixels,w,h,t);\r
51     Device::checkKernelError("rippling0");\r
52     }\r
53 \r
54 /*--------------------------------------*\\r
55  |*             Private                 *|\r
56  \*-------------------------------------*/\r
57 \r
58 __global__ void rippling0(uchar4* ptrDevPixels, int w, int h, float t)\r
59     {\r
60     Rippling0Math rippling0Math(w, h);\r
61 \r
62     const int TID = Indice2D::tid();\r
63     const int NB_THREAD = Indice2D::nbThread();\r
64 \r
65     const int WH=w*h;\r
66 \r
67     uchar4 color;\r
68     color.w = 255; // alpha\r
69 \r
70     int pixelI;\r
71     int pixelJ;\r
72 \r
73     int s = TID;\r
74     while (s < WH)\r
75         {\r
76         IndiceTools::toIJ(s, w, &pixelI, &pixelJ); // update (pixelI, pixelJ)\r
77 \r
78         rippling0Math.color(pixelI, pixelJ, t, &color); // update color\r
79         ptrDevPixels[s] = color;\r
80 \r
81         s += NB_THREAD;\r
82         }\r
83 \r
84     }\r
85 \r
86 \r
87 \r
88 /*----------------------------------------------------------------------*\\r
89  |*                     End                                             *|\r
90  \*---------------------------------------------------------------------*/\r
91 \r