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
diff --git a/WCudaMSE/Student_Cuda_Image/src/cpp/core/06_Convolution/moo/host/Convolution.cu b/WCudaMSE/Student_Cuda_Image/src/cpp/core/06_Convolution/moo/host/Convolution.cu
new file mode 100644 (file)
index 0000000..ecc4464
--- /dev/null
@@ -0,0 +1,67 @@
+#include <iostream>
+#include <assert.h>
+#include <stdio.h>
+using namespace std;
+
+#include "Device.h"
+
+#include "Convolution.h"
+#include "ConvolutionDevice.h"
+
+
+const float Convolution::kernel[9][9] =
+       {{0.0828, 0.1987, 0.3705, 0.5366, 0.6063, 0.5366, 0.3705, 0.1987, 0.0828},
+       {0.1987, 0.4746, 0.8646, 1.1794, 1.2765, 1.1794, 0.8646, 0.4746, 0.1987},
+       {0.3705, 0.8646, 1.3475, 1.0033, 0.4061, 1.0033, 1.3475, 0.8646, 0.3705},
+       {0.5366, 1.1794, 1.0033, -2.8306, -6.4829, -2.8306, 1.0033, 1.1794, 0.5366},
+       {0.6063, 1.2765, 0.4061, -6.4829, -12.7462, -6.4829, 0.4061, 1.2765, 0.6063},
+       {0.5366, 1.1794, 1.0033, -2.8306, -6.4829, -2.8306, 1.0033, 1.1794, 0.5366},
+       {0.3705, 0.8646, 1.3475, 1.0033, 0.4061, 1.0033, 1.3475, 0.8646, 0.3705},
+       {0.1987, 0.4746, 0.8646, 1.1794, 1.2765, 1.1794, 0.8646, 0.4746, 0.1987},
+       {0.0828, 0.1987, 0.3705, 0.5366, 0.6063, 0.5366, 0.3705, 0.1987, 0.0828}};
+
+Convolution::Convolution(int w, int h) :
+      w(w), h(h),
+      dg(8, 8, 1),
+      db(32, 32, 1),
+      title("Convolution")
+    {
+    Device::assertDim(dg, db);
+    }
+
+Convolution::~Convolution()
+    {
+    }
+
+void Convolution::runGPU(uchar4* ptrDevPixels)
+    {
+    convolution<<<dg,db>>>(ptrDevPixels, this->w, this->h, this->t);
+
+    // HANDLE_ERROR(cudaDeviceSynchronize()); // Pour flusher les 'printf' (pour le DEBUG).
+    }
+
+void Convolution::animationStep()
+    {
+    this->t += 0.1; // TODO.
+    }
+
+int Convolution::getW()
+    {
+    return this->w;
+    }
+
+int Convolution::getH()
+    {
+    return this->h;
+    }
+
+float Convolution::getT()
+    {
+    return this->t;
+    }
+
+string Convolution::getTitle()
+    {
+    return this->title;
+    }
+