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
IndexMatrix.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 #include <algorithm>
41 #include <ios>
42 #include <iterator>
43 #include <memory>
44 #include <stdexcept>
45 #include <string>
46 #include <sstream>
47 #include <tuple>
48 #include <utility>
49 #include <vector>
50 
51 #include <pvsutil/Assert.h>
52 #include <pvsutil/Logger.h>
53 
54 #include <SkelCL/IndexMatrix.h>
55 #include <SkelCL/Distributions.h>
56 
57 #include <SkelCL/detail/Device.h>
58 #include <SkelCL/detail/DeviceBuffer.h>
59 #include <SkelCL/detail/DeviceList.h>
60 #include <SkelCL/detail/Distribution.h>
61 #include <SkelCL/detail/Event.h>
62 
63 namespace skelcl {
64 
66  : _maxIndex{size.rowCount() - 1, size.columnCount() - 1},
67  _distribution(new skelcl::detail::Distribution<Matrix<IndexPoint>>())
68 {
69  LOG_DEBUG_INFO("Created new IndexMatrix object (", this, ") with ",
70  getDebugInfo());
71 }
72 
74 {
75  LOG_DEBUG_INFO("IndexMatrix object (", this, ") with ", getDebugInfo(),
76  " destroyed");
77 }
78 
79 // template <>
80 // const_iterator Matrix<IndexPoint>::begin() const
81 // {
82 // }
83 
84 // template <>
85 // const_iterator Matrix<IndexPoint>::end() const;
86 // {
87 // }
88 
90 {
91  return {_maxIndex.rowID() + 1, _maxIndex.columnID() + 1};
92 }
93 
94 detail::Sizes Matrix<IndexPoint>::sizes() const
95 {
96  ASSERT(_distribution != nullptr);
97 
98  detail::Sizes s;
99  for (auto& devicePtr : _distribution->devices()) {
100  s.push_back(this->_distribution->sizeForDevice(*this, devicePtr));
101  }
102  return s;
103 }
104 
106 {
107  return {n.rowCount(), n.columnCount()};
108 }
109 
111 {
112  if (std::make_tuple(n.rowCount(), n.columnCount()) >=
113  std::make_tuple(_maxIndex.rowID(), _maxIndex.columnID())) {
114  throw std::out_of_range("Out of range access.");
115  }
116  return {n.rowCount(), n.columnCount()};
117 }
118 
120 {
121  return {0, 0};
122 }
123 
125 {
126  return _maxIndex;
127 }
128 
129 detail::Distribution<Matrix<IndexPoint>>&
131 {
132  ASSERT(_distribution != nullptr);
133  return *_distribution;
134 }
135 
137  detail::Distribution<Matrix<IndexPoint>>>&& newDistribution) const
138 {
139  ASSERT(newDistribution != nullptr);
140  ASSERT(newDistribution->isValid());
141 
142  _distribution = std::move(newDistribution);
143 
144  ASSERT(_distribution->isValid());
145 
146  LOG_DEBUG_INFO("IndexMatrix object (", this,
147  ") assigned new distribution, now with ", getDebugInfo());
148 }
149 
151 {
152  return std::string();
153 }
154 
155 std::string Matrix<IndexPoint>::getInfo() const
156 {
157  std::stringstream s;
158  s << "size: {" << size().rowCount() << ", " << size().columnCount() << "}";
159  return s.str();
160 }
161 
162 std::string Matrix<IndexPoint>::getDebugInfo() const
163 {
164  std::stringstream s;
165  s << getInfo();
166  return s.str();
167 }
168 
169 const detail::DeviceBuffer&
170 Matrix<IndexPoint>::deviceBuffer(const detail::Device& /*device*/) const
171 {
172  ASSERT_MESSAGE(false, "This function should never be called!");
173  static detail::DeviceBuffer db;
174  return db;
175 }
176 
177 std::vector<IndexPoint>& Matrix<IndexPoint>::hostBuffer() const
178 {
179  ASSERT_MESSAGE(false, "This function should never be called!");
180  static std::vector<IndexPoint> v;
181  return v;
182 }
183 
185 {
186  ASSERT_MESSAGE(false, "This function should never be called!");
187 }
188 
190 {
191  ASSERT_MESSAGE(false, "This function should never be called!");
192 }
193 
194 } // namespace skelcl
195 
196 
The Matrix class is a two dimensional container which makes its data accessible on the host as well a...
Definition: Matrix.h:190
Matrix()
Creates a new empty Matrix.
This class defines a two dimensional size for a Matrix.
Definition: Matrix.h:67
size_type rowCount() const
Returns the number of rows.
Definition: MatrixSize.cpp:56
size_type columnCount() const
Returns the number of columns.
Definition: MatrixSize.cpp:61
host_buffer_type::value_type value_type
The type of the elements.
Definition: Matrix.h:197
~Matrix()
Destructor.
The IndexMatrix (a.k.a. Matrix) class is a special implementation of a Matrix with Elemen...
Definition: IndexMatrix.h:73