Skip to content

Commit 9156d22

Browse files
authored
feat: add scatter_reduce base (#400)
1 parent 8043834 commit 9156d22

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

src/base/scatter_reduce.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#ifndef INFINI_OPS_BASE_SCATTER_REDUCE_H_
2+
#define INFINI_OPS_BASE_SCATTER_REDUCE_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class ScatterReduce : public Operator<ScatterReduce> {
9+
public:
10+
ScatterReduce(const Tensor input, const int64_t dim, const Tensor index,
11+
const Tensor src, const std::string reduce,
12+
const bool include_self, Tensor out)
13+
: input_shape_{input.shape()},
14+
input_strides_{input.strides()},
15+
input_type_{input.dtype()},
16+
index_shape_{index.shape()},
17+
index_strides_{index.strides()},
18+
index_type_{index.dtype()},
19+
src_shape_{src.shape()},
20+
src_strides_{src.strides()},
21+
src_type_{src.dtype()},
22+
out_shape_{out.shape()},
23+
out_strides_{out.strides()},
24+
out_type_{out.dtype()},
25+
dim_{dim},
26+
reduce_{reduce},
27+
include_self_{include_self},
28+
device_index_{out.device().index()} {}
29+
30+
virtual void operator()(const Tensor input, const int64_t dim,
31+
const Tensor index, const Tensor src,
32+
const std::string reduce, const bool include_self,
33+
Tensor out) const = 0;
34+
35+
protected:
36+
Tensor::Shape input_shape_;
37+
38+
Tensor::Strides input_strides_;
39+
40+
DataType input_type_;
41+
42+
Tensor::Shape index_shape_;
43+
44+
Tensor::Strides index_strides_;
45+
46+
DataType index_type_;
47+
48+
Tensor::Shape src_shape_;
49+
50+
Tensor::Strides src_strides_;
51+
52+
DataType src_type_;
53+
54+
Tensor::Shape out_shape_;
55+
56+
Tensor::Strides out_strides_;
57+
58+
DataType out_type_;
59+
60+
int64_t dim_{};
61+
62+
std::string reduce_{};
63+
64+
bool include_self_{};
65+
66+
int device_index_{0};
67+
};
68+
69+
} // namespace infini::ops
70+
71+
#endif

0 commit comments

Comments
 (0)