Skip to content

Commit 96b7efe

Browse files
committed
feat: add nll_loss_forward base
1 parent cfea02e commit 96b7efe

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

src/base/nll_loss_forward.h

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

0 commit comments

Comments
 (0)