Update specific data problem

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2264 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
boufaras 2011-05-25 21:46:06 +00:00
commit 88ee328e00
2 changed files with 45 additions and 44 deletions

View file

@ -35,23 +35,23 @@
#ifndef _PPPData_H_ #ifndef _PPPData_H_
#define _PPPData_H_ #define _PPPData_H_
#include <memory/moCudaSpecificData.h> #include <memory/moGPUSpecificData.h>
template<class ElemType> template<class ElemType>
class PPPData: public moCudaSpecificData { class PPPData: public moGPUSpecificData {
public: public:
using moCudaSpecificData::cudaObject; using moGPUSpecificData::GPUObject;
/** /**
* Default Constructor * Default Constructor
*/ */
PPPData() : PPPData() :
moCudaSpecificData() { moGPUSpecificData() {
(*this).load(); //(*this).load();
} }
/** /**
@ -62,18 +62,18 @@ public:
PPPData(const PPPData & _pppData) { PPPData(const PPPData & _pppData) {
a_h = new int[Md * Nd]; a_h = new int[Md * Nd];
H_h = new int[Nd + 1]; H_h = new int[Nd];
for (int i = 0; i < Md; i++) for (int i = 0; i < Md; i++)
for (int j = 0; j < Nd; j++) { for (int j = 0; j < Nd; j++) {
a_h[i * Nd + j] = _pppData.a_h[i * Nd + j]; a_h[i * Nd + j] = _pppData.a_h[i * Nd + j];
} }
for (int k = 0; k <= Nd; k++) { for (int k = 0; k < Nd; k++) {
H_h[k] = _pppData.H_h[k]; H_h[k] = _pppData.H_h[k];
} }
cudaObject.memCopy(a_d, a_h, Nd * Md); GPUObject.memCopy(a_d, a_h, Nd * Md);
cudaObject.memCopy(H_d, H_h, Nd + 1); GPUObject.memCopy(H_d, H_h, Nd);
} }
@ -86,17 +86,17 @@ public:
PPPData & operator=(const PPPData & _pppData) { PPPData & operator=(const PPPData & _pppData) {
a_h = new int[Md * Nd]; a_h = new int[Md * Nd];
H_h = new int[Nd + 1]; H_h = new int[Nd];
for (int i = 0; i < Md; i++) for (int i = 0; i < Md; i++)
for (int j = 0; j < Nd; j++) { for (int j = 0; j < Nd; j++) {
a_h[i * Nd + j] = _pppData.a_h[i * Nd + j]; a_h[i * Nd + j] = _pppData.a_h[i * Nd + j];
} }
for (int k = 0; k <= Nd; k++) { for (int k = 0; k < Nd; k++) {
H_h[k] = _pppData.H_h[k]; H_h[k] = _pppData.H_h[k];
} }
cudaObject.memCopy(a_d, a_h, Nd * Md); GPUObject.memCopy(a_d, a_h, Nd * Md);
cudaObject.memCopy(H_d, H_h, Nd + 1); GPUObject.memCopy(H_d, H_h, Nd);
return (*this); return (*this);
} }
@ -106,8 +106,8 @@ public:
*/ */
~PPPData() { ~PPPData() {
cudaObject.memFree(a_d); GPUObject.memFree(a_d);
cudaObject.memFree(H_d); GPUObject.memFree(H_d);
delete[] a_h; delete[] a_h;
delete[] H_h; delete[] H_h;
} }
@ -124,22 +124,20 @@ public:
int *v = new int[Nd]; int *v = new int[Nd];
int *s = new int[Md]; int *s = new int[Md];
a_h = new int[Md * Nd]; a_h = new int[Md * Nd];
H_h = new int[Nd + 1]; H_h = new int[Nd];
for (int i = 0; i < Nd; i++)
H_h[i] = 0;
for (int i = 0; i < Md; i++) { for (int i = 0; i < Md; i++) {
for (int j = 0; j < Nd; j++) { for (int j = 0; j < Nd; j++) {
if (rng.rand() % 2) a_h[i * Nd + j] =pow(-1,rand());
a_h[i * Nd + j] = 1;
else
a_h[i * Nd + j] = -1;
} }
} }
cout <<"v: "<<endl;
for (int i = 0; i < Nd; i++) { for (int i = 0; i < Nd; i++) {
if (rng.rand() % 2) v[i]=pow(-1,rand());
v[i] = 1; printf("%d ", v[i]);
else
v[i] = -1;
} }
cout << endl;
for (int i = 0; i < Md; i++) { for (int i = 0; i < Md; i++) {
s[i] = 0; s[i] = 0;
@ -150,22 +148,25 @@ public:
a_h[i * Nd + k] = -a_h[i * Nd + k]; a_h[i * Nd + k] = -a_h[i * Nd + k];
s[i] = -s[i]; s[i] = -s[i];
} }
if(s[i]>0)
H_h[s[i]-1]++;
} }
for (int i = 0; i < Nd; i++)
printf("%d ", H_h[i]);
cout<<endl;
for (int i = 0; i <= Nd; i++)
H_h[i] = 0;
for (int i = 0; i < Md; i++)
H_h[s[i]]++;
//Allocate and copy QAP data from CPU memory to GPU global memory //Allocate and copy QAP data from CPU memory to GPU global memory
cudaObject.memCopy(a_d, a_h, Nd * Md); GPUObject.memCopy(a_d, a_h, Nd * Md);
cudaObject.memCopy(H_d, H_h, Nd + 1); GPUObject.memCopy(H_d, H_h, Nd);
delete[] v; delete[] v;
delete[] s; delete[] s;
} }
public: public:
ElemType* a_h; ElemType* a_h;

View file

@ -35,22 +35,22 @@
#ifndef _QAPData_H_ #ifndef _QAPData_H_
#define _QAPData_H_ #define _QAPData_H_
#include <memory/moCudaSpecificData.h> #include <memory/moGPUSpecificData.h>
template<class ElemType> template<class ElemType>
class QAPData: public moCudaSpecificData { class QAPData: public moGPUSpecificData {
public: public:
using moCudaSpecificData::sizeData; using moGPUSpecificData::sizeData;
using moCudaSpecificData::cudaObject; using moGPUSpecificData::GPUObject;
/** /**
* Default Constructor * Default Constructor
*/ */
QAPData() : QAPData() :
moCudaSpecificData() { moGPUSpecificData() {
} }
/** /**
@ -83,8 +83,8 @@ public:
} }
cudaObject.memCopy(a_d, a_h, sizeData * sizeData); GPUObject.memCopy(a_d, a_h, sizeData * sizeData);
cudaObject.memCopy(b_d, b_h, sizeData * sizeData); GPUObject.memCopy(b_d, b_h, sizeData * sizeData);
} }
@ -107,8 +107,8 @@ public:
b_h[i * sizeData + j] = _qapData.b_h[i * sizeData + j]; b_h[i * sizeData + j] = _qapData.b_h[i * sizeData + j];
} }
cudaObject.memCopy(a_d, a_h, sizeData * sizeData); GPUObject.memCopy(a_d, a_h, sizeData * sizeData);
cudaObject.memCopy(b_d, b_h, sizeData * sizeData); GPUObject.memCopy(b_d, b_h, sizeData * sizeData);
return (*this); return (*this);
} }
@ -117,8 +117,8 @@ public:
*/ */
~QAPData() { ~QAPData() {
cudaObject.memFree(a_d); GPUObject.memFree(a_d);
cudaObject.memFree(b_d); GPUObject.memFree(b_d);
delete[] a_h; delete[] a_h;
delete[] b_h; delete[] b_h;
} }
@ -151,8 +151,8 @@ public:
file >> b_h[i * sizeData + j]; file >> b_h[i * sizeData + j];
//Allocate and copy QAP data from CPU memory to GPU global memory //Allocate and copy QAP data from CPU memory to GPU global memory
cudaObject.memCopy(a_d, a_h, sizeData * sizeData); GPUObject.memCopy(a_d, a_h, sizeData * sizeData);
cudaObject.memCopy(b_d, b_h, sizeData * sizeData); GPUObject.memCopy(b_d, b_h, sizeData * sizeData);
} }