24#ifndef TVM_TOPI_NN_SOFTMAX_H_
25#define TVM_TOPI_NN_SOFTMAX_H_
51 std::string tag =
"softmax_output") {
63 tvm::ffi::Map<ffi::String, ffi::Any> attrs;
70 for (
size_t i = 0;
i < ndim; ++
i) {
71 if (
static_cast<int>(
i) == axis) {
82 for (
size_t i = 0;
i < ndim; ++
i) {
88 auto _compute_max = [&](
const ffi::Array<PrimVar>& indices) {
104 const ffi::Array<PrimVar>& indices) {
118 [&](
const ffi::Array<PrimVar>& indices) {
return _normalize(
exp,
expsum, indices); }, name,
132 std::string tag =
"log_softmax_output") {
147 x->shape, [&](
PrimVar i,
PrimVar j) { return x(i, j) - max_elem(i) - tvm::log(expsum(i)); },
static IntImm Int32(int64_t value, Span span=Span())
Construct a scalar int32 constant.
Definition expr.h:528
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:401
Range container
Definition expr.h:610
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:98
Iteration Variable, represents an iteration over an integer interval.
Definition var.h:194
Checked scalar view over a VarNode.
Definition var.h:46
Tensor expression language DSL.
Definition extracted_task.h:33
IterVar reduce_axis(Range dom, std::string name="rv")
Create a new IterVar for reduction operations.
Tensor compute(ffi::Array< PrimExpr > shape, FCompute fcompute, std::string name="tensor", std::string tag="", ffi::Map< ffi::String, ffi::Any > attrs={})
Construct a new tensor by computing over shape, using the computation rule: result_tensor[axis] = fco...
Tensor softmax(const Tensor &x, int axis=-1, std::string name="tensor", std::string tag="softmax_output")
Softmax activation.
Definition softmax.h:50
Tensor log_softmax(const Tensor &x, std::string name="tensor", std::string tag="log_softmax_output")
Log softmax activation.
Definition softmax.h:131
ffi::Array< PrimExpr > MakeReduceTargetShape(const std::vector< int > &real_axis, const Tensor &data, bool keepdims, bool atleast1d)
Calculate the target shape for a reduce op.
Definition reduction.h:99
PrimExpr MaxOp(PrimExpr source, ffi::Array< IterVar > axis, ffi::Array< PrimExpr > init={}, Span span=Span())
Wrap tvm::max to ensure we get the correct overload.
Definition reduction.h:313
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
PrimExpr max(PrimExpr a, PrimExpr b, Span span=Span())
take maximum of two values
PrimExpr exp(PrimExpr x, Span span=Span())
Definition op.h:752
PrimExpr sum(PrimExpr source, ffi::Array< tirx::IterVar > axis, ffi::Array< PrimExpr > init={}, Span span=Span())
sum of source expression over axis
Operation node can generate one or multiple Tensors.
Reduction op constructors.