Skip to content

Added vpu optimized mean int8#221

Open
LeslieXMOS wants to merge 1 commit into
xmos:developfrom
LeslieXMOS:feature/mean8_xs3_vpu
Open

Added vpu optimized mean int8#221
LeslieXMOS wants to merge 1 commit into
xmos:developfrom
LeslieXMOS:feature/mean8_xs3_vpu

Conversation

@LeslieXMOS

Copy link
Copy Markdown
Contributor

Accelerate mean_int8 when running in xs3 instruction with VPU

mean_int8 will use mean_in8_mean when

  • the mean_axis is the last axis, which means end_dim_size =1
  • mean_dim_size needs to be divided by 4 (word alignment needed by xs3 VPU)

Inside mean_int8 it will use s32_to_f32 from xcore_math to quickly convert int32_t data to float.

This PR also provided a 2x faster asm for rounding float to int8_t

Comment thread lib_nn/src/asm/mean8.S
Comment on lines +46 to +52
stw r4, sp[NSTACKWORDS-1]
stw r5, sp[NSTACKWORDS-2]
stw r6, sp[NSTACKWORDS-3]
stw r7, sp[NSTACKWORDS-4]
stw r8, sp[NSTACKWORDS-5]
stw r9, sp[NSTACKWORDS-6]
stw r10, sp[NSTACKWORDS-7]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use some stds to save a bit of time.

Comment thread lib_nn/src/asm/mean8.S
#define vpu_buffer r4
#define mean_cnt r5

ldw vpu_buffer, sp[NSTACKWORDS+1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is mean to find a base address within the current stack frame - should it be an ldaw?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This load the vpu_buffer pointer address passes as the fourth argument of the function.
The vpu buffer is created outside the function, not live within the stack of this function.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, I see. (Sorry, I forget it's not RISC-V sometimes - where we have 8 argument registers).

Comment thread lib_nn/src/asm/mean8.S
{ bau r11 ; nop }

.cc_bottom FUNCTION_NAME.function
.set FUNCTION_NAME.nstackwords, NSTACKWORDS+s32_to_f32.nstackwords+round8.nstackwords

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be NSTACKWORDS + (s32_to_f32.nstackwords $M round8.nstackwords) I think (round8 and s32_to_f32 aren't called concurrently.

Comment thread lib_nn/src/asm/mean8.S
.globl FUNCTION_NAME
.align 16
FUNCTION_NAME:
{ dualentsp NSTACKWORDS ; nop }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DUALENTSP_lu6 is usually better unless there's a useful instruction you can packetise - that way it takes a single cycle whichever issue mode the function is entered it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants