From 74f3dc3776e77f5478204eeeca1fa05395a62ff6 Mon Sep 17 00:00:00 2001 From: Jiacheng Huang Date: Wed, 13 May 2026 14:39:02 +0800 Subject: [PATCH 1/2] feat: add `nll_loss2d` base --- src/base/nll_loss2d.h | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/base/nll_loss2d.h diff --git a/src/base/nll_loss2d.h b/src/base/nll_loss2d.h new file mode 100644 index 000000000..fef9a4c10 --- /dev/null +++ b/src/base/nll_loss2d.h @@ -0,0 +1,57 @@ +#ifndef INFINI_OPS_BASE_NLL_LOSS2D_H_ +#define INFINI_OPS_BASE_NLL_LOSS2D_H_ + +#include "operator.h" + +namespace infini::ops { + +class NllLoss2d : public Operator { + public: + NllLoss2d(const Tensor input, const Tensor target, const int64_t reduction, + const int64_t ignore_index, Tensor out) + : input_shape_{input.shape()}, + input_strides_{input.strides()}, + input_type_{input.dtype()}, + target_shape_{target.shape()}, + target_strides_{target.strides()}, + target_type_{target.dtype()}, + out_shape_{out.shape()}, + out_strides_{out.strides()}, + out_type_{out.dtype()}, + reduction_{reduction}, + ignore_index_{ignore_index}, + device_index_{out.device().index()} {} + + virtual void operator()(const Tensor input, const Tensor target, + const int64_t reduction, const int64_t ignore_index, + Tensor out) const = 0; + + protected: + Tensor::Shape input_shape_; + + Tensor::Strides input_strides_; + + DataType input_type_; + + Tensor::Shape target_shape_; + + Tensor::Strides target_strides_; + + DataType target_type_; + + Tensor::Shape out_shape_; + + Tensor::Strides out_strides_; + + DataType out_type_; + + int64_t reduction_{}; + + int64_t ignore_index_{}; + + int device_index_{0}; +}; + +} // namespace infini::ops + +#endif \ No newline at end of file From d43b1b2c51320101aa38ff3793e3c6c5c9d9ca8b Mon Sep 17 00:00:00 2001 From: Jiacheng Huang Date: Mon, 18 May 2026 19:52:08 +0800 Subject: [PATCH 2/2] fix: add trailing newline to base header --- src/base/nll_loss2d.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/nll_loss2d.h b/src/base/nll_loss2d.h index fef9a4c10..cf2eca0bf 100644 --- a/src/base/nll_loss2d.h +++ b/src/base/nll_loss2d.h @@ -54,4 +54,4 @@ class NllLoss2d : public Operator { } // namespace infini::ops -#endif \ No newline at end of file +#endif