independent ParadisEO-GPU package
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2591 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
682c458e90
commit
c031a4a810
5 changed files with 662 additions and 0 deletions
|
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
<moGPUBitVector.h>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
|
Karima Boufaras, Thé Van LUONG
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can use,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
As a counterpart to the access to the source code and rights to copy,
|
||||||
|
modify and redistribute granted by the license, users are provided only
|
||||||
|
with a limited warranty and the software's author, the holder of the
|
||||||
|
economic rights, and the successive licensors have only limited liability.
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __moGPUBitVector_H_
|
||||||
|
#define __moGPUBitVector_H_
|
||||||
|
|
||||||
|
#include <GPUType/moGPUVector.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of Bit vector representation on GPU.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class Fitness>
|
||||||
|
|
||||||
|
class moGPUBitVector: public moGPUVector<bool, Fitness> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define bool vector corresponding to Solution
|
||||||
|
**/
|
||||||
|
typedef bool ElemType;
|
||||||
|
using moGPUVector<bool, Fitness>::vect;
|
||||||
|
using moGPUVector<bool, Fitness>::N;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUBitVector() :
|
||||||
|
moGPUVector<bool, Fitness> () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Constructor.
|
||||||
|
*@param _neighborhoodSize The neighborhood size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUBitVector(unsigned _neighborhoodSize) :
|
||||||
|
moGPUVector<bool, Fitness> (_neighborhoodSize) {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Constructor.
|
||||||
|
*@param _neighborhoodSize The neighborhood size.
|
||||||
|
*@param _b Value to assign to vector.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUBitVector(unsigned _neighborhoodSize, bool _b) :
|
||||||
|
moGPUVector<bool, Fitness> (_neighborhoodSize) {
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < _neighborhoodSize; i++)
|
||||||
|
vect[i] = _b;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Initializer of random bit vector.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void create() {
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < N; i++) {
|
||||||
|
|
||||||
|
vect[i] = (int) (rng.rand() / RAND_MAX);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Function inline to set the size of vector, called from host.
|
||||||
|
*@param _size the vector size
|
||||||
|
*/
|
||||||
|
|
||||||
|
void setSize(unsigned _size) {
|
||||||
|
|
||||||
|
if (_size < N) {
|
||||||
|
moGPUBitVector<Fitness> tmp_vect(_size);
|
||||||
|
for (unsigned i = 0; i < tmp_vect.N; i++)
|
||||||
|
tmp_vect.vect[i] = vect[i];
|
||||||
|
(tmp_vect).invalidate();
|
||||||
|
(*this) = tmp_vect;
|
||||||
|
} else if (_size > N) {
|
||||||
|
moGPUBitVector<Fitness> tmp_vect(_size);
|
||||||
|
for (unsigned i = 0; i < N; i++)
|
||||||
|
tmp_vect.vect[i] = vect[i];
|
||||||
|
(tmp_vect).invalidate();
|
||||||
|
(*this) = tmp_vect;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
|
* @param _os A std::ostream.
|
||||||
|
*/
|
||||||
|
void printOn(std::ostream& _os) const {
|
||||||
|
EO<Fitness>::printOn(_os);
|
||||||
|
_os << ' ';
|
||||||
|
_os << N << ' ';
|
||||||
|
for (unsigned int i = 0; i < N; i++)
|
||||||
|
_os << (*this)[i] << ' ';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
/*
|
||||||
|
<moGPUIntVector.h>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
|
Karima Boufaras, Thé Van LUONG
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can use,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
As a counterpart to the access to the source code and rights to copy,
|
||||||
|
modify and redistribute granted by the license, users are provided only
|
||||||
|
with a limited warranty and the software's author, the holder of the
|
||||||
|
economic rights, and the successive licensors have only limited liability.
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __moGPUIntVector_H_
|
||||||
|
#define __moGPUIntVector_H_
|
||||||
|
|
||||||
|
#include <GPUType/moGPUVector.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of integer vector representation on GPU.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class Fitness>
|
||||||
|
|
||||||
|
class moGPUIntVector: public moGPUVector<int, Fitness> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
using moGPUVector<int, Fitness>::vect;
|
||||||
|
using moGPUVector<int, Fitness>::N;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUIntVector() :
|
||||||
|
moGPUVector<int, Fitness> () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Constructor.
|
||||||
|
*@param _neighborhoodSize The neighborhood size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUIntVector(unsigned _neighborhoodSize) :
|
||||||
|
moGPUVector<int, Fitness> (_neighborhoodSize) {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Initializer of random integer vector.
|
||||||
|
*/
|
||||||
|
virtual void create() {
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < N; i++)
|
||||||
|
vect[i] = ((int) (rng.rand())) % N + 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Function inline to set the size of vector, called from host.
|
||||||
|
*@param _size the vector size
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual inline __host__ void setSize(unsigned _size) {
|
||||||
|
|
||||||
|
if(N==_size)
|
||||||
|
return;
|
||||||
|
moGPUIntVector<Fitness> tmp_vect(_size);
|
||||||
|
if(_size<N) {
|
||||||
|
for (unsigned i = 0; i < tmp_vect.N; i++)
|
||||||
|
tmp_vect.vect[i]= vect[i];
|
||||||
|
}
|
||||||
|
else if(_size>N) {
|
||||||
|
for (unsigned i = 0; i <N; i++)
|
||||||
|
tmp_vect.vect[i]= vect[i];
|
||||||
|
}
|
||||||
|
(tmp_vect).invalidate();
|
||||||
|
(*this)=tmp_vect;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
|
* @param _os A std::ostream.
|
||||||
|
*/
|
||||||
|
void printOn(std::ostream& _os) const {
|
||||||
|
EO<Fitness>::printOn(_os);
|
||||||
|
_os << ' ';
|
||||||
|
_os << N << ' ';
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < N; i++)
|
||||||
|
_os << vect[i] << ' ';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*
|
||||||
|
<moGPUPermutationVector.h>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
|
Karima Boufaras, Thé Van LUONG
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can use,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
As a counterpart to the access to the source code and rights to copy,
|
||||||
|
modify and redistribute granted by the license, users are provided only
|
||||||
|
with a limited warranty and the software's author, the holder of the
|
||||||
|
economic rights, and the successive licensors have only limited liability.
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __moGPUPermutationVector_H_
|
||||||
|
#define __moGPUPermutationVector_H_
|
||||||
|
|
||||||
|
#include <GPUType/moGPUIntVector.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of Permutation vector representation on GPU.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class Fitness>
|
||||||
|
|
||||||
|
class moGPUPermutationVector: public moGPUIntVector<Fitness> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
using moGPUIntVector<Fitness>::vect;
|
||||||
|
using moGPUIntVector<Fitness>::N;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUPermutationVector() :
|
||||||
|
moGPUIntVector<Fitness> () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Constructor.
|
||||||
|
*@param _size The solution size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUPermutationVector(unsigned _size) :
|
||||||
|
moGPUIntVector<Fitness> (_size) {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*Initializer of random permuatation vector.
|
||||||
|
*/
|
||||||
|
void create() {
|
||||||
|
|
||||||
|
unsigned random;
|
||||||
|
int tmp;
|
||||||
|
for (unsigned i = 0; i < N; i++)
|
||||||
|
vect[i] = i;
|
||||||
|
// we want a random permutation so we shuffle
|
||||||
|
for (unsigned i = 0; i < N; i++) {
|
||||||
|
random = rng.rand() % (N - i) + i;
|
||||||
|
tmp = vect[i];
|
||||||
|
vect[i] = vect[random];
|
||||||
|
vect[random] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
<moGPURealVector.h>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
|
Karima Boufaras, Thé Van LUONG
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can use,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
As a counterpart to the access to the source code and rights to copy,
|
||||||
|
modify and redistribute granted by the license, users are provided only
|
||||||
|
with a limited warranty and the software's author, the holder of the
|
||||||
|
economic rights, and the successive licensors have only limited liability.
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __moGPURealVector_H_
|
||||||
|
#define __moGPURealVector_H_
|
||||||
|
|
||||||
|
#include <GPUType/moGPUVector.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of real vector representation on GPU.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class Fitness>
|
||||||
|
|
||||||
|
class moGPURealVector: public moGPUVector<float, Fitness> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
using moGPUVector<float, Fitness>::vect;
|
||||||
|
using moGPUVector<float, Fitness>::N;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPURealVector() :
|
||||||
|
moGPUVector<float, Fitness> () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Constructor.
|
||||||
|
*@param _neighborhoodSize The neighborhood size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPURealVector(unsigned _neighborhoodSize) :
|
||||||
|
moGPUVector<float, Fitness> (_neighborhoodSize) {
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Initializer of random real vector.
|
||||||
|
*/
|
||||||
|
void create() {
|
||||||
|
for (unsigned i = 0; i < N; i++)
|
||||||
|
vect[i] = (float) rng.rand() / RAND_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Function inline to set the size of vector, called from host.
|
||||||
|
*@param _size the vector size
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual inline __host__ void setSize(unsigned _size) {
|
||||||
|
|
||||||
|
if(_size<N) {
|
||||||
|
moGPURealVector<Fitness> tmp_vect(_size);
|
||||||
|
for (unsigned i = 0; i < tmp_vect.N; i++)
|
||||||
|
tmp_vect.vect[i]= vect[i];
|
||||||
|
(tmp_vect).invalidate();
|
||||||
|
(*this)=tmp_vect;
|
||||||
|
}
|
||||||
|
else if(_size>N) {
|
||||||
|
moGPURealVector<Fitness> tmp_vect(_size);
|
||||||
|
for (unsigned i = 0; i <N; i++)
|
||||||
|
tmp_vect.vect[i]= vect[i];
|
||||||
|
(tmp_vect).invalidate();
|
||||||
|
(*this)=tmp_vect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
|
* @param _os A std::ostream.
|
||||||
|
*/
|
||||||
|
void printOn(std::ostream& _os) const {
|
||||||
|
EO<Fitness>::printOn(_os);
|
||||||
|
_os << ' ';
|
||||||
|
_os << N << ' ';
|
||||||
|
unsigned int i;
|
||||||
|
for (i = 0; i < N; i++)
|
||||||
|
_os << vect[i] << ' ';
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
184
branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUVector.h
Normal file
184
branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUVector.h
Normal file
|
|
@ -0,0 +1,184 @@
|
||||||
|
/*
|
||||||
|
<moGPUVector.h>
|
||||||
|
Copyright (C) DOLPHIN Project-Team, INRIA Lille - Nord Europe, 2006-2010
|
||||||
|
|
||||||
|
Karima Boufaras, Thé Van LUONG
|
||||||
|
|
||||||
|
This software is governed by the CeCILL license under French law and
|
||||||
|
abiding by the rules of distribution of free software. You can use,
|
||||||
|
modify and/ or redistribute the software under the terms of the CeCILL
|
||||||
|
license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
"http://www.cecill.info".
|
||||||
|
|
||||||
|
As a counterpart to the access to the source code and rights to copy,
|
||||||
|
modify and redistribute granted by the license, users are provided only
|
||||||
|
with a limited warranty and the software's author, the holder of the
|
||||||
|
economic rights, and the successive licensors have only limited liability.
|
||||||
|
|
||||||
|
In this respect, the user's attention is drawn to the risks associated
|
||||||
|
with loading, using, modifying and/or developing or reproducing the
|
||||||
|
software by the user in light of its specific status of free software,
|
||||||
|
that may mean that it is complicated to manipulate, and that also
|
||||||
|
therefore means that it is reserved for developers and experienced
|
||||||
|
professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
encouraged to load and test the software's suitability as regards their
|
||||||
|
requirements in conditions enabling the security of their systems and/or
|
||||||
|
data to be ensured and, more generally, to use and operate it in the
|
||||||
|
same conditions as regards security.
|
||||||
|
The fact that you are presently reading this means that you have had
|
||||||
|
knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
|
||||||
|
ParadisEO WebSite : http://paradiseo.gforge.inria.fr
|
||||||
|
Contact: paradiseo-help@lists.gforge.inria.fr
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __moGPUVector_H_
|
||||||
|
#define __moGPUVector_H_
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of a GPU solution representation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
template<class ElemT, class Fitness>
|
||||||
|
|
||||||
|
class moGPUVector: public EO<Fitness> {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define vector type corresponding to Solution
|
||||||
|
*/
|
||||||
|
typedef ElemT ElemType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUVector() :
|
||||||
|
N(0) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Constructor.
|
||||||
|
*@param _size The solution size.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUVector(unsigned _size) :
|
||||||
|
N(_size) {
|
||||||
|
vect = new ElemType[N];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Copy Constructor
|
||||||
|
*@param _vector The vector passed to the function to determine the new content.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUVector(const moGPUVector & _vector) {
|
||||||
|
|
||||||
|
N = _vector.N;
|
||||||
|
vect = new ElemType[N];
|
||||||
|
for (unsigned i = 0; i < N; i++)
|
||||||
|
vect[i] = _vector.vect[i];
|
||||||
|
if (!(_vector.invalid()))
|
||||||
|
fitness(_vector.fitness());
|
||||||
|
else
|
||||||
|
(*this).invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructor.
|
||||||
|
*/
|
||||||
|
|
||||||
|
~moGPUVector() {
|
||||||
|
if (N >= 1)
|
||||||
|
delete[] vect;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*How to fill the solution vector.
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual void create() =0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Assignment operator
|
||||||
|
*@param _vector The vector passed to the function to determine the new content.
|
||||||
|
*@return a new vector.
|
||||||
|
*/
|
||||||
|
|
||||||
|
moGPUVector& operator=(const moGPUVector & _vector) {
|
||||||
|
|
||||||
|
if (!(N == _vector.N)) {
|
||||||
|
N = _vector.N;
|
||||||
|
vect = new ElemType[N];
|
||||||
|
}
|
||||||
|
for (unsigned i = 0; i < N; i++){
|
||||||
|
vect[i] = _vector[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(_vector.invalid()))
|
||||||
|
fitness(_vector.fitness());
|
||||||
|
else
|
||||||
|
(*this).invalidate();
|
||||||
|
return (*this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*An accessor read only on the i'th element of the vector (function inline can be called from host or device).
|
||||||
|
*@param _i The i'th element of vector.
|
||||||
|
*@return The i'th element of the vector for read only
|
||||||
|
*/
|
||||||
|
|
||||||
|
inline __host__ __device__ const ElemType & operator[](unsigned _i) const {
|
||||||
|
|
||||||
|
return vect[_i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*An accessor read-write on the i'th element of the vector(function inline can be called from host or device).
|
||||||
|
*@param _i The i'th element of the vector.
|
||||||
|
*@return The i'th element of the vector for read-write
|
||||||
|
*/
|
||||||
|
|
||||||
|
inline __host__ __device__ ElemType & operator[](unsigned _i) {
|
||||||
|
|
||||||
|
return vect[_i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*Function inline to get the size of vector, called from host and device.
|
||||||
|
*@return The vector size's
|
||||||
|
*/
|
||||||
|
|
||||||
|
inline __host__ __device__ unsigned size() {
|
||||||
|
|
||||||
|
return N;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* method to set the size of vector
|
||||||
|
*@param _size the vector size
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual void setSize(unsigned _size)=0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write object. Called printOn since it prints the object _on_ a stream.
|
||||||
|
* @param _os A std::ostream.
|
||||||
|
*/
|
||||||
|
|
||||||
|
virtual void printOn(std::ostream& _os) const=0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
ElemType * vect;
|
||||||
|
unsigned N;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue