1/*******************************************************************************
2* Copyright 2022 Intel Corporation
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 GPU_JIT_IR_REDUCE_HPP
18#define GPU_JIT_IR_REDUCE_HPP
19
20#include "gpu/jit/ir/ir.hpp"
21#include "gpu/jit/ir/reorder.hpp"
22#include "gpu/jit/ir/tensor.hpp"
23
24namespace dnnl {
25namespace impl {
26namespace gpu {
27namespace jit {
28
29// Implements reduction of GRF buffer for given layout.
30class reduce_t : public func_impl_t {
31public:
32 IR_DECL_DERIVED_TYPE_ID(reduce_t, func_impl_t)
33
34 static func_t make(const layout_t &src_layout, const layout_t &dst_layout) {
35 return func_t(new reduce_t(src_layout, dst_layout));
36 }
37
38 bool is_equal(const object_impl_t &obj) const override {
39 if (!obj.is<self_type>()) return false;
40 auto &other = obj.as<self_type>();
41
42 return (src_layout == other.src_layout)
43 && (dst_layout == other.dst_layout);
44 }
45
46 size_t get_hash() const override {
47 return ir_utils::get_hash(src_layout, dst_layout);
48 }
49
50 std::string str() const override {
51 std::ostringstream oss;
52 oss << "reduce[" << src_layout << ", " << dst_layout << "]";
53 return oss.str();
54 }
55
56 IR_DEFINE_ARG_GET(dst_buf, 0)
57 IR_DEFINE_ARG_GET(src_buf, 1)
58
59 layout_t src_layout;
60 layout_t dst_layout;
61
62private:
63 reduce_t(const layout_t &src_layout, const layout_t &dst_layout)
64 : func_impl_t(_type_info())
65 , src_layout(src_layout)
66 , dst_layout(dst_layout) {}
67};
68
69stmt_t create_reduce_stmt(const layout_t &src, const layout_t &dst,
70 const expr_t &src_buf, const expr_t &dst_buf, const tensor_t &_subtile,
71 uint32_t reduction_mask, bool drop_dims = true);
72
73} // namespace jit
74} // namespace gpu
75} // namespace impl
76} // namespace dnnl
77
78#endif
79