Rate This Document
Findability
Accuracy
Completeness
Readability

Instructions

Interface Definition

Initialize SoftmaxLayerFWD. During the construction, the tensor information of the input matrix, weight matrix, and output matrix needs to be passed. The bias matrix is optional. If it is not passed, the second constructor will be called for initialization.

SoftmaxLayerFWD(const TensorInfo &srcInfo, const TensorInfo &dstInfo, SizeType axis, SoftmaxAlgorithmKind algorithm)->void
Table 1 Input parameters of SoftmaxLayerFWD

Parameter

Data Type

Description

Value Range

srcInfo

KuDNN::TensorInfo

Source tensor information.

{shape, type, layout}

dstInfo

KuDNN::TensorInfo

Destination tensor information.

{shape, type, layout}

axis

KuDNN::SizeType

Dimension information.

0 < axis < srcInfo. For example, if srcInfo has three dimensions, 0 < axi s< 3.

algorithm

KuDNN::SoftmaxAlgorithmKind

Computation type.

KuDNN::SoftmaxAlgorithmKind::SOFTMAX

To perform operator computation, the memory addresses for storing the input and output data must be passed.

Run(const void *src, void *dst)->void

Table 2 Input parameters of Run

Parameter

Data Type

Description

Value Range

src

void *

Pointer to the source matrix data.

Pointer to the input memory address.

dst

void *

Pointer to the destination matrix data.

Pointer to the output memory address.

ValidateInput verifies the input parameters of SoftMax. It is automatically triggered during operator construction.

ValidateInput(const TensorInfo &srcInfo, const TensorInfo &dstInfo, SizeType axis, SoftmaxAlgorithmKind algorithm)->KuDNN::Status

Table 3 Input parameters of ValidateInput

Parameter

Data Type

Description

Value Range

srcInfo

KuDNN::TensorInfo

Source tensor information.

{shape, type, layout}

dstInfo

KuDNN::TensorInfo

Destination tensor information.

{shape, type, layout}

axis

KuDNN::SizeType

Dimension information.

0 < axis < srcInfo.

For example, if srcInfo has three dimensions, 0 < axis < 3.

algKind

KuDNN::SoftmaxAlgorithmKind

Computation type

KuDNN::SoftmaxAlgorithmKind::SOFTMAX

Supported Data Types

  • SoftMax supports the FP32 data type. (The Shape, Type, and Layout parameters must be passed during TensorInfo object initialization. The following lists the data types supported by Type.)
    Table 4 Type supported during TensorInfo object initialization

    srcInfo

    dstInfo

    KuDNN::Element::TypeT::F32(fp32)

    KuDNN::Element::TypeT::F32(fp32)

  • A maximum of 5 dimensions are supported. The supported sequential data layouts include a, ab, abc, abcd, and abcde.

    They correspond to KuDNN::Layout::A, KuDNN::Layout::AB, KuDNN::Layout::ABC, KuDNN::Layout::ABCD, and KuDNN::Layout::ABCDE, respectively.

    Table 5 Layout supported during TensorInfo object initialization

    Dimension

    srcInfo

    dstInfo

    1D

    a

    a

    2D

    ab

    ab

    3D

    abc

    abc

    4D

    abcd

    abcd

    5D

    abcde

    abcde

Examples

SoftMax operation with two-dimensional data of the F32 type:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
// Example
using SizeType = KuDNN::SizeType;
using Shape = KuDNN::Shape;
using Type KuDNN::Element::TypeT
// Tensor initialization
const KuDNN::TensorInfo srcTensor= {{3, 2}, KuDNN::Element::TypeT::F32, KuDNN::Layout::AB};
const KuDNN::TensorInfo dstTensor= {{3, 2}, KuDNN::Element::TypeT::F32, KuDNN::Layout::AB};
SizeType axis = 1;KuDNN::SoftmaxAlgorithmKind algKind = KuDNN::SoftmaxAlgorithmKind::SOFTMAX
SizeType srcSize = srcATensor.GetTotalTensorSize();
SizeType dstSize = weiBTensor.GetTotalTensorSize();
// Allocate memory for storing the input parameters and result.
float * src = malloc(srcSize* sizeof(float));
float * dst = malloc(dstSize* sizeof(float));
// Construct the operator.
KuDNN::SoftmaxLayerFWD softMaxLayerFwd(srcTensor, dstTensor, axis, algKind);
// Run the operator.
softMaxLayerFwd.Run(src, dst);