| 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 "MatrixMultiply.h" |
| 14 |
|
| 15 |
#include "atlas/linalg/Indexing.h" |
| 16 |
#include "atlas/linalg/Introspection.h" |
| 17 |
#include "atlas/linalg/View.h" |
| 18 |
#include "atlas/linalg/dense/Backend.h" |
| 19 |
#include "atlas/runtime/Exception.h" |
| 20 |
|
| 21 |
#if ATLAS_ECKIT_HAVE_ECKIT_585 |
| 22 |
#include "eckit/linalg/LinearAlgebraDense.h" |
| 23 |
#else |
| 24 |
#include "eckit/linalg/LinearAlgebra.h" |
| 25 |
#endif |
| 26 |
|
| 27 |
namespace atlas { |
| 28 |
namespace linalg { |
| 29 |
|
| 30 |
|
| 31 |
namespace dense { |
| 32 |
namespace { |
| 33 |
template <typename Backend> |
| 34 |
struct MatrixMultiplyHelper { |
| 35 |
template <typename Mat> |
| 36 |
static void apply( const Mat& A, const Mat& B, Mat& C, |
| 37 |
const eckit::Configuration& config ) { |
| 38 |
MatrixMultiply<Backend>::apply( A,B,C, config ); |
| 39 |
} |
| 40 |
}; |
| 41 |
|
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
template <typename Mat> |
| 46 |
void matrix_multiply( const Mat& A, const Mat& B, Mat& C, const eckit::Configuration& config ) { |
| 47 |
std::string type = config.getString( "type", dense::current_backend() ); |
| 48 |
if ( type == dense::backend::eckit_linalg::type() ) { |
| 49 |
dense::MatrixMultiplyHelper<dense::backend::eckit_linalg>::apply( A, B, C, config ); |
| 50 |
} |
| 51 |
else { |
| 52 |
if( type == "openmp" ) { |
| 53 |
type = "generic"; |
| 54 |
dense::MatrixMultiplyHelper<dense::backend::eckit_linalg>::apply( A, B, C, util::Config("backend",type) ); |
| 55 |
} |
| 56 |
#if ATLAS_ECKIT_HAVE_ECKIT_585 |
| 57 |
else if( eckit::linalg::LinearAlgebraDense::hasBackend(type) ) { |
| 58 |
#else |
| 59 |
else if( eckit::linalg::LinearAlgebra::hasBackend(type) ) { |
| 60 |
#endif |
| 61 |
dense::MatrixMultiplyHelper<dense::backend::eckit_linalg>::apply( A, B, C, util::Config("backend",type) ); |
| 62 |
} |
| 63 |
else { |
| 64 |
throw_NotImplemented( "matrix_multiply cannot be performed with unsupported backend [" + type + "]", |
| 65 |
Here() ); |
| 66 |
} |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
template <typename Matrix> |
| 71 |
void matrix_multiply( const Matrix& A, const Matrix& B, Matrix& C ) { |
| 72 |
matrix_multiply( A, B, C, dense::Backend() ); |
| 73 |
} |
| 74 |
|
| 75 |
} // namespace linalg |
| 76 |
} // namespace atlas |