Skip to content

Commit 2460842

Browse files
authored
feat: add max base (#327)
1 parent b53b01a commit 2460842

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

src/base/max.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#ifndef INFINI_OPS_BASE_MAX_H_
2+
#define INFINI_OPS_BASE_MAX_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class Max : public Operator<Max> {
9+
public:
10+
Max(const Tensor input, const Tensor other, Tensor out)
11+
: input_shape_{input.shape()},
12+
input_strides_{input.strides()},
13+
input_type_{input.dtype()},
14+
other_shape_{other.shape()},
15+
other_strides_{other.strides()},
16+
other_type_{other.dtype()},
17+
out_shape_{out.shape()},
18+
out_strides_{out.strides()},
19+
out_type_{out.dtype()},
20+
device_index_{out.device().index()} {}
21+
22+
Max(const Tensor input, const int64_t dim, const bool keepdim, Tensor max,
23+
Tensor max_values)
24+
: input_shape_{input.shape()},
25+
input_strides_{input.strides()},
26+
input_type_{input.dtype()},
27+
max_shape_{max.shape()},
28+
max_strides_{max.strides()},
29+
max_type_{max.dtype()},
30+
max_values_shape_{max_values.shape()},
31+
max_values_strides_{max_values.strides()},
32+
max_values_type_{max_values.dtype()},
33+
dim_{dim},
34+
keepdim_{keepdim},
35+
device_index_{max.device().index()} {}
36+
37+
Max(const Tensor input, Tensor out)
38+
: input_shape_{input.shape()},
39+
input_strides_{input.strides()},
40+
input_type_{input.dtype()},
41+
out_shape_{out.shape()},
42+
out_strides_{out.strides()},
43+
out_type_{out.dtype()},
44+
device_index_{out.device().index()} {}
45+
46+
virtual void operator()(const Tensor input, const Tensor other,
47+
Tensor out) const = 0;
48+
49+
virtual void operator()(const Tensor input, const int64_t dim,
50+
const bool keepdim, Tensor max,
51+
Tensor max_values) const = 0;
52+
53+
virtual void operator()(const Tensor input, Tensor out) const = 0;
54+
55+
protected:
56+
Tensor::Shape input_shape_;
57+
58+
Tensor::Strides input_strides_;
59+
60+
DataType input_type_;
61+
62+
Tensor::Shape other_shape_;
63+
64+
Tensor::Strides other_strides_;
65+
66+
DataType other_type_;
67+
68+
Tensor::Shape out_shape_;
69+
70+
Tensor::Strides out_strides_;
71+
72+
DataType out_type_;
73+
74+
Tensor::Shape max_shape_;
75+
76+
Tensor::Strides max_strides_;
77+
78+
DataType max_type_;
79+
80+
Tensor::Shape max_values_shape_;
81+
82+
Tensor::Strides max_values_strides_;
83+
84+
DataType max_values_type_;
85+
86+
int64_t dim_{};
87+
88+
bool keepdim_{};
89+
90+
int device_index_{0};
91+
};
92+
93+
} // namespace infini::ops
94+
95+
#endif

0 commit comments

Comments
 (0)