blob: 52963ab35792653e38c8e9a07b8d3caa6052022a [file] [log] [blame]
Michele Di Giorgiod02d5ed2021-01-22 09:47:04 +00001/*
2 * Copyright (c) 2021 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#pragma once
26
27#include "arm_gemm.hpp"
28#include "common.hpp"
29
30namespace arm_conv
31{
32namespace depthwise
33{
34using arm_gemm::Nothing;
35
36enum class DepthwiseMethod
37{
38 DEFAULT,
39 DEPTHFIRST,
40 PLANAR,
41};
42
43struct KernelDescription
44{
45 DepthwiseMethod method = DepthwiseMethod::DEFAULT;
46 std::string name = "";
47 bool is_default = false;
48 uint64_t cycle_estimate = 0;
49
50 KernelDescription(
51 DepthwiseMethod method,
52 std::string name,
53 bool is_default,
54 uint64_t cycle_estimate)
55 : method(method), name(name), is_default(is_default), cycle_estimate(cycle_estimate)
56 {
57 }
58
59 KernelDescription() noexcept {};
60};
61
62class IDepthwiseCommon
63{
64public:
65 virtual ~IDepthwiseCommon() = default;
66
67 // Determine the amount of storage space required for the rearranged weights
68 // and bias.
69 virtual size_t get_storage_size(void) const = 0;
70
71 // Rearrange the weights and biases into a storage buffer.
72 // Accepts a pointer to a buffer into which to store the packed parameters, a
73 // pointer the bias vector (which may be nullptr in the case of no bias) and
74 // a pointer to the array of weights (stored in HWIO order).
75 virtual void pack_parameters(
76 void *buffer,
77 const void *biases,
78 const void *weights,
79 size_t ld_weight_col = 0,
80 size_t ld_weight_row = 0) = 0;
81
82 // Determine the amount of working space required
83 virtual size_t get_working_size(unsigned int n_threads, unsigned int n_input_channels) const = 0;
84
85 // Execute the convolution over the specified area of memory.
86 virtual void execute(
87 const void *input, // Pointer to input tensor
88 const void *parameters, // Packed parameters buffer
89 void *output,
90 void *working_space,
91 unsigned int thread_id,
92 unsigned int n_threads) const = 0;
93
94 virtual void execute(
95 const void *input,
96 size_t ld_input_col,
97 size_t ld_input_row,
98 size_t ld_input_batch,
99 const void *parameters,
100 void *output,
101 size_t ld_output_col,
102 size_t ld_output_row,
103 size_t ld_output_batch,
104 void *working_space,
105 unsigned int thread_id,
106 unsigned int n_threads) const = 0;
107
108 virtual void execute(
109 unsigned int batches,
110 unsigned int input_height,
111 unsigned int input_width,
112 unsigned int channels,
113 const PaddingValues &,
114 const void *input,
115 size_t ld_input_col,
116 size_t ld_input_row,
117 size_t ld_input_batch,
118 const void *parameters,
119 unsigned int output_height,
120 unsigned int output_width,
121 void *output,
122 size_t ld_output_col,
123 size_t ld_output_row,
124 size_t ld_output_batch,
125 void *working_space,
126 unsigned int thread_id,
127 unsigned int n_threads) const = 0;
128};
129
130} // namespace depthwise
131} // namespace arm_conv