-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy patheigen_backend_with_snn_matmul.h
119 lines (106 loc) · 3.89 KB
/
eigen_backend_with_snn_matmul.h
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright Codeplay Software Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PORTDNN_INCLUDE_BACKEND_EIGEN_BACKEND_WITH_SNN_MATMUL_H_
#define PORTDNN_INCLUDE_BACKEND_EIGEN_BACKEND_WITH_SNN_MATMUL_H_
/**
* \file
* Contains the implementation of \ref sycldnn::backend::EigenBackendSNNMatmul,
* which provides pointer handling through Eigen and matrix multiplies via
* portDNN's internal matmul kernels.
*/
#include "portdnn/backend/common_backend.h"
#include "portdnn/backend/eigen_external_handler.h"
#include "portdnn/backend/eigen_internal_handler.h"
#include "portdnn/backend/eigen_pointer_to_eigen_pointer.h"
#include "portdnn/backend/snn_matmul_provider.h"
#include "portdnn/backend/snn_reduce_provider.h"
namespace sycldnn {
namespace backend {
// Forward declaration to allow the BackendTraits specialisation.
struct EigenBackendSNNMatmul;
/**
* The template specialisation of \ref
* sycldnn::backend::BackendTraits<EigenBackendSNNMatmul>.
*
* Provides the pointer types for the EigenBackendSNNMatmul.
*/
template <>
struct BackendTraits<EigenBackendSNNMatmul> {
/**
* The external pointer type for EigenBackendSNNMatmul.
*/
template <typename T>
using pointer_type = T*;
/**
* The internal pointer type for EigenBackendSNNMatmul.
*/
template <typename T>
using internal_pointer_type = T*;
};
/**
* Eigen backend for portDNN.
*
* Provides pointer handling and matrix multiplies using Eigen.
*/
struct EigenBackendSNNMatmul final
: public CommonBackend,
public EigenExternalHandler<EigenBackendSNNMatmul>,
public EigenToEigenPointer,
public EigenInternalHandler<EigenBackendSNNMatmul>,
public SNNReduceProvider<EigenBackendSNNMatmul>,
public SNNMatmulProvider<EigenBackendSNNMatmul> {
/** The pointer type used in interface of the EigenBackend. */
template <typename T>
using pointer_type =
typename BackendTraits<EigenBackendSNNMatmul>::template pointer_type<T>;
/** The internal pointer type used internally by the EigenBackend. */
template <typename T>
using internal_pointer_type = typename BackendTraits<
EigenBackendSNNMatmul>::template internal_pointer_type<T>;
/**
* Constructs an instance of \ref sycldnn::backend::EigenBackendSNNMatmul from
* an
* instance of Eigen's SyclDevice.
* \param device The Eigen::SyclDevice to construct the backend from.
*/
explicit EigenBackendSNNMatmul(Eigen::SyclDevice const& device)
: CommonBackend(device.sycl_queue()), device_{device} {}
/**
* Gets a descriptive name for this backend.
* \return a descriptive name for this backend.
*/
static char const* name() { return "EigenBackendSNNMatmul"; }
/**
* Gets the SYCL queue that the backend is bound to.
* \return Returns the SYCL queue that the backend is bound to.
*/
cl::sycl::queue get_queue() { return device_.sycl_queue(); }
/**
* Get a const reference to the Eigen SyclDevice used in this backend.
* \return A const reference to the Eigen SyclDevice.
*/
Eigen::SyclDevice const& get_eigen_device() const { return device_; }
/**
* Get a reference to the Eigen SyclDevice used in this backend.
* \return A reference to the Eigen SyclDevice.
*/
Eigen::SyclDevice& get_eigen_device() { return device_; }
private:
Eigen::SyclDevice device_;
};
} // namespace backend
} // namespace sycldnn
#endif // PORTDNN_INCLUDE_BACKEND_EIGEN_BACKEND_WITH_SNN_MATMUL_H_