/**\r
* getParaAnimation\r
*/\r
- virtual float getT()=0;\r
-\r
- virtual string getTitle()=0;\r
+ virtual float getT() = 0;\r
\r
+ virtual string getTitle() = 0;\r
};\r
\r
#endif\r
<buildSpec>\r
<buildCommand>\r
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>\r
- <triggers>full,incremental,</triggers>\r
+ <triggers>clean,full,incremental,</triggers>\r
<arguments>\r
<dictionary>\r
<key>?name?</key>\r
int* ptrDev_c; // on device (GPU)\r
\r
// Specifier nb thread : ici 1 thread au total !\r
- dim3 dg = dim3(1,1,1);\r
+ dim3 dg = dim3(1, 1, 1);\r
dim3 db = dim3(1, 1, 1);\r
\r
// Debug\r
--- /dev/null
+#include <iostream>
+
+#include "Indice2D.h"
+#include "cudaTools.h"
+#include "Device.h"
+
+using std::cout;
+using std::endl;
+
+static __global__ void add(float* ptrDevV1, float* ptrDevV2, int n, float* ptrDevResult);
+static __device__ float work(float v1, float v2);
+
+__global__ void add(float* ptrDevV1, float* ptrDevV2, int n, float* ptrDevResult)
+ {
+ const int NB_THREAD = Indice2D::nbThread();
+ const int TID = Indice2D::tid();
+
+ int s = TID;
+
+ while (s < n)
+ {
+ ptrDevResult[s] = work(ptrDevV1[s], ptrDevV2[s]);
+ s += NB_THREAD;
+ }
+ }
+
+__device__ float work(float v1, float v2)
+ {
+ return v1 + v2;
+ }
+
+bool addVectors()
+ {
+ // Inputs (passé en paramètre de la fonction dans un cas général).
+ float v1[] = { 1, 2, 3 };
+ float v2[] = { 10, 20, 30 };
+
+ // Outputs (renvoyer de la fonction dans un cas général).
+ float vRes[3];
+
+ // Allocation coté GPU.
+ float* ptrDevV1, *ptrDevV2, *ptrDevVResult = 0;
+ const size_t vecSize = 3 * sizeof(float);
+ HANDLE_ERROR(cudaMalloc(&ptrDevV1, vecSize));
+ HANDLE_ERROR(cudaMalloc(&ptrDevV2, vecSize));
+ HANDLE_ERROR(cudaMalloc(&ptrDevVResult, vecSize));
+
+ HANDLE_ERROR(cudaMemset(ptrDevV1, 0, vecSize));
+ HANDLE_ERROR(cudaMemset(ptrDevV2, 0, vecSize));
+ HANDLE_ERROR(cudaMemset(ptrDevVResult, 0, vecSize));
+
+ HANDLE_ERROR(cudaMemcpy(ptrDevV1, v1, vecSize, cudaMemcpyHostToDevice));
+ HANDLE_ERROR(cudaMemcpy(ptrDevV2, v2, vecSize, cudaMemcpyHostToDevice));
+
+ const dim3 dg(2, 2, 1);
+ const dim3 db(2, 2, 1);
+ Device::assertDim(dg, db);
+
+ add<<<dg, db>>>(ptrDevV1, ptrDevV2, 3, ptrDevVResult);
+
+ // Barrière implicite de synchronisation ('cudaMemCpy').
+ HANDLE_ERROR(cudaMemcpy(vRes, ptrDevVResult, vecSize, cudaMemcpyDeviceToHost));
+
+ return vRes[0] == 11 && vRes[1] == 22 && vRes[2] == 33;
+ }
\*-------------------------------------*/
extern bool useHello(void);
+extern bool addVectors();
/*--------------------------------------*\
|* Public *|
{
bool isOk = true;
isOk &= useHello();
+ isOk &= addVectors();
cout << "\nisOK = " << isOk << endl;
cout << "\nEnd : mainCore" << endl;
{
Device::printCurrent();
- bool IS_TEST = true;
+ bool IS_TEST = false;
if (IS_TEST)
{
void color(int i, int j, float t, uchar4* ptrColor)\r
{\r
const double dxy10 = dxy(j, i) / 10.0;\r
- const double grayLevelFloat = 128.0 + 127.0 * cos(dxy10 - 100.0 * t / 7.0) / (dxy10 + 1);\r
+ const double grayLevelFloat = 128.0 + 127.0 * cos(dxy10 - t / 7.0) / (dxy10 + 1);\r
const uchar grayLevel = (uchar)(long(grayLevelFloat) % 256);\r
\r
ptrColor->x = grayLevel;\r
\r
static Rippling0Image* createGL(void)\r
{\r
- float dt = 2 * PI / 1000; // animation para\r
+ float dt = 1;\r
\r
int dw = 16 * 60; // =32*30=960\r
int dh = 16 * 60; // =32*30=960\r
void color(int i, int j, float t, uchar4& color)\r
{\r
const double dxy10 = dxy(j, i) / 10.0;\r
- const double grayLevelFloat = 128.0 + 127.0 * cos(dxy10 - t / 7.0 / 10.0) / (dxy10 + 1);\r
+ const double grayLevelFloat = 128.0 + 127.0 * cos(dxy10 - t / 7.0) / (dxy10 + 1);\r
const uchar grayLevel = (uchar)(long(grayLevelFloat) % 256);\r
\r
color.x = grayLevel;\r
\r
const int TID = Indice2D::tid();\r
const int NB_THREAD = Indice2D::nbThread();\r
-\r
const int WH = w * h;\r
\r
uchar4 color;\r
- color.z = 255;\r
+ color.z = 255; // Par défaut, l'image est opaque.\r
\r
int pixelI;\r
int pixelJ;\r
int s = TID;\r
while (s < WH)\r
{\r
- IndiceTools::toIJ(s, w, &pixelI, &pixelJ); // update (pixelI, pixelJ)\r
-\r
- ripplingMath.color(pixelI, pixelJ, t, color); // update color\r
+ IndiceTools::toIJ(s, w, &pixelI, &pixelJ);\r
+ ripplingMath.color(pixelI, pixelJ, t, color);\r
ptrDevPixels[s] = color;\r
-\r
s += NB_THREAD;\r
}\r
}\r
\*-------------------------*/\r
\r
Rippling::Rippling(int w, int h, float dt)\r
- : w(w), h(h), dt(dt), t(0)\r
+ : w(w), h(h), dt(dt), t(0),\r
+ dg(8, 8, 1),\r
+ db(16, 16, 1),\r
+ title("Rippling Cuda")\r
{\r
assert(w == h);\r
\r
- // Tools\r
- this->dg = dim3(8, 8, 1); // disons a optimiser\r
- this->db = dim3(16, 16, 1); // disons a optimiser\r
-\r
- // Outputs\r
- this->title = "Rippling Cuda";\r
-\r
//print(dg, db);\r
Device::assertDim(dg, db);\r
}\r
\r
Rippling* RipplingProvider::createMOO()\r
{\r
- float dt = 1;\r
-\r
- int dw = 16 * 60; // =32*30=960\r
- int dh = 16 * 60; // =32*30=960\r
+ const float dt = 1;\r
+ const int dw = 16 * 60; // =32*30=960\r
+ const int dh = 16 * 60; // =32*30=960\r
\r
return new Rippling(dw, dh, dt);\r
}\r
\r
int mainGL(void)\r
{\r
- //Rippling0Image* ptrRippling0 = Rippling0Provider::createGL();\r
+ Rippling0Image* ptrRippling0 = Rippling0Provider::createGL();\r
Image* ptrRippling = RipplingProvider::createGL();\r
// TODO : Insert autres Images ...\r
\r
- bool isAnimation = true;\r
- bool isSelection = true;\r
+ const bool isAnimation = true;\r
+ const bool isSelection = true;\r
\r
- //GLUTImageViewers rippling0Viewer(ptrRippling0, isAnimation, isSelection, 0, 0);\r
+ GLUTImageViewers rippling0Viewer(ptrRippling0, isAnimation, isSelection, 0, 0);\r
GLUTImageViewers ripplingViewer(ptrRippling, isAnimation, isSelection, 10, 10);\r
// TODO : Insert here autres ImageViewers ...\r
\r
GLUTImageViewers::runALL(); // Bloquant, Tant qu'une fenetre est ouverte\r
\r
// destruction\r
- {\r
- //delete ptrRippling0;\r
- delete ptrRippling;\r
- }\r
+ delete ptrRippling0;\r
+ delete ptrRippling;\r
\r
return EXIT_SUCCESS;\r
}\r