1. Definitions¶
1.1. Main¶
This section describes the master topsflame aten header file.
1.2. Define¶
This section describes topsflame definitions.
-
enum topsatenDataType_t¶
topsatenDataType_t
Values:
-
enumerator TOPSATEN_DATA_NONE¶
TOPSATEN_DATA_NONE -1
-
enumerator TOPSATEN_DATA_I8¶
TOPSATEN_DATA_I8 0
-
enumerator TOPSATEN_DATA_U8¶
TOPSATEN_DATA_U8 1
-
enumerator TOPSATEN_DATA_I16¶
TOPSATEN_DATA_I16 2
-
enumerator TOPSATEN_DATA_U16¶
TOPSATEN_DATA_U16 3
-
enumerator TOPSATEN_DATA_FP16¶
TOPSATEN_DATA_FP16 4
-
enumerator TOPSATEN_DATA_BF16¶
TOPSATEN_DATA_BF16 5
-
enumerator TOPSATEN_DATA_I32¶
TOPSATEN_DATA_I32 6
-
enumerator TOPSATEN_DATA_U32¶
TOPSATEN_DATA_U32 7
-
enumerator TOPSATEN_DATA_FP32¶
TOPSATEN_DATA_FP32 8
-
enumerator TOPSATEN_DATA_EF32¶
TOPSATEN_DATA_EF32 9
-
enumerator TOPSATEN_DATA_TF32¶
TOPSATEN_DATA_TF32 10
-
enumerator TOPSATEN_DATA_I64¶
TOPSATEN_DATA_I64 11
-
enumerator TOPSATEN_DATA_U64¶
TOPSATEN_DATA_U64 12
-
enumerator TOPSATEN_DATA_F64¶
TOPSATEN_DATA_F64 13
-
enumerator TOPSATEN_DATA_PRED¶
TOPSATEN_DATA_PRED 14
-
enumerator TOPSATEN_DATA_I4¶
TOPSATEN_DATA_I4 15
-
enumerator TOPSATEN_DATA_NONE¶
-
enum topsatenStatus_t¶
topsatenStatus_t
Values:
-
enumerator TOPSATEN_STATUS_SUCCESS¶
TOPSATEN_STATUS_SUCCESS 0
-
enumerator TOPSATEN_STATUS_ALLOC_FAILED¶
TOPSATEN_STATUS_ALLOC_FAILED 1
-
enumerator TOPSATEN_STATUS_BAD_PARAM¶
TOPSATEN_STATUS_BAD_PARAM 2
-
enumerator TOPSATEN_STATUS_NOT_SUPPORT¶
TOPSATEN_STATUS_NOT_SUPPORT 3
-
enumerator TOPSATEN_STATUS_INTERNAL_ERROR¶
TOPSATEN_STATUS_INTERNAL_ERROR 4
-
enumerator TOPSATEN_STATUS_RUNTIME_ERROR¶
TOPSATEN_STATUS_RUNTIME_ERROR 5
-
enumerator TOPSATEN_STATUS_EXECUTE_ERROR¶
TOPSATEN_STATUS_EXECUTE_ERROR 6
-
enumerator TOPSATEN_STATUS_SUCCESS¶
-
enum topsatenMemoryFormat_t¶
topsatenMemoryFormat_t
Values:
-
enumerator TOPSATEN_MEMORY_NONE¶
topsatenMemoryFormat_t == null.
-
enumerator TOPSATEN_MEMORY_CONTIGUOUS¶
strides in decreasing order. s[0] > s[2] > s[3] > s[1] == 1 aka NHWC order.
-
enumerator TOPSATEN_MEMORY_NHWC¶
s[0] > s[2] > s[3] > s[4] > s[1] == 1 aka NDHWC order.
-
enumerator TOPSATEN_MEMORY_NDHWC¶
-
enumerator TOPSATEN_MEMORY_PRESERVE¶
preserve the format as input tensor
-
enumerator TOPSATEN_MEMORY_NONE¶
-
enum topsatenDevice_t¶
topsatenDevice_t
Values:
-
enumerator TOPSATEN_DEVICE_CPU¶
-
enumerator TOPSATEN_DEVICE_GCU¶
tensor on cpu
-
enumerator TOPSATEN_DEVICE_CPU¶
-
enum topsatenActivationMode_t¶
topsatenActivationMode_t
Values:
-
enumerator TOPSATEN_ACTIVATION_NONE¶
TOPSATEN_ACTIVATION_NONE 0
-
enumerator TOPSATEN_ACTIVATION_RELU¶
TOPSATEN_ACTIVATION_RELU 1
-
enumerator TOPSATEN_ACTIVATION_SIGMOID¶
TOPSATEN_ACTIVATION_SIGMOID 2
-
enumerator TOPSATEN_ACTIVATION_CLIPPED_RELU¶
TOPSATEN_ACTIVATION_CLIPPED_RELU 3
-
enumerator TOPSATEN_ACTIVATION_ELU¶
TOPSATEN_ACTIVATION_ELU 4
-
enumerator TOPSATEN_ACTIVATION_IDENTITY¶
TOPSATEN_ACTIVATION_IDENTITY 5
-
enumerator TOPSATEN_ACTIVATION_TANH¶
TOPSATEN_ACTIVATION_TANH 6
-
enumerator TOPSATEN_ACTIVATION_SWISH¶
TOPSATEN_ACTIVATION_SWISH 7
-
enumerator TOPSATEN_ACTIVATION_LEAKY_RELU¶
TOPSATEN_ACTIVATION_LEAKY_RELU 8
-
enumerator TOPSATEN_ACTIVATION_GELU¶
TOPSATEN_ACTIVATION_GELU 9
-
enumerator TOPSATEN_ACTIVATION_SWIGLU¶
TOPSATEN_ACTIVATION_SWIGLU 10
-
enumerator TOPSATEN_ACTIVATION_HARD_SWISH¶
TOPSATEN_ACTIVATION_HARD_SWISH 11
-
enumerator TOPSATEN_ACTIVATION_NONE¶
-
enum topsatenTopkCmpMode_t¶
topsatenTopkCmpMode_t
Values:
-
enumerator TOPSATEN_TOPK_TYPE_INVALID¶
TOPSATEN_TOPK_TYPE_INVALID 0
-
enumerator TOPSATEN_TOPK_TYPE_MAX¶
TOPSATEN_TOPK_TYPE_MAX 1
-
enumerator TOPSATEN_TOPK_TYPE_MIN¶
TOPSATEN_TOPK_TYPE_MIN 2
-
enumerator TOPSATEN_TOPK_TYPE_INVALID¶
-
enum topsatenSortCmpMode_t¶
topsatenSortCmpMode_t
Values:
-
enumerator TOPSATEN_SORT_TYPE_INVALID¶
TOPSATEN_SORT_TYPE_INVALID 0
-
enumerator TOPSATEN_SORT_TYPE_ASCEND¶
TOPSATEN_SORT_TYPE_ASCEND 1
-
enumerator TOPSATEN_SORT_TYPE_DESCEND¶
TOPSATEN_SORT_TYPE_DESCEND 2
-
enumerator TOPSATEN_SORT_TYPE_INVALID¶
-
enum topsatenSortStableMode_t¶
topsatenSortStableMode_t
Values:
-
enumerator TOPSATEN_SORT_STABLE_INVALID¶
TOPSATEN_SORT_STABLE_INVALID 0
-
enumerator TOPSATEN_SORT_STABLE¶
TOPSATEN_SORT_STABLE 1
-
enumerator TOPSATEN_SORT_INSTABLE¶
TOPSATEN_SORT_INSTABLE 2
-
enumerator TOPSATEN_SORT_STABLE_INVALID¶
-
enum topsatenBatchNormMode_t¶
Values:
-
enumerator TOPSATEN_BATCHNORM_PER_ACTIVATION¶
-
enumerator TOPSATEN_BATCHNORM_SPATIAL¶
-
enumerator TOPSATEN_BATCHNORM_SPATIAL_PERSISTENT¶
-
enumerator TOPSATEN_BATCHNORM_PER_ACTIVATION¶
-
enum topsatenScatterType_t¶
topsatenScatterType_t
Values:
-
enumerator TOPSATEN_SCATTER_ADD¶
TOPSATEN_SCATTER_ADD 0
-
enumerator TOPSATEN_SCATTER_SUB¶
TOPSATEN_SCATTER_SUB 1
-
enumerator TOPSATEN_SCATTER_MUL¶
TOPSATEN_SCATTER_MUL 2
-
enumerator TOPSATEN_SCATTER_MAX¶
TOPSATEN_SCATTER_MAX 3
-
enumerator TOPSATEN_SCATTER_MIN¶
TOPSATEN_SCATTER_MIN 4
-
enumerator TOPSATEN_SCATTER_ADD¶
-
enum topsatenScatterComputationType_t¶
topsatenScatterComputationType_t
Values:
-
enumerator TOPSATEN_SCATTER_COMP_UPDATE¶
TOPSATEN_SCATTER_COMP_UPDATE 0
-
enumerator TOPSATEN_SCATTER_COMP_ADD¶
TOPSATEN_SCATTER_COMP_ADD 1
-
enumerator TOPSATEN_SCATTER_COMP_SUB¶
TOPSATEN_SCATTER_COMP_SUB 2
-
enumerator TOPSATEN_SCATTER_COMP_NUM¶
TOPSATEN_SCATTER_COMP_NUM 3
-
enumerator TOPSATEN_SCATTER_COMP_UPDATE¶
-
enum topsatenConvolutionFwdAlgo_t¶
Values:
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_AUTO¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_IMPLICIT_GEMM¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_IMPLICIT_PRECOMP_GEMM¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_GEMM¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_DIRECT¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_FFT¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_FFT_TILING¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_WINOGRAD¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_WINOGRAD_NONFUSED¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_COUNT¶
-
enumerator TOPSATEN_CONVOLUTION_FWD_ALGO_AUTO¶
-
enum topsatenConvolutionBwdFilterAlgo_t¶
Values:
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_0¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_1¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_FFT¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_3¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_WINOGRAD¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_WINOGRAD_NONFUSED¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_FFT_TILING¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_COUNT¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_FILTER_ALGO_0¶
-
enum topsatenRoiAlignOpType_t¶
topsatenRoiAlignOpType_t
Values:
-
enumerator TOPSATEN_ROIALIGN_AVG_FP32¶
-
enumerator TOPSATEN_ROIALIGN_AVG_FP16¶
-
enumerator TOPSATEN_ROIALIGN_MAX_FP32¶
-
enumerator TOPSATEN_ROIALIGN_MAX_FP16¶
-
enumerator TOPSATEN_ROIALIGN_AVG_FP32¶
-
enum topsatenConvolutionBwdDataAlgo_t¶
Values:
-
enumerator TOPSATEN_CONVOLUTION_BWD_DATA_ALGO_0¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_DATA_ALGO_1¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_DATA_ALGO_FFT¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_DATA_ALGO_FFT_TILING¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_DATA_ALGO_WINOGRAD¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_DATA_ALGO_WINOGRAD_NONFUSED¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_DATA_ALGO_COUNT¶
-
enumerator TOPSATEN_CONVOLUTION_BWD_DATA_ALGO_0¶
-
enum topsatenRoiAlignMode_t¶
topsatenRoiAlignMode_t
Values:
-
enumerator TOPSATEN_ROIALIGN_AVG¶
-
enumerator TOPSATEN_ROIALIGN_MAX¶
-
enumerator TOPSATEN_ROIALIGN_AVG¶
-
enum topsatenPadMode_t¶
topsatenPadMode_t
Values:
-
enumerator TOPSATEN_PAD_CONSTANT¶
-
enumerator TOPSATEN_PAD_REFLECT¶
-
enumerator TOPSATEN_PAD_EDGE¶
-
enumerator TOPSATEN_PAD_REPLICATE¶
-
enumerator TOPSATEN_PAD_CIRCULAR¶
-
enumerator TOPSATEN_PAD_MAXIMUM¶
-
enumerator TOPSATEN_PAD_LINEAR_RAMP¶
-
enumerator TOPSATEN_PAD_MEAN¶
-
enumerator TOPSATEN_PAD_MEDIAN¶
-
enumerator TOPSATEN_PAD_MINIMUM¶
-
enumerator TOPSATEN_PAD_SYMMETRIC¶
-
enumerator TOPSATEN_PAD_WRAP¶
-
enumerator TOPSATEN_PAD_EMPTY¶
-
enumerator TOPSATEN_PAD_CONSTANT¶
-
enum topsatenRoiAlignCoordinateTransformationMode_t¶
topsatenRoiAlignCoordinateTransformationMode_t
Values:
-
enumerator TOPSATEN_ROIALIGN_HALF_PIXL_TRUE¶
-
enumerator TOPSATEN_ROIALIGN_HALF_PIXL_FALSE¶
-
enumerator TOPSATEN_ROIALIGN_HALF_PIXL_TRUE¶
-
enum topsatenColorConversionCodes_t¶
topsatenColorConversionCodes_t
Values:
-
enumerator TOPSATEN_COLORCVT_YUV2RGB¶
YUV444packed to RGB888packed
-
enumerator TOPSATEN_COLORCVT_YUV2BGR¶
YUV444packed to BGR888packed
-
enumerator TOPSATEN_COLORCVT_RGB2GRAY¶
RGB888packed to GRAY
-
enumerator TOPSATEN_COLORCVT_BGR2GRAY¶
BGR888packed to GRAY
-
enumerator TOPSATEN_COLORCVT_YUV2RGB¶
-
enum topsatenBlasOperation_t¶
Values:
-
enumerator TOPSATEN_BLAS_OP_N¶
-
enumerator TOPSATEN_BLAS_OP_T¶
-
enumerator TOPSATEN_BLAS_OP_C¶
-
enumerator TOPSATEN_BLAS_OP_HERMITAN¶
-
enumerator TOPSATEN_BLAS_OP_CONJG¶
-
enumerator TOPSATEN_BLAS_OP_N¶
-
enum topsatenLayoutType_t¶
topsatenLayoutType_t
Values:
-
enumerator TOPSATEN_LAYOUT_STRIDED¶
TOPSATEN_LAYOUT_STRIDED 0
-
enumerator TOPSATEN_LAYOUT_SPARSE¶
TOPSATEN_LAYOUT_SPARSE 1
-
enumerator TOPSATEN_LAYOUT_STRIDED¶
-
enum topsatenAlgorithm_t¶
Values:
-
enumerator TOPSATEN_DEFAULT_ALGO¶
-
enumerator TOPSATEN_PHILOX4_32_ALGO¶
-
enumerator TOPSATEN_DEFAULT_ALGO¶
-
typedef void *topsatenDeviceMemHandle_t¶
The type of device memory handle.
- topsatenStatus_t TOPSATEN_EXPORT topsatenInit ()
get the version of the Device-Independent Operator Inetrface
This function initialize the topsOP library, this function must be called prior to making any other topsOP calls.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenFinalize ()
This function finalize the topOP library, this function is usually the last call made to topsOP.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGetVersionInfo (char *version_info)
This function get the verison info of the aten lib.
- Returns
- TOPSATEN_EXPORT std::ostream & operator<< (std::ostream &os, const topsatenTensor &tensor)
- TOPSATEN_EXPORT std::ostream & operator<< (std::ostream &os, const topsatenDataType_t &dtype)
- TOPSATEN_EXPORT std::ostream & operator<< (std::ostream &os, const topsatenStatus_t &status)
- TOPSATEN_EXPORT std::ostream & operator<< (std::ostream &os, const topsatenSize_t &size)
- TOPSATEN_EXPORT std::ostream & operator<< (std::ostream &os, const topsatenScalar_t &scalar)
- TOPSATEN_EXPORT std::ostream & operator<< (std::ostream &os, const topsatenGenerator_t &generator)
-
TOPSATEN_EXPORT¶
-
TOPSATEN_VERSION_INFO_LEN¶
-
struct topsatenSize_t¶
- #include <topsaten_define.h>
A struct to descript a data pointer and its length
-
struct topsatenScalar_t¶
- #include <topsaten_define.h>
A struct to descript a scalar
-
struct topsatenGenerator_t¶
- #include <topsaten_define.h>
A struct to descript a random number generator
-
class topsatenTensor¶
- #include <topsaten_define.h>
2. TopsAten API Function¶
2.1. Aten ops¶
This section describes topsflame common aten ops api definitions.
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexSelect (topsatenTensor &out, const topsatenTensor &in, int64_t dim, const topsatenTensor &index, topsStream_t stream=nullptr)
index_select operator
- Parameters
out – The output tensor
in – Input tensor
dim – the dimension in which to index
index – the 1-D tensor containing the indices to index
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinspace (topsatenTensor &output, const topsatenScalar_t &start, const topsatenScalar_t &end, const int64_t step, topsStream_t stream=nullptr)
This function performs the Linspace function.
- Parameters
output – The output tensor.
start – The topsatenScalar_t of start.
end – The topsatenScalar_t of end.
step – The step for linspace.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAdd (topsatenTensor &out, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
add operator
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs tensor
alpha – The multiplier for lhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAdd (topsatenTensor &out, const topsatenScalar_t &lhs, const topsatenTensor &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
add operator
- Parameters
out – The output tensor
lhs – Input lhs scalar
rhs – Input rhs tensor
alpha – The multiplier for lhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAdd (topsatenTensor &out, const topsatenTensor &lhs, const topsatenScalar_t &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
add operator
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs scalar
alpha – The multiplier for lhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAll (topsatenTensor &output, const topsatenTensor &input, int64_t dim, bool keepdim, topsStream_t stream=nullptr)
This function returns True if all element in the row evaluate to True and False otherwise, for each row of input in the given dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dim – The dimension to reduce.
keepdim – Whether the output tensor has dim retained or not.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAll (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dim, bool keepdim, topsStream_t stream=nullptr)
This function returns True if all element in the rows evaluate to True and False otherwise, for rows of input in the given dimensions.
- Parameters
output – The output tensor.
input – The input tensor.
dim – The dimensions to reduce.
keepdim – Whether the output tensor has dim retained or not.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAll (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns True if all element in the input evaluate to True and False otherwise.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAny (topsatenTensor &output, const topsatenTensor &input, int64_t dim, bool keepdim, topsStream_t stream=nullptr)
This function returns True if any element in the row evaluate to True and False otherwise, for each row of input in the given dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dim – The dimension to reduce.
keepdim – Whether the output tensor has dim retained or not.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAny (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dim, bool keepdim, topsStream_t stream=nullptr)
This function returns True if any element in the rows evaluate to True and False otherwise, for rows of input in the given dimensions.
- Parameters
output – The output tensor.
input – The input tensor.
dim – The dimensions to reduce.
keepdim – Whether the output tensor has dim retained or not.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAny (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns True if any element in the input evaluate to True and False otherwise.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenOnes (topsatenTensor &output, const topsatenSize_t &size, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
Returns a tensor filled with the scalar value one.
- Parameters
output – Result tensor
size – output shape.
data_type – output data type.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenClamp (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &min, const topsatenScalar_t &max, topsStream_t stream=nullptr)
Returns the tensor after performing a lower and a higher bound truncation operation on the input tensor.
- Parameters
output – The output tensor.
input – Input tensor to perform lower bound truncation operation.
min – Replace elements less than the specified lower limit tensor with elements corresponding to the lower limit tensor.
max – Replace elements less than the specified higher limit tensor with elements corresponding to the higher limit tensor.
stream – Tops stream.
- Returns
topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenClamp (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &min, const topsatenTensor &max, topsStream_t stream=nullptr)
Returns the tensor after performing a lower and a higher bound truncation operation on the input tensor.
- Parameters
output – The output tensor.
input – Input tensor to perform lower bound truncation operation.
min – Input tensor, the lower boundary.
max – Input tensor, the higher boundary.
stream – Tops stream.
- Returns
topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenZeros (topsatenTensor &output, const topsatenSize_t &size, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
Returns a tensor filled with the scalar value zero.
- Parameters
output – Result tensor
size – output shape.
data_type – output data type.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenZerosLike (topsatenTensor &out, const topsatenTensor &input, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, const topsatenMemoryFormat_t &format, topsStream_t stream=nullptr)
Returns a zero tensor with the same size as input.
- Parameters
out – The output tensor
input – The tensor size will define the size of the output tensor
dtype – The data type of the output tensor
format – The memory format of the output tensor
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenProd (topsatenTensor &output, const topsatenTensor &input, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
This function returns the product of elements of all the input.
- Parameters
output – The output tensor.
input – The input tensor.
data_type – the data type of the input and output tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenProd (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dims_in, bool keepdims, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
This function returns the product of elements of input in the dimension dims.
- Parameters
output – The output tensor.
input – The input tensor.
dims_in – The dims_in to reduce, maybe a list or tuple.
keepdims – Whether the output tensor has dim retained or no.
data_type – the data type of the input and output tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenProd (topsatenTensor &output, const topsatenTensor &input, int32_t dim, bool keepdims, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
This function returns the product of elements of input in the dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dim – The dim to reduce.
keepdims – Whether the output tensor has dim retained or no.
data_type – the data type of the input and output tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMin (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns the minimum value of all the input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMin (topsatenTensor &output, const topsatenTensor &input, int32_t dim, bool keepdims, topsStream_t stream=nullptr)
This function returns the minimum value of input in the dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dim – The dim to reduce.
keepdims – Whether the output tensor has dim retained or no.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMin (topsatenTensor &output, const topsatenTensor &input1, const topsatenTensor &input2, topsStream_t stream=nullptr)
This function returns the minimum value of input1 and input2.
- Parameters
output – The output tensor.
input1 – The input tensor.
input2 – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMin (topsatenTensor &output, const topsatenTensor &input1, const topsatenScalar_t &input2, topsStream_t stream=nullptr)
This function returns the minimum value of input1 and input2.
- Parameters
output – The output tensor.
input1 – The input tensor.
input2 – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMin (topsatenTensor &output, const topsatenScalar_t &input1, const topsatenTensor &input2, topsStream_t stream=nullptr)
This function returns the minimum value of input1 and input2.
- Parameters
output – The output tensor.
input1 – The input scalar.
input2 – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMin (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dims_in, bool keepdims, topsStream_t stream=nullptr)
This function returns the minimum value of input in the dimension dims.
- Parameters
output – The output tensor.
input – The input tensor.
dims_in – The dims_in to reduce.
keepdims – Whether the output tensor has dim retained or no.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMin (topsatenTensor &output, topsatenTensor &output_idx, const topsatenTensor &input, int32_t dim, bool keepdims, topsStream_t stream=nullptr)
This function returns the minimum value of input in the dimension dim.
- Parameters
output – The output tensor.
output_idx – The output tensor, index of the minimum value.
input – The input tensor.
dim – The dim to reduce.
keepdims – Whether the output tensor has dim retained or no.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMin (topsatenTensor &output, topsatenTensor &output_idx, const topsatenTensor &input, const topsatenSize_t &dims_in, bool keepdims, topsStream_t stream=nullptr)
This function returns the minimum value of input in the dimension dim.
- Parameters
output – The output tensor.
output_idx – The output tensor, index of the minimum value.
input – The input tensor.
dims_in – The dims to reduce.
keepdims – Whether the output tensor has dim retained or no.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMax (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns the maximum value of all the input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMax (topsatenTensor &output, const topsatenTensor &input, int32_t dim, bool keepdims, topsStream_t stream=nullptr)
This function returns the maximum value of input in the dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dim – The dim to reduce.
keepdims – Whether the output tensor has dim retained or no.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMax (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dims_in, bool keepdims, topsStream_t stream=nullptr)
This function returns the maximum value of input in the dimension dims.
- Parameters
output – The output tensor.
input – The input tensor.
dims_in – The dims_in to reduce.
keepdims – Whether the output tensor has dim retained or no.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMax (topsatenTensor &output, const topsatenTensor &input1, const topsatenTensor &input2, topsStream_t stream=nullptr)
This function returns the maximum value of input1 and input2.
- Parameters
output – The output tensor.
input1 – The input tensor.
input2 – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMax (topsatenTensor &output, const topsatenTensor &input1, const topsatenScalar_t &input2, topsStream_t stream=nullptr)
This function returns the maximum value of input1 and input2.
- Parameters
output – The output tensor.
input1 – The input tensor.
input2 – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMax (topsatenTensor &output, const topsatenScalar_t &input1, const topsatenTensor &input2, topsStream_t stream=nullptr)
This function returns the maximum value of input1 and input2.
- Parameters
output – The output tensor.
input1 – The input scalar.
input2 – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMax (topsatenTensor &output, topsatenTensor &output_idx, const topsatenTensor &input, int32_t dim, bool keepdims, topsStream_t stream=nullptr)
This function returns the maximum value of input in the dimension dim.
- Parameters
output – The output tensor.
output_idx – The output tensor, index of the maximum value.
input – The input tensor.
dim – The dim to reduce.
keepdims – Whether the output tensor has dim retained or no.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMax (topsatenTensor &output, topsatenTensor &output_idx, const topsatenTensor &input, const topsatenSize_t &dims_in, bool keepdims, topsStream_t stream=nullptr)
This function returns the maximum value of input in the dimension dim.
- Parameters
output – The output tensor.
output_idx – The output tensor, index of the maximum value.
input – The input tensor.
dims_in – The dims to reduce.
keepdims – Whether the output tensor has dim retained or no.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMean (topsatenTensor &output, const topsatenTensor &input, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
This function returns the mean value of all the input.
- Parameters
output – The output tensor.
input – The input tensor.
data_type – the data type of the input and output tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMean (topsatenTensor &output, const topsatenTensor &input, int32_t dim, bool keepdims, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
This function returns the mean value of input in the dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dim – The dim to reduce.
keepdims – Whether the output tensor has dim retained or no.
data_type – the data type of the input and output tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMean (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dims_in, bool keepdims, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
This function returns the mean value of input in the dimension dims.
- Parameters
output – The output tensor.
input – The input tensor.
dims_in – The dims to reduce.
keepdims – Whether the output tensor has dim retained or no.
data_type – the data type of the input and output tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinear (topsatenTensor &out, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenTensor &bias, topsStream_t stream=nullptr)
linear operator
- Parameters
out – the output tensor
lhs – the input tensor of lhs
rhs – the input tensor of rhs
bias – the input tensor of bias
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinearQuant (topsatenTensor &out, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenTensor &bias, const topsatenTensor &scale, topsStream_t stream=nullptr)
linearquant operator
- Parameters
out – the output tensor
lhs – the input tensor of lhs
rhs – the input tensor of rhs
bias – the input tensor of bias
scale – the input tensor of scale
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCopy (topsatenTensor &out, const topsatenTensor &input, bool non_blocking, topsStream_t stream=nullptr)
This function performs the copy function.
- Parameters
out – The output tensor.
input – The source tensor.
non_blocking – If true and this copy is between CPU and GCU
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenToCopy (topsatenTensor &out, const topsatenTensor &input, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, const topsatenDevice_t &device, const topsatenMemoryFormat_t &format, bool non_blocking, topsStream_t stream=nullptr)
This function performs the to_copy function.
- Parameters
out – The output tensor.
input – The source tensor.
dtype – The data type of the output tensor
layout – The layout type of the output tensor
device – The device of the output tensor allocated
format – The memory format of the output tensor
non_blocking – If true and this copy is between CPU and GCU
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenClone (topsatenTensor &out, const topsatenTensor &input, const topsatenMemoryFormat_t &format, topsStream_t stream=nullptr)
This function performs the clone function.
- Parameters
out – The output tensor.
input – The input tensor.
format – The format of the out tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenEmpty (topsatenTensor &out, const topsatenSize_t &size, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, const topsatenMemoryFormat_t &format, topsStream_t stream=nullptr)
Returns a tensor filled with uninitialized data. The shape of the tensor is defined by argument ‘size’.
- Parameters
out – The output tensor
size – The shape of the output tensor
dtype – The data type of the output tensor
layout – The logical layout of the output tensor
format – The memory format of the output tensor
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenEmptyLike (topsatenTensor &out, const topsatenTensor &input, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, const topsatenMemoryFormat_t &format, topsStream_t stream=nullptr)
Returns an uninitialized tensor with the same size as input.
- Parameters
out – The output tensor
input – The tensor size will define the size of the output tensor
dtype – The data type of the output tensor
layout – The logical layout of the output tensor
format – The memory format of the output tensor
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenEmptyStrided (topsatenTensor &out, const topsatenSize_t &size, const topsatenSize_t &stride, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, topsStream_t stream=nullptr)
Creates a tensor with the specified size and stride and filled with undefined data.
- Parameters
out – The output tensor
size – The shape of the output tensor
stride – The strides of the output tensor
dtype – The data type of the output tensor
layout – The logical layout of the output tensor
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenEmptyPermuted (topsatenTensor &out, const topsatenSize_t &size, const topsatenSize_t &physical_layout, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, topsStream_t stream=nullptr)
Returns a tensor filled with uninitialized data. The shape of the tensor is defined by argument ‘size’. The stride of the tensor is defined by argument ‘physical_layout’.
- Parameters
out – The output tensor
size – The shape of the output tensor
physical_layout – The physical layout of the output memory
dtype – The data type of the output tensor
layout – The logical layout of the output tensor
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenAsStrided (topsatenTensor &out, const topsatenTensor &input, const topsatenSize_t &size, const topsatenSize_t &stride, const int64_t storage_offset, topsStream_t stream=nullptr)
Create a view of an existing tensor.
- Parameters
out – The output tensor.
input – The input tensor.
size – The shape of the output tensor.
stride – The stride of the output tensor.
storage_offset – The offset in the underlying storage of the output tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenExpand (topsatenTensor &out, const topsatenTensor &input, const topsatenSize_t &size, topsStream_t stream=nullptr)
Return a new view of the input tensor with singleton dimensions expanded to a larger size.
- Parameters
out – The output tensor.
input – The input tensor.
size – The shape of the output tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandperm (topsatenTensor &output, const int64_t n, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
Returns a random permutation of integers from 0 to n - 1.
- Parameters
output – Output tensor
n – the upper bound
dtype – the desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandperm (topsatenTensor &output, const int64_t n, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
Returns a random permutation of integers from 0 to n - 1.
- Parameters
output – Output tensor
n – the upper bound
dtype – the desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandom (topsatenTensor &output, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
Fills self tensor with numbers sampled from the discrete uniform distribution only bounded by self data type.
- Parameters
output – Output tensor
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandom (topsatenTensor &output, const int64_t to, const topsatenGenerator_t &generator, topsStream_t stream)
Fills self tensor with numbers sampled from the discrete uniform distribution over [0, to].
- Parameters
output – Output tensor
to – the upper bound
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandom (topsatenTensor &output, const int64_t from, const int64_t *to, const topsatenGenerator_t &generator, topsStream_t stream)
Fills self tensor with numbers sampled from the discrete uniform distribution over [from, to].
- Parameters
output – Output tensor
from – the lower bound
to – the upper bound
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBaddbmm (topsatenTensor &out, const topsatenTensor &self, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenScalar_t &beta={TOPSATEN_DATA_FP32, {1.0}}, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {1.0}}, topsStream_t stream=nullptr)
baddbmm operator
- Parameters
out – the output tensor
self – the input tensor of self
lhs – the input tensor of lhs
rhs – the input tensor of rhs
beta – scaling factor
alpha – scaling factor used to blend the computation result
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIsSameSize (bool &flag, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
Determine if two tensor sizes are the same.
- Parameters
flag – the output flag
lhs – the input tensor of lhs
rhs – the input tensor of rhs
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandint (topsatenTensor &output, int64_t high, const topsatenSize_t &size, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
Returns a tensor filled with random integers generated uniformly between [0, high].
- Parameters
output – Output tensor
high – the upper bound
size – the shape of the output tensor
dtype – the desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandint (topsatenTensor &output, int64_t high, const topsatenSize_t &size, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
Returns a tensor filled with random integers generated uniformly between [0, high].
- Parameters
output – Output tensor
high – the upper bound
size – the shape of the output tensor
dtype – the desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandint (topsatenTensor &output, int64_t low, int64_t high, const topsatenSize_t &size, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
Returns a tensor filled with random integers generated uniformly between [low, high].
- Parameters
output – Output tensor
low – the lower bound
high – the upper bound
size – the shape of the output tensor
dtype – the desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandint (topsatenTensor &output, int64_t low, int64_t high, const topsatenSize_t &size, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
Returns a tensor filled with random integers generated uniformly between [low, high].
- Parameters
output – Output tensor
low – the lower bound
high – the upper bound
size – the shape of the output tensor
dtype – the desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNewEmpty (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &size, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
Returns a tensor filled with uninitialized data. The shape of the tensor is defined by argument ‘size’.
- Parameters
output – The output tensor
input – The input tensor
size – The shape of the output tensor
dtype – The data type of the output tensor
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenSoftmaxForward (topsatenTensor &output, const topsatenTensor &input, const int64_t dims, topsStream_t stream=nullptr)
This function performs the forward softmax.
- Parameters
output – The output tensor.
input – The input tensor.
dims – The dims of output tensor.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSoftmaxForward (topsatenTensor &output, const topsatenTensor &input, const int64_t dims, const bool half_to_float, topsStream_t stream=nullptr)
This function performs the forward softmax.
- Parameters
output – The output tensor.
input – The input tensor.
dims – The dims of output tensor.
half_to_float – Only when a is true, it is legal for the input to be half and the output to be float
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLogSoftmaxForward (topsatenTensor &output, const topsatenTensor &input, const int64_t dims, topsStream_t stream=nullptr)
This function performs the log_softmax.
- Parameters
output – The output tensor.
input – The input tensor.
dims – The dims of output tensor.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLogSoftmaxForward (topsatenTensor &output, const topsatenTensor &input, const int64_t dims, const bool half_to_float, topsStream_t stream=nullptr)
This function performs the log_softmax.
- Parameters
output – The output tensor.
input – The input tensor.
dims – The dims of output tensor.
half_to_float – Only when a is true, it is legal for the input to be half and the output to be float
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCat (topsatenTensor &output, const std::vector< topsatenTensor > &inputs, int64_t dim, topsStream_t stream=nullptr)
concatenate operator
- Parameters
output – The output tensor
inputs – The input tensor
dim – concatenate dim
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenStack (topsatenTensor &output, const std::vector< topsatenTensor > &inputs, int64_t dim, topsStream_t stream=nullptr)
stack operator
- Parameters
output – The output tensor
inputs – The input tensor
dim – concatenate dim
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNewEmptyStrided (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &size, const topsatenSize_t &stride, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
Creates a tensor with the specified size and stride and filled with undefined data.
- Parameters
output – The output tensor
input – The input tensor
size – The shape of the output tensor
stride – The strides of the output tensor
dtype – The data type of the output tensor
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenContiguous (topsatenTensor &output, const topsatenTensor &input, const topsatenMemoryFormat_t &format, topsStream_t stream=nullptr)
contiguous operator
- Parameters
output – The output tensor
input – The input tensor
format – memory format, specifying storage type
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRepeat (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &repeats, topsStream_t stream=nullptr)
Repeats this tensor along the specified dimensions.
- Parameters
output – The output tensor.
input – The input tensor.
repeats – The number of times to repeat this tensor along each dimension.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRepeatInterleave (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &repeats, int64_t dim, int64_t output_size, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenRepeatInterleave (topsatenTensor &output, const topsatenTensor &input, int64_t repeats, int64_t dim, int64_t output_size, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenRepeatInterleave (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &repeats, int64_t output_size, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenRepeatInterleave (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &repeats, const topsatenScalar_t &dim, const topsatenScalar_t &output_size, topsStream_t stream=nullptr)
Repeat elements of a tensor.
- Parameters
output – The output tensor.
input – The input tensor.
repeats – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
dim – The dimension along which to repeat values. By default, use the flattened input array, and return a flat output array
output_size – output size
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRepeatInterleave (topsatenTensor &output, const topsatenTensor &input, const int64_t &repeats, const topsatenScalar_t &dim, const topsatenScalar_t &output_size, topsStream_t stream=nullptr)
Repeat elements of a tensor.
- Parameters
output – The output tensor.
input – The input tensor.
repeats – The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
dim – The dimension along which to repeat values. By default, use the flattened input array, and return a flat output array
output_size – output size
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenTanh (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the hyperbolic tangent of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSilu (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function applies the Sigmoid Linear Unit (SiLU) function, element-wise.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRsqrt (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the reciprocal of the square-root of each of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenResolveNeg (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with materialized negation if input’s negative bit is set to True, else returns input. The output tensor will always have its negative bit set to False.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenResolveConj (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with materialized conjugation if input’s conjugate bit is set to True, else returns input. The output tensor will always have its conjugate bit set to False.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenPow (topsatenTensor &output, const topsatenScalar_t &input, const topsatenTensor &exponent, topsStream_t stream=nullptr)
This function takes the power of each element in input with exponent and returns a tensor with the result.
- Parameters
output – The output tensor.
input – The input scalar.
exponent – the exponent tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenPow (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &exponent, topsStream_t stream=nullptr)
This function takes the power of each element in input with exponent and returns a tensor with the result.
- Parameters
output – The output tensor.
input – The input tensor.
exponent – the exponent scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenPow (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &exponent, topsStream_t stream=nullptr)
This function takes the power of each element in input with exponent and returns a tensor with the result.
- Parameters
output – The output tensor.
input – The input tensor.
exponent – the exponent tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNeg (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the negative of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenExponential (topsatenTensor &output, double lambd, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function fills input tensor with elements drawn from the exponential distribution:
- Parameters
output – The output tensor.
lambd – The lambda parameter in exponential distributions.
generator – Creates and returns a generator object that manages the state of an algorithm that generates pseudo-random numbers.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSub (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
This function subtracts rhs, scaled by alpha, from lhs. output = lhs - rhs * alpha.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The tensor to subtract from lhs.
alpha – The multiplier for rhs.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSub (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
This function subtracts rhs, scaled by alpha, from lhs. output = lhs - rhs * alpha.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The number to subtract from lhs.
alpha – The multiplier for rhs.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSub (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
This function subtracts rhs, scaled by alpha, from lhs. output = lhs - rhs * alpha.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The tensor to subtract from lhs.
alpha – The multiplier for rhs.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRsub (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
This function subtracts lhs, scaled by alpha, from rhs. output = rhs - lhs * alpha.
- Parameters
output – The output tensor.
lhs – The scalar to subtract from rhs.
rhs – The input tensor.
alpha – The multiplier for lhs.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRsub (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
This function subtracts lhs, scaled by alpha, from rhs. output = rhs - lhs * alpha.
- Parameters
output – The output tensor.
lhs – The number to subtract from rhs.
rhs – The input tensor.
alpha – The multiplier for lhs.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRsub (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenScalar_t &alpha, topsStream_t stream=nullptr)
This function subtracts lhs, scaled by alpha, from rhs. output = rhs - lhs * alpha.
- Parameters
output – The output tensor.
lhs – The tensor to subtract from rhs.
rhs – The input tensor.
alpha – The multiplier for lhs.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNe (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is not equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNe (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is not equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNe (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is not equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachMul (std::vector< topsatenTensor > &output, const std::vector< topsatenTensor > &self, const topsatenScalar_t &scalar, topsStream_t stream=nullptr)
This function multiplies lhs by rhs.
- Parameters
output – The output tensor list.
lhs – The input tensor list.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachMul (std::vector< topsatenTensor > &output, const std::vector< topsatenTensor > &self, const std::vector< topsatenScalar_t > &scalars, topsStream_t stream=nullptr)
This function multiplies lhs by rhs.
- Parameters
output – The output tensor list.
lhs – The input tensor list.
rhs – The input scalar list.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachMul (std::vector< topsatenTensor > &output, const std::vector< topsatenTensor > &self, const topsatenTensor &other, topsStream_t stream=nullptr)
This function multiplies lhs by rhs.
- Parameters
output – The output tensor list.
lhs – The input tensor list.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachMul (std::vector< topsatenTensor > &output, const std::vector< topsatenTensor > &self, const std::vector< topsatenTensor > &other, topsStream_t stream=nullptr)
This function multiplies lhs by rhs.
- Parameters
output – The output tensor list.
lhs – The input tensor list.
rhs – The input tensor list.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMul (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function multiplies lhs by rhs.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMul (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function multiplies lhs by rhs.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMul (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function multiplies lhs by rhs.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLt (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is less than rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLt (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is less than rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLt (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is less than rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGt (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is greater than rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGt (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is greater than rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGt (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is greater than rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGe (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is greater than or equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGe (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is greater than or equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGe (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is greater than or equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLe (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is smaller than or equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLe (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is smaller than or equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLe (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is smaller than or equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenOr (topsatenTensor &output, const topsatenTensor &rhs, const topsatenScalar_t &lhs, topsStream_t stream=nullptr)
This function computes the bitwise or of lhs and rhs. The lhs tensor must be of integral or Boolean types. For bool tensors, it computes the logical or.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenOr (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function computes the bitwise or of lhs and rhs. The lhs tensor must be of integral or Boolean types. For bool tensors, it computes the logical or.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenEq (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenEq (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenEq (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function returns a boolean tensor that is True where lhs is equal to rhs and False elsewhere.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiv (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function divides each element of the input lhs by the corresponding element of rhs.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiv (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, const char *const roundingMode, topsStream_t stream=nullptr)
This function divides each element of the input lhs by the corresponding element of rhs.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
roundingMode – Type of rounding applied to the result.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiv (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function divides each element of the input lhs by the corresponding element of rhs.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiv (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, const char *const roundingMode, topsStream_t stream=nullptr)
This function divides each element of the input lhs by the corresponding element of rhs.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
roundingMode – Type of rounding applied to the result.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiv (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function divides each element of the input lhs by the corresponding element of rhs.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiv (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, const char *const roundingMode, topsStream_t stream=nullptr)
This function divides each element of the input lhs by the corresponding element of rhs.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
roundingMode – Type of rounding applied to the result.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBitwiseAnd (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function computes the bitwise AND of lhs and rhs. The lhs tensor must be of integral or Boolean types. For bool tensors, it computes the logical AND.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBitwiseAnd (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function computes the bitwise AND of lhs and rhs. The lhs tensor must be of integral or Boolean types. For bool tensors, it computes the logical AND.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBitwiseAnd (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function computes the bitwise AND of lhs and rhs. The lhs tensor must be of integral or Boolean types. For bool tensors, it computes the logical AND.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBitwiseOr (topsatenTensor &output, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function computes the bitwise or of lhs and rhs. The lhs tensor must be of integral or Boolean types. For bool tensors, it computes the logical or.
- Parameters
output – The output tensor.
lhs – The input scalar.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBitwiseOr (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function computes the bitwise or of lhs and rhs. The lhs tensor must be of integral or Boolean types. For bool tensors, it computes the logical or.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBitwiseOr (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function computes the bitwise or of lhs and rhs. The lhs tensor must be of integral or Boolean types. For bool tensors, it computes the logical or.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndex (topsatenTensor &output, const topsatenTensor &input, const std::vector< topsatenTensor > &indices, topsStream_t stream=nullptr)
This function obtains the output tensor based on the index information of indicators of different dimensions.
- Parameters
output – The output tensor.
input – The input tensor.
indices – Index values of each dimension to be output.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexGetOutputDim (std::vector< int64_t > &output_dim, const topsatenTensor &input, const std::vector< topsatenTensor > &indices, topsStream_t stream=nullptr)
This function is to provide the index output shape.
- Parameters
output_dim – The output tensor shape.
input – The input tensor.
indices – Index values of each dimension to be output.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenEmbedding (topsatenTensor &output, const topsatenTensor &weight, const topsatenTensor &indices, int64_t paddingIdx, bool scaleGradByFreq, bool sparse, topsStream_t stream=nullptr)
This function is a simple lookup table that stores embeddings of a fixed dictionary and size.
- Parameters
output – The output tensor.
weight – A weight matrix that stores embedding vectors.
indices – Contains the tensor containing the index to be found in the weight matrix.
paddingIdx – If specified, the entries at padding_idx do not contribute to the gradient; therefore, the embedding vector at padding_idx is not updated during training, i.e. it remains as a fixed “pad”. For a newly constructed Embedding, the embedding vector at padding_idx will default to all zeros, but can be updated to another value to be used as the padding vector.
scaleGradByFreq – If given, this will scale gradients by the inverse of frequency of the words in the mini-batch. Default False.
sparse – If True, gradient w.r.t. weight matrix will be a sparse tensor. See Notes for more details regarding sparse gradients.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCumsum (topsatenTensor &output, const topsatenTensor &input, int32_t dims, const topsatenDataType_t &dtype, topsStream_t stream=nullptr)
This function returns the cumulative sum of elements of input in the dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dims – The dimension to do the operation over.
dtype – The desired data type of returned tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCumsum (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dims, const topsatenDataType_t &dtype, topsStream_t stream=nullptr)
This function returns the cumulative sum of elements of input in the dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dims – The dims to reduce, maybe a list or tuple.
dtype – The desired data type of returned tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCumprod (topsatenTensor &output, const topsatenTensor &input, int32_t dims, const topsatenDataType_t &dtype, topsStream_t stream=nullptr)
This function returns the cumulative product of elements of input in the dimension dim.
- Parameters
output – The output tensor.
input – The input tensor.
dims – The dimension to do the operation over.
dtype – The desired data type of returned tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArange (topsatenTensor &output, const topsatenScalar_t &end, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
This function returns the cumulative sum of elements of input in the dimension dim.
- Parameters
output – The output tensor.
end – The ending value for the set of points.
dtype – The desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArange (topsatenTensor &output, const topsatenScalar_t &start, const topsatenScalar_t &end, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
This function returns the cumulative sum of elements of input in the dimension dim.
- Parameters
output – The output tensor.
start – The starting value for the set of points.
end – The ending value for the set of points.
dtype – The desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArange (topsatenTensor &output, const topsatenScalar_t &start, const topsatenScalar_t &end, const topsatenScalar_t &step, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
This function returns the cumulative sum of elements of input in the dimension dim.
- Parameters
output – The output tensor.
start – The starting value for the set of points.
end – The ending value for the set of points.
step – The gap between each pair of adjacent points.
dtype – The desired data type of returned tensor.
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAcosh (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the inverse hyperbolic cosine of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArccosh (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the inverse hyperbolic cosine of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAsinh (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the inverse hyperbolic sine of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArcsinh (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the inverse hyperbolic sine of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAtanh (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the inverse hyperbolic tangent of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArctanh (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the inverse hyperbolic tangent of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAsin (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the arcsine of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArcsin (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the arcsine of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAtan (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the arctangent of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArctan (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the arctangent of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCopysign (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
This function creates a new floating-point tensor with the magnitude of input and the sign of other, elementwise.
- Parameters
output – The output tensor.
lhs – The magnitudes.
rhs – The number contains values whose signbits are applied to the magnitudes in input.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCopysign (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function creates a new floating-point tensor with the magnitude of input and the sign of other, elementwise.
- Parameters
output – The output tensor.
lhs – The magnitudes.
rhs – The tensor contains values whose signbits are applied to the magnitudes in input.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLogicalNot (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function computes the element-wise logical NOT of the given input tensor. If not specified, the output tensor will have the bool dtype.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLogicalXor (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function computes the element-wise logical XOR of the given input tensors. Zeros are treated as False and nonzeros are treated as True.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The tensor to compute XOR with.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLogicalAnd (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function computes the element-wise logical AND of the given input tensors. Zeros are treated as False and nonzeros are treated as True.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The tensor to compute AND with.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLogicalOr (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
This function computes the element-wise logical OR of the given input tensors. Zeros are treated as False and nonzeros are treated as True.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The tensor to compute OR with.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGlu (topsatenTensor &output, const topsatenTensor &input, const int32_t dim=-1, topsStream_t stream=nullptr)
This function applies the Gated Linear Unit (GLU) activation operation on the input tensor, splitting it into two halves on a specified dimension and then multiplying one half by the sigmoid of the other half for non-linear transformation.
- Parameters
output – The output tensor.
input – The input tensor.
dim – Dimension on which to split the input. Default: -1.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGluJvp (topsatenTensor &output, const topsatenTensor &glu, const topsatenTensor &x, const topsatenTensor &dx, const int32_t dim, topsStream_t stream=nullptr)
This function calculates the Jacobian-vector product (JVP) for the Gated Linear Unit (GLU) activation function.
- Parameters
output – The output tensor.
glu – The the GLU output.
x – The input tensor.
dx – The perturbation of the input.
dim – The dimension along which the GLU operation.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHardsigmoid (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function computes the hard sigmoid activation of the input tensor and writes the result directly into the output tensor.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHardtanh (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &min_val={TOPSATEN_DATA_FP32, {.fval=-1.0}}, const topsatenScalar_t &max_val={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
This function applies the hard hyperbolic tangent activation to the input tensor self, clipping its values to be within the range specified by min_val and max_val.
- Parameters
output – The output tensor.
input – The input tensor.
min_val – Minimum value of the linear region range. Default: -1.
max_val – Maximum value of the linear region range. Default: 1.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHardswish (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function applies the Hard Swish activation function to the input tensor, providing a piecewise linear approximation of the Swish activation for efficient computation.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMatmul (topsatenTensor &out, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
matmul operator
- Parameters
out – the output tensor
lhs – the input tensor of lhs
rhs – the input tensor of rhs
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBmm (topsatenTensor &out, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
bmm operator
- Parameters
out – the output tensor
lhs – the input tensor of lhs
rhs – the input tensor of rhs
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenOuter (topsatenTensor &out, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
outer operator
- Parameters
out – the output tensor
lhs – the input tensor of lhs
rhs – the input tensor of rhs
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAddmm (topsatenTensor &out, const topsatenTensor &self, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenScalar_t &beta={TOPSATEN_DATA_FP32, {1.0}}, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {1.0}}, topsStream_t stream=nullptr)
addmm operator
- Parameters
out – the output tensor
self – the input tensor of self
lhs – the input tensor of lhs
rhs – the input tensor of rhs
alpha – scaling factor used to blend the computation result
beta – scaling factor
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenScatter (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &index, const topsatenTensor &source, int32_t dim, const topsatenScatterComputationType_t &computation, topsStream_t stream=nullptr)
This function performs the scatter function.
- Parameters
output – Scatter result
input – Tensor we are scattering from.
index – The indices of elements to scatter.
source – The source element(s) to scatter.
dim – The axis along which to index.
computation – Reduction operation to apply.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenScatter (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &index, topsatenScalar_t &source, int32_t dim, const topsatenScatterComputationType_t &computation, topsStream_t stream=nullptr)
This function performs the scatter function.
- Parameters
output – Scatter result
input – Tensor we are scattering from.
index – The indices of elements to scatter.
source – The source element to scatter.
dim – The axis along which to index.
computation – Reduction operation to apply.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRngUniform (topsatenTensor &output, double from, double to, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function generate random uniform data.
- Parameters
output – Output tensor
from – Scalar of type T specifying lower limit of interval
to – Scalar of type T specifying upper limit of interval
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDropout (topsatenTensor &output, const topsatenTensor &input, double p, bool train, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function performs forward dropout operation.
- Parameters
output – Result tensor
input – Input tensor
p – The probability with which the value from input is set to zero during the dropout layer
train – Indicate if it is a train process.
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNativeDropout (topsatenTensor &output, topsatenTensor &mask, const topsatenTensor &input, double p, bool train, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function performs forward dropout operation.
- Parameters
output – Result tensor
mask – Mask tensor
input – Input tensor
p – The probability with which the value from input is set to zero during the dropout layer
train – Indicate if it is a train process.
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNativeDropoutBackward (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &mask, double scale, topsStream_t stream=nullptr)
This function performs backward dropout operation.
- Parameters
output – Result tensor
input – Input tensor
mask – Mask tensor
scale – The probability with which the value from input is set to zero during the dropout layer
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHARDTANHBwd (topsatenTensor &output, const topsatenTensor &grad_output, const topsatenTensor &self, const topsatenScalar_t &min, const topsatenScalar_t &max, topsStream_t stream=nullptr)
This function performs the backward hardtanh.
- Parameters
grad_output – The input tensor dy.
self – The input tensor x.
output – The output tensor.
min – min_value.
max – max_value
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenEluBackward (topsatenTensor &output, const topsatenTensor &grad_input, const topsatenTensor &input, const topsatenScalar_t &alpha, const topsatenScalar_t &scale, const topsatenScalar_t &input_scale, bool is_result, topsStream_t stream=nullptr)
This function performs the elu backward function. is_result = True : input > 0 : grad_input * scale : input <= 0 : grad_input * input_scale * (b_op + alpha * scale) is_result = False : input > 0 : grad_input * scale : input <= 0 : grad_input * scale * alpha * input_scale * exp(input_scale * b_op)
- Parameters
output – elu backward result.
input – The source tensor.
alpha – The alpha.
scale – The scale.
input_scale – The scale of input.
is_result – If True, input is Y, else input is X.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenTanhBackward (topsatenTensor &grad_input, const topsatenTensor &grad_output, const topsatenTensor &output, topsStream_t stream=nullptr)
Computes the backward pass for the hyperbolic tangent function.
This function calculates the gradient of the loss with respect to the input tensor using the hyperbolic tangent backward formula: grad_input = grad_output * (1
output^2).
- Parameters
grad_input[out] – The computed gradient of the loss with respect to the input tensor.
grad_output[in] – The gradient of the loss with respect to the output tensor.
output[in] – The output tensor from the forward pass of the hyperbolic tangent function.
stream[in] – The stream for asynchronous execution (if applicable).
- Returns
topsatenStatus_t Indication of the operation status.
- topsatenStatus_t TOPSATEN_EXPORT topsatenSiluBackward (topsatenTensor &grad_input, const topsatenTensor &grad_output, const topsatenTensor &self, topsStream_t stream=nullptr)
This function applies the SiLU backwad function, element-wise.
- Parameters
grad_input – The output tensor.
grad_output – The input tensor.
self – The input tensor. x of silu(x)
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandn (topsatenTensor &output, const topsatenSize_t &size, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, topsStream_t stream=nullptr)
Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).
- Parameters
output – The output tensor
size – The shape of the output tensor
dtype – The data type of the output tensor
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandn (topsatenTensor &output, const topsatenSize_t &size, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
Returns a tensor filled with random numbers from a normal distribution with mean 0 and variance 1 (also called the standard normal distribution).
- Parameters
output – The output tensor
size – The shape of the output tensor
dtype – The data type of the output tensor
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
generator – Creates and returns a generator object that manages the state of an algorithm that generates pseudo-random numbers.
stream – Tops stream
- topsatenStatus_t TOPSATEN_EXPORT topsatenRandnLike (topsatenTensor &output, const topsatenTensor &input, const topsatenDataType_t &dtype, const topsatenLayoutType_t &layout, bool pinMemory, const topsatenMemoryFormat_t &format, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function performs forward dropout operation.
- Parameters
output – Result tensor
input – Input tensor
dtype – The data type of the output tensor
layout – The desired layout of returned Tensor.
pinMemory – If set to True, the returned tensor will be allocated in pinned memory. Works only for CPU tensor.
format – Memory format, specifying storage type
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNormal (topsatenTensor &output, double mean, double std, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given.
- Parameters
output – The output tensor.
mean – the mean of each output element’s normal distribution.
std – the standard deviation of each output element’s normal distribution.
generator – Creates and returns a generator object that manages the state of an algorithm that generates pseudo-random numbers.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNormal (topsatenTensor &output, const topsatenTensor &mean, double std, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given.
- Parameters
output – The output tensor.
mean – the mean of each output element’s normal distribution.
std – the standard deviation of each output element’s normal distribution.
generator – Creates and returns a generator object that manages the state of an algorithm that generates pseudo-random numbers.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNormal (topsatenTensor &output, double mean, const topsatenTensor &std, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given.
- Parameters
output – The output tensor.
mean – the mean of each output element’s normal distribution.
std – the standard deviation of each output element’s normal distribution.
generator – Creates and returns a generator object that manages the state of an algorithm that generates pseudo-random numbers.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNormal (topsatenTensor &output, const topsatenTensor &mean, const topsatenTensor &std, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
This function returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are given.
- Parameters
output – The output tensor.
mean – the mean of each output element’s normal distribution.
std – the standard deviation of each output element’s normal distribution.
generator – Creates and returns a generator object that manages the state of an algorithm that generates pseudo-random numbers.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenResultType (topsatenDataType_t &dtype, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
Returns the type that would result from performing an arithmetic operation on the provided input tensors.
- Parameters
dtype – The output data type
lhs – Input lhs tensor
rhs – Input rhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenResultType (topsatenDataType_t &dtype, const topsatenScalar_t &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
Returns the type that would result from performing an arithmetic operation on the provided input tensors.
- Parameters
dtype – The output data type
lhs – Input lhs scalar
rhs – Input rhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenResultType (topsatenDataType_t &dtype, const topsatenTensor &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
Returns the type that would result from performing an arithmetic operation on the provided input tensors.
- Parameters
dtype – The output data type
lhs – Input lhs tensor
rhs – Input rhs scalar
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenResultType (topsatenDataType_t &dtype, const topsatenScalar_t &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
Returns the type that would result from performing an arithmetic operation on the provided input tensors.
- Parameters
dtype – The output data type
lhs – Input lhs scalar
rhs – Input rhs scalar
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenTile (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dims, topsStream_t stream=nullptr)
Constructs a tensor by repeating the elements of input. The dims argument specifies the number of repetitions in each dimension.
- Parameters
output – The output tensor
input – The input tensor
dims – The number of repetitions per dimension
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNewOnes (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &size, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
Returns a Tensor of size size filled with 1.
- Parameters
output – The output tensor
input – The input tensor
size – The shape of the output tensor
data_type – output data type.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIsNonzero (bool &flag, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns True if the input is a single element tensor which is not equal to zero after type conversions.
- Parameters
flag – The flag to indicate if the input is a single element tensor which is not equal to zero after type conversions.
input – The input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNLLLossForward (topsatenTensor &output, topsatenTensor &total_weight, const topsatenTensor &input, const topsatenTensor &target, const topsatenTensor &weight, const int64_t reduction, const int64_t ignore_index, topsStream_t stream=nullptr)
This function computes the negative log likelihood loss. It is useful to train a classification problem with C classes.
- Parameters
output – The output tensor.
total_weight – The sum of the weights of the loss values for each sample
input – The input tensor.
target – The target that this loss expects should be a class index in the range [0, C-1] where C = number of classes.
weight – The weight tensor shouled be 1D tensor, assigning weight to each of the classes.
reduction – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied, ‘mean’: the weighted mean of the output is taken, ‘sum’: the output will be summed.
ignore_index – Specifies a target value that is ignored and does not contribute to the input gradient.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNLLLoss2DForward (topsatenTensor &output, topsatenTensor &total_weight, const topsatenTensor &input, const topsatenTensor &target, const topsatenTensor &weight, const int64_t reduction, const int64_t ignore_index, topsStream_t stream=nullptr)
This function computes the negative log likelihood loss. It is useful to train a classification problem with C classes.
- Parameters
output – The output tensor.
total_weight – The sum of the weights of the loss values for each sample
input – The input tensor.
target – The target that this loss expects should be a class index in the range [0, C-1] where C = number of classes.
weight – The weight tensor shouled be 1D tensor, assigning weight to each of the classes.
reduction – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied, ‘mean’: the weighted mean of the output is taken, ‘sum’: the output will be summed.
ignore_index – Specifies a target value that is ignored and does not contribute to the input gradient.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCrossEntropyLoss (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &target, const topsatenTensor &weight, const int64_t reduction, const int64_t ignore_index, const double label_smoothing, topsStream_t stream=nullptr)
This function computes the cross entropy loss between input logits and target.
- Parameters
output – The output tensor.
input – The input tensor.
target – The target that this loss expects should be a class index in the range [0, C-1] where C = number of classes.
weight – The weight tensor shouled be 1D tensor, assigning weight to each of the classes.
reduction – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied, ‘mean’: the weighted mean of the output is taken, ‘sum’: the output will be summed.
ignore_index – Specifies a target value that is ignored and does not contribute to the input gradient.
stream – Tops stream
label_smoothing – A float in [0.0, 1.0]. Specifies the amount of smoothing when computing the loss, where 0.0 means no smoothing.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenScaledDotProductAttention (topsatenTensor &output, const topsatenTensor &query, const topsatenTensor &key, const topsatenTensor &value, const topsatenTensor &attn_mask, const topsatenScalar_t &dropout_p, bool is_causal, const topsatenScalar_t &scale, topsStream_t stream=nullptr)
multi query kv attention operator
- Parameters
output – The output tensor
query – input tensor query
key – input tensor key
value – input tensor value
attn_mask – Attention mask
dropout_p – Dropout probability
is_causal – If true, assumes causal attention masking
scale –
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenScaledDotProductEfficientAttention (std::tuple< topsatenTensor, topsatenTensor, topsatenTensor, topsatenTensor > &output, const topsatenTensor &query, const topsatenTensor &key, const topsatenTensor &value, const topsatenTensor &attn_mask, bool compute_log_sumexp, const topsatenScalar_t &dropout_p, bool is_causal, const topsatenScalar_t &scale, topsStream_t stream=nullptr)
scaled dot product efficient attention operator
- Parameters
output – The output tuple, below is details
out – The first output tensor in output tuple
logsumexp – The output tensor
seed – The output tensor
offset – The last output tensor in output tuple
query – input tensor query
key – input tensor key
value – input tensor value
attn_mask – Attention mask
compute_log_sumexp – whether compute log mask
dropout_p – Dropout probability
is_causal – If true, assumes causal attention masking
scale – scale value
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenScaledDotProductFlashAttention (std::tuple< topsatenTensor, topsatenTensor, topsatenTensor, topsatenTensor, int64_t, int64_t, topsatenTensor, topsatenTensor, topsatenTensor > &output, const topsatenTensor &query, const topsatenTensor &key, const topsatenTensor &value, const topsatenScalar_t &dropout_p, bool is_causal, bool return_debug_mask, const topsatenScalar_t &scale, topsStream_t stream=nullptr)
scaled dot product flash attention operator
- Parameters
output – The output tuple, below is details
out – The first output tensor in output tuple
logsumexp – The output tensor
cum_seq_q – The output tensor
cum_seq_k – The output tensor
max_q – The max q
max_k – The max k
philox_seed – The output tensor
philox_offset – The output tensor
debug_attn_mask – The last output tensor in output tuple
query – input tensor query
key – input tensor key
value – input tensor value
dropout_p – Dropout probability
is_causal – If true, assumes causal attention masking
return_debug_mask – whether return debug mask
scale – scale value
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenWhere (topsatenTensor &output, const topsatenTensor &condition, const topsatenTensor &input, const topsatenTensor &other, topsStream_t stream=nullptr)
Return a tensor of elements selected from either input or other, depending on condition.
- Parameters
out – The output tensor
condition – bool tensor used to select values from input and other
input – values selected at indices where condition is true
other – values selected at indices where condition is false
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenWhere (topsatenTensor &output, const topsatenTensor &condition, const topsatenScalar_t &input, const topsatenTensor &other, topsStream_t stream=nullptr)
Return a tensor of elements selected from either input or other, depending on condition.
- Parameters
output – The output tensor
condition – bool tensor used to select values from input and other
input – value selected at indices where condition is true
other – values selected at indices where condition is false
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenWhere (topsatenTensor &output, const topsatenTensor &condition, const topsatenTensor &input, const topsatenScalar_t &other, topsStream_t stream=nullptr)
Return a tensor of elements selected from either input or other, depending on condition.
- Parameters
output – The output tensor
condition – bool tensor used to select values from input and other
input – values selected at indices where condition is true
other – value selected at indices where condition is false
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenWhere (topsatenTensor &output, const topsatenTensor &condition, const topsatenScalar_t &input, const topsatenScalar_t &other, topsStream_t stream=nullptr)
Return a tensor of elements selected from either input or other, depending on condition.
- Parameters
output – The output tensor
condition – bool tensor used to select values from input and other
input – value selected at indices where condition is true
other – value selected at indices where condition is false
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenWhere (std::vector< topsatenTensor > &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Return the indices of the elements that are non-zero.
- Parameters
output – The output tensors
input – input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLerp (topsatenTensor &output, const topsatenTensor &start, const topsatenTensor &end, const topsatenTensor &weight, topsStream_t stream=nullptr)
Does a linear interpolation of start and end based on weight.
out[i] = start[i] + weight[i]*(end[i] - start[i])
- Parameters
out – The output tensor
start – The tensor with the starting points
end – The tensor with the ending points
weight – The weight for the interpolation formula
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLerp (topsatenTensor &output, const topsatenTensor &start, const topsatenTensor &end, const topsatenScalar_t &weight, topsStream_t stream=nullptr)
Does a linear interpolation of start and end based on weight.
out[i] = start[i] + weight*(end[i] - start[i])
- Parameters
out – The output tensor
start – The tensor with the starting points
end – The tensor with the ending points
weight – The weight for the interpolation formula
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenFlip (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dimensions, topsStream_t stream=nullptr)
Reverse the order of an n-D tensor along given axis in dims.
- Parameters
out – The output tensor
input – The input tensor
dimensions – Given axies
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenClampMin (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &min, topsStream_t stream=nullptr)
Returns the tensor after performing a lower bound truncation operation on the input tensor.
- Parameters
output – The output tensor
input – Input tensor to perform lower bound truncation operation
min – Replace elements less than the specified lower limit tensor with elements corresponding to the lower limit tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenClampMin (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &min, topsStream_t stream=nullptr)
Returns the tensor after performing a lower bound truncation operation on the input tensor.
- Parameters
output – The output tensor
input – Input tensor to perform lower bound truncation operation
min – Replace elements less than the specified lower limit value with this value
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArgmax (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &dimensions, const bool keepdims, topsStream_t stream=nullptr)
This function gets the relative indices of maximum value for the dimensions being reduced.
- Parameters
output_idx – the output tensor of indices
input – the input tensor
dimensions – the dimensions to reduce
keepdims – whether the output tensor has dim retained or not
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAmax (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dims, bool keepdim, topsStream_t stream=nullptr)
This function performs a max computation.
- Parameters
output – the output tensor
input – the input tensor
dimensions – the dimensions to reduce max
keepdims – whether the output tensor has dim retained or not
data – type
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSum (topsatenTensor &output, const topsatenTensor &input, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
This function performs a addition computation.
- Parameters
output – the output tensor
input – the input tensor
data_type – data type
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSum (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dimensions, const bool keepdims, const topsatenDataType_t &data_type, topsStream_t stream=nullptr)
This function performs a addition computation.
- Parameters
output – the output tensor
input – the input tensor
dimensions – the dimensions to reduce sum
keepdims – whether the output tensor has dim retained or not
data_type – data type
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenTo (topsatenTensor &output, const topsatenTensor &input, topsatenDataType_t &dtype, const bool non_blocking, const bool copy, const topsatenMemoryFormat_t &format, topsStream_t stream=nullptr)
This function performs the convert function.
- Parameters
output – The output tensor.
input – The source tensor.
dtype – The data type of the output tensor
non_blocking – If true and this copy is between CPU and GCU
copy – Whether to create a new tensor
format – The memory format of the output tensor
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNonzero (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function performs the nonzero function.
- Parameters
out – The output tensor, output_num must be input_rank * input_num.
input – The source tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCountNonzero (int32_t *count_nonzero, const topsatenTensor &input, topsStream_t stream=nullptr)
This function performs the nonzero function.
- Parameters
count_nonzero – The number of nonzero elements in the input tensor.
input – The source tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenTopk (topsatenTensor &output_value, topsatenTensor &output_index, const topsatenTensor &input, int64_t k, int64_t axis, bool is_sorted, bool is_largest, topsStream_t stream=nullptr)
This function performs the topk function.
- Parameters
output_value – output value tensor
output_index – output index tensor
input – input tensort
k – The K value is used to take the largest first k value or the smallest first k value, k should be less than or equal to dim_input[axis].
axis – Take the dimensions of the first k values.
is_sorted – Whether the results are sorted or not.
is_largest – The select of topk computation( true: Get the top k largest values false: Get the top k smallest values
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMultinomial (topsatenTensor &output, const topsatenTensor &input, const int64_t num_samples, const bool replacement, const topsatenGenerator_t &generator, topsStream_t stream=nullptr)
Returns a tensor where each row contains num_samples indices sampled from the multinomial probability distribution located in the corresponding row of tensor input.
- Parameters
output – the output tensor.
input – The input tensor
num_samples – samples nums per Categories.
replacement – sample with replacement or not.
generator – Generator used to initialize random number generator states
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMasked_fill (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &mask, const topsatenScalar_t &value, topsStream_t stream=nullptr)
Fills elements of new tensor with value where mask is True. The shape of mask must be broadcastable with the shape of the underlying tensor.
- Parameters
output – the output tensor.
input – The input tensor.
mask – the mask tensor.
value – the filled value.
stream – Tops stream.
- Returns
topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenMasked_fill (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &mask, const topsatenTensor &value_tensor, topsStream_t stream=nullptr)
Fills elements of new tensor with value where mask is True. The shape of mask must be broadcastable with the shape of the underlying tensor.
- Parameters
output – the output tensor.
input – The input tensor.
mask – the mask tensor.
value_tensor – the filled value tensor, it is scalar tensor.
stream – Tops stream.
- Returns
topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenFill_ (topsatenTensor &filled_tensor, const topsatenScalar_t &value, topsStream_t stream=nullptr)
Fills self tensor with the specified value.
- Parameters
filled_tensor – The filled tensor.
value – the filled value.
stream – Tops stream.
- Returns
topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenFill_ (topsatenTensor &filled_tensor, const topsatenTensor &value, topsStream_t stream=nullptr)
Fills self tensor with the specified value.
- Parameters
filled_tensor – The filled tensor.
value – the filled value tensor.
stream – Tops stream.
- Returns
topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenFull (topsatenTensor &output, const topsatenSize_t &size, const topsatenScalar_t &value, topsStream_t stream=nullptr)
Fills self tensor with the specified value.
- Parameters
output – The output tensor.
size – dimension of output.
value – the value to fill the output tensor with.
stream – Tops stream.
- Returns
topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenMm (topsatenTensor &out, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
mm operator
- Parameters
out – the output tensor
lhs – the input tensor of lhs
rhs – the input tensor of rhs
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNegConj (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Negate the real part of the input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenConj (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Negate the imaginary part of the input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBitwiseNot (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Computes the bitwise NOT of the given input tensor.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAbs (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Computes the absolute value of each element in input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenExp (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns a new tensor with the exponential of the elements of the input tensor.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenExpm1 (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Computes the exponential of the elements minus 1 of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSigmoid (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Computes the expit of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSqrt (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns a new tensor with the square-root of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGelu (topsatenTensor &output, const topsatenTensor &input, const char *const approximate="none", topsStream_t stream=nullptr)
Applies the Gaussian Error Linear Units function of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
approximate – The gelu approximation algorithm to use.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenElu (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {.fval=1.0}}, const topsatenScalar_t &scale={TOPSATEN_DATA_FP32, {.fval=1.0}}, const topsatenScalar_t &input_scale={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Applies the Exponential Linear Unit (ELU) function.
- Parameters
output – The output tensor.
input – The input tensor.
alpha – Value for the ELU formulation. Default: 1.0
scale – Value for the ELU formulation. Default: 1.0
input_scale – Value for the ELU formulation. Default: 1.0
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRelu (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Applies the rectified linear unit function element-wise.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLeakyRelu (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &negative_slope={TOPSATEN_DATA_FP32, {.fval=0.01}}, topsStream_t stream=nullptr)
Applies the function: leaky_relu(x) = x >= 0 ? x : negative_slope * x.
- Parameters
output – The output tensor.
input – The input tensor.
negative_slope – Controls the angle of the negative slope (which is used for negative input values). Default: 1e-2
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenTypeAs (topsatenTensor &out_to, const topsatenTensor &out_from, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns this tensor cast to the type of the given tensor.
- Parameters
out_to – The output tensor.
out_from – The tensor to be convert.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachLerp (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &input, const std::vector< topsatenTensor > &end, const std::vector< topsatenTensor > &weight, topsStream_t stream=nullptr)
Returns a new tensor with boolean elements representing if each element of input is NaN or not.
Does a linear interpolation of start and end based on weight.
out[i] = input[i] + weight * (end[i] - input[i])
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
out – The output tensor
input – The tensor with the starting points
end – The tensor with the ending points
weight – The weight for the interpolation formula
stream – Tops stream
- Returns
topsatenStatus_t
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachLerp (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &input, const std::vector< topsatenTensor > &end, const topsatenScalar_t &weight, topsStream_t stream=nullptr)
Does a linear interpolation of start and end based on weight.
out[i] = input[i] + weight * (end[i] - input[i])
- Parameters
out – The output tensor
input – The tensor with the starting points
end – The tensor with the ending points
weight – The weight for the interpolation formula
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAdd (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
Foreach add operator.
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs scalar
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAdd (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &lhs, const std::vector< topsatenTensor > &rhs, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Foreach add operator.
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs tensor
alpha – The multiplier for lhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAdd (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &lhs, const std::vector< topsatenScalar_t > &rhs, topsStream_t stream=nullptr)
Foreach add operator.
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs scalar
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAdd (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &lhs, const topsatenTensor &rhs, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Foreach add operator.
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs tensor
alpha – The multiplier for lhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachSqrt (std::vector< topsatenTensor > &output, const std::vector< topsatenTensor > &input, topsStream_t stream=nullptr)
Returns a new tensor with the square-root of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachDiv (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &lhs, const topsatenScalar_t &rhs, topsStream_t stream=nullptr)
Foreach div operator.
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs scalar
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachDiv (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &lhs, const std::vector< topsatenTensor > &rhs, topsStream_t stream=nullptr)
Foreach div operator.
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachDiv (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &lhs, const std::vector< topsatenScalar_t > &rhs, topsStream_t stream=nullptr)
Foreach div operator.
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs scalar
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachDiv (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
Foreach div operator.
- Parameters
out – The output tensor
lhs – Input lhs tensor
rhs – Input rhs tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAddcdiv (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &input, const std::vector< topsatenTensor > &tensor1, const std::vector< topsatenTensor > &tensor2, const topsatenScalar_t &value={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Foreach addcdiv operator.
out[i] = input[i] + value * (tensor1[i] / tensor2[i])
- Parameters
out – The output tensor
input – The tensor to be added
tensor1 – The numerator tensor
tensor2 – The denominator tensor
value – Multiplier for tensor1 / tensor2
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAddcdiv (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &input, const std::vector< topsatenTensor > &tensor1, const std::vector< topsatenTensor > &tensor2, const std::vector< topsatenScalar_t > &value, topsStream_t stream=nullptr)
Foreach addcdiv operator.
out[i] = input[i] + value * (tensor1[i] / tensor2[i])
- Parameters
out – The output tensor
input – The tensor to be added
tensor1 – The numerator tensor
tensor2 – The denominator tensor
value – Multiplier for tensor1 / tensor2
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAddcdiv (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &input, const std::vector< topsatenTensor > &tensor1, const std::vector< topsatenTensor > &tensor2, const topsatenTensor &value, topsStream_t stream=nullptr)
Foreach addcdiv operator.
out[i] = input[i] + value[i] * (tensor1[i] / tensor2[i])
- Parameters
out – The output tensor
input – The tensor to be added
tensor1 – The numerator tensor
tensor2 – The denominator tensor
value – Multiplier for tensor1 / tensor2
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAddcmul (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &input, const std::vector< topsatenTensor > &tensor1, const std::vector< topsatenTensor > &tensor2, const topsatenScalar_t &value={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Foreach addcmul operator.
out[i] = input[i] + value * (tensor1[i] * tensor2[i])
- Parameters
out – The output tensor
input – The tensor to be added
tensor1 – The numerator tensor
tensor2 – The denominator tensor
value – Multiplier for tensor1 / tensor2
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAddcmul (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &input, const std::vector< topsatenTensor > &tensor1, const std::vector< topsatenTensor > &tensor2, const std::vector< topsatenScalar_t > &value, topsStream_t stream=nullptr)
Foreach addcmul operator.
out[i] = input[i] + value * (tensor1[i] * tensor2[i])
- Parameters
out – The output tensor
input – The tensor to be added
tensor1 – The numerator tensor
tensor2 – The denominator tensor
value – Multiplier for tensor1 / tensor2
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachAddcmul (std::vector< topsatenTensor > &out, const std::vector< topsatenTensor > &input, const std::vector< topsatenTensor > &tensor1, const std::vector< topsatenTensor > &tensor2, const topsatenTensor &value, topsStream_t stream=nullptr)
Foreach addcmul operator.
out[i] = input[i] + value[i] * (tensor1[i] * tensor2[i])
- Parameters
out – The output tensor
input – The tensor to be added
tensor1 – The numerator tensor
tensor2 – The denominator tensor
value – Multiplier for tensor1 / tensor2
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAddcdiv (topsatenTensor &out, const topsatenTensor &input, const topsatenTensor &tensor1, const topsatenTensor &tensor2, const topsatenScalar_t &value={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Addcdiv operator.
out[i] = input[i] + value * (tensor1[i] / tensor2[i])
- Parameters
out – The output tensor
input – The tensor to be added
tensor1 – The numerator tensor
tensor2 – The denominator tensor
value – Multiplier for tensor1 / tensor2
stream – Tops stream
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAddcmul (topsatenTensor &out, const topsatenTensor &input, const topsatenTensor &tensor1, const topsatenTensor &tensor2, const topsatenScalar_t &value={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Addcmul operator.
out[i] = input[i] + value * (tensor1[i] * tensor2[i])
- Parameters
out – The output tensor
input – The tensor to be added
tensor1 – The numerator tensor
tensor2 – The denominator tensor
value – Multiplier for tensor1 * tensor2
stream – Tops stream
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenConjPhysical (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Computes the element-wise conjugate of the given input tensor. If input has a non-complex dtype, this function just returns input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAcos (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Computes the inverse cosine of each element in input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArccos (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Computes the inverse cosine of each element in input. Alias for topsatenAcos.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAddRelu (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
AddRelu(x, y) = alpha * max(x + y, 0)
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input tensor.
alpha – Multiplier for max(x + y, 0)
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAddRelu (topsatenTensor &output, const topsatenTensor &lhs, const topsatenScalar_t &rhs, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
AddRelu(x, y) = alpha * max(x + y, 0)
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
alpha – Multiplier for max(x + y, 0)
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAddmv (topsatenTensor &out, const topsatenTensor &input, const topsatenTensor &mat, const topsatenTensor &vec, const topsatenScalar_t &beta={TOPSATEN_DATA_FP32, {.fval=1.0}}, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Performs a matrix-vector product of the matrix mat and the vector vec. The vector input is added to the final result.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
beta – Multiplier for input
alpha – Multiplier for mat @ vec
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAddr (topsatenTensor &out, const topsatenTensor &input, const topsatenTensor &mat, const topsatenTensor &vec, const topsatenScalar_t &beta={TOPSATEN_DATA_FP32, {.fval=1.0}}, const topsatenScalar_t &alpha={TOPSATEN_DATA_FP32, {.fval=1.0}}, topsStream_t stream=nullptr)
Performs a outer-product product of the matrix mat and the vector vec. The vector input is added to the final result.
- Parameters
output – The output tensor.
lhs – The input tensor.
rhs – The input scalar.
beta – Multiplier for input
alpha – Multiplier for mat ⊗ vec
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIsAllTrue (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns True if all element in the input evaluate to True and False otherwise.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIsAnyTrue (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns True if any element in the input evaluate to True and False otherwise.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAllclose (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &other, const double &rtol=1e-05, const double &atol=1e-08, const bool &equal_nan=false, topsStream_t stream=nullptr)
This function checks if input and other satisfy the condition: ∣input − other∣ ≤ atol + rtol × ∣other∣
- Parameters
output – The output tensor.
input – First tensor to compare
other – Second tensor to compare
rtol – Relative tolerance. Default: 1e-05
atol – Absolute tolerance. Default: 1e-08
equal_nan – If True, then two NaN s will be considered equal. Default: False
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArgmin (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &dim={TOPSATEN_DATA_NONE, {}}, const bool &keepdim=false, topsStream_t stream=nullptr)
This function gets the relative indices of minimum value for the dimensions being reduced.
- Parameters
output – The output tensor of indices
input – The input tensor
dim – The dimensions to reduce
keepdim – Whether the output tensor has dim retained or not
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIsNan (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenIsInf (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns a new tensor with boolean elements representing if each element of input is infinite or not.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSin (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the sine of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCos (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the cosine of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLog (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the ln() of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenReciprocal (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the reciprocal of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexPut (topsatenTensor &self, const std::vector< topsatenTensor > &indices, const topsatenTensor &value, const bool accumulate, topsStream_t stream=nullptr)
This function performs the function that put values from the tensor values into the tensor self using the indices specified in indices.
- Parameters
self – index put input and result
indices – tensors arrray used to index into self
indices_num – indice number
value – tensor of same dtype as self
accumulate – if accumulate is True, the elements in values are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexPutImpl (topsatenTensor &self, const std::vector< topsatenTensor > &indices, const topsatenTensor &value, const bool accumulate, const bool unsafe, topsStream_t stream=nullptr)
This function performs the function that put values from the tensor values into the tensor self using the indices specified in indices.
- Parameters
self – index put input and result
indices – tensors arrray used to index into self
value – tensor of same dtype as self
accumulate – if accumulate is True, the elements in values are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexPut (topsatenTensor &self, const std::vector< topsatenTensor > &indices, const topsatenScalar_t &value, const bool accumulate, topsStream_t stream=nullptr)
This function performs the function that put values from the tensor values into the tensor self using the indices specified in indices.
- Parameters
self – index put input and result
indices – tensors arrray used to index into self
value – scalar value
accumulate – if accumulate is True, the elements in values are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexPutImpl (topsatenTensor &self, const std::vector< topsatenTensor > &indices, const topsatenScalar_t &value, const bool accumulate, const bool unsafe, topsStream_t stream=nullptr)
This function performs the function that put values from the tensor values into the tensor self using the indices specified in indices.
- Parameters
self – index put input and result
indices – tensors arrray used to index into self
value – scalar value
accumulate – if accumulate is True, the elements in values are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
unsafe – when set to true, typically indicates that the function may bypass certain safety checks or validations.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexPut (topsatenTensor &output, const topsatenTensor &input, const std::vector< topsatenTensor > &indices, const topsatenTensor &value, const bool accumulate, topsStream_t stream=nullptr)
This function performs the function that put values from the tensor values into the tensor self using the indices specified in indices.
- Parameters
output – index put result
input – index put input
indices – tensors arrray used to index into self
indices_num – indice number
value – tensor of same dtype as self
accumulate – if accumulate is True, the elements in values are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexPutImpl (topsatenTensor &output, const topsatenTensor &input, const std::vector< topsatenTensor > &indices, const topsatenTensor &value, const bool accumulate, const bool unsafe, topsStream_t stream=nullptr)
This function performs the function that put values from the tensor values into the tensor self using the indices specified in indices.
- Parameters
output – index put result
input – index put input
indices – tensors arrray used to index into self
value – tensor of same dtype as self
accumulate – if accumulate is True, the elements in values are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexPut (topsatenTensor &output, const topsatenTensor &input, const std::vector< topsatenTensor > &indices, const topsatenScalar_t &value, const bool accumulate, topsStream_t stream=nullptr)
This function performs the function that put values from the tensor values into the tensor self using the indices specified in indices.
- Parameters
output – index put result
input – index put input
indices – tensors arrray used to index into self
value – scalar value
accumulate – if accumulate is True, the elements in values are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexPutImpl (topsatenTensor &output, const topsatenTensor &input, const std::vector< topsatenTensor > &indices, const topsatenScalar_t &value, const bool accumulate, const bool unsafe, topsStream_t stream=nullptr)
This function performs the function that put values from the tensor values into the tensor self using the indices specified in indices.
- Parameters
output – index put result
input – index put input
indices – tensors arrray used to index into self
value – scalar value
accumulate – if accumulate is True, the elements in values are added to self. If accumulate is False, the behavior is undefined if indices contain duplicate elements.
unsafe – when set to true, typically indicates that the function may bypass certain safety checks or validations.
stream:Tops – stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLayerNorm (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &normalized_shape, const topsatenTensor &weight, const topsatenTensor &bias, const topsatenScalar_t &epsilon, topsStream_t stream=nullptr)
This function performs the forward layer normalization.
- Parameters
output – Normalized tensor.
input – Tensor to be normalized.
normalized_shape – The shape of the normalization dimension.
weight – Weight tensor.
bias – Bias tensor.
epsilon – The epsilon value to use to avoid division by zero.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNativeLayerNorm (topsatenTensor &output, topsatenTensor &mean, topsatenTensor &rstd, const topsatenTensor &input, const topsatenSize_t &normalized_shape, const topsatenTensor &weight, const topsatenTensor &bias, const topsatenScalar_t &epsilon, topsStream_t stream=nullptr)
This function performs the forward layer normalization.
- Parameters
output – Normalized tensor.
mean – Mean of input along dimensions [axis,…,r-1].
rstd – Reciprocal of standard deviation of input along dimensions [axis,…,r-1].
input – Tensor to be normalized.
normalized_shape – The shape of the normalization dimension.
weight – Weight tensor.
bias – Bias tensor.
epsilon – The epsilon value to use to avoid division by zero.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGroupNorm (topsatenTensor &output, const topsatenTensor &input, const int64_t group, const topsatenTensor &weight, const topsatenTensor &bias, const double eps=1e-05, topsStream_t stream=nullptr)
This function performs the forward group normalization.
- Parameters
output – Normalized tensor.
input – Tensor to be normalized.
group – Number of groups to separate the channels into.
weight – Weight tensor.
bias – Bias tensor.
eps – A value added to the denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNativeGroupNorm (topsatenTensor &output, topsatenTensor &mean, topsatenTensor &rstd, const topsatenTensor &input, const topsatenTensor &weight, const topsatenTensor &bias, const int64_t N, const int64_t C, const int64_t HxW, const int64_t group, const double eps, topsStream_t stream=nullptr)
This function performs the forward native group normalization.
- Parameters
output – Normalized tensor.
mean – Mean of input computed separately over each group.
rstd – Reciprocal of standard deviation of input computed separately over each group.
input – Tensor to be normalized.
weight – Weight tensor.
bias – Bias tensor.
N – Number of batchs expected in input.
C – Number of channels expected in input.
HxW – Product of other dimensions except N/C in input.
group – Number of groups to separate the channels into.
eps – A value added to the denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNativeBatchNorm (topsatenTensor &output, topsatenTensor &save_mean, topsatenTensor &save_var, const topsatenTensor &input, const topsatenTensor &weight, const topsatenTensor &bias, topsatenTensor &running_mean, topsatenTensor &running_var, const bool training, const double momentum, const double eps, topsStream_t stream=nullptr)
This function performs the forward batch normalization.
- Parameters
output – Normalized tensor.
save_mean – Save mean tensor.
save_var – Save var tensor.
input – Tensor to be normalized.
weight – An optional parameter used to scale the normalized tensor.
bias – An optional parameter used to shift the normalized tensor.
running_mean – An optional parameter used to specify the running mean used for normalization.
running_var – An optional parameter used to specify the running variance used for normalization.
training – Is training or not.
momentum – An parameter specifying the momentum for the running mean and variance.
eps – A value added to the denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenInstanceNorm (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &weight, const topsatenTensor &bias, topsatenTensor &running_mean, topsatenTensor &running_var, const bool use_input_stats, const double momentum, const double eps, topsStream_t stream=nullptr)
This function performs the forward instance normalization.
- Parameters
output – Normalized tensor.
input – Tensor to be normalized.
weight – An optional parameter used to scale the normalized tensor.
bias – An optional parameter used to shift the normalized tensor.
running_mean – An optional parameter used to specify the running mean used for normalization.
running_var – An optional parameter used to specify the running variance used for normalization.
use_input_stats – Is use_input_stats or not.
momentum – An parameter specifying the momentum for the running mean and variance.
eps – A value added to the denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenWeightNormInterface (topsatenTensor &w, topsatenTensor &norm, const topsatenTensor &v, const topsatenTensor &g, int dim, topsStream_t stream=nullptr)
This function performs the forward weight normalization.
- Parameters
w – Normalized magnitude.
norm – Normalized direction.
v – Parameters specify the magnitude.
g – Parameters specify the direction.
dim – Dimension over which to compute the norm.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinalgVectorNorm (topsatenTensor &output, const topsatenTensor &input, const topsatenScalar_t &ord, const topsatenSize_t &reduce_dim, const bool keepdim=false, const topsatenDataType_t &dtype=TOPSATEN_DATA_NONE, topsStream_t stream=nullptr)
This function computes a vector norm.
- Parameters
output – The output tensor.
input – The input tensor.
ord – The order of vector norm.
reduce_dim – The dimension or dimensions to reduce. None is equivalent to input_dims.
keepdim – Whether the output tensor has dim retained or not.
dtype – The data type of the output tensor.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenForeachNorm (std::vector< topsatenTensor > &output, const std::vector< topsatenTensor > &input, const topsatenScalar_t &ord, topsStream_t stream=nullptr)
This function computes a norm list.
- Parameters
output – The output tensor list.
input – The input tensor list.
ord – The order of norm.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRoll (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &shifts, const topsatenSize_t &dims, topsStream_t stream=nullptr)
The function is used to perform a circular shift of a tensor along a specified dimension. It can roll the elements of the tensor forward or backward along the specified dimension, and elements beyond the boundary will be moved to the other side.
- Parameters
output – The output tensor.
inputs – The input tensors.
shifts – The number of positions to scroll. Can be a positive number (scrolling left) or a negative number (scrolling right).
dims – The dimension to scroll. The default is None, which means scrolling through all dimensions.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSort (topsatenTensor &sorted, topsatenTensor &indices, const topsatenTensor &input, bool stable, int64_t dim, bool descending, topsStream_t stream=nullptr)
This function returns sorted tensor of input tensor and corresponding indices.
- Parameters
sorted – The output sorted tensor.
indices – The output indices tensor.
input – The input tensor.
stable – If True, the sorting algorithm will be stable.
dim – The dimension to sort along.
descending – Controls the sorting order (ascending or descending).
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenArgSort (topsatenTensor &indices, const topsatenTensor &input, bool stable, int64_t dim, bool descending, topsStream_t stream=nullptr)
This function returns the indices of the elements that are sorted.
- Parameters
indices – The output indices tensor.
input – The input tensor.
stable – If True, the sorting algorithm will be stable.
dim – The dimension to sort along.
descending – Controls the sorting order (ascending or descending).
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGather (topsatenTensor &output, const topsatenTensor &input, int64_t dim, const topsatenTensor &index, bool sparse_grad, topsStream_t stream=nullptr)
This function performs the gather function.
- Parameters
output – Gather result.
input – The source tensor.
index – The indices of elements to gather.
dim – The axis along which to index.
sparse_grad – If True, gradient w.r.t. input will be a sparse tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGather (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &index, int64_t dim, bool sparse_grad, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenEinSum (topsatenTensor &output, const char *equation, const std::vector< topsatenTensor > &inputs, topsatenSize_t &path, topsStream_t stream=nullptr)
This function computes Einstein summation convention on the inputs.
- Parameters
output – The output tensor.
inputs – The input tensors.
equation – The syntax to be computed.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenPad (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &pads, const topsatenPadMode_t &mode, const topsatenScalar_t &value, topsStream_t stream=nullptr)
This function performs the pad function.
- Parameters
output – output tensor
input – input tensor
pads –
mode –
value – A scalar value to be used if the mode chosen is
constant
(by default it is 0).stream –
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenReflectionPad1d (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &pads, topsStream_t stream=nullptr)
This function performs the reflect pad function.
- Parameters
output –
input –
pads –
stream –
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenReflectionPad2d (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &pads, topsStream_t stream=nullptr)
This function performs the reflect pad function.
- Parameters
output –
input –
pads –
stream –
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenReflectionPad3d (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &pads, topsStream_t stream=nullptr)
This function performs the reflect pad function.
- Parameters
output –
input –
pads –
stream –
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenUpsampleNearest2d (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &output_size, const topsatenScalar_t &scales_h, const topsatenScalar_t &scales_w, topsStream_t stream=nullptr)
This function performs the upsample nearest2d function.
- Parameters
out – The output tensor.
input – The source tensor.
scales_h – The topsatenScalar_t of scales_h.
scales_w – The topsatenScalar_t of scales_w.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenUpsampleNearest3d (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &output_size, const topsatenScalar_t &scales_d, const topsatenScalar_t &scales_h, const topsatenScalar_t &scales_w, topsStream_t stream=nullptr)
This function performs the upsample nearest3d function.
- Parameters
output – The output tensor.
input – The source tensor.
output_size – The size of the output tensor.
scales_d – The topsatenScalar_t of scales_d.
scales_h – The topsatenScalar_t of scales_h.
scales_w – The topsatenScalar_t of scales_w.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDenseDim (int &dim, const topsatenTensor &self, topsStream_t stream=nullptr)
This function return the number of dense dimensions in a sparse tensor ‘self’. For a normal tensor, this function simply returns the rank of the tensor.
- Parameters
dim – The output result.
self – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSparseDim (int &dim, const topsatenTensor &self, topsStream_t stream=nullptr)
This function return the number of sparse dimensions in a sparse tensor ‘self’. For a normal tensor, this function simply returns 0.
- Parameters
dim – The output result.
self – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenVar (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &dim, const topsatenScalar_t &correction, bool keepdim, topsStream_t stream=nullptr)
This function return the variance over the dimensions specified by dim.
- Parameters
output – : The output tensor
input – : The input tensor
dim – : The dimension or dimensions to reduce
correction – : Difference between the sample size and sample degrees of freedom
keepdim – : Whether the output tensor has dim retained or not
stream – : Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenTriu (topsatenTensor &result, const topsatenTensor &self, int64_t k, topsStream_t stream=nullptr)
This function returns the upper triangular part of a matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.
- Parameters
result – The output tensor.
self – The input tensor.
k – the diagonal to consider.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenReshapeAlias (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &size, const topsatenSize_t &strides, topsStream_t stream=nullptr)
This function is meant to be used in the implementation of reshape.
- Parameters
output – : The output tensor
input – : The input tensor
size – : The size of output tensor
strides – : Strides to use if operation can be just a view.
stream – : tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenTril (topsatenTensor &result, const topsatenTensor &self, int64_t k, topsStream_t stream=nullptr)
This function returns the lower triangular part of the matrix (2-D tensor) or batch of matrices input, the other elements of the result tensor out are set to 0.
- Parameters
result – The output tensor.
self – The input tensor.
k – the diagonal to consider.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiag (topsatenTensor &output, const topsatenTensor &input, int64_t diagonal, topsStream_t stream=nullptr)
This function returnsthen returns a 2-D square tensor with the elements of input as the diagonal.
- Parameters
result – The output tensor.
self – : The input tensor.
offset – the diagonal to consider.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenUpsampleBilinear2d (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &size, bool align_corners, const topsatenScalar_t &scale_h, const topsatenScalar_t &scale_w, topsStream_t stream=nullptr)
This function performs 2D bilinear upsampling on a multi-channel input signal. You can define the scale using either the output size (h, w) or a scaling factor (scale_factor).
- Parameters
output – The out tensor.
input – The input tensor.
size – output spatial sizes.
align_corners – if True, the corner pixels of the input and output tensors are aligned
scale_h – multiplier for spatial size.
scale_w – multiplier for spatial size.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenPolar (topsatenTensor &result, const topsatenTensor &abs, const topsatenTensor &angle, topsStream_t stream=nullptr)
This function constructs a complex tensor whose elements are Cartesian coordinates corresponding to the polar coordinates with absolute value and angle.
- Parameters
output – The output tensor.
lhs – The input tensor containing absolute values.
rhs – The input tensor containing angle values.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNLLLossBackward (topsatenTensor &result, const topsatenTensor &grad_output, const topsatenTensor &self, const topsatenTensor &target, const topsatenTensor &weight, const int64_t &reduction, const int64_t &ignore_index, const topsatenTensor &total_weight, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenLogSoftmaxBackwardData (topsatenTensor &result, const topsatenTensor &grad_output, const topsatenTensor &output, const int64_t &dim, const topsatenDataType_t &input_dtype, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenSliceBackward (topsatenTensor &result, const topsatenTensor &grad_output, const topsatenSize_t &input_sizes, const int64_t &dim, const int64_t &start, const int64_t &end, const int64_t &step, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenSiluBackward (topsatenTensor &result, const topsatenTensor &grad_output, const topsatenTensor &self, const topsatenTensor &grad_input, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenSoftmaxBackwardData (topsatenTensor &result, const topsatenTensor &grad_output, const topsatenTensor &output, const int64_t &dim, const topsatenDataType_t &input_dtype, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenIndexSelectBackward (topsatenTensor &result, const topsatenTensor &grad, const topsatenSize_t &self_sizes, const int64_t &dim, const topsatenTensor &index, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenEmbeddingBackward (topsatenTensor &result, const topsatenTensor &grad, const topsatenTensor &indices, const int64_t &num_weights, const int64_t &padding_idx, const bool &scale_grad_by_freq, const bool &sparse, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenAmpUpdateScale (topsatenTensor &output, const topsatenTensor &input, topsatenTensor &growth_tracker, const topsatenTensor &found_inf, double scale_growth_factor, double scale_backoff_factor, int64_t growth_interval, topsStream_t stream=nullptr)
This function computes the output based on the input tensor.
- Parameters
input – A one-element float tensor containing the scale value.
growth_tracker – A one-element int tensor containing the number of recent consecutive unskipped steps.
found_inf – A one-element float tensor. If > 0, indicates infs/nans and 0 if no infs/nans were found.
scale_growth_factor – Multiplier if no infs/NaNs were found.
scale_backoff_factor – Multiplier if infs/NaNs were found.
growth_interval – Number of consecutive unskipped steps that must occur for current_scale to be multiplied by growth_factor.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenScaledDotProductAttention (topsatenTensor &result, const topsatenTensor &query, const topsatenTensor &key, const topsatenTensor &value, const topsatenTensor &attn_mask, const double &dropout_p, const bool &is_causal, const double &scale, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenIsPinned (bool &result, const topsatenTensor &self, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenScaledDotProductFlashAttentionBackward (topsatenTensor &result, const topsatenTensor &grad_out, const topsatenTensor &query, const topsatenTensor &key, const topsatenTensor &value, const topsatenTensor &out, const topsatenTensor &logsumexp, const topsatenTensor &cum_seq_q, const topsatenTensor &cum_seq_k, const int64_t &max_q, const int64_t &max_k, const double &dropout_p, const bool &is_causal, const topsatenTensor &philox_seed, const topsatenTensor &philox_offset, const topsatenScalar_t &scale, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenSquare (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the square of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMeshgrid (std::vector< topsatenTensor > &output, const std::vector< topsatenTensor > &input, const char *index="ij", topsStream_t stream=nullptr)
This function create the grids of coordinate specified by input.
- Parameters
output – : The output tensor.
input – : The input tensor.
index – : Mode to be specify, default - ‘ij’.
stream – : tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLocalScalarDense (topsatenScalar_t &result, const topsatenTensor &self, topsStream_t stream=nullptr)
This function.
- Parameters
result – The scalar output.
self – : The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiagEmbed (topsatenTensor &output, const topsatenTensor &input, int64_t offset, int64_t dim1, int64_t dim2, topsStream_t stream=nullptr)
This function returns a tensor whose diagonals of certain 2D planes are filled by input tensor.
- Parameters
output – The output tensor.
input – : The input tensor.
offset – The offset scalar.
dim1 – : The dim1 scalar.
dim2 – : The dim2 scalar.
stream – : Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiagonal (topsatenTensor &output, const topsatenTensor &input, int64_t offset, int64_t dim1, int64_t dim2, topsStream_t stream=nullptr)
This function return the partial view of diagonal elements of the given tensor with respect to dim1 and dim2.
- Parameters
output – The output tensor.
input – : The input tensor.
offset – The offset scalar.
dim1 – : The dim1 scalar.
dim2 – : The dim2 scalar.
stream – : Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenEye (topsatenTensor &output, const int32_t n, topsStream_t stream=nullptr)
Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
- Parameters
output – : The output tensor
n – : The number of rows
stream – : tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenEye (topsatenTensor &output, const int32_t n, const int32_t m, topsStream_t stream=nullptr)
Returns a 2-D tensor with ones on the diagonal and zeros elsewhere.
- Parameters
output – : The output tensor
n – : The number of rows
m – : The number of columns, default is n.
stream – : tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinalgCheckErrors (const topsatenTensor &info, const char *api_name, bool is_matrix, topsStream_t stream=nullptr)
This function throws an error based on the info tensor and API name for Linear Algebra Ops.
- Parameters
info – : The input tensor.
api_name – : Specify the api name
is_matrix – : Set true if input is matrix.
stream – : Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinalgSolveEx_ (topsatenTensor &output, topsatenTensor &LU, topsatenTensor &pivots, topsatenTensor &info, const topsatenTensor &lhs, const topsatenTensor &rhs, bool left, bool check_errors, topsStream_t stream=nullptr)
A version of linalg solve() : Computes the solution of a square system of linear equations with a unique solution, that does not perform error checks unless check_errors=True. Return tensors of result, LU, pivots, info.
- Parameters
output – The output tuple of tensors.
LU – The LU tensor.
pivots – The pivots tensor.
info – The info tensor.
lhs – The lhs tensor, tensor of shape (*, n, n) where * is zero or more batch dimensions
rhs – The right-hand side tensor of shape (*, n) or (*, n, k) or (n,) or (n, k) according to the rules described above
left – Whether to solve the system AX=B or XA=B. Default: True.
check_errors – Controls whether to check the content of infos and raise an error if it is non-zero. Default: False.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinalgSolveEx (topsatenTensor &output, topsatenTensor &info, const topsatenTensor &lhs, const topsatenTensor &rhs, bool left, bool check_errors, topsStream_t stream=nullptr)
A version of linalg solve() : Computes the solution of a square system of linear equations with a unique solution, that does not perform error checks unless check_errors=True. Returns - result, info.
- Parameters
output – The output tuple of tensors.
info – The info tensor.
lhs – The lhs tensor, tensor of shape (*, n, n) where * is zero or more batch dimensions
rhs – The right-hand side tensor of shape (*, n) or (*, n, k) or (n,) or (n, k) according to the rules described above
left – Whether to solve the system AX=B or XA=B. Default: True.
check_errors – Controls whether to check the content of infos and raise an error if it is non-zero. Default: False.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinalgSolve (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, bool left, topsStream_t stream=nullptr)
Computes the solution of a square system of linear equations with a unique solution.
- Parameters
output – The output tensor.
lhs – The input tensor, tensor of shape (*, n, n) where * is zero or more batch dimensions
rhs – The right-hand side tensor of shape (*, n) or (*, n, k) or (n,) or (n, k) according to the rules described above
left – Whether to solve the system AX=B or XA=B. Default: True.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenConstant_Pad_Nd (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &pad, const topsatenScalar_t &value, topsStream_t stream=nullptr)
Pads the input tensor boundaries with a constant value.
- Parameters
output – : The output tensor
input – : The input tensor
pad – : m-elements tuple
value – : fill value for padding, Default is 0
stream – : Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinalgLuFactorEx (topsatenTensor &LU, topsatenTensor &pivots, topsatenTensor &info, const topsatenTensor &input, bool pivot, bool check_errors, topsStream_t stream=nullptr)
A version of linalg () : Computes the solution of a square system of linear equations with a unique solution, that does not perform error checks unless check_errors=True. Return tensors of result, LU, pivots, info.
- Parameters
LU – The LU tensor.
pivots – The pivots tensor.
info – The info tensor.
lhs – The lhs tensor, tensor of shape (*, n, n) where * is zero or more batch dimensions
pivot – Whether to solve the system AX=B or XA=B. Default: True.
check_errors – Controls whether to check the content of infos and raise an error if it is non-zero. Default: False.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLinalgLuSolve (topsatenTensor &output, topsatenTensor &LU, topsatenTensor &pivots, topsatenTensor &B, bool left, bool adjoint, topsStream_t stream=nullptr)
A version of linalg solve() : Computes the solution of a square system of linear equations with a unique solution, that does not perform error checks unless check_errors=True. Return tensors of result, LU, pivots, info.
- Parameters
output – The output tuple of tensors.
LU – The LU tensor.
pivots – The pivots tensor.
B – The right-hand side tensor of shape (*, n) or (*, n, k) or (n,) or (n, k) according to the rules described above
left – Whether to solve the system AX=B or XA=B. Default: True.
check_errors – Controls whether to check the content of infos and raise an error if it is non-zero. Default: False.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAffineGridGenerator (topsatenTensor &output, const topsatenTensor &theta, const topsatenSize_t &size, bool align_corners, topsStream_t stream=nullptr)
Generates a 2D or 3D flow field (sampling grid), given a batch of affine matrices theta.
- Parameters
output – : The output tensor
theta – : The theta tensor
size – : The size of output tensor
align_corners – : If True, consider -1 and 1 to refer to the centers of the corner pixels rather than the image corners. Default: False
stream – : tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMaxPool2d (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &kernel_size, const topsatenSize_t &stride, const topsatenSize_t &padding, const topsatenSize_t &dilation, bool ceil_mode, topsStream_t stream=nullptr)
- Parameters
output – : The output tensor.
input – : The input tensor.
kernel_size – : size of the pooling region. Can be a single number or a tuple (kH, kW).
stride – : stride of the pooling operation. Can be a single number or a tuple (sH, sW).
padding – : Implicit negative infinity padding to be added on both sides, must be >= 0 and <= kernel_size / 2.
dilation – : The stride between elements within a sliding window, must be > 0.
ceil_mode – : If True, will use ceil instead of floor to compute the output shape.
stream – : tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMaxPool2dIndices (topsatenTensor &output, topsatenTensor &indices, const topsatenTensor &input, const topsatenSize_t &kernel_size, const topsatenSize_t &stride, const topsatenSize_t &padding, const topsatenSize_t &dilation, bool ceil_mode, topsStream_t stream=nullptr)
Applies a 2D max pooling over an input with several input planes.
- Parameters
output – : The output tensor.
indices – : The tensor to store indices.
input – : The input tensor.
kernel_size – : size of the pooling region. Can be a single number or a tuple (kH, kW).
stride – : stride of the pooling operation. Can be a single number or a tuple (sH, sW).
padding – : Implicit negative infinity padding to be added on both sides, must be >= 0 and <= kernel_size / 2.
dilation – : The stride between elements within a sliding window, must be > 0.
ceil_mode – : If True, will use ceil instead of floor to compute the output shape.
stream – : tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAvgPool2d (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t &kernel_size, const topsatenSize_t &stride, const topsatenSize_t &padding, bool ceil_mode, bool count_include_pad, const topsatenScalar_t &divisor_override, topsStream_t stream=nullptr)
- Parameters
output – : The output tensor.
input – : The input tensor.
kernel_size – : size of the pooling region. Can be a single number or a tuple (kH, kW).
stride – : stride of the pooling operation. Can be a single number or a tuple (sH, sW).
padding – : Implicit negative infinity padding to be added on both sides, must be >= 0 and <= kernel_size / 2.
ceil_mode – : If True, will use ceil instead of floor to compute the output shape.
count_include_pad – : when True, will include the zero-padding in the averaging calculation.
divisor_override – : optional(int) if specified, it will be used as divisor, otherwise size of the pooling region will be used.
stream – : tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenUnique2 (topsatenTensor &output, topsatenTensor &indices, topsatenTensor &counts, const topsatenTensor &input, bool sorted, bool return_inverse, bool return_counts, topsStream_t stream=nullptr)
Returns unique elements from the input tensor along with optional additional information.
- Parameters
output – : The output tensor with unique elements.
indices – : If return_indices is true, it will contain indexes to map elements in the original input to the output. Same shape as input.
counts – : The number of occurrences for each unique value. Same shape as output.
input – : The input tensor.
sorted – : If true, the unique elements are returned in sorted order.
return_inverse – : If true, returns the indices of the unique elements in the original tensor.
return_counts – : If true, returns the counts of each unique element.
stream – : tops stream
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBlackmanWindow (topsatenTensor &output, int64_t window_length, topsStream_t stream=nullptr)
Returns a 1-D blackman window of same length as input window_length parameter.
- Parameters
output – The output tensor.
window_length – The window length.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBlackmanWindow (topsatenTensor &output, int64_t window_length, bool periodic, topsStream_t stream=nullptr)
Returns a 1-D blackman window of same length as input window_length parameter.
- Parameters
output – The output tensor.
window_length – The window length.
periodic – The boolean parameter for periodic.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenFrac (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns a new tensor with fractional portion of each element in input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNanToNum (topsatenTensor &output, const topsatenTensor &input, double nan, double posinf, double neginf, topsStream_t stream=nullptr)
Replaces nan, posinf and neginf in the input with the values specified by nan, posinf and neginf.
- Parameters
output – The output tensor.
input – The input tensor.
nan – The replacement for nan.
posinf – The replacement for positive infinity.
neginf – The replacement for negative infinity.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenNanToNum (topsatenTensor &output, const topsatenTensor &input, topsatenScalar_t nan, topsatenScalar_t posinf, topsatenScalar_t neginf, topsStream_t stream=nullptr)
Replaces nan, posinf and neginf in the input with the values specified by nan, posinf and neginf.
- Parameters
output – The output tensor.
input – The input tensor.
nan – The replacement for nan.
posinf – The replacement for positive infinity.
neginf – The replacement for negative infinity.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenErf (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with the erf of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBinaryCrossEntropy (topsatenTensor &output, const topsatenTensor &inputs, const topsatenTensor &targets, const topsatenTensor &weights, const int64_t reduction, topsStream_t stream=nullptr)
This function computes the binary cross entropy.
- Parameters
output – The output tensor.
inputs – The input tensors.
targets – The target tensors.
weight – Optional weight tensors.
reduction – Parameter to specify which reduction operation should be performed.
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSgn (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
It computes a new tensor whose elements have the same angles as the corresponding elements of input and absolute values (i.e. magnitudes) of one for complex tensors.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHammingWindow (topsatenTensor &out, int64_t window_length, bool periodic, double alpha, double beta, topsStream_t stream=nullptr)
The Hamming window is a mathematical function used in signal processing.
- Parameters
out – The output tensor.
window_length – The size of returned window.
periodic – If True, returns a window to be used as periodic function. If False, return a symmetric window.
alpha – The coefficient alpha in the equation above.
beta – The coefficient beta in the equation above
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHammingWindow (topsatenTensor &out, int64_t window_length, topsStream_t stream=nullptr)
The Hamming window is a mathematical function used in signal processing.
- Parameters
out – The output tensor.
window_length – The size of returned window.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHammingWindow (topsatenTensor &out, int64_t window_length, bool periodic, topsStream_t stream=nullptr)
The Hamming window is a mathematical function used in signal processing.
- Parameters
out – The output tensor.
window_length – The size of returned window.
periodic – If True, returns a window to be used as periodic function. If False, return a symmetric window.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHammingWindow (topsatenTensor &out, int64_t window_length, bool periodic, double alpha, topsStream_t stream=nullptr)
The Hamming window is a mathematical function used in signal processing.
- Parameters
out – The output tensor.
window_length – The size of returned window.
periodic – If True, returns a window to be used as periodic function. If False, return a symmetric window.
alpha – The coefficient alpha in the equation above.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHingeEmbeddingLoss (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &target, double margin, int64_t reduction, topsStream_t stream=nullptr)
This function computes the hinge embedding loss between input and target.
- Parameters
output – The output tensor.
input – The input tensor.
target – The target that this loss expects
reduction – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied, ‘mean’: the weighted mean of the output is taken, ‘sum’: the output will be summed.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHannWindow (topsatenTensor &output, int64_t window_length, topsStream_t stream=nullptr)
Returns a 1-D Hann window of same length as input window_length parameter.
- Parameters
output – The output tensor.
window_length – The window length.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenHannWindow (topsatenTensor &output, int64_t window_length, bool periodic, topsStream_t stream=nullptr)
Returns a 1-D Hann window of same length as input window_length parameter.
- Parameters
output – The output tensor.
window_length – The window length.
periodic – The boolean parameter for periodic.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBinaryCrossEntropyWithLogits (topsatenTensor &output, const topsatenTensor &inputs, const topsatenTensor &targets, const topsatenTensor &weights, const topsatenTensor &pos_weights, const int64_t reduction, topsStream_t stream=nullptr)
This function computes the binary cross entropy with logits loss.
- Parameters
inputs – The input tensors.
targets – The target tensors.
weight – Optional weight tensors.
pos_weight – Optional pos_weight tensors.
reduction – Parameter to specify which reduction operation should be performed.
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenGcd (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
Returns a new tensor with gcd of the two input tensor elements.
- Parameters
out – The output tensor.
lhs – The lhs tensor.
rhs – The rhs tensor.
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLcm (topsatenTensor &output, const topsatenTensor &lhs, const topsatenTensor &rhs, topsStream_t stream=nullptr)
Returns a new tensor with lcm of the two input tensor elements.
- Parameters
out – The output tensor.
lhs – The lhs tensor.
rhs – The rhs tensor.
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenMarginRankingLoss (topsatenTensor &output, const topsatenTensor &input1, const topsatenTensor &input2, const topsatenTensor &target, double margin, int64_t reduction, topsStream_t stream=nullptr)
This function computes the loss based on relative distances between pairs of inputs and target.
- Parameters
output – The output tensor.
input1 – The input1 tensor.
input2 – The input2 tensor.
target – The target tesnsor (containing 1 or -1)
margin – A double value. Specifies the minimum difference needed for the loss.
reduction – Specifies the reduction to apply to the output: ‘none’ | ‘mean’ | ‘sum’. ‘none’: no reduction will be applied, ‘mean’: the mean of the output is taken, ‘sum’: the output will be summed.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenKaiserWindow (topsatenTensor &out, int64_t window_length, bool periodic, double beta, topsStream_t stream=nullptr)
The Kaiser window is a mathematical function used in digital signal processing.
- Parameters
out – The output tensor.
window_length – The size of returned window.
periodic – If True, returns a window to be used as periodic function. If False, return a symmetric window.
beta – The coefficient β in the equation above
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenKaiserWindow (topsatenTensor &out, int64_t window_length, topsStream_t stream=nullptr)
The Kaisar window is a mathematical function used in digital signal processing.
- Parameters
out – The output tensor.
window_length – The size of returned window.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenKaiserWindow (topsatenTensor &out, int64_t window_length, bool periodic, topsStream_t stream=nullptr)
The Kaiser window is a mathematical function used in digital signal processing.
- Parameters
out – The output tensor.
window_length – The size of returned window.
periodic – If True, returns a window to be used as periodic function. If False, return a symmetric window.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAngle (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns a new tensor with the element-wise angle (in radians) of the given input tensor.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCov (topsatenTensor &output, const topsatenTensor &input, int64_t correction, const topsatenTensor &fweight, const topsatenTensor &aweight, topsStream_t stream=nullptr)
This function calculates covariance tensor of the variables given by the input tensor.
- Parameters
output – The covariance tensor of the variables.
input – A 2D tensor matrix containing multiple variables and observations, or 1D tensor representing a single variable.
correction – correction value.
fweights – Fweights tensor.
aweights – Aweights tensor.
stream – Tops stream
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBartlettWindow (topsatenTensor &output, int64_t window_length, topsStream_t stream=nullptr)
Returns a 1-D bartlett window of same length as input window_length parameter.
- Parameters
output – The output tensor.
window_length – The window length.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBartlettWindow (topsatenTensor &output, int64_t window_length, bool periodic, topsStream_t stream=nullptr)
Returns a 1-D bartlett window of same length as input window_length parameter.
- Parameters
output – The output tensor.
window_length – The window length.
periodic – The boolean parameter for periodic.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCosineEmbeddingLoss (topsatenTensor &output, const topsatenTensor &input1, const topsatenTensor &input2, const topsatenTensor &target, double margin, int64_t reduction, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenSplit (std::vector< topsatenTensor > &out, const topsatenTensor input, const int64_t size, const int64_t dim, topsStream_t stream=nullptr)
Splits the tensor into chunks. Each chunk is a view of the original tensor.
- Parameters
out – The output chunks.
input – The input tensor.
size – The size of a single chunk or list of sizes for each chunk.
dim – The dimension along which to split the input tensor.
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenSplit (std::vector< topsatenTensor > &out, const topsatenTensor input, const topsatenSize_t size, const int64_t dim, topsStream_t stream=nullptr)
Splits the tensor into chunks. Each chunk is a view of the original tensor.
- Parameters
out – The output chunks.
input – The input tensor.
size – The size of a single chunk or list of sizes for each chunk.
dim – The dimension along which to split the input tensor.
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenLogspace (topsatenTensor &output, const topsatenScalar_t &start, const topsatenScalar_t &end, int64_t step, double base, topsStream_t stream=nullptr)
This function returns the Logarithmically spaced elements based of input in inputs and steps.
- Parameters
output – : The output tensor.
start – : The starting value for the set of points.
end – : The ending value for the set of points.
step – : The total number of elements between start and end.
base – : The base of the logarithm function. Default: 10.0.
stream – : Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenAmpForeachNonFiniteCheckAndUnscale (std::vector< topsatenTensor > &output, topsatenTensor &found_inf, const std::vector< topsatenTensor > &input, const topsatenTensor &inv_scale, topsStream_t stream=nullptr)
Return a new tensor list which contains input tensors multiplied by the scalar value in inv_scale and a changes the value in found found_inf to one if ‘inf’ or ‘NAN’ value is found in any tensor.
- Parameters
output – The output tensor list.
found_inf – The output tensor.
input – The input tensor list.
inv_scale – The input tensor.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCosineSimilarity (topsatenTensor &output, const topsatenTensor &input1, const topsatenTensor &input2, int64_t dim, double eps, topsStream_t stream=nullptr)
Returns cosine similarity between input1 and input2 computed along specified dim.
- Parameters
output – The output tensor.
input1 – The input1 tensor.
input2 – The input2 tensor.
dim – The dimension where cosine similarity is computed.
eps – A small value to avoid division by zero.
stream – Tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDiff (topsatenTensor &output, const topsatenTensor &inputs, int64_t n, int64_t dim, const topsatenTensor &prepend, const topsatenTensor &append, topsStream_t stream=nullptr)
This function computes the n-th forward difference along the given dimension.
- Parameters
output – The output tensor.
inputs – The input tensors.
n – n times to recursively compute the difference
dim – the dimension to compute the difference along
prepend – Optional prepend tensors.
append – Optional append tensors.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenBilinear (topsatenTensor &out, const topsatenTensor &input1, const topsatenTensor &input2, const topsatenTensor &weight, const topsatenTensor &bias, topsStream_t stream=nullptr)
Computes the bilinear operation.
- Parameters
out – The output tensor where the result of the bilinear operation will be stored.
input1 – The first input tensor.
input2 – The second input tensor.
weight – The weight tensor representing weight in the bilinear operation.
bias – The bias tensor representing the bias in the bilinear operation.
stream – TOPS stream.
- Returns
Returns a topsopStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenTrunc (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns a new tensor with the truncated integer values of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRavel (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a contiguous flattened tensor.
- Parameters
output – The output tensor.
inputs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRad2Deg (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with each of the elements of input converted from angles in radians to degrees.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenRound (topsatenTensor &out, const topsatenTensor &input, int64_t decimal, topsStream_t stream=nullptr)
Computes the round operation.
- Parameters
out – The output tensor where the result of the round operation will be stored.
input – The input tensor.
decimal – Number of decimal places to round to.
stream – TOPS stream.
- Returns
Returns a topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenRound (topsatenTensor &out, const topsatenTensor &input, topsStream_t stream=nullptr)
Computes the round operation.
- Parameters
out – The output tensor where the result of the round operation will be stored.
input – The input tensor.
stream – TOPS stream.
- Returns
Returns a topsatenStatus_t.
- topsatenStatus_t TOPSATEN_EXPORT topsatenSumToSize (topsatenTensor &output, const topsatenTensor &input, const topsatenSize_t size, topsStream_t stream=nullptr)
This function computes sum on the input tensor based on the size param. Size must be broadcastable to the input tensor shape.
- Parameters
output – the output tensor
input – the input tensor
size – size
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenFix (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
Returns a new tensor with the truncated integer values of the elements of input.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenDeg2rad (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns a new tensor with each of the elements of input converted from angles in degree to radian.
- Parameters
output – The output tensor.
input – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenCartesianProd (topsatenTensor &output, const std::vector< topsatenTensor > &inputs, topsStream_t stream=nullptr)
This function finds the cartesian product specified by input.
- Parameters
output – : The output tensor.
input – : The input tensor.
stream – : tops stream.
- Returns
topsopStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsatenPositive (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
This function returns the same input tensor and is not supported for Boolean datatype.
- Parameters
output – The output tensor.
inputs – The input tensor.
stream – Tops stream.
- Returns
topsatenStatus_t
2.2. Aten cnn ops¶
This section describes topsflame cnn ops api definitions.
- topsatenStatus_t TOPSATEN_EXPORT topsatenConvolution (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &filter, const topsatenTensor &bias, const topsatenSize_t &stride, const topsatenSize_t &padding, const topsatenSize_t &dilation, bool transposed, const topsatenSize_t &output_padding, int64_t groups, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenConvTranspose2d (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &filter, const topsatenTensor &bias, const topsatenSize_t &stride, const topsatenSize_t &padding, const topsatenSize_t &output_padding, int64_t groups, const topsatenSize_t &dilation, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenConvDepthwise2d (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &filter, const topsatenTensor &bias, const topsatenSize_t &stride, const topsatenSize_t &padding, const topsatenSize_t &dilation, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT topsatenConv2d (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &filter, const topsatenTensor &bias, const topsatenSize_t &stride, const topsatenSize_t &padding, const topsatenSize_t &dilation, int64_t groups, topsStream_t stream=nullptr)
- topsatenStatus_t TOPSATEN_EXPORT _topsatenConvolution (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &filter, const topsatenTensor &bias, const topsatenSize_t &stride, const topsatenSize_t &padding, const topsatenSize_t &dilation, bool transposed, const topsatenSize_t &output_padding, int64_t groups, bool benchmark, bool deterministic, bool cudnn_enabled, bool allow_tf32, topsStream_t stream=nullptr)
2.3. Aten vllm ops¶
This section describes topsflame aten vllm ops api definitions.
- topsatenStatus_t TOPSATEN_EXPORT topsvllmRotaryEmbedding (topsatenTensor &query, topsatenTensor &key, const topsatenTensor &positions, const topsatenTensor &cos_sin_cache, int head_size, bool is_neox, topsStream_t stream=nullptr)
rotary_embedding
- Parameters
query – The output/input tensor [num_tokens, num_heads * head_size] float32 float16
key – The output/input tensor [num_tokens, num_kv_heads * head_size] float32 float16
positions – Input tensor [num_tokens] int64
cos_sin_cache – Input tensor [max_position, rot_dim] float32 float16
head_size – Input scalar
is_neox – Input scalar
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmMemoryEfficientAttention (topsatenTensor &output, const topsatenTensor &query, const topsatenTensor &key, const topsatenTensor &value, const topsatenTensor &attn_bias, const topsatenScalar_t &dropout_p, const topsatenScalar_t &scale, topsStream_t stream=nullptr)
multi query kv attention operator
- Parameters
output – The output tensor
query – input tensor query
key – input tensor key
value – input tensor value
attn_bias – Attention mask
dropout_p – Dropout probability
scale –
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmMemEfficientAttention (topsatenTensor &output, const topsatenTensor &query, const topsatenTensor &key, const topsatenTensor &value, const topsatenTensor &attn_bias, const topsatenScalar_t &dropout_p, const topsatenScalar_t &scale, const std::vector< int32_t > &seqlens, topsStream_t stream=nullptr)
multi query kv attention operator
- Parameters
output – The output tensor
query – input tensor query
key – input tensor key
value – input tensor value
attn_bias – Attention mask
dropout_p – Dropout probability
scale –
seqlens –
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmSiluAndMul (topsatenTensor &out, const topsatenTensor &in, topsStream_t stream=nullptr)
silu and mul operator
- Parameters
out – The output tensor
in – Input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmGeluAndMul (topsatenTensor &out, const topsatenTensor &in, topsStream_t stream=nullptr)
gelu and mul operator
- Parameters
out – The output tensor
in – Input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmGeluTanhAndMul (topsatenTensor &out, const topsatenTensor &in, topsStream_t stream=nullptr)
gelu tanh and mul operator
- Parameters
out – The output tensor
in – Input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmGeluNew (topsatenTensor &out, const topsatenTensor &in, topsStream_t stream=nullptr)
gelu new operator
- Parameters
out – The output tensor
in – Input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmGeluFast (topsatenTensor &out, const topsatenTensor &in, topsStream_t stream=nullptr)
gelu fast operator
- Parameters
out – The output tensor
in – Input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmReshapeAndCache (topsatenTensor &key_cache, topsatenTensor &value_cache, const topsatenTensor &key, const topsatenTensor &value, const topsatenTensor &slot_mapping, topsStream_t stream=nullptr)
reshape and cache operator
- Parameters
out – The key cache tensor
out – The value cache tensor
in – Key tensor
in – Value tensor
in – Slot mapping tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmPagedAttentionV1 (topsatenTensor &output, const topsatenTensor &query, const topsatenTensor &key_cache, const topsatenTensor &value_cache, const topsatenTensor &head_mapping, const topsatenScalar_t &scale, const topsatenTensor &block_tables, const topsatenTensor &context_lens, const topsatenScalar_t &block_size, const topsatenScalar_t &max_context_len, const topsatenTensor &alibi_slopes, topsStream_t stream=nullptr)
paged attention v1 operator
- Parameters
output – The output tensor
query – input tensor query
key_cache – input tensor cached key
value_cache – input tensor cached value
scale – scale
block_tables – input tensor block table
context_lens – input tensor context len
block_size – block size
max_context_len – max length of context
alibi_slopes – input tensor alibi slopes
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmRmsNorm (topsatenTensor &output, const topsatenTensor &input, const topsatenTensor &weight, const topsatenScalar_t &epsilon, topsStream_t stream=nullptr)
Compute RMSNorm on the input.
- Parameters
output – Output tensor of shape […, hidden_size].
input – Input tensor of shape […, hidden_size].
gamma – Gamma tensor of shape [hidden_size].
epsilon – Value added to denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmFusedAddRmsNorm (topsatenTensor &input, topsatenTensor &residual, const topsatenTensor &weight, float epsilon, topsStream_t stream=nullptr)
In-place fused Add and RMS Normalization.
- Parameters
input – Input tensor of shape […, hidden_size].
residual – Residual tensor of shape […, hidden_size].
weight – Weight tensor of shape [hidden_size].
epsilon – Value added to denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmFusedAddRmsNorm (topsatenTensor &output, topsatenTensor &residual_update, const topsatenTensor &input, const topsatenTensor &residual, const topsatenTensor &weight, float epsilon, topsStream_t stream=nullptr)
Fused Add and RMS Normalization.
- Parameters
output – Output tensor of shape […, hidden_size].
residual_update – Update residual tensor of shape […, hidden_size].
input – Input tensor of shape […, hidden_size].
residual – Residual tensor of shape […, hidden_size].
weight – Weight tensor of shape [hidden_size].
epsilon – Value added to denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmBgmv (topsatenTensor &output, const topsatenTensor &y, const topsatenTensor &x, const topsatenTensor &w, const topsatenTensor &indicies, int layer_idx, float scale, topsStream_t stream=nullptr)
bgmv.
- Parameters
output – Shape: [B, H2]. Output vectors. Can be the same as y.
y – Shape: [B, H2]. Input y vectors.
x – Shape: [B, H1]. Input x vectors.
w – Shape: [None, L, H2, H1]. All of the transposed weight matrices.
indicies – Shape: [B]. Indices of the weight matrices.
layer_idx – Layer index of the weight matrices.
scale – Scaling factor.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsvllmBgmvLowLevel (topsatenTensor &output, const topsatenTensor &y, const topsatenTensor &x, const topsatenTensor &w, const topsatenTensor &indicies, int layer_idx, float scale, int h_in, int h_out, int y_offset, topsStream_t stream=nullptr)
bgmv low level.
- Parameters
output – Shape: [B, H2]. Output vectors. Can be the same as y.
y – Shape: [B, H2]. Input y vectors.
x – Shape: [B, H1]. Input x vectors.
w – Shape: [None, L, H2, H1]. All of the transposed weight matrices.
indicies – Shape: [B]. Indices of the weight matrices.
layer_idx – Layer index of the weight matrices.
scale – Scaling factor.
h_in – Size of the x column slice.
h_out – Size of the y column slice.
y_offset – Offset to apply to the starting column of y.
stream – Tops stream
- Returns
topsatenStatus_t
2.4. Aten transform engine ops¶
This section describes topsflame aten transform engine ops api definitions.
- topsatenStatus_t TOPSATEN_EXPORT topsteScaledSoftmaxForward (topsatenTensor &out, const topsatenTensor &in, const topsatenScalar_t &scale, topsStream_t stream=nullptr)
scaled softmax forward operator
- Parameters
out – The output tensor
in – Input tensor
scale – The multiplier for input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsteScaledMaskedSoftmaxForward (topsatenTensor &out, const topsatenTensor &in, const topsatenTensor &mask, const topsatenScalar_t &scale, topsStream_t stream=nullptr)
scaled masked softmax forward operator
- Parameters
out – The output tensor
in – Input tensor
mask – Mask tensor
scale – The multiplier for input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsteScaledUpperTriangMaskedSoftmaxForward (topsatenTensor &out, const topsatenTensor &in, const topsatenScalar_t &scale, topsStream_t stream=nullptr)
scaled upper triang masked softmax forward operator
- Parameters
out – The output tensor
in – Input tensor
scale – The multiplier for input tensor
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsteLayerNormFwd (topsatenTensor &output, topsatenTensor &mean, topsatenTensor &rstd, const topsatenTensor &input, const topsatenTensor &gamma, const topsatenTensor &beta, const topsatenScalar_t &epsilon, topsStream_t stream=nullptr)
Compute LayerNorm on the input.
- Parameters
output – Output tensor of shape [N, H].
mean – Mean of the input calculated over the last dimension. Shape: [N].
rstd – Inverse of the variance of the input calculated over the last dimension. Shape: [N].
input – Input tensor of shape [N, H].
gamma – Gamma tensor of shape [H].
beta – Beta tensor of shape [H].
epsilon – Value added to denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsteBlasGemm (topsatenTensor &out, topsatenTensor &pre_gelu_out, const topsatenTensor &lhs, const topsatenTensor &rhs, const topsatenTensor &bias, const topsatenBlasOperation_t &transa, const topsatenBlasOperation_t &transb, const bool accumalate, const topsStream_t stream=nullptr)
gemm operator
- Parameters
out – the output tensor
pre_gelu_out – Output matrix before GELU activation
lhs – the input tensor of lhs
rhs – the input tensor of rhs
bias – the input tensor of bias
transa – lhs transpose info
transb – rhs transpose info
accumalate – Whether to accumulate the result
stream – tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsteRmsNormFwd (topsatenTensor &output, topsatenTensor &rstd, const topsatenTensor &input, const topsatenTensor &gamma, const topsatenScalar_t &epsilon, topsStream_t stream=nullptr)
Compute RMSNorm on the input.
- Parameters
output – Output tensor of shape [N, H].
rstd – Reciprocal of the root mean square of the input calculated over the last dimension. Shape: [N].
input – Input tensor of shape [N, H].
gamma – Gamma tensor of shape [H].
epsilon – Value added to denominator for numerical stability.
stream – Tops stream
- Returns
topsatenStatus_t
- topsatenStatus_t TOPSATEN_EXPORT topsteGelu (topsatenTensor &output, const topsatenTensor &input, topsStream_t stream=nullptr)
gelu operator
- Parameters
output – the output tensor
input – the input tensor of lhs
stream – tops stream
- Returns
topsatenStatus_t