LossFunction

LossFunction#

MIOpen: LossFunction
LossFunction

Enumerations

enum  miopenCTCLossAlgo_t { MIOPEN_CTC_LOSS_ALGO_DETERMINISTIC = 0 }
 
enum  miopenLossReductionMode_t {
  MIOPEN_LOSS_REDUCTION_NONE = 0 ,
  MIOPEN_LOSS_REDUCTION_SUM = 1 ,
  MIOPEN_LOSS_REDUCTION_MEAN = 2
}
 

Functions

 MIOPEN_DECLARE_OBJECT (miopenCTCLossDescriptor)
 Creates the miopenCTCLossDescriptor_t type. More...
 
miopenStatus_t miopenCreateCTCLossDescriptor (miopenCTCLossDescriptor_t *ctcLossDesc)
 Create a CTC loss function Descriptor. More...
 
miopenStatus_t miopenGetCTCLossDescriptor (miopenCTCLossDescriptor_t ctcLossDesc, miopenDataType_t *dataType, int *blank_label_id, bool *apply_softmax_layer)
 Retrieves a CTC loss function descriptor's details. More...
 
miopenStatus_t miopenDestroyCTCLossDescriptor (miopenCTCLossDescriptor_t ctcLossDesc)
 Destroys a CTC loss function descriptor object. More...
 
miopenStatus_t miopenSetCTCLossDescriptor (miopenCTCLossDescriptor_t ctcLossDesc, miopenDataType_t dataType, const int blank_label_id, bool apply_softmax_layer)
 Set the details of a CTC loss function descriptor. More...
 
miopenStatus_t miopenGetCTCLossWorkspaceSize (miopenHandle_t handle, const miopenTensorDescriptor_t probsDesc, const miopenTensorDescriptor_t gradientsDesc, const int *labels, const int *labelLengths, const int *inputLengths, miopenCTCLossAlgo_t algo, const miopenCTCLossDescriptor_t ctcLossDesc, size_t *workSpaceSize)
 Query the amount of memory required to execute miopenCTCLoss. More...
 
miopenStatus_t miopenCTCLoss (miopenHandle_t handle, const miopenTensorDescriptor_t probsDesc, const void *probs, const int *labels, const int *labelLengths, const int *inputLengths, void *losses, const miopenTensorDescriptor_t gradientsDesc, void *gradients, miopenCTCLossAlgo_t algo, const miopenCTCLossDescriptor_t ctcLossDesc, void *workSpace, size_t workSpaceSize)
 Execute forward inference for CTCLoss layer. More...
 
miopenStatus_t miopenGetSoftMarginLossForwardWorkspaceSize (miopenHandle_t handle, miopenTensorDescriptor_t inputDesc, miopenTensorDescriptor_t targetDesc, miopenTensorDescriptor_t outputDesc, miopenLossReductionMode_t reduction, size_t *sizeInBytes)
 Helper function to query the minimum workspace size required by the SoftMarginLossForward call. More...
 
miopenStatus_t miopenSoftMarginLossForward (miopenHandle_t handle, miopenTensorDescriptor_t inputDesc, const void *input, miopenTensorDescriptor_t targetDesc, const void *target, miopenTensorDescriptor_t outputDesc, void *output, miopenLossReductionMode_t reduction, void *workspace=nullptr, size_t workspaceSizeInBytes=0)
 Execute a SoftMarginLoss forward layer. More...
 
miopenStatus_t miopenSoftMarginLossBackward (miopenHandle_t handle, miopenTensorDescriptor_t inputDesc, const void *input, miopenTensorDescriptor_t targetDesc, const void *target, miopenTensorDescriptor_t doutputDesc, const void *doutput, miopenTensorDescriptor_t dinputDesc, void *dinput, miopenLossReductionMode_t reduction)
 Execute a SoftMarginLoss backward layer. More...
 
miopenStatus_t miopenGetMultiMarginLossForwardWorkspaceSize (miopenHandle_t handle, miopenTensorDescriptor_t inputDesc, miopenTensorDescriptor_t targetDesc, miopenTensorDescriptor_t weightDesc, miopenTensorDescriptor_t outputDesc, long p, float margin, miopenLossReductionMode_t reduction, size_t *sizeInBytes)
 Helper function to query the minimum workspace size required by the MultiMarginLossForward call. More...
 
miopenStatus_t miopenMultiMarginLossForward (miopenHandle_t handle, miopenTensorDescriptor_t inputDesc, const void *input, miopenTensorDescriptor_t targetDesc, const void *target, miopenTensorDescriptor_t weightDesc, const void *weight, miopenTensorDescriptor_t outputDesc, void *output, long p, float margin, miopenLossReductionMode_t reduction, void *workspace, size_t workspaceSizeInBytes)
 Execute a MultiMarginLoss forward layer. More...
 

Detailed Description

Enumeration Type Documentation

◆ miopenCTCLossAlgo_t

Algorithms available to execute the CTC loss operation

Enumerator
MIOPEN_CTC_LOSS_ALGO_DETERMINISTIC 

Results are guaranteed to be reproducible

Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenLossReductionMode_t

Reduction mode for loss function

Enumerator
MIOPEN_LOSS_REDUCTION_NONE 

output tensor elements are not reduced

MIOPEN_LOSS_REDUCTION_SUM 

output tensor elements are summed up

MIOPEN_LOSS_REDUCTION_MEAN 

output tensor elements are summed up and divided with total number of elements to get mean value

Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

Function Documentation

◆ MIOPEN_DECLARE_OBJECT()

MIOPEN_DECLARE_OBJECT ( miopenCTCLossDescriptor  )

Creates the miopenCTCLossDescriptor_t type.

◆ miopenCreateCTCLossDescriptor()

miopenStatus_t miopenCreateCTCLossDescriptor ( miopenCTCLossDescriptor_t *  ctcLossDesc)

Create a CTC loss function Descriptor.

API for creating an uninitialized CTC loss function descriptor.

Parameters
ctcLossDescPointer to the CTC loss function descriptor type (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenCTCLoss()

miopenStatus_t miopenCTCLoss ( miopenHandle_t  handle,
const miopenTensorDescriptor_t  probsDesc,
const void *  probs,
const int *  labels,
const int *  labelLengths,
const int *  inputLengths,
void *  losses,
const miopenTensorDescriptor_t  gradientsDesc,
void *  gradients,
miopenCTCLossAlgo_t  algo,
const miopenCTCLossDescriptor_t  ctcLossDesc,
void *  workSpace,
size_t  workSpaceSize 
)

Execute forward inference for CTCLoss layer.

Interface for executing the forward inference pass on a CTCLoss.

Parameters
handleMIOpen handle (input)
probsDescTensor descriptor for probabilities (input)
probsPointer to the probabilities tensor (input)
labelsPointer to the flattened labels list (input)
labelLengthsPointer to the lengths list for "labels" (input)
inputLengthsPointer to the list of the time steps in each batch (input)
lossesPointer to the computed losses of CTC (Output)
gradientsDescTensor descriptor for gradients (input)
gradientsPointer to the computed gradients of CTC (Output)
algoCTC loss algorithm selected (input)
ctcLossDescCTC loss function descriptor type (input)
workSpacePointer to memory allocated for execute CTC loss operation (input)
workSpaceSizeNumber of bytes of workspace required for CTC loss operation with selected algorithm (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenDestroyCTCLossDescriptor()

miopenStatus_t miopenDestroyCTCLossDescriptor ( miopenCTCLossDescriptor_t  ctcLossDesc)

Destroys a CTC loss function descriptor object.

Parameters
ctcLossDescCTC loss function descriptor type (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenGetCTCLossDescriptor()

miopenStatus_t miopenGetCTCLossDescriptor ( miopenCTCLossDescriptor_t  ctcLossDesc,
miopenDataType_t dataType,
int *  blank_label_id,
bool *  apply_softmax_layer 
)

Retrieves a CTC loss function descriptor's details.

Parameters
ctcLossDescCTC loss function descriptor (input)
dataTypeData type used in this CTC loss operation, only fp32 currently supported (output)
blank_label_idUser defined index for blank label (output)
apply_softmax_layerBoolean to toggle input layer property (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenGetCTCLossWorkspaceSize()

miopenStatus_t miopenGetCTCLossWorkspaceSize ( miopenHandle_t  handle,
const miopenTensorDescriptor_t  probsDesc,
const miopenTensorDescriptor_t  gradientsDesc,
const int *  labels,
const int *  labelLengths,
const int *  inputLengths,
miopenCTCLossAlgo_t  algo,
const miopenCTCLossDescriptor_t  ctcLossDesc,
size_t *  workSpaceSize 
)

Query the amount of memory required to execute miopenCTCLoss.

This function calculates the amount of memory required to run the CTC loss function given a CTC loss function descriptor with the specified algorithm.

Parameters
handleMIOpen handle (input)
probsDescTensor descriptor for probabilities (input)
gradientsDescTensor descriptor for gradients (input)
labelsPointer to the flattened labels list (input)
labelLengthsPointer to the lengths list for "labels" (input)
inputLengthsPointer to the list of the time steps in each batch (input)
algoCTC loss algorithm selected (input)
ctcLossDescCTC loss function descriptor type (input)
workSpaceSizeNumber of bytes of workspace required for CTC loss operation with selected algorithm (output)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenGetMultiMarginLossForwardWorkspaceSize()

miopenStatus_t miopenGetMultiMarginLossForwardWorkspaceSize ( miopenHandle_t  handle,
miopenTensorDescriptor_t  inputDesc,
miopenTensorDescriptor_t  targetDesc,
miopenTensorDescriptor_t  weightDesc,
miopenTensorDescriptor_t  outputDesc,
long  p,
float  margin,
miopenLossReductionMode_t  reduction,
size_t *  sizeInBytes 
)

Helper function to query the minimum workspace size required by the MultiMarginLossForward call.

Parameters
[in]handleMIOpen Handle
[in]inputDescTensor descriptor for input tensor (N, C) where N is the batch size and C is the number of classes
[in]targetDescTensor descriptor for target tensor, must have shape (N). Each value is between 0 and C - 1
[in]weightDescTensor descriptor for weight tensor. It is a manual rescaling weight given to each class. It has to be a Tensor of size C
[in]outputDescTensor descriptor for output tensor. If reduction is 'none, then it must have shape (N). Otherwise, it is a scalar
[in]pHas a default value of 1. The only supported values are 1 and 2
[in]marginHas a default value of 1
[in]reductionReduction mode (sum, mean)
[out]sizeInBytesPointer to data to return the minimum workspace size
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenGetSoftMarginLossForwardWorkspaceSize()

miopenStatus_t miopenGetSoftMarginLossForwardWorkspaceSize ( miopenHandle_t  handle,
miopenTensorDescriptor_t  inputDesc,
miopenTensorDescriptor_t  targetDesc,
miopenTensorDescriptor_t  outputDesc,
miopenLossReductionMode_t  reduction,
size_t *  sizeInBytes 
)

Helper function to query the minimum workspace size required by the SoftMarginLossForward call.

Parameters
[in]handleMIOpen Handle
[in]inputDescTensor descriptor for input tensor
[in]targetDescTensor descriptor for target tensor
[in]outputDescTensor descriptor for output tensor
[in]reductionReduction mode (sum, mean). For none reduction we don't need to use this function
[out]sizeInBytesPointer to data to return the minimum workspace size
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenMultiMarginLossForward()

miopenStatus_t miopenMultiMarginLossForward ( miopenHandle_t  handle,
miopenTensorDescriptor_t  inputDesc,
const void *  input,
miopenTensorDescriptor_t  targetDesc,
const void *  target,
miopenTensorDescriptor_t  weightDesc,
const void *  weight,
miopenTensorDescriptor_t  outputDesc,
void *  output,
long  p,
float  margin,
miopenLossReductionMode_t  reduction,
void *  workspace,
size_t  workspaceSizeInBytes 
)

Execute a MultiMarginLoss forward layer.

Parameters
[in]handleMIOpen handle
[in]inputDescTensor descriptor for input tensor (N, C) where N is the batch size and C is the number of classes.
[in]inputData tensor input
[in]targetDescTensor descriptor for target tensor, must have shape (N). Each value is between 0 and C - 1
[in]targetData tensor target
[in]weightDescTensor descriptor for weight tensor. It is a manual rescaling weight given to each class. It has to be a Tensor of size C
[in]weightData tensor weight
[in]outputDescTensor descriptor for output tensor. If reduction is 'none, then it must have shape (N). Otherwise, it is a scalar.
[out]outputData tensor output
[in]pHas a default value of 1. The only supported values are 1 and 2
[in]marginHas a default value of 1
[in]reductionReduction mode. If reduction mode is mean or sum, you must provide param workspace and workspaceSizeInBytes. Call miopenGetMultiMarginLossForwardWorkspaceSize to get workspaceSizeInBytes
[in]workspaceAddress of the allocated workspace data. Set = nullptr if reduction = 'none'
[in]workspaceSizeInBytesSize in bytes of the allocated workspace data. Set = 0 if reduction = 'none
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenSetCTCLossDescriptor()

miopenStatus_t miopenSetCTCLossDescriptor ( miopenCTCLossDescriptor_t  ctcLossDesc,
miopenDataType_t  dataType,
const int  blank_label_id,
bool  apply_softmax_layer 
)

Set the details of a CTC loss function descriptor.

Parameters
ctcLossDescCTC loss function descriptor type (input)
dataTypeData type used in this CTC loss operation, only fp32 currently supported (input)
blank_label_idUser defined index for blank label, default 0 (input)
apply_softmax_layerBoolean to toggle input layer property (input)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenSoftMarginLossBackward()

miopenStatus_t miopenSoftMarginLossBackward ( miopenHandle_t  handle,
miopenTensorDescriptor_t  inputDesc,
const void *  input,
miopenTensorDescriptor_t  targetDesc,
const void *  target,
miopenTensorDescriptor_t  doutputDesc,
const void *  doutput,
miopenTensorDescriptor_t  dinputDesc,
void *  dinput,
miopenLossReductionMode_t  reduction 
)

Execute a SoftMarginLoss backward layer.

Parameters
[in]handleMIOpen handle
[in]inputDescTensor descriptor for input tensor
[in]inputData tensor input
[in]targetDescTensor descriptor for target tensor
[in]targetData tensor target
[in]doutputDescTensor descriptor for output gradient
[in]doutputOutput gradient
[in]dinputDescTensor descriptor for input gradient
[out]dinputInput gradient
[in]reductionReduction mode (none, sum, mean)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.

◆ miopenSoftMarginLossForward()

miopenStatus_t miopenSoftMarginLossForward ( miopenHandle_t  handle,
miopenTensorDescriptor_t  inputDesc,
const void *  input,
miopenTensorDescriptor_t  targetDesc,
const void *  target,
miopenTensorDescriptor_t  outputDesc,
void *  output,
miopenLossReductionMode_t  reduction,
void *  workspace = nullptr,
size_t  workspaceSizeInBytes = 0 
)

Execute a SoftMarginLoss forward layer.

Parameters
[in]handleMIOpen handle
[in]inputDescTensor descriptor for input tensor
[in]inputData tensor input
[in]targetDescTensor descriptor for target tensor
[in]targetData tensor target
[in]outputDescTensor descriptor for output tensor
[out]outputData tensor output
[in]reductionReduction mode. If reduction mode is mean or sum, you must provide param workspace and workspaceSizeInBytes. Call miopenGetSoftMarginLossForwardWorkspaceSize to get workspaceSizeInBytes
[in]workspaceAddress of the allocated workspace data (Default = null)
[in]workspaceSizeInBytesSize in bytes of the allocated workspace data (Default = 0)
Returns
miopenStatus_t
Examples
/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-miopen/checkouts/docs-6.3.0/include/miopen/miopen.h.