Début du TP convolution. Pour l'instant uniquement lecture d'une vidéo.
[GPU.git] / WCudaMSE / Student_Cuda_Image / src / cpp / core / 06_Convolution / moo / host / Convolution.cu
1 #include <iostream>
2 #include <assert.h>
3 #include <stdio.h>
4 using namespace std;
5
6 #include "Device.h"
7
8 #include "Convolution.h"
9 #include "ConvolutionDevice.h"
10
11
12 const float Convolution::kernel[9][9] =
13        {{0.0828, 0.1987, 0.3705, 0.5366, 0.6063, 0.5366, 0.3705, 0.1987, 0.0828},
14        {0.1987, 0.4746, 0.8646, 1.1794, 1.2765, 1.1794, 0.8646, 0.4746, 0.1987},
15        {0.3705, 0.8646, 1.3475, 1.0033, 0.4061, 1.0033, 1.3475, 0.8646, 0.3705},
16        {0.5366, 1.1794, 1.0033, -2.8306, -6.4829, -2.8306, 1.0033, 1.1794, 0.5366},
17        {0.6063, 1.2765, 0.4061, -6.4829, -12.7462, -6.4829, 0.4061, 1.2765, 0.6063},
18        {0.5366, 1.1794, 1.0033, -2.8306, -6.4829, -2.8306, 1.0033, 1.1794, 0.5366},
19        {0.3705, 0.8646, 1.3475, 1.0033, 0.4061, 1.0033, 1.3475, 0.8646, 0.3705},
20        {0.1987, 0.4746, 0.8646, 1.1794, 1.2765, 1.1794, 0.8646, 0.4746, 0.1987},
21        {0.0828, 0.1987, 0.3705, 0.5366, 0.6063, 0.5366, 0.3705, 0.1987, 0.0828}};
22
23 Convolution::Convolution(int w, int h) :
24       w(w), h(h),
25       dg(8, 8, 1),
26       db(32, 32, 1),
27       title("Convolution")
28     {
29     Device::assertDim(dg, db);
30     }
31
32 Convolution::~Convolution()
33     {
34     }
35
36 void Convolution::runGPU(uchar4* ptrDevPixels)
37     {
38     convolution<<<dg,db>>>(ptrDevPixels, this->w, this->h, this->t);
39
40     // HANDLE_ERROR(cudaDeviceSynchronize()); // Pour flusher les 'printf' (pour le DEBUG).
41     }
42
43 void Convolution::animationStep()
44     {
45     this->t += 0.1; // TODO.
46     }
47
48 int Convolution::getW()
49     {
50     return this->w;
51     }
52
53 int Convolution::getH()
54     {
55     return this->h;
56     }
57
58 float Convolution::getT()
59     {
60     return this->t;
61     }
62
63 string Convolution::getTitle()
64     {
65     return this->title;
66     }
67