| 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 |
#pragma once |
| 12 |
|
| 13 |
#include "eckit/config/Configuration.h" |
| 14 |
#include "eckit/linalg/Matrix.h" |
| 15 |
|
| 16 |
#include "atlas/linalg/Indexing.h" |
| 17 |
#include "atlas/linalg/View.h" |
| 18 |
#include "atlas/linalg/dense/Backend.h" |
| 19 |
#include "atlas/runtime/Exception.h" |
| 20 |
#include "atlas/util/Config.h" |
| 21 |
|
| 22 |
namespace atlas { |
| 23 |
namespace linalg { |
| 24 |
|
| 25 |
using Matrix = eckit::linalg::Matrix; |
| 26 |
using Configuration = eckit::Configuration; |
| 27 |
|
| 28 |
// C = A . B |
| 29 |
template <typename Matrix> |
| 30 |
void matrix_multiply(const Matrix& A, const Matrix& B, Matrix& C); |
| 31 |
|
| 32 |
template <typename Matrix> |
| 33 |
void matrix_multiply(const Matrix& A, const Matrix& B, Matrix& C, const eckit::Configuration&); |
| 34 |
|
| 35 |
class MatrixMultiply { |
| 36 |
public: |
| 37 |
MatrixMultiply() = default; |
| 38 |
MatrixMultiply(const std::string& backend): backend_{backend} {} |
| 39 |
MatrixMultiply(const dense::Backend& backend): backend_(backend) {} |
| 40 |
|
| 41 |
void operator()(const Matrix& A, const Matrix& B, Matrix& C) const { matrix_multiply(A, B, C, backend()); } |
| 42 |
|
| 43 |
const dense::Backend& backend() const { return backend_; } |
| 44 |
|
| 45 |
private: |
| 46 |
dense::Backend backend_; |
| 47 |
}; |
| 48 |
|
| 49 |
namespace dense { |
| 50 |
|
| 51 |
// Template class which needs (full or partial) specialization for concrete template parameters |
| 52 |
template <typename Backend> |
| 53 |
struct MatrixMultiply { |
| 54 |
static void apply(const Matrix& A, const Matrix& B, Matrix& C, const Configuration&) { |
| 55 |
throw_NotImplemented("MatrixMultiply needs a template specialization with the implementation", Here()); |
| 56 |
} |
| 57 |
}; |
| 58 |
} // namespace dense |
| 59 |
|
| 60 |
} // namespace linalg |
| 61 |
} // namespace atlas |
| 62 |
|
| 63 |
#include "MatrixMultiply.tcc" |
| 64 |
#include "MatrixMultiply_EckitLinalg.h" |