Skip to content

Commit b94e29e

Browse files
committed
feat: add MultiMarginLossBackwardGradInput base
1 parent 57ec7e3 commit b94e29e

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef INFINI_OPS_BASE_MULTI_MARGIN_LOSS_BACKWARD_GRAD_INPUT_H_
2+
#define INFINI_OPS_BASE_MULTI_MARGIN_LOSS_BACKWARD_GRAD_INPUT_H_
3+
4+
#include "operator.h"
5+
6+
namespace infini::ops {
7+
8+
class MultiMarginLossBackwardGradInput
9+
: public Operator<MultiMarginLossBackwardGradInput> {
10+
public:
11+
MultiMarginLossBackwardGradInput(const Tensor grad_output, const Tensor self,
12+
const Tensor target, const double p,
13+
const double margin, 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+
self_shape_{self.shape()},
18+
self_strides_{self.strides()},
19+
self_type_{self.dtype()},
20+
target_shape_{target.shape()},
21+
target_strides_{target.strides()},
22+
target_type_{target.dtype()},
23+
grad_input_shape_{grad_input.shape()},
24+
grad_input_strides_{grad_input.strides()},
25+
grad_input_type_{grad_input.dtype()},
26+
device_index_{grad_input.device().index()} {}
27+
28+
virtual void operator()(const Tensor grad_output, const Tensor self,
29+
const Tensor target, const double p,
30+
const double margin, Tensor grad_input) const = 0;
31+
32+
protected:
33+
Tensor::Shape grad_output_shape_;
34+
Tensor::Strides grad_output_strides_;
35+
DataType grad_output_type_;
36+
Tensor::Shape self_shape_;
37+
Tensor::Strides self_strides_;
38+
DataType self_type_;
39+
Tensor::Shape target_shape_;
40+
Tensor::Strides target_strides_;
41+
DataType target_type_;
42+
Tensor::Shape grad_input_shape_;
43+
Tensor::Strides grad_input_strides_;
44+
DataType grad_input_type_;
45+
int device_index_{0};
46+
};
47+
48+
} // namespace infini::ops
49+
50+
#endif

0 commit comments

Comments
 (0)