From c031a4a81012f97c9dbe6280971dfbd32e5a116d Mon Sep 17 00:00:00 2001 From: boufaras Date: Mon, 9 Jan 2012 10:30:15 +0000 Subject: [PATCH] independent ParadisEO-GPU package git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2591 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/GPUType/moGPUBitVector.h | 141 ++++++++++++++ .../src/GPUType/moGPUIntVector.h | 122 ++++++++++++ .../src/GPUType/moGPUPermutationVector.h | 92 +++++++++ .../src/GPUType/moGPURealVector.h | 123 ++++++++++++ .../paradiseo-gpu/src/GPUType/moGPUVector.h | 184 ++++++++++++++++++ 5 files changed, 662 insertions(+) create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUBitVector.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUIntVector.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUPermutationVector.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPURealVector.h create mode 100644 branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUVector.h diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUBitVector.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUBitVector.h new file mode 100644 index 000000000..be50bc019 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUBitVector.h @@ -0,0 +1,141 @@ +/* + + 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 +#include + +/** + * Implementation of Bit vector representation on GPU. + */ + +template + +class moGPUBitVector: public moGPUVector { + +public: + + /** + * Define bool vector corresponding to Solution + **/ + typedef bool ElemType; + using moGPUVector::vect; + using moGPUVector::N; + + /** + * Default constructor. + */ + + moGPUBitVector() : + moGPUVector () { + + } + + /** + *Constructor. + *@param _neighborhoodSize The neighborhood size. + */ + + moGPUBitVector(unsigned _neighborhoodSize) : + moGPUVector (_neighborhoodSize) { + create(); + } + + /** + *Constructor. + *@param _neighborhoodSize The neighborhood size. + *@param _b Value to assign to vector. + */ + + moGPUBitVector(unsigned _neighborhoodSize, bool _b) : + moGPUVector (_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 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 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::printOn(_os); + _os << ' '; + _os << N << ' '; + for (unsigned int i = 0; i < N; i++) + _os << (*this)[i] << ' '; + + } + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUIntVector.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUIntVector.h new file mode 100644 index 000000000..a6b2a88ae --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUIntVector.h @@ -0,0 +1,122 @@ +/* + + 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 +#include + +/** + * Implementation of integer vector representation on GPU. + */ + +template + +class moGPUIntVector: public moGPUVector { + +public: + + using moGPUVector::vect; + using moGPUVector::N; + + /** + * Default constructor. + */ + + moGPUIntVector() : + moGPUVector () { + + } + + /** + *Constructor. + *@param _neighborhoodSize The neighborhood size. + */ + + moGPUIntVector(unsigned _neighborhoodSize) : + moGPUVector (_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 tmp_vect(_size); + if(_sizeN) { + for (unsigned i = 0; i ::printOn(_os); + _os << ' '; + _os << N << ' '; + unsigned int i; + for (i = 0; i < N; i++) + _os << vect[i] << ' '; + + } + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUPermutationVector.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUPermutationVector.h new file mode 100644 index 000000000..bd3fcc4f3 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUPermutationVector.h @@ -0,0 +1,92 @@ +/* + + 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 + +/** + * Implementation of Permutation vector representation on GPU. + */ + +template + +class moGPUPermutationVector: public moGPUIntVector { + +public: + + using moGPUIntVector::vect; + using moGPUIntVector::N; + + /** + * Default constructor. + */ + + moGPUPermutationVector() : + moGPUIntVector () { + + } + + /** + *Constructor. + *@param _size The solution size. + */ + + moGPUPermutationVector(unsigned _size) : + moGPUIntVector (_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 diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPURealVector.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPURealVector.h new file mode 100644 index 000000000..2a8b2bebe --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPURealVector.h @@ -0,0 +1,123 @@ +/* + + 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 +#include + +/** + * Implementation of real vector representation on GPU. + */ + +template + +class moGPURealVector: public moGPUVector { + +public: + + using moGPUVector::vect; + using moGPUVector::N; + + /** + * Default constructor. + */ + + moGPURealVector() : + moGPUVector () { + + } + + /** + *Constructor. + *@param _neighborhoodSize The neighborhood size. + */ + + moGPURealVector(unsigned _neighborhoodSize) : + moGPUVector (_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 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 tmp_vect(_size); + for (unsigned i = 0; i ::printOn(_os); + _os << ' '; + _os << N << ' '; + unsigned int i; + for (i = 0; i < N; i++) + _os << vect[i] << ' '; + + } + +}; + +#endif diff --git a/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUVector.h b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUVector.h new file mode 100644 index 000000000..d9b9afe83 --- /dev/null +++ b/branches/ParadisEO-GPU/paradiseo-gpu/src/GPUType/moGPUVector.h @@ -0,0 +1,184 @@ +/* + + 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 + +/** + * Implementation of a GPU solution representation. + */ + +template + +class moGPUVector: public EO { + +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