Skip to content

Commit 9624afa

Browse files
committed
feat: add nll_loss2d_backward base
1 parent cfea02e commit 9624afa

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

src/base/nll_loss2d_backward.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#ifndef INFINI_OPS_BASE_NLL_LOSS2D_BACKWARD_H_
2+
#define INFINI_OPS_BASE_NLL_LOSS2D_BACKWARD_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class NllLoss2dBackward : public Operator<NllLoss2dBackward> {
9+
public:
10+
NllLoss2dBackward(const Tensor grad_output, const Tensor input,
11+
const Tensor target, const int64_t reduction,
12+
const int64_t ignore_index, const Tensor total_weight,
13+
Tensor grad_input)
14+
: grad_output_shape_{grad_output.shape()},
15+
grad_output_strides_{grad_output.strides()},
16+
grad_output_type_{grad_output.dtype()},
17+
input_shape_{input.shape()},
18+
input_strides_{input.strides()},
19+
input_type_{input.dtype()},
20+
target_shape_{target.shape()},
21+
target_strides_{target.strides()},
22+
target_type_{target.dtype()},
23+
total_weight_shape_{total_weight.shape()},
24+
total_weight_strides_{total_weight.strides()},
25+
total_weight_type_{total_weight.dtype()},
26+
grad_input_shape_{grad_input.shape()},
27+
grad_input_strides_{grad_input.strides()},
28+
grad_input_type_{grad_input.dtype()},
29+
reduction_{reduction},
30+
ignore_index_{ignore_index},
31+
device_index_{grad_input.device().index()} {}
32+
33+
virtual void operator()(const Tensor grad_output, const Tensor input,
34+
const Tensor target, const int64_t reduction,
35+
const int64_t ignore_index, const Tensor total_weight,
36+
Tensor grad_input) const = 0;
37+
38+
protected:
39+
Tensor::Shape grad_output_shape_;
40+
41+
Tensor::Strides grad_output_strides_;
42+
43+
DataType grad_output_type_;
44+
45+
Tensor::Shape input_shape_;
46+
47+
Tensor::Strides input_strides_;
48+
49+
DataType input_type_;
50+
51+
Tensor::Shape target_shape_;
52+
53+
Tensor::Strides target_strides_;
54+
55+
DataType target_type_;
56+
57+
Tensor::Shape total_weight_shape_;
58+
59+
Tensor::Strides total_weight_strides_;
60+
61+
DataType total_weight_type_;
62+
63+
Tensor::Shape grad_input_shape_;
64+
65+
Tensor::Strides grad_input_strides_;
66+
67+
DataType grad_input_type_;
68+
69+
int64_t reduction_{};
70+
71+
int64_t ignore_index_{};
72+
73+
int device_index_{0};
74+
};
75+
76+
} // namespace infini::ops
77+
78+
#endif

0 commit comments

Comments
 (0)