SkelCL
SkelCL is a high level multi GPU skeleton library developed at the university of Münster, Germany.
 All Classes Namespaces Files Functions Variables Typedefs Groups
IndexVector.cpp
1 /*****************************************************************************
2  * Copyright (c) 2011-2012 The SkelCL Team as listed in CREDITS.txt *
3  * http://skelcl.uni-muenster.de *
4  * *
5  * This file is part of SkelCL. *
6  * SkelCL is available under multiple licenses. *
7  * The different licenses are subject to terms and condition as provided *
8  * in the files specifying the license. See "LICENSE.txt" for details *
9  * *
10  *****************************************************************************
11  * *
12  * SkelCL is free software: you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation, either version 3 of the License, or *
15  * (at your option) any later version. See "LICENSE-gpl.txt" for details. *
16  * *
17  * SkelCL is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  *****************************************************************************
23  * *
24  * For non-commercial academic use see the license specified in the file *
25  * "LICENSE-academic.txt". *
26  * *
27  *****************************************************************************
28  * *
29  * If you are interested in other licensing models, including a commercial- *
30  * license, please contact the author at michel.steuwer@uni-muenster.de *
31  * *
32  *****************************************************************************/
33 
39 
40 #ifndef INDEX_VECTOR_DEF_H_
41 #define INDEX_VECTOR_DEF_H_
42 
43 #include <algorithm>
44 #include <ios>
45 #include <iterator>
46 #include <memory>
47 #include <stdexcept>
48 #include <string>
49 #include <sstream>
50 #include <utility>
51 #include <vector>
52 
53 #include <pvsutil/Assert.h>
54 #include <pvsutil/Logger.h>
55 
56 #include <SkelCL/IndexVector.h>
57 #include <SkelCL/Distributions.h>
58 
59 #include <SkelCL/detail/Device.h>
60 #include <SkelCL/detail/DeviceBuffer.h>
61 #include <SkelCL/detail/DeviceList.h>
62 #include <SkelCL/detail/Distribution.h>
63 #include <SkelCL/detail/Event.h>
64 
65 
66 namespace skelcl {
67 
69  //const detail::Distribution<Vector<Index>>& distribution)
70  : _maxIndex(size-1),
71  //_distribution(detail::cloneAndConvert<Index>(distribution))
72  _distribution(new skelcl::detail::Distribution < Vector < Index >> ())
73  {
74  LOG_DEBUG_INFO("Created new IndexVector object (", this, ") with ",
75  getDebugInfo());
76  }
77 
79  : _maxIndex(rhs._maxIndex),
80  _distribution(detail::cloneAndConvert<Vector<Index>>(rhs.distribution()))
81  {
82  LOG_DEBUG_INFO("Created new IndexVector object (", this, ") by copying (",
83  &rhs, ") with ", getDebugInfo());
84  }
85 
87  {
88  LOG_DEBUG_INFO("IndexVector object (", this, ") with ", getDebugInfo(),
89  " destroyed");
90  }
91 
92  // template <>
93  // const_iterator Vector<Index>::begin() const
94  // {
95  // }
96 
97  // template <>
98  // const_iterator Vector<Index>::end() const;
99  // {
100  // }
101 
103  {
104  return _maxIndex+1;
105  }
106 
107  detail::Sizes Vector<Index>::sizes() const
108  {
109  ASSERT(_distribution != nullptr);
110 
111  detail::Sizes s;
112  for (auto& devicePtr : _distribution->devices()) {
113  s.push_back(this->_distribution->sizeForDevice(*this, devicePtr));
114  }
115  return s;
116  }
117 
119  {
120  return n;
121  }
122 
124  {
125  if (n >= _maxIndex) throw std::out_of_range("Out of range access.");
126  return n;
127  }
128 
130  {
131  return 0;
132  }
133 
135  {
136  return _maxIndex;
137  }
138 
139  detail::Distribution<Vector<Index>>& Vector<Index>::distribution() const
140  {
141  ASSERT(_distribution != nullptr);
142  return *_distribution;
143  }
144 
145  void
147  std::unique_ptr<detail::Distribution<Vector<Index>>>&&
148  newDistribution) const
149  {
150  ASSERT(newDistribution != nullptr);
151  ASSERT(newDistribution->isValid());
152 
153  _distribution = std::move(newDistribution);
154  ASSERT(_distribution->isValid());
155 
156  LOG_DEBUG_INFO("IndexVector object (", this,
157  ") assigned new distribution, now with ", getDebugInfo());
158  }
159 
161  {
162  return std::string();
163  }
164 
165  std::string Vector<Index>::getInfo() const
166  {
167  std::stringstream s;
168  s << "size: " << size();
169  return s.str();
170  }
171 
172  std::string Vector<Index>::getDebugInfo() const
173  {
174  std::stringstream s;
175  s << getInfo();
176  return s.str();
177  }
178 
179  const detail::DeviceBuffer&
180  Vector<Index>::deviceBuffer(const detail::Device& /*device*/) const
181  {
182  ASSERT_MESSAGE(false, "This function should never be called!");
183  static detail::DeviceBuffer db;
184  return db;
185  }
186 
187  std::vector<Index>& Vector<Index>::hostBuffer() const
188  {
189  ASSERT_MESSAGE(false, "This function should never be called!");
190  static std::vector<Index> v;
191  return v;
192  }
193 
195  {
196  ASSERT_MESSAGE(false, "This function should never be called!");
197  }
198 
200  {
201  ASSERT_MESSAGE(false, "This function should never be called!");
202  }
203 
204 } // namespace skelcl
205 
206 #endif // INDEX_VECTOR_DEF_H_
207 
reference at(size_type pos)
Returns a reference to the element at the specified location pos. Boundary checks are performed...
~Vector()
Destructs the Vector.
size_type size() const
Returns the number of elements in the Vector.
void setDistribution(const detail::Distribution< Vector< U >> &distribution) const
Set a new distribution to the vector.
const detail::DeviceBuffer & deviceBuffer(const detail::Device &device) const
Returns the buffer for the given device used to store elements of the vector accordingly to the curre...
host_buffer_type::size_type size_type
The integral type used to define the number of the elements in the Vector.
Definition: Vector.h:148
static std::string deviceFunctions()
Returns the source code of helper functions simplifying access to the vector on the device...
void dataOnDeviceModified() const
Marks the data on the device as been modified.
size_t size_type
Defines the type used to denote size of the Vector.
Definition: IndexVector.h:82
reference operator[](size_type pos)
Returns a reference to the element at the specified location pos. No boundary checks are performed...
detail::Distribution< Vector< T > > & distribution() const
Returns the current distribution of the vector.
The Vector class is a one dimensional container which makes its data accessible on the host as well a...
Definition: Vector.h:113
This class defines an Index, i.e. an unsigned integer representing a value in a one-dimensional index...
Definition: Index.h:54
host_buffer_type::value_type value_type
The type of the elements.
Definition: Vector.h:120
detail::Sizes sizes() const
Returns the number of elements stored on each device.
void dataOnHostModified() const
Marks the data on the host as been modified.
reference front()
Returns a reference to the first element in the Vector. Calling front() on an empty Vector is undefin...
Vector()
Creates a new empty Vector.
The IndexVector (a.k.a. Vector) class is a special implementation of a Vector with Elements of...
Definition: IndexVector.h:72
host_buffer_type & hostBuffer() const
Returns a reference to the underlying object storing the elements on the host.
reference back()
Returns a reference to the last element in the Vector. Calling back() on an empty Vector is undefined...