Skip to content

Commit 3704a79

Browse files
codexvoltjia
authored andcommitted
feat(torch): add generated operator bases
1 parent 2a5d6af commit 3704a79

469 files changed

Lines changed: 27034 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/base/abs.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef INFINI_OPS_BASE_ABS_H_
2+
#define INFINI_OPS_BASE_ABS_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class Abs : public Operator<Abs> {
9+
public:
10+
Abs(const Tensor input, Tensor out)
11+
: input_shape_{input.shape()},
12+
input_strides_{input.strides()},
13+
input_type_{input.dtype()},
14+
out_shape_{out.shape()},
15+
out_strides_{out.strides()},
16+
out_type_{out.dtype()},
17+
device_index_{out.device().index()} {}
18+
19+
virtual void operator()(const Tensor input, Tensor out) const = 0;
20+
21+
protected:
22+
Tensor::Shape input_shape_;
23+
24+
Tensor::Strides input_strides_;
25+
26+
DataType input_type_;
27+
28+
Tensor::Shape out_shape_;
29+
30+
Tensor::Strides out_strides_;
31+
32+
DataType out_type_;
33+
34+
int device_index_{0};
35+
};
36+
37+
} // namespace infini::ops
38+
39+
#endif

src/base/absolute.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef INFINI_OPS_BASE_ABSOLUTE_H_
2+
#define INFINI_OPS_BASE_ABSOLUTE_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class Absolute : public Operator<Absolute> {
9+
public:
10+
Absolute(const Tensor input, Tensor out)
11+
: input_shape_{input.shape()},
12+
input_strides_{input.strides()},
13+
input_type_{input.dtype()},
14+
out_shape_{out.shape()},
15+
out_strides_{out.strides()},
16+
out_type_{out.dtype()},
17+
device_index_{out.device().index()} {}
18+
19+
virtual void operator()(const Tensor input, Tensor out) const = 0;
20+
21+
protected:
22+
Tensor::Shape input_shape_;
23+
24+
Tensor::Strides input_strides_;
25+
26+
DataType input_type_;
27+
28+
Tensor::Shape out_shape_;
29+
30+
Tensor::Strides out_strides_;
31+
32+
DataType out_type_;
33+
34+
int device_index_{0};
35+
};
36+
37+
} // namespace infini::ops
38+
39+
#endif

src/base/acos.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef INFINI_OPS_BASE_ACOS_H_
2+
#define INFINI_OPS_BASE_ACOS_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class Acos : public Operator<Acos> {
9+
public:
10+
Acos(const Tensor input, Tensor out)
11+
: input_shape_{input.shape()},
12+
input_strides_{input.strides()},
13+
input_type_{input.dtype()},
14+
out_shape_{out.shape()},
15+
out_strides_{out.strides()},
16+
out_type_{out.dtype()},
17+
device_index_{out.device().index()} {}
18+
19+
virtual void operator()(const Tensor input, Tensor out) const = 0;
20+
21+
protected:
22+
Tensor::Shape input_shape_;
23+
24+
Tensor::Strides input_strides_;
25+
26+
DataType input_type_;
27+
28+
Tensor::Shape out_shape_;
29+
30+
Tensor::Strides out_strides_;
31+
32+
DataType out_type_;
33+
34+
int device_index_{0};
35+
};
36+
37+
} // namespace infini::ops
38+
39+
#endif

src/base/acosh.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef INFINI_OPS_BASE_ACOSH_H_
2+
#define INFINI_OPS_BASE_ACOSH_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class Acosh : public Operator<Acosh> {
9+
public:
10+
Acosh(const Tensor input, Tensor out)
11+
: input_shape_{input.shape()},
12+
input_strides_{input.strides()},
13+
input_type_{input.dtype()},
14+
out_shape_{out.shape()},
15+
out_strides_{out.strides()},
16+
out_type_{out.dtype()},
17+
device_index_{out.device().index()} {}
18+
19+
virtual void operator()(const Tensor input, Tensor out) const = 0;
20+
21+
protected:
22+
Tensor::Shape input_shape_;
23+
24+
Tensor::Strides input_strides_;
25+
26+
DataType input_type_;
27+
28+
Tensor::Shape out_shape_;
29+
30+
Tensor::Strides out_strides_;
31+
32+
DataType out_type_;
33+
34+
int device_index_{0};
35+
};
36+
37+
} // namespace infini::ops
38+
39+
#endif

src/base/adaptive_avg_pool2d.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef INFINI_OPS_BASE_ADAPTIVE_AVG_POOL2D_H_
2+
#define INFINI_OPS_BASE_ADAPTIVE_AVG_POOL2D_H_
3+
4+
#include <vector>
5+
6+
#include "operator.h"
7+
8+
namespace infini::ops {
9+
10+
class AdaptiveAvgPool2d : public Operator<AdaptiveAvgPool2d> {
11+
public:
12+
AdaptiveAvgPool2d(const Tensor input, const std::vector<int64_t> output_size,
13+
Tensor out)
14+
: input_shape_{input.shape()},
15+
input_strides_{input.strides()},
16+
input_type_{input.dtype()},
17+
out_shape_{out.shape()},
18+
out_strides_{out.strides()},
19+
out_type_{out.dtype()},
20+
output_size_{output_size},
21+
device_index_{out.device().index()} {}
22+
23+
virtual void operator()(const Tensor input,
24+
const std::vector<int64_t> output_size,
25+
Tensor out) const = 0;
26+
27+
protected:
28+
Tensor::Shape input_shape_;
29+
30+
Tensor::Strides input_strides_;
31+
32+
DataType input_type_;
33+
34+
Tensor::Shape out_shape_;
35+
36+
Tensor::Strides out_strides_;
37+
38+
DataType out_type_;
39+
40+
std::vector<int64_t> output_size_{};
41+
42+
int device_index_{0};
43+
};
44+
45+
} // namespace infini::ops
46+
47+
#endif

src/base/adaptive_avg_pool3d.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef INFINI_OPS_BASE_ADAPTIVE_AVG_POOL3D_H_
2+
#define INFINI_OPS_BASE_ADAPTIVE_AVG_POOL3D_H_
3+
4+
#include <vector>
5+
6+
#include "operator.h"
7+
8+
namespace infini::ops {
9+
10+
class AdaptiveAvgPool3d : public Operator<AdaptiveAvgPool3d> {
11+
public:
12+
AdaptiveAvgPool3d(const Tensor input, const std::vector<int64_t> output_size,
13+
Tensor out)
14+
: input_shape_{input.shape()},
15+
input_strides_{input.strides()},
16+
input_type_{input.dtype()},
17+
out_shape_{out.shape()},
18+
out_strides_{out.strides()},
19+
out_type_{out.dtype()},
20+
output_size_{output_size},
21+
device_index_{out.device().index()} {}
22+
23+
virtual void operator()(const Tensor input,
24+
const std::vector<int64_t> output_size,
25+
Tensor out) const = 0;
26+
27+
protected:
28+
Tensor::Shape input_shape_;
29+
30+
Tensor::Strides input_strides_;
31+
32+
DataType input_type_;
33+
34+
Tensor::Shape out_shape_;
35+
36+
Tensor::Strides out_strides_;
37+
38+
DataType out_type_;
39+
40+
std::vector<int64_t> output_size_{};
41+
42+
int device_index_{0};
43+
};
44+
45+
} // namespace infini::ops
46+
47+
#endif
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef INFINI_OPS_BASE_ADAPTIVE_AVG_POOL3D_BACKWARD_H_
2+
#define INFINI_OPS_BASE_ADAPTIVE_AVG_POOL3D_BACKWARD_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class AdaptiveAvgPool3dBackward : public Operator<AdaptiveAvgPool3dBackward> {
9+
public:
10+
AdaptiveAvgPool3dBackward(const Tensor grad_output, const Tensor input,
11+
Tensor grad_input)
12+
: grad_output_shape_{grad_output.shape()},
13+
grad_output_strides_{grad_output.strides()},
14+
grad_output_type_{grad_output.dtype()},
15+
input_shape_{input.shape()},
16+
input_strides_{input.strides()},
17+
input_type_{input.dtype()},
18+
grad_input_shape_{grad_input.shape()},
19+
grad_input_strides_{grad_input.strides()},
20+
grad_input_type_{grad_input.dtype()},
21+
device_index_{grad_input.device().index()} {}
22+
23+
virtual void operator()(const Tensor grad_output, const Tensor input,
24+
Tensor grad_input) const = 0;
25+
26+
protected:
27+
Tensor::Shape grad_output_shape_;
28+
29+
Tensor::Strides grad_output_strides_;
30+
31+
DataType grad_output_type_;
32+
33+
Tensor::Shape input_shape_;
34+
35+
Tensor::Strides input_strides_;
36+
37+
DataType input_type_;
38+
39+
Tensor::Shape grad_input_shape_;
40+
41+
Tensor::Strides grad_input_strides_;
42+
43+
DataType grad_input_type_;
44+
45+
int device_index_{0};
46+
};
47+
48+
} // namespace infini::ops
49+
50+
#endif

src/base/adaptive_max_pool2d.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef INFINI_OPS_BASE_ADAPTIVE_MAX_POOL2D_H_
2+
#define INFINI_OPS_BASE_ADAPTIVE_MAX_POOL2D_H_
3+
4+
#include <vector>
5+
6+
#include "operator.h"
7+
8+
namespace infini::ops {
9+
10+
class AdaptiveMaxPool2d : public Operator<AdaptiveMaxPool2d> {
11+
public:
12+
AdaptiveMaxPool2d(const Tensor input, const std::vector<int64_t> output_size,
13+
Tensor out, Tensor indices)
14+
: input_shape_{input.shape()},
15+
input_strides_{input.strides()},
16+
input_type_{input.dtype()},
17+
out_shape_{out.shape()},
18+
out_strides_{out.strides()},
19+
out_type_{out.dtype()},
20+
indices_shape_{indices.shape()},
21+
indices_strides_{indices.strides()},
22+
indices_type_{indices.dtype()},
23+
output_size_{output_size},
24+
device_index_{out.device().index()} {}
25+
26+
virtual void operator()(const Tensor input,
27+
const std::vector<int64_t> output_size, Tensor out,
28+
Tensor indices) const = 0;
29+
30+
protected:
31+
Tensor::Shape input_shape_;
32+
33+
Tensor::Strides input_strides_;
34+
35+
DataType input_type_;
36+
37+
Tensor::Shape out_shape_;
38+
39+
Tensor::Strides out_strides_;
40+
41+
DataType out_type_;
42+
43+
Tensor::Shape indices_shape_;
44+
45+
Tensor::Strides indices_strides_;
46+
47+
DataType indices_type_;
48+
49+
std::vector<int64_t> output_size_{};
50+
51+
int device_index_{0};
52+
};
53+
54+
} // namespace infini::ops
55+
56+
#endif

0 commit comments

Comments
 (0)