InfiniOps
Operator Library for Accelerators
Loading...
Searching...
No Matches
softmax.h
Go to the documentation of this file.
1#ifndef INFINI_OPS_BASE_SOFTMAX_H_
2#define INFINI_OPS_BASE_SOFTMAX_H_
3
4#include <optional>
5
6#include "operator.h"
7
8namespace infini::ops {
9
10class Softmax : public Operator<Softmax> {
11 public:
12 Softmax(const Tensor input, const int64_t dim,
13 const std::optional<DataType> dtype, 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 dim_{dim < 0 ? dim + static_cast<int64_t>(input.ndim()) : dim},
21 dtype_{dtype},
22 ndim_{out.ndim()},
23 dim_size_{out.size(dim_)},
24 row_count_{dim_size_ == 0 ? 0 : out.numel() / dim_size_},
25 device_index_{out.device().index()} {}
26
27 virtual void operator()(const Tensor input, const int64_t dim,
28 const std::optional<DataType> dtype,
29 Tensor out) const = 0;
30
31 protected:
32 Tensor::Shape input_shape_;
33
34 Tensor::Strides input_strides_;
35
36 DataType input_type_;
37
38 Tensor::Shape out_shape_;
39
40 Tensor::Strides out_strides_;
41
42 DataType out_type_;
43
44 int64_t dim_{};
45
46 std::optional<DataType> dtype_{};
47
48 Tensor::Size ndim_{0};
49
50 Tensor::Size dim_size_{0};
51
52 Tensor::Size row_count_{0};
53
55};
56
57} // namespace infini::ops
58
59#endif
Definition generated/include/operator.h:282
Definition softmax.h:10
virtual void operator()(const Tensor input, const int64_t dim, const std::optional< DataType > dtype, Tensor out) const =0
std::optional< DataType > dtype_
Definition softmax.h:46
Tensor::Shape input_shape_
Definition softmax.h:32
Tensor::Size row_count_
Definition softmax.h:52
int device_index_
Definition softmax.h:54
Tensor::Shape out_shape_
Definition softmax.h:38
Tensor::Size dim_size_
Definition softmax.h:50
Tensor::Strides out_strides_
Definition softmax.h:40
DataType out_type_
Definition softmax.h:42
Softmax(const Tensor input, const int64_t dim, const std::optional< DataType > dtype, Tensor out)
Definition softmax.h:12
int64_t dim_
Definition softmax.h:44
DataType input_type_
Definition softmax.h:36
Tensor::Size ndim_
Definition softmax.h:48
Tensor::Strides input_strides_
Definition softmax.h:34
Definition generated/include/operator.h:28
infini::rt::TensorView Tensor
Definition tensor.h:8