• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017-2020 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 #ifndef ARM_COMPUTE_NEMINMAXLAYERKERNEL_H
26 #define ARM_COMPUTE_NEMINMAXLAYERKERNEL_H
27 
28 #include "src/core/NEON/INEKernel.h"
29 #include "support/Mutex.h"
30 
31 #include <cstdint>
32 
33 namespace arm_compute
34 {
35 class ITensor;
36 
37 /** Interface for the kernel to perform min max search on a 3D tensor. */
38 class NEMinMaxLayerKernel : public INEKernel
39 {
40 public:
name()41     const char *name() const override
42     {
43         return "NEMinMaxLayerKernel";
44     }
45     /** Default constructor */
46     NEMinMaxLayerKernel();
47     /** Prevent instances of this class from being copied (As this class contains pointers) */
48     NEMinMaxLayerKernel(const NEMinMaxLayerKernel &) = delete;
49     /** Prevent instances of this class from being copied (As this class contains pointers) */
50     NEMinMaxLayerKernel &operator=(const NEMinMaxLayerKernel &) = delete;
51     /** Prevent instances of this class from being moved (As this class contains non movable objects) */
52     NEMinMaxLayerKernel(NEMinMaxLayerKernel &&) = delete;
53     /** Prevent instances of this class from being moved (As this class contains non movable objects) */
54     NEMinMaxLayerKernel &operator=(NEMinMaxLayerKernel &&) = delete;
55     /** Default destructor */
56     ~NEMinMaxLayerKernel() = default;
57 
58     /** Initialise the kernel's input and outputs.
59      *
60      * @note output[0] = minimum
61      * @note output[1] = maximum
62      *
63      * @param[in]  input  Input tensor with at least 3 dimensions. The dimensions over the third will be interpreted as batches. Data type supported: F32.
64      * @param[out] output Output tensor with shape [2, batches, ...] which stores the minimum and maximum value for each 3D input tensor.
65      *                    The dimensions over the second must match the batched dimensions of the input tensor. Data types supported: F32
66      */
67     void configure(const ITensor *input, ITensor *output);
68     /** Static function to check if given info will lead to a valid configuration of @ref CLMinMaxLayerKernel
69      *
70      * @param[in] input  Input tensor info.  Data types supported: F32.
71      * @param[in] output Output tensor info with shape [2, batches, ...] which stores the minimum and maximum values for each 3D input tensor.
72      *                   The dimensions over the second must match the batched dimensions of the input tensor. Data types supported: F32.
73      *
74      * @return a status
75      */
76     static Status validate(const ITensorInfo *input, const ITensorInfo *output);
77     /** Resets global minimum and maximum. */
78     void reset();
79 
80     // Inherited methods overridden:
81     void run(const Window &window, const ThreadInfo &info) override;
82 
83 private:
84     void update_min_max(float *out_ptr, float min, float max);
85     const ITensor     *_input;
86     ITensor           *_output;
87     arm_compute::Mutex _mtx;
88 };
89 } // namespace arm_compute
90 #endif /* ARM_COMPUTE_NEMINMAXLAYERKERNEL_H */
91