Skip to content

Commit

Permalink
Updata internal ovxlib to rel1.2.6 (#690)
Browse files Browse the repository at this point in the history
Internal ovxlib commit hash: c5d3e69356579fc7b595a7c0939fc7e4e0aaab5a

Type: Code Improvement

Signed-off-by: Feiyue Chen <[email protected]>
  • Loading branch information
chenfeiyue-cfy authored Apr 2, 2024
1 parent 3ea908c commit 3b80968
Show file tree
Hide file tree
Showing 69 changed files with 4,878 additions and 590 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.50
1.2.6
2 changes: 2 additions & 0 deletions src/tim/vx/internal/include/interface/ops.def
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,5 @@ DEF_OP(RESIZE_3D)
DEF_OP(REDUCEL2)
DEF_OP(CROP_AND_RESIZE)
DEF_OP(TAN)
DEF_OP(RMSNORM)
DEF_OP(SHAPE)
6 changes: 4 additions & 2 deletions src/tim/vx/internal/include/kernel/vsi_nn_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define _VSI_NN_KERNEL_H

#include <stdint.h>
#include <stdarg.h>

#include "vsi_nn_log.h"
#include "vsi_nn_ops.h"
#include "vsi_nn_graph.h"
Expand Down Expand Up @@ -81,6 +83,7 @@ typedef enum
U4,
FP8_E4M3,
FP8_E5M2,
INVALID_DTYPE,
} VSI_PUBLIC_TYPE vsi_nn_kernel_dtype_e;

typedef enum
Expand Down Expand Up @@ -532,9 +535,8 @@ static VSI_INLINE_API vsi_nn_kernel_dtype_e vsi_nn_kernel_map_dtype
return FP8_E5M2;
default:
VSILOGE("error data type %d", dtype);
break;
return INVALID_DTYPE;
}
return I8;
} /* vsi_nn_kernel_map_dtype() */

static VSI_INLINE_API vsi_nn_type_e vsi_nn_dtype_map_kernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef struct _vsi_nn_resize_internal_param
vsi_bool half_pixel_centers;
float factor;
vsi_enum layout;
vsi_enum type;
} vsi_nn_resize_internal_param;

#ifdef __cplusplus
Expand Down
54 changes: 54 additions & 0 deletions src/tim/vx/internal/include/ops/vsi_nn_op_rmsnorm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/****************************************************************************
*
* Copyright (c) 2020 Vivante Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/

#ifndef _VSI_NN_OP_RMSNORM_H
#define _VSI_NN_OP_RMSNORM_H

#include "vsi_nn_types.h"

#ifdef __cplusplus
extern "C" {
#endif


typedef struct _rmsnorm_local_data_t {
int32_t placeholder;
} rmsnorm_local_data_t;

typedef struct _vsi_nn_rmsnorm_param
{
struct _rmsnorm_local_data_t* local;
float eps;
int32_t axis;
} vsi_nn_rmsnorm_param;

_compiler_assert(offsetof(vsi_nn_rmsnorm_param, local) == 0, \
vsi_nn_rmsnorm_h );

#ifdef __cplusplus
}
#endif

#endif

47 changes: 47 additions & 0 deletions src/tim/vx/internal/include/ops/vsi_nn_op_shape.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/****************************************************************************
*
* Copyright (c) 2020 Vivante Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/

#ifndef _VSI_NN_OP_SHAPE_H
#define _VSI_NN_OP_SHAPE_H

#include "vsi_nn_types.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _vsi_nn_shape_param
{
struct _shape_local_data_t* local;
// Add parameters here
} vsi_nn_shape_param;
_compiler_assert(offsetof(vsi_nn_shape_param, local) == 0, \
vsi_nn_shape_h );

#ifdef __cplusplus
}
#endif

#endif

72 changes: 51 additions & 21 deletions src/tim/vx/internal/include/utils/vsi_nn_dtype_util_prv.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
extern "C" {
#endif

/*
* A helper union for fp32 bit casting.
*/
typedef union {
float val;
uint32_t data;
} fp32_bit_cast_t;

static VSI_INLINE_API vsi_bool type_is_integer
(
const vsi_nn_type_e type
Expand Down Expand Up @@ -203,9 +211,11 @@ static VSI_INLINE_API vsi_bool fp32_is_inf
float val
)
{
uint32_t u_value = *(uint32_t*)&val;
fp32_bit_cast_t fp32_bit_cast;
fp32_bit_cast.val = val;
uint32_t fp32_data = fp32_bit_cast.data;

if ((u_value & (uint32_t)VSI_NN_INT32_MAX) == (uint32_t)VSI_NN_FLOAT32_INF)
if ((fp32_data & (uint32_t)VSI_NN_INT32_MAX) == (uint32_t)VSI_NN_FLOAT32_INF)
{
return TRUE;
}
Expand All @@ -232,7 +242,9 @@ static VSI_INLINE_API int32_t fp32_to_affine

if (fp32_is_inf(in) != 0)
{
uint32_t sign = (*(uint32_t*)&in) >> 31;
fp32_bit_cast_t fp32_bit_cast;
fp32_bit_cast.val = in;
uint32_t sign = fp32_bit_cast.data >> 31;
data = sign == 1 ? (int32_t)min_range : (int32_t)max_range;
}

Expand Down Expand Up @@ -277,7 +289,9 @@ static VSI_INLINE_API int32_t fp32_to_dfp

if (fp32_is_inf(in) != 0)
{
uint32_t sign = (*(uint32_t*)&in) >> 31;
fp32_bit_cast_t fp32_bit_cast;
fp32_bit_cast.val = in;
uint32_t sign = fp32_bit_cast.data >> 31;
data = sign == 1 ? (int32_t)min_range : (int32_t) max_range;
}

Expand Down Expand Up @@ -373,8 +387,9 @@ static VSI_INLINE_API float bfp16_to_fp32
int16_t in
)
{
int32_t t1, t2, t3;
uint32_t t1, t2, t3;
float out;
fp32_bit_cast_t fp32_bit_cast;

t1 = in & 0x00FF; // Mantissa
t2 = in & 0xFF00; // Sign bit + Exponent
Expand All @@ -384,20 +399,23 @@ static VSI_INLINE_API float bfp16_to_fp32
t2 <<= 16; // Shift (sign + Exponent) bit into position
t1 |= t2; // Re-insert (sign + Exponent) bit

*((uint32_t*)&out) = t1;
fp32_bit_cast.data = t1;
out = fp32_bit_cast.val;

return t3 == 0 ? 0 : out;
return t3 == 0 ? 0.0f : out;
} /* bfp16_to_fp32() */

static VSI_INLINE_API uint16_t fp32_to_fp16
(
float in
)
{
uint32_t fp32 = *((uint32_t *) &in);
uint32_t t1 = (fp32 & 0x80000000u) >> 16; /* sign bit. */
uint32_t t2 = (fp32 & 0x7F800000u) >> 13; /* Exponent bits */
uint32_t t3 = (fp32 & 0x007FE000u) >> 13; /* Mantissa bits, no rounding */
fp32_bit_cast_t fp32_bit_cast;
fp32_bit_cast.val = in;
uint32_t fp32_data = fp32_bit_cast.data;
uint32_t t1 = (fp32_data & 0x80000000u) >> 16; /* sign bit. */
uint32_t t2 = (fp32_data & 0x7F800000u) >> 13; /* Exponent bits */
uint32_t t3 = (fp32_data & 0x007FE000u) >> 13; /* Mantissa bits, no rounding */
uint32_t fp16 = 0u;
if( t2 >= 0x023c00u )
{
Expand All @@ -420,8 +438,10 @@ static VSI_INLINE_API uint16_t fp32_to_bfp16
float in
)
{
uint32_t fp32 = *((unsigned int *) &in);
uint32_t t1 = fp32 >> 16;
fp32_bit_cast_t fp32_bit_cast;
fp32_bit_cast.val = in;
uint32_t fp32_data = fp32_bit_cast.data;
uint32_t t1 = fp32_data >> 16;

return (uint16_t) t1;
} /* fp32_to_bfp16() */
Expand All @@ -435,10 +455,12 @@ static VSI_INLINE_API uint16_t fp32_to_bfp16_rtne
Convert a float point to bfloat16, with round-nearest-to-even as rounding method.
*/

uint32_t fp32 = *((unsigned int *) &in);
fp32_bit_cast_t fp32_bit_cast;
fp32_bit_cast.val = in;
uint32_t fp32_data = fp32_bit_cast.data;
uint16_t out;

uint32_t lsb = (fp32 >> 16) & 1; /* Least significant bit of resulting bfloat. */
uint32_t lsb = (fp32_data >> 16) & 1; /* Least significant bit of resulting bfloat. */
uint32_t rounding_bias = 0x7fff + lsb;

if ( VSI_NN_FLOAT32_NAN == in )
Expand All @@ -447,8 +469,8 @@ static VSI_INLINE_API uint16_t fp32_to_bfp16_rtne
}
else
{
fp32 += rounding_bias;
out = (uint16_t) (fp32 >> 16);
fp32_data += rounding_bias;
out = (uint16_t) (fp32_data >> 16);
}

return out;
Expand All @@ -466,7 +488,9 @@ static VSI_INLINE_API uint16_t fp32_to_bfp16_rtne

static VSI_INLINE_API uint8_t fp32_to_fp8_e4m3(float in, const float scale) {
float fp8_f32 = in / scale;
int32_t in_val = *((int32_t*)&fp8_f32);
fp32_bit_cast_t fp32_bit_cast;
fp32_bit_cast.val = fp8_f32;
uint32_t in_val = fp32_bit_cast.data;

uint32_t in_sign = (in_val >> (FLOAT_EXPONENT_SIZE + FLOAT_MANTISSA_SIZE)) & 0x1; /* bit 31 is sign */
uint32_t in_exp = (in_val >> FLOAT_MANTISSA_SIZE) & 0xFF; /* bit[30: 24] is exp */
Expand Down Expand Up @@ -512,7 +536,9 @@ static VSI_INLINE_API uint8_t fp32_to_fp8_e4m3(float in, const float scale) {

static VSI_INLINE_API uint8_t fp32_to_fp8_e5m2(float in, const float scale) {
float fp8_f32 = in / scale;
int32_t in_val = *((int32_t*)&fp8_f32);
fp32_bit_cast_t fp32_bit_cast;
fp32_bit_cast.val = fp8_f32;
uint32_t in_val = fp32_bit_cast.data;
uint32_t in_sign = (in_val >> (FLOAT_EXPONENT_SIZE + FLOAT_MANTISSA_SIZE)) & 0x1; /* bit 31 is sign */
uint32_t in_exp = (in_val >> FLOAT_MANTISSA_SIZE) & 0xFF; /* bit[30: 24] is exp */
uint32_t in_man = (in_val & 0x7FFFFF); /* low 23 bits is man */
Expand Down Expand Up @@ -561,6 +587,7 @@ static VSI_INLINE_API float fp8_e4m3_to_fp32(uint8_t in, const float scale) {
uint32_t exponentOut = 0;
uint32_t mantissaOut = 0;
uint32_t out_u = 0;
fp32_bit_cast_t fp32_bit_cast;

{
uint32_t signIn;
Expand Down Expand Up @@ -610,7 +637,8 @@ static VSI_INLINE_API float fp8_e4m3_to_fp32(uint8_t in, const float scale) {
}
final:
out_u = signOut << 31 | exponentOut << 23 | mantissaOut;
val_fp32 = *((float*)&out_u);
fp32_bit_cast.data = out_u;
val_fp32 = fp32_bit_cast.val;

return val_fp32 * scale;
} /* fp8_e4m3_to_fp32() */
Expand All @@ -621,6 +649,7 @@ static VSI_INLINE_API float fp8_e5m2_to_fp32(int8_t in, const float scale) {
uint32_t exponentOut = 0;
uint32_t mantissaOut = 0;
uint32_t out_u = 0;
fp32_bit_cast_t fp32_bit_cast;

{
uint32_t signIn;
Expand Down Expand Up @@ -670,7 +699,8 @@ static VSI_INLINE_API float fp8_e5m2_to_fp32(int8_t in, const float scale) {
}
final:
out_u = signOut << 31 | exponentOut << 23 | mantissaOut;
val_fp32 = *((float*)&out_u);
fp32_bit_cast.data = out_u;
val_fp32 = fp32_bit_cast.val;
return val_fp32 * scale;
} /* fp8_e5m2_to_fp32() */

Expand Down
2 changes: 0 additions & 2 deletions src/tim/vx/internal/include/vsi_nn_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ typedef struct _vsi_nn_hw_config_t
{
char target_name[VSI_NN_MAX_TARGET_NAME];
vsi_nn_hw_evis_t evis;
#if VX_HARDWARE_CAPS_PARAMS_EXT_SUPPORT
uint32_t subGroupSize;
#endif
uint32_t use_40bits_va;
uint32_t support_stream_processor;
uint32_t sp_exec_count;
Expand Down
4 changes: 4 additions & 0 deletions src/tim/vx/internal/include/vsi_nn_node_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
#include "ops/vsi_nn_op_resize_3d.h"
#include "ops/vsi_nn_op_reducel2.h"
#include "ops/vsi_nn_op_crop_and_resize.h"
#include "ops/vsi_nn_op_rmsnorm.h"
#include "ops/vsi_nn_op_shape.h"
/* custom node head define define */
#include "custom/vsi_nn_custom_node_type.h"
#include "ops/vsi_nn_op_inverse_sigmoid.h"
Expand Down Expand Up @@ -408,6 +410,8 @@ typedef union _vsi_nn_nn_param
vsi_nn_resize_3d_param resize_3d;
vsi_nn_reducel2_param reducel2;
vsi_nn_crop_and_resize_param crop_and_resize;
vsi_nn_rmsnorm_param rmsnorm;
vsi_nn_shape_param shape;
void* client_param;

/* custom node data struct define */
Expand Down
2 changes: 1 addition & 1 deletion src/tim/vx/internal/include/vsi_nn_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C"{

#define VSI_NN_VERSION_MAJOR 1
#define VSI_NN_VERSION_MINOR 2
#define VSI_NN_VERSION_PATCH 2
#define VSI_NN_VERSION_PATCH 6
#define VSI_NN_VERSION \
(VSI_NN_VERSION_MAJOR * 10000 + VSI_NN_VERSION_MINOR * 100 + VSI_NN_VERSION_PATCH)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static vsi_nn_kernel_node_t _setup
vsi_status status = VSI_FAILURE;
vsi_nn_kernel_node_param_t node_params[_TINY_YOLOV4_POSTPROCESS_CONFIDENCE_PARAM_NUM];
vsi_nn_kernel_node_t node = NULL;
vsi_size_t shape[2][VSI_NN_MAX_DIM_NUM] = { 0 };
vsi_size_t shape[2][VSI_NN_MAX_DIM_NUM] = { { 0 } };
vsi_nn_tensor_t* reshape_tensors[2] = { NULL };

VSI_UNREFERENCED(params);
Expand Down
Loading

0 comments on commit 3b80968

Please sign in to comment.