| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include <iostream> |
| 12 |
#include <type_traits> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
#include "atlas/array.h" |
| 16 |
#include "atlas/array/ArrayDataStore.h" |
| 17 |
#include "atlas/array/ArrayView.h" |
| 18 |
#include "atlas/array/DataType.h" |
| 19 |
#include "atlas/array/MakeView.h" |
| 20 |
#include "atlas/array/gridtools/GridToolsArrayHelpers.h" |
| 21 |
#include "atlas/array/gridtools/GridToolsDataStore.h" |
| 22 |
#include "atlas/array/gridtools/GridToolsTraits.h" |
| 23 |
#include "atlas/array/helpers/ArrayInitializer.h" |
| 24 |
#include "atlas/array_fwd.h" |
| 25 |
#include "atlas/runtime/Log.h" |
| 26 |
|
| 27 |
#if ATLAS_HAVE_ACC |
| 28 |
#include "atlas_acc_support/atlas_acc.h" |
| 29 |
#endif |
| 30 |
|
| 31 |
//------------------------------------------------------------------------------ |
| 32 |
|
| 33 |
using namespace atlas::array::gridtools; |
| 34 |
using namespace atlas::array::helpers; |
| 35 |
|
| 36 |
namespace atlas { |
| 37 |
namespace array { |
| 38 |
|
| 39 |
//------------------------------------------------------------------------------ |
| 40 |
|
| 41 |
namespace gridtools { |
| 42 |
|
| 43 |
//------------------------------------------------------------------------------ |
| 44 |
|
| 45 |
template <int Rank> |
| 46 |
using UintSequence = std::make_integer_sequence<unsigned int, Rank>; |
| 47 |
|
| 48 |
template <typename Value, template <class> class Storage, typename StorageInfo> |
| 49 |
static Array* wrap_array(::gridtools::data_store<Storage<Value>, StorageInfo>* ds, const ArraySpec& spec) { |
| 50 |
assert(ds); |
| 51 |
using data_store_t = typename std::remove_pointer<decltype(ds)>::type; |
| 52 |
ArrayDataStore* data_store = new GridToolsDataStore<data_store_t>(ds); |
| 53 |
return new ArrayT<Value>(data_store, spec); |
| 54 |
} |
| 55 |
|
| 56 |
//------------------------------------------------------------------------------ |
| 57 |
|
| 58 |
} // namespace gridtools |
| 59 |
|
| 60 |
template <typename Value> |
| 61 |
class ArrayT_impl { |
| 62 |
public: |
| 63 |
ArrayT_impl(ArrayT<Value>& array): array_(array) {} |
| 64 |
|
| 65 |
template <typename... UInts, typename = ::gridtools::is_all_integral<UInts...>> |
| 66 |
void construct(UInts... dims) { |
| 67 |
static_assert(sizeof...(UInts) > 0, "1"); |
| 68 |
auto gt_storage = create_gt_storage<Value, typename default_layout_t<sizeof...(dims)>::type>(dims...); |
| 69 |
using data_store_t = typename std::remove_pointer<decltype(gt_storage)>::type; |
| 70 |
array_.data_store_ = std::make_unique<GridToolsDataStore<data_store_t>>(gt_storage); |
| 71 |
array_.spec_ = make_spec(gt_storage, dims...); |
| 72 |
} |
| 73 |
|
| 74 |
template <int Alignment, typename... UInts, typename = ::gridtools::is_all_integral<UInts...>> |
| 75 |
void construct_aligned(UInts... dims) { |
| 76 |
static_assert(sizeof...(UInts) > 0, "1"); |
| 77 |
auto gt_storage = create_gt_storage<Value, typename default_layout_t<sizeof...(dims)>::type, |
| 78 |
::gridtools::alignment<Alignment>>(dims...); |
| 79 |
using data_store_t = typename std::remove_pointer<decltype(gt_storage)>::type; |
| 80 |
array_.data_store_ = std::make_unique<GridToolsDataStore<data_store_t>>(gt_storage); |
| 81 |
array_.spec_ = make_spec(gt_storage, dims...); |
| 82 |
} |
| 83 |
|
| 84 |
template <typename... UInts, typename = ::gridtools::is_all_integral<UInts...>> |
| 85 |
void construct(ArrayAlignment alignment, UInts... dims) { |
| 86 |
static_assert(sizeof...(UInts) > 0, "1"); |
| 87 |
switch (int(alignment)) { |
| 88 |
case 1: |
| 89 |
construct(dims...); |
| 90 |
break; |
| 91 |
case 2: |
| 92 |
construct_aligned<2>(dims...); |
| 93 |
break; |
| 94 |
case 4: |
| 95 |
construct_aligned<4>(dims...); |
| 96 |
break; |
| 97 |
case 8: |
| 98 |
construct_aligned<8>(dims...); |
| 99 |
break; |
| 100 |
case 16: |
| 101 |
construct_aligned<16>(dims...); |
| 102 |
break; |
| 103 |
case 32: |
| 104 |
construct_aligned<32>(dims...); |
| 105 |
break; |
| 106 |
case 64: |
| 107 |
construct_aligned<64>(dims...); |
| 108 |
break; |
| 109 |
default: |
| 110 |
ATLAS_NOTIMPLEMENTED; |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
void construct(const ArrayShape& shape) { |
| 116 |
assert(shape.size() > 0); |
| 117 |
switch (shape.size()) { |
| 118 |
case 1: |
| 119 |
return construct(shape[0]); |
| 120 |
case 2: |
| 121 |
return construct(shape[0], shape[1]); |
| 122 |
case 3: |
| 123 |
return construct(shape[0], shape[1], shape[2]); |
| 124 |
case 4: |
| 125 |
return construct(shape[0], shape[1], shape[2], shape[3]); |
| 126 |
case 5: |
| 127 |
return construct(shape[0], shape[1], shape[2], shape[3], shape[4]); |
| 128 |
default: { |
| 129 |
std::stringstream err; |
| 130 |
err << "shape not recognized"; |
| 131 |
throw_Exception(err.str(), Here()); |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
void construct(const ArraySpec& spec) { |
| 137 |
auto& shape = spec.shape(); |
| 138 |
assert(shape.size() > 0); |
| 139 |
switch (shape.size()) { |
| 140 |
case 1: |
| 141 |
return construct(spec.alignment(), shape[0]); |
| 142 |
case 2: |
| 143 |
return construct(spec.alignment(), shape[0], shape[1]); |
| 144 |
case 3: |
| 145 |
return construct(spec.alignment(), shape[0], shape[1], shape[2]); |
| 146 |
case 4: |
| 147 |
return construct(spec.alignment(), shape[0], shape[1], shape[2], shape[3]); |
| 148 |
case 5: |
| 149 |
return construct(spec.alignment(), shape[0], shape[1], shape[2], shape[3], shape[4]); |
| 150 |
default: { |
| 151 |
std::stringstream err; |
| 152 |
err << "shape not recognized"; |
| 153 |
throw_Exception(err.str(), Here()); |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
void construct(const ArrayShape& shape, const ArrayLayout& layout) { |
| 159 |
ATLAS_ASSERT(shape.size() > 0); |
| 160 |
ATLAS_ASSERT(shape.size() == layout.size()); |
| 161 |
switch (shape.size()) { |
| 162 |
case 1: |
| 163 |
return construct(shape[0]); |
| 164 |
case 2: { |
| 165 |
if (layout[0] == 0 && layout[1] == 1) { |
| 166 |
return construct_with_layout<::gridtools::layout_map<0, 1>>(shape[0], shape[1]); |
| 167 |
} |
| 168 |
if (layout[0] == 1 && layout[1] == 0) { |
| 169 |
return construct_with_layout<::gridtools::layout_map<1, 0>>(shape[0], shape[1]); |
| 170 |
} |
| 171 |
} |
| 172 |
case 3: { |
| 173 |
if (layout[0] == 0 && layout[1] == 1 && layout[2] == 2) { |
| 174 |
return construct_with_layout<::gridtools::layout_map<0, 1, 2>>(shape[0], shape[1], shape[2]); |
| 175 |
} |
| 176 |
if (layout[0] == 0 && layout[1] == 2 && layout[2] == 1) { |
| 177 |
return construct_with_layout<::gridtools::layout_map<0, 2, 1>>(shape[0], shape[1], shape[2]); |
| 178 |
} |
| 179 |
if (layout[0] == 1 && layout[1] == 0 && layout[2] == 2) { |
| 180 |
return construct_with_layout<::gridtools::layout_map<1, 0, 2>>(shape[0], shape[1], shape[2]); |
| 181 |
} |
| 182 |
if (layout[0] == 1 && layout[1] == 2 && layout[2] == 0) { |
| 183 |
return construct_with_layout<::gridtools::layout_map<1, 2, 0>>(shape[0], shape[1], shape[2]); |
| 184 |
} |
| 185 |
if (layout[0] == 2 && layout[1] == 0 && layout[2] == 1) { |
| 186 |
return construct_with_layout<::gridtools::layout_map<2, 0, 1>>(shape[0], shape[1], shape[2]); |
| 187 |
} |
| 188 |
if (layout[0] == 2 && layout[1] == 1 && layout[2] == 0) { |
| 189 |
return construct_with_layout<::gridtools::layout_map<2, 1, 0>>(shape[0], shape[1], shape[2]); |
| 190 |
} |
| 191 |
} |
| 192 |
case 4: { |
| 193 |
if (layout[0] == 0 && layout[1] == 1 && layout[2] == 2 && layout[3] == 3) { |
| 194 |
return construct_with_layout<::gridtools::layout_map<0, 1, 2, 3>>(shape[0], shape[1], shape[2], |
| 195 |
shape[3]); |
| 196 |
} |
| 197 |
if (layout[0] == 3 && layout[1] == 2 && layout[2] == 1 && layout[3] == 0) { |
| 198 |
return construct_with_layout<::gridtools::layout_map<3, 2, 1, 0>>(shape[0], shape[1], shape[2], |
| 199 |
shape[3]); |
| 200 |
} |
| 201 |
} |
| 202 |
case 5: { |
| 203 |
if (layout[0] == 0 && layout[1] == 1 && layout[2] == 2 && layout[3] == 3 && layout[4] == 4) { |
| 204 |
return construct_with_layout<::gridtools::layout_map<0, 1, 2, 3, 4>>(shape[0], shape[1], shape[2], |
| 205 |
shape[3], shape[4]); |
| 206 |
} |
| 207 |
if (layout[0] == 4 && layout[1] == 3 && layout[2] == 2 && layout[3] == 1 && layout[4] == 0) { |
| 208 |
return construct_with_layout<::gridtools::layout_map<4, 3, 2, 1, 0>>(shape[0], shape[1], shape[2], |
| 209 |
shape[3], shape[4]); |
| 210 |
} |
| 211 |
} |
| 212 |
default: { |
| 213 |
std::stringstream err; |
| 214 |
if (shape.size() > 5) { |
| 215 |
err << "shape not recognized"; |
| 216 |
} |
| 217 |
else { |
| 218 |
err << "Layout < "; |
| 219 |
for (size_t j = 0; j < layout.size(); ++j) { |
| 220 |
err << layout[j] << " "; |
| 221 |
} |
| 222 |
err << "> not implemented in Atlas."; |
| 223 |
} |
| 224 |
throw_Exception(err.str(), Here()); |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
template <typename Layout, typename... UInts, typename = ::gridtools::is_all_integral<UInts...>> |
| 230 |
void construct_with_layout(UInts... dims) { |
| 231 |
auto gt_data_store_ptr = create_gt_storage<Value, Layout>(dims...); |
| 232 |
using data_store_t = typename std::remove_pointer<decltype(gt_data_store_ptr)>::type; |
| 233 |
array_.data_store_ = std::make_unique<GridToolsDataStore<data_store_t>>(gt_data_store_ptr); |
| 234 |
array_.spec_ = make_spec(gt_data_store_ptr, dims...); |
| 235 |
} |
| 236 |
|
| 237 |
template <typename... Ints> |
| 238 |
void resize_variadic(Ints... c) { |
| 239 |
if (sizeof...(c) != array_.rank()) { |
| 240 |
std::stringstream err; |
| 241 |
err << "Trying to resize an array of Rank " << array_.rank() << " by dimensions with Rank " << sizeof...(c) |
| 242 |
<< std::endl; |
| 243 |
throw_Exception(err.str(), Here()); |
| 244 |
} |
| 245 |
|
| 246 |
if (array_.valid()) { |
| 247 |
array_.syncHostDevice(); |
| 248 |
} |
| 249 |
|
| 250 |
Array* resized = Array::create<Value>(ArrayShape{(idx_t)c...}); |
| 251 |
|
| 252 |
array_initializer::apply(array_, *resized); |
| 253 |
array_.replace(*resized); |
| 254 |
delete resized; |
| 255 |
} |
| 256 |
|
| 257 |
template <typename UInt, UInt... Indices> |
| 258 |
void apply_resize(const ArrayShape& shape, std::integer_sequence<UInt, Indices...>) { |
| 259 |
return resize_variadic(shape[Indices]...); |
| 260 |
} |
| 261 |
private: |
| 262 |
ArrayT<Value>& array_; |
| 263 |
}; |
| 264 |
|
| 265 |
//------------------------------------------------------------------------------ |
| 266 |
|
| 267 |
template <typename Value> |
| 268 |
Array* Array::create(idx_t dim0) { |
| 269 |
return new ArrayT<Value>(dim0); |
| 270 |
} |
| 271 |
template <typename Value> |
| 272 |
Array* Array::create(idx_t dim0, idx_t dim1) { |
| 273 |
return new ArrayT<Value>(dim0, dim1); |
| 274 |
} |
| 275 |
template <typename Value> |
| 276 |
Array* Array::create(idx_t dim0, idx_t dim1, idx_t dim2) { |
| 277 |
return new ArrayT<Value>(dim0, dim1, dim2); |
| 278 |
} |
| 279 |
template <typename Value> |
| 280 |
Array* Array::create(idx_t dim0, idx_t dim1, idx_t dim2, idx_t dim3) { |
| 281 |
return new ArrayT<Value>(dim0, dim1, dim2, dim3); |
| 282 |
} |
| 283 |
template <typename Value> |
| 284 |
Array* Array::create(idx_t dim0, idx_t dim1, idx_t dim2, idx_t dim3, idx_t dim4) { |
| 285 |
return new ArrayT<Value>(dim0, dim1, dim2, dim3, dim4); |
| 286 |
} |
| 287 |
template <typename Value> |
| 288 |
Array* Array::create(const ArrayShape& shape) { |
| 289 |
return new ArrayT<Value>(shape); |
| 290 |
} |
| 291 |
template <typename Value> |
| 292 |
Array* Array::create(const ArrayShape& shape, const ArrayLayout& layout) { |
| 293 |
return new ArrayT<Value>(shape, layout); |
| 294 |
} |
| 295 |
template <typename Value> |
| 296 |
Array* Array::wrap(Value* data, const ArraySpec& spec) { |
| 297 |
ArrayShape const& shape = spec.shape(); |
| 298 |
ArrayStrides const& strides = spec.strides(); |
| 299 |
|
| 300 |
assert(shape.size() > 0); |
| 301 |
|
| 302 |
switch (shape.size()) { |
| 303 |
case 1: |
| 304 |
return wrap_array( |
| 305 |
wrap_gt_storage<Value, 1>(data, get_array_from_vector<1>(shape), get_array_from_vector<1>(strides)), |
| 306 |
spec); |
| 307 |
case 2: |
| 308 |
return wrap_array( |
| 309 |
wrap_gt_storage<Value, 2>(data, get_array_from_vector<2>(shape), get_array_from_vector<2>(strides)), |
| 310 |
spec); |
| 311 |
case 3: |
| 312 |
return wrap_array( |
| 313 |
wrap_gt_storage<Value, 3>(data, get_array_from_vector<3>(shape), get_array_from_vector<3>(strides)), |
| 314 |
spec); |
| 315 |
case 4: |
| 316 |
return wrap_array( |
| 317 |
wrap_gt_storage<Value, 4>(data, get_array_from_vector<4>(shape), get_array_from_vector<4>(strides)), |
| 318 |
spec); |
| 319 |
case 5: |
| 320 |
return wrap_array( |
| 321 |
wrap_gt_storage<Value, 5>(data, get_array_from_vector<5>(shape), get_array_from_vector<5>(strides)), |
| 322 |
spec); |
| 323 |
case 6: |
| 324 |
return wrap_array( |
| 325 |
wrap_gt_storage<Value, 6>(data, get_array_from_vector<6>(shape), get_array_from_vector<6>(strides)), |
| 326 |
spec); |
| 327 |
case 7: |
| 328 |
return wrap_array( |
| 329 |
wrap_gt_storage<Value, 7>(data, get_array_from_vector<7>(shape), get_array_from_vector<7>(strides)), |
| 330 |
spec); |
| 331 |
case 8: |
| 332 |
return wrap_array( |
| 333 |
wrap_gt_storage<Value, 8>(data, get_array_from_vector<8>(shape), get_array_from_vector<8>(strides)), |
| 334 |
spec); |
| 335 |
case 9: |
| 336 |
return wrap_array( |
| 337 |
wrap_gt_storage<Value, 9>(data, get_array_from_vector<9>(shape), get_array_from_vector<9>(strides)), |
| 338 |
spec); |
| 339 |
default: { |
| 340 |
std::stringstream err; |
| 341 |
err << "shape not recognized"; |
| 342 |
throw_Exception(err.str(), Here()); |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
template <typename Value> |
| 347 |
Array* Array::wrap(Value* data, const ArrayShape& shape) { |
| 348 |
return wrap(data, ArraySpec(shape)); |
| 349 |
} |
| 350 |
|
| 351 |
Array* Array::create(DataType datatype, const ArrayShape& shape) { |
| 352 |
switch (datatype.kind()) { |
| 353 |
case DataType::KIND_REAL64: |
| 354 |
return create<double>(shape); |
| 355 |
case DataType::KIND_REAL32: |
| 356 |
return create<float>(shape); |
| 357 |
case DataType::KIND_INT32: |
| 358 |
return create<int>(shape); |
| 359 |
case DataType::KIND_INT64: |
| 360 |
return create<long>(shape); |
| 361 |
case DataType::KIND_UINT64: |
| 362 |
return create<unsigned long>(shape); |
| 363 |
default: { |
| 364 |
std::stringstream err; |
| 365 |
err << "data kind " << datatype.kind() << " not recognised."; |
| 366 |
throw_Exception(err.str(), Here()); |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
Array* Array::create(DataType datatype, const ArrayShape& shape, const ArrayLayout& layout) { |
| 372 |
switch (datatype.kind()) { |
| 373 |
case DataType::KIND_REAL64: |
| 374 |
return create<double>(shape, layout); |
| 375 |
case DataType::KIND_REAL32: |
| 376 |
return create<float>(shape, layout); |
| 377 |
case DataType::KIND_INT32: |
| 378 |
return create<int>(shape, layout); |
| 379 |
case DataType::KIND_INT64: |
| 380 |
return create<long>(shape, layout); |
| 381 |
case DataType::KIND_UINT64: |
| 382 |
return create<unsigned long>(shape, layout); |
| 383 |
|
| 384 |
default: { |
| 385 |
std::stringstream err; |
| 386 |
err << "data kind " << datatype.kind() << " not recognised."; |
| 387 |
throw_Exception(err.str(), Here()); |
| 388 |
} |
| 389 |
} |
| 390 |
} |
| 391 |
|
| 392 |
Array* Array::create(DataType datatype, ArraySpec&& spec) { |
| 393 |
switch (datatype.kind()) { |
| 394 |
case DataType::KIND_REAL64: |
| 395 |
return new ArrayT<double>(std::move(spec)); |
| 396 |
case DataType::KIND_REAL32: |
| 397 |
return new ArrayT<float>(std::move(spec)); |
| 398 |
case DataType::KIND_INT32: |
| 399 |
return new ArrayT<int>(std::move(spec)); |
| 400 |
case DataType::KIND_INT64: |
| 401 |
return new ArrayT<long>(std::move(spec)); |
| 402 |
case DataType::KIND_UINT64: |
| 403 |
return new ArrayT<unsigned long>(std::move(spec)); |
| 404 |
default: { |
| 405 |
std::stringstream err; |
| 406 |
err << "data kind " << datatype.kind() << " not recognised."; |
| 407 |
throw_NotImplemented(err.str(), Here()); |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
Array* Array::create(ArraySpec&& spec) { |
| 413 |
return create(spec.datatype(), std::move(spec)); |
| 414 |
} |
| 415 |
|
| 416 |
//------------------------------------------------------------------------------ |
| 417 |
|
| 418 |
Array::~Array() = default; |
| 419 |
|
| 420 |
//------------------------------------------------------------------------------ |
| 421 |
|
| 422 |
template <typename Value> |
| 423 |
size_t ArrayT<Value>::footprint() const { |
| 424 |
size_t size = sizeof(*this); |
| 425 |
size += bytes(); |
| 426 |
return size; |
| 427 |
} |
| 428 |
|
| 429 |
//------------------------------------------------------------------------------ |
| 430 |
|
| 431 |
template <typename Value> |
| 432 |
void ArrayT<Value>::accMap() const { |
| 433 |
data_store_->accMap(); |
| 434 |
} |
| 435 |
|
| 436 |
template <typename Value> |
| 437 |
void ArrayT<Value>::accUnmap() const { |
| 438 |
data_store_->accUnmap(); |
| 439 |
} |
| 440 |
|
| 441 |
template <typename Value> |
| 442 |
bool ArrayT<Value>::accMapped() const { |
| 443 |
return data_store_->accMapped(); |
| 444 |
} |
| 445 |
|
| 446 |
//------------------------------------------------------------------------------ |
| 447 |
|
| 448 |
template <typename Value> |
| 449 |
void ArrayT<Value>::insert(idx_t idx1, idx_t size1) { |
| 450 |
// if( hostNeedsUpdate() ) { |
| 451 |
// updateHost(); |
| 452 |
//} |
| 453 |
if (not hasDefaultLayout()) { |
| 454 |
ATLAS_NOTIMPLEMENTED; |
| 455 |
} |
| 456 |
|
| 457 |
ArrayShape nshape = shape(); |
| 458 |
if (idx1 > nshape[0]) { |
| 459 |
throw_Exception("can not insert into an array at a position beyond its size", Here()); |
| 460 |
} |
| 461 |
nshape[0] += size1; |
| 462 |
|
| 463 |
Array* resized = Array::create<Value>(nshape); |
| 464 |
|
| 465 |
array_initializer_partitioned<0>::apply(*this, *resized, idx1, size1); |
| 466 |
|
| 467 |
replace(*resized); |
| 468 |
delete resized; |
| 469 |
} |
| 470 |
|
| 471 |
//------------------------------------------------------------------------------ |
| 472 |
|
| 473 |
template <typename Value> |
| 474 |
void ArrayT<Value>::resize(idx_t dim0) { |
| 475 |
ArrayT_impl<Value>(*this).resize_variadic(dim0); |
| 476 |
} |
| 477 |
|
| 478 |
template <typename Value> |
| 479 |
void ArrayT<Value>::resize(idx_t dim0, idx_t dim1) { |
| 480 |
ArrayT_impl<Value>(*this).resize_variadic(dim0, dim1); |
| 481 |
} |
| 482 |
|
| 483 |
template <typename Value> |
| 484 |
void ArrayT<Value>::resize(idx_t dim0, idx_t dim1, idx_t dim2) { |
| 485 |
ArrayT_impl<Value>(*this).resize_variadic(dim0, dim1, dim2); |
| 486 |
} |
| 487 |
|
| 488 |
template <typename Value> |
| 489 |
void ArrayT<Value>::resize(idx_t dim0, idx_t dim1, idx_t dim2, idx_t dim3) { |
| 490 |
ArrayT_impl<Value>(*this).resize_variadic(dim0, dim1, dim2, dim3); |
| 491 |
} |
| 492 |
|
| 493 |
template <typename Value> |
| 494 |
void ArrayT<Value>::resize(idx_t dim0, idx_t dim1, idx_t dim2, idx_t dim3, idx_t dim4) { |
| 495 |
ArrayT_impl<Value>(*this).resize_variadic(dim0, dim1, dim2, dim3, dim4); |
| 496 |
} |
| 497 |
|
| 498 |
template <typename Value> |
| 499 |
void ArrayT<Value>::copy(const Array& other, const Array::CopyPolicy&) { |
| 500 |
array_initializer::apply(other, *this); |
| 501 |
} |
| 502 |
|
| 503 |
template <typename Value> |
| 504 |
void ArrayT<Value>::dump(std::ostream& out) const { |
| 505 |
switch (rank()) { |
| 506 |
case 1: |
| 507 |
make_host_view<Value, 1>(*this).dump(out); |
| 508 |
break; |
| 509 |
case 2: |
| 510 |
make_host_view<Value, 2>(*this).dump(out); |
| 511 |
break; |
| 512 |
case 3: |
| 513 |
make_host_view<Value, 3>(*this).dump(out); |
| 514 |
break; |
| 515 |
case 4: |
| 516 |
make_host_view<Value, 4>(*this).dump(out); |
| 517 |
break; |
| 518 |
case 5: |
| 519 |
make_host_view<Value, 5>(*this).dump(out); |
| 520 |
break; |
| 521 |
case 6: |
| 522 |
make_host_view<Value, 6>(*this).dump(out); |
| 523 |
break; |
| 524 |
case 7: |
| 525 |
make_host_view<Value, 7>(*this).dump(out); |
| 526 |
break; |
| 527 |
case 8: |
| 528 |
make_host_view<Value, 8>(*this).dump(out); |
| 529 |
break; |
| 530 |
case 9: |
| 531 |
make_host_view<Value, 9>(*this).dump(out); |
| 532 |
break; |
| 533 |
default: |
| 534 |
ATLAS_NOTIMPLEMENTED; |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
template <typename Value> |
| 539 |
void ArrayT<Value>::resize(const ArrayShape& shape) { |
| 540 |
assert(shape.size() > 0); |
| 541 |
switch (shape.size()) { |
| 542 |
case 1: |
| 543 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<1>()); |
| 544 |
case 2: |
| 545 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<2>()); |
| 546 |
case 3: |
| 547 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<3>()); |
| 548 |
case 4: |
| 549 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<4>()); |
| 550 |
case 5: |
| 551 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<5>()); |
| 552 |
case 6: |
| 553 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<6>()); |
| 554 |
case 7: |
| 555 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<7>()); |
| 556 |
case 8: |
| 557 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<8>()); |
| 558 |
case 9: |
| 559 |
return ArrayT_impl<Value>(*this).apply_resize(shape, UintSequence<9>()); |
| 560 |
default: { |
| 561 |
std::stringstream err; |
| 562 |
err << "shape not recognized"; |
| 563 |
throw_Exception(err.str(), Here()); |
| 564 |
} |
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
//------------------------------------------------------------------------------ |
| 569 |
|
| 570 |
template <typename Value> |
| 571 |
ArrayT<Value>::ArrayT(ArrayDataStore* ds, const ArraySpec& spec) { |
| 572 |
data_store_ = std::unique_ptr<ArrayDataStore>(ds); |
| 573 |
spec_ = spec; |
| 574 |
} |
| 575 |
|
| 576 |
template <typename Value> |
| 577 |
ArrayT<Value>::ArrayT(idx_t dim0) { |
| 578 |
ArrayT_impl<Value>(*this).construct(dim0); |
| 579 |
} |
| 580 |
|
| 581 |
template <typename Value> |
| 582 |
ArrayT<Value>::ArrayT(idx_t dim0, idx_t dim1) { |
| 583 |
ArrayT_impl<Value>(*this).construct(dim0, dim1); |
| 584 |
} |
| 585 |
template <typename Value> |
| 586 |
ArrayT<Value>::ArrayT(idx_t dim0, idx_t dim1, idx_t dim2) { |
| 587 |
ArrayT_impl<Value>(*this).construct(dim0, dim1, dim2); |
| 588 |
} |
| 589 |
template <typename Value> |
| 590 |
ArrayT<Value>::ArrayT(idx_t dim0, idx_t dim1, idx_t dim2, idx_t dim3) { |
| 591 |
ArrayT_impl<Value>(*this).construct(dim0, dim1, dim2, dim3); |
| 592 |
} |
| 593 |
template <typename Value> |
| 594 |
ArrayT<Value>::ArrayT(idx_t dim0, idx_t dim1, idx_t dim2, idx_t dim3, idx_t dim4) { |
| 595 |
ArrayT_impl<Value>(*this).construct(dim0, dim1, dim2, dim3, dim4); |
| 596 |
} |
| 597 |
|
| 598 |
template <typename Value> |
| 599 |
ArrayT<Value>::ArrayT(const ArrayShape& shape) { |
| 600 |
ArrayT_impl<Value>(*this).construct(shape); |
| 601 |
} |
| 602 |
|
| 603 |
template <typename Value> |
| 604 |
ArrayT<Value>::ArrayT(const ArrayShape& shape, const ArrayAlignment& alignment) { |
| 605 |
ArrayT_impl<Value>(*this).construct(ArraySpec(shape, alignment)); |
| 606 |
} |
| 607 |
|
| 608 |
template <typename Value> |
| 609 |
ArrayT<Value>::ArrayT(const ArrayShape& shape, const ArrayLayout& layout) { |
| 610 |
ArrayT_impl<Value>(*this).construct(shape, layout); |
| 611 |
} |
| 612 |
|
| 613 |
template <typename Value> |
| 614 |
ArrayT<Value>::ArrayT(ArraySpec&& spec) { |
| 615 |
ArrayT_impl<Value>(*this).construct(spec); |
| 616 |
} |
| 617 |
|
| 618 |
//------------------------------------------------------------------------------ |
| 619 |
|
| 620 |
} // namespace array |
| 621 |
} // namespace atlas |
| 622 |
|
| 623 |
//------------------------------------------------------------------------------ |
| 624 |
// Explicit template instantiations |
| 625 |
namespace atlas { |
| 626 |
namespace array { |
| 627 |
|
| 628 |
template class ArrayT<int>; |
| 629 |
template class ArrayT<long>; |
| 630 |
template class ArrayT<float>; |
| 631 |
template class ArrayT<double>; |
| 632 |
template class ArrayT<unsigned long>; |
| 633 |
|
| 634 |
template Array* Array::create<int>(idx_t); |
| 635 |
template Array* Array::create<long>(idx_t); |
| 636 |
template Array* Array::create<float>(idx_t); |
| 637 |
template Array* Array::create<double>(idx_t); |
| 638 |
template Array* Array::create<long unsigned>(idx_t); |
| 639 |
|
| 640 |
template Array* Array::create<int>(idx_t, idx_t); |
| 641 |
template Array* Array::create<long>(idx_t, idx_t); |
| 642 |
template Array* Array::create<float>(idx_t, idx_t); |
| 643 |
template Array* Array::create<double>(idx_t, idx_t); |
| 644 |
template Array* Array::create<long unsigned>(idx_t, idx_t); |
| 645 |
|
| 646 |
template Array* Array::create<int>(idx_t, idx_t, idx_t); |
| 647 |
template Array* Array::create<long>(idx_t, idx_t, idx_t); |
| 648 |
template Array* Array::create<float>(idx_t, idx_t, idx_t); |
| 649 |
template Array* Array::create<double>(idx_t, idx_t, idx_t); |
| 650 |
template Array* Array::create<long unsigned>(idx_t, idx_t, idx_t); |
| 651 |
|
| 652 |
template Array* Array::create<int>(idx_t, idx_t, idx_t, idx_t); |
| 653 |
template Array* Array::create<long>(idx_t, idx_t, idx_t, idx_t); |
| 654 |
template Array* Array::create<float>(idx_t, idx_t, idx_t, idx_t); |
| 655 |
template Array* Array::create<double>(idx_t, idx_t, idx_t, idx_t); |
| 656 |
template Array* Array::create<long unsigned>(idx_t, idx_t, idx_t, idx_t); |
| 657 |
|
| 658 |
template Array* Array::create<int>(idx_t, idx_t, idx_t, idx_t, idx_t); |
| 659 |
template Array* Array::create<long>(idx_t, idx_t, idx_t, idx_t, idx_t); |
| 660 |
template Array* Array::create<float>(idx_t, idx_t, idx_t, idx_t, idx_t); |
| 661 |
template Array* Array::create<double>(idx_t, idx_t, idx_t, idx_t, idx_t); |
| 662 |
template Array* Array::create<long unsigned>(idx_t, idx_t, idx_t, idx_t, idx_t); |
| 663 |
|
| 664 |
template Array* Array::create<int>(const ArrayShape&); |
| 665 |
template Array* Array::create<long>(const ArrayShape&); |
| 666 |
template Array* Array::create<float>(const ArrayShape&); |
| 667 |
template Array* Array::create<double>(const ArrayShape&); |
| 668 |
template Array* Array::create<long unsigned>(const ArrayShape&); |
| 669 |
|
| 670 |
template Array* Array::create<int>(const ArrayShape&, const ArrayLayout&); |
| 671 |
template Array* Array::create<long>(const ArrayShape&, const ArrayLayout&); |
| 672 |
template Array* Array::create<float>(const ArrayShape&, const ArrayLayout&); |
| 673 |
template Array* Array::create<double>(const ArrayShape&, const ArrayLayout&); |
| 674 |
template Array* Array::create<long unsigned>(const ArrayShape&, const ArrayLayout&); |
| 675 |
|
| 676 |
template Array* Array::wrap<int>(int*, const ArrayShape&); |
| 677 |
template Array* Array::wrap<long>(long*, const ArrayShape&); |
| 678 |
template Array* Array::wrap<float>(float*, const ArrayShape&); |
| 679 |
template Array* Array::wrap<double>(double*, const ArrayShape&); |
| 680 |
template Array* Array::wrap<long unsigned>(long unsigned*, const ArrayShape&); |
| 681 |
|
| 682 |
template Array* Array::wrap<int>(int*, const ArraySpec&); |
| 683 |
template Array* Array::wrap<long>(long*, const ArraySpec&); |
| 684 |
template Array* Array::wrap<float>(float*, const ArraySpec&); |
| 685 |
template Array* Array::wrap<double>(double*, const ArraySpec&); |
| 686 |
template Array* Array::wrap<long unsigned>(long unsigned*, const ArraySpec&); |
| 687 |
|
| 688 |
} // namespace array |
| 689 |
} // namespace atlas |