forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblas.cpp
More file actions
97 lines (81 loc) · 3.11 KB
/
blas.cpp
File metadata and controls
97 lines (81 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <af/blas.h>
#include <blas.hpp>
#include <handle.hpp>
#include <Array.hpp>
#include <af/array.h>
#include <af/defines.h>
#include <ArrayInfo.hpp>
#include <err_common.hpp>
#include <backend.hpp>
template<typename T>
static inline af_array matmul(const af_array lhs, const af_array rhs,
af_blas_transpose optLhs, af_blas_transpose optRhs)
{
return getHandle(detail::matmul<T>(getArray<T>(lhs), getArray<T>(rhs), optLhs, optRhs));
}
template<typename T>
static inline af_array dot(const af_array lhs, const af_array rhs,
af_blas_transpose optLhs, af_blas_transpose optRhs)
{
return getHandle(detail::dot<T>(getArray<T>(lhs), getArray<T>(rhs), optLhs, optRhs));
}
af_err af_matmul( af_array *out,
const af_array lhs, const af_array rhs,
af_blas_transpose optLhs, af_blas_transpose optRhs)
{
using namespace detail;
try {
ArrayInfo lhsInfo = getInfo(lhs);
ArrayInfo rhsInfo = getInfo(rhs);
af_dtype lhs_type = lhsInfo.getType();
af_dtype rhs_type = rhsInfo.getType();
TYPE_ASSERT(lhs_type == rhs_type);
af_array output = 0;
int aColDim = (optLhs == AF_NO_TRANSPOSE) ? 1 : 0;
int bRowDim = (optRhs == AF_NO_TRANSPOSE) ? 0 : 1;
DIM_ASSERT(1, lhsInfo.dims()[aColDim] == rhsInfo.dims()[bRowDim]);
switch(lhs_type) {
case f32: output = matmul<float >(lhs, rhs, optLhs, optRhs); break;
case c32: output = matmul<cfloat >(lhs, rhs, optLhs, optRhs); break;
case f64: output = matmul<double >(lhs, rhs, optLhs, optRhs); break;
case c64: output = matmul<cdouble>(lhs, rhs, optLhs, optRhs); break;
default: TYPE_ERROR(1, lhs_type);
}
std::swap(*out, output);
}
CATCHALL
return AF_SUCCESS;
}
af_err af_dot( af_array *out,
const af_array lhs, const af_array rhs,
af_blas_transpose optLhs, af_blas_transpose optRhs)
{
using namespace detail;
try {
ArrayInfo lhsInfo = getInfo(lhs);
ArrayInfo rhsInfo = getInfo(rhs);
DIM_ASSERT(1, lhsInfo.dims()[0] == rhsInfo.dims()[0]);
af_dtype lhs_type = lhsInfo.getType();
af_dtype rhs_type = rhsInfo.getType();
TYPE_ASSERT(lhs_type == rhs_type);
af_array output = 0;
switch(lhs_type) {
case f32: output = dot<float >(lhs, rhs, optLhs, optRhs); break;
//case c32: output = dot<cfloat >(lhs, rhs, optLhs, optRhs); break;
case f64: output = dot<double >(lhs, rhs, optLhs, optRhs); break;
//case c64: output = dot<cdouble>(lhs, rhs, optLhs, optRhs); break;
default: TYPE_ERROR(1, lhs_type);
}
std::swap(*out, output);
}
CATCHALL
return AF_SUCCESS;
}