• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_LITE_SRC_RUNTIME_KERNEL_OPENCL_KERNEL_REDUCE_H_
18 #define MINDSPORE_LITE_SRC_RUNTIME_KERNEL_OPENCL_KERNEL_REDUCE_H_
19 
20 #include <vector>
21 #include <string>
22 #include "src/litert/lite_kernel.h"
23 #include "src/litert/kernel/opencl/opencl_kernel.h"
24 #include "nnacl/reduce_parameter.h"
25 
26 namespace mindspore::kernel {
27 class ReduceOpenCLKernel : public OpenCLKernel {
28  public:
29   using OpenCLKernel::OpenCLKernel;
30   ~ReduceOpenCLKernel() override = default;
31 
32   int Run() override;
33   int Prepare() override;
34   int CheckSpecs() override;
35   int SetConstArgs() override;
36   int SetGlobalLocal() override;
37   int Tune() override;
38 
39  private:
40   int SetAxes();
41   int SetShapeSizeIs0Axes();
42   int SetShapeSizeIs1Axes();
43   cl_float4 GenC4Mask();
44   static std::string GetReduceTypeStr(int type);
45 
46   bool IsHWCReduce();
47   bool IsHWReduce();
48   bool IsWCReduce();
49   bool IsHReduce();
50   bool IsWReduce();
51   bool IsCReduce();
52   int IsReduceAxesSupport();
53 
54   GpuTensorInfo inShape;
55   bool use_local_{false};
56   bool reduce_axes_[4]{false};
57   static const size_t LOCAL_CACHE_THREAD{16};
58   int axes_[MAX_SHAPE_SIZE];
59 };
60 }  // namespace mindspore::kernel
61 
62 #endif  // MINDSPORE_LITE_SRC_RUNTIME_KERNEL_OPENCL_KERNEL_REDUCE_H_
63