Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
807 changes: 504 additions & 303 deletions Jenkinsfile

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(lib_voice_examples)

if(DEFINED XCORE_TARGET)
set(XCORE_TARGET ${XCORE_TARGET})
else()
set(XCORE_TARGET XK-EVK-XU316)
endif()

add_subdirectory(app_aec)
add_subdirectory(app_vnr)

Expand Down
6 changes: 5 additions & 1 deletion examples/app_aec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_aec)

set(APP_HW_TARGET XK-EVK-XU316)
if(DEFINED XCORE_TARGET)
set(APP_HW_TARGET ${XCORE_TARGET})
else()
set(APP_HW_TARGET XK-EVK-XU316)
endif()

if(NOT BUILD_NATIVE)
set(APP_COMPILER_FLAGS_1th -report -DAEC_THREADS=1)
Expand Down
7 changes: 6 additions & 1 deletion examples/app_pipeline/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_pipeline)

set(APP_HW_TARGET XK-EVK-XU316)
if(DEFINED XCORE_TARGET)
set(APP_HW_TARGET ${XCORE_TARGET})
else()
set(APP_HW_TARGET XK-EVK-XU316)
endif()

set(APP_COMPILER_FLAGS_std_arch -report)
set(APP_COMPILER_FLAGS_alt_arch -report -DALT_ARCH_MODE=1)

Expand Down
58 changes: 40 additions & 18 deletions examples/app_pipeline/src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
#include <xcore/channel.h>
#include <xcore/chanend.h>
#include <xcore/channel_transaction.h>
#include <xcore/parallel.h>

extern void pipeline_tile0_init(pipeline_state_tile0_t *state);
extern void pipeline_tile1_init(pipeline_state_tile1_t *state);
DECLARE_JOB(pipeline_wrapper_thread0, (chanend_t));
DECLARE_JOB(pipeline_wrapper_thread1, (chanend_t));

extern void pipeline_process_frame_tile0(pipeline_state_tile0_t *state,
extern void pipeline_thread0_init(pipeline_state_thread0_t *state);
extern void pipeline_thread1_init(pipeline_state_thread1_t *state);

extern void pipeline_process_frame_thread0(pipeline_state_thread0_t *state,
int32_t (*input_y_data)[AP_FRAME_ADVANCE],
int32_t (*input_x_data)[AP_FRAME_ADVANCE],
int32_t (*output_data)[AP_FRAME_ADVANCE],
pipeline_metadata_t *md_output);

extern void pipeline_process_frame_tile1(pipeline_state_tile1_t *state, pipeline_metadata_t *md_input,
extern void pipeline_process_frame_thread1(pipeline_state_thread1_t *state, pipeline_metadata_t *md_input,
int32_t (*input_data)[AP_FRAME_ADVANCE],
int32_t output_data[AP_FRAME_ADVANCE]);

Expand All @@ -39,43 +43,61 @@ static inline void consumer(int32_t frame_y[AP_FRAME_ADVANCE]) {
printf("frame done\n");
}

void pipeline_wrapper_tile0(chanend_t c_pcm_out)
void pipeline_wrapper_thread0(chanend_t c_pcm_out)
{
int32_t DWORD_ALIGNED frame_y[AP_MAX_Y_CHANNELS][AP_FRAME_ADVANCE];
int32_t DWORD_ALIGNED frame_x[AP_MAX_X_CHANNELS][AP_FRAME_ADVANCE];

// Initialise pipeline
pipeline_state_tile0_t DWORD_ALIGNED pipeline_tile0_state;
pipeline_tile0_init(&pipeline_tile0_state);
pipeline_state_thread0_t DWORD_ALIGNED pipeline_thread0_state;
pipeline_thread0_init(&pipeline_thread0_state);

for(unsigned b = 0; b < 5; b++){
producer(frame_y, frame_x);

pipeline_metadata_t md;
int32_t DWORD_ALIGNED tile0_output[AP_MAX_Y_CHANNELS][AP_FRAME_ADVANCE];
pipeline_process_frame_tile0(&pipeline_tile0_state, frame_y, frame_x, tile0_output, &md);
int32_t DWORD_ALIGNED thread0_output[AP_MAX_Y_CHANNELS][AP_FRAME_ADVANCE];
pipeline_process_frame_thread0(&pipeline_thread0_state, frame_y, frame_x, thread0_output, &md);

// Send data to process to the other tile and receive processed output back
//Transfer to other tile
// Send data to process to the other thread and receive processed output back
//Transfer to other thread
chan_out_byte(c_pcm_out, 1);
chan_out_buf_byte(c_pcm_out, (uint8_t*)&md, sizeof(pipeline_metadata_t));
chan_out_buf_word(c_pcm_out, (uint32_t*)&tile0_output[0][0], (AP_MAX_Y_CHANNELS * AP_FRAME_ADVANCE));
chan_out_buf_word(c_pcm_out, (uint32_t*)&thread0_output[0][0], (AP_MAX_Y_CHANNELS * AP_FRAME_ADVANCE));
}
chan_out_byte(c_pcm_out, 0);
}

void pipeline_wrapper_tile1(chanend_t c_pcm_in)
void pipeline_wrapper_thread1(chanend_t c_pcm_in)
{
pipeline_state_tile1_t DWORD_ALIGNED pipeline_tile1_state;
pipeline_state_thread1_t DWORD_ALIGNED pipeline_thread1_state;
pipeline_metadata_t md;
int32_t DWORD_ALIGNED tile0_output[AP_MAX_Y_CHANNELS][AP_FRAME_ADVANCE];
int32_t DWORD_ALIGNED thread0_output[AP_MAX_Y_CHANNELS][AP_FRAME_ADVANCE];
int32_t DWORD_ALIGNED pipeline_output[AP_FRAME_ADVANCE];

pipeline_tile1_init(&pipeline_tile1_state);
pipeline_thread1_init(&pipeline_thread1_state);
while(1) {
uint8_t status = chan_in_byte(c_pcm_in);
if (!status) break;
chan_in_buf_byte(c_pcm_in, (uint8_t*)&md, sizeof(pipeline_metadata_t));
chan_in_buf_word(c_pcm_in, (uint32_t*)&tile0_output[0][0], (AP_MAX_Y_CHANNELS * AP_FRAME_ADVANCE));
chan_in_buf_word(c_pcm_in, (uint32_t*)&thread0_output[0][0], (AP_MAX_Y_CHANNELS * AP_FRAME_ADVANCE));

pipeline_process_frame_tile1(&pipeline_tile1_state, &md, tile0_output, pipeline_output);
pipeline_process_frame_thread1(&pipeline_thread1_state, &md, thread0_output, pipeline_output);

consumer(pipeline_output);
}
}

// producer -> stage1 -> (thread0_to_thread1) -> stage2 -> stage3 -> stage4 -> consumer
// producer and stage1 run on thread0
// stage2, stage3, stage4 and consumer run on thread1

int main() {
channel_t ch = chan_alloc();
PAR_JOBS(
PJOB(pipeline_wrapper_thread0, (ch.end_a)),
PJOB(pipeline_wrapper_thread1, (ch.end_b))
);
chan_free(ch);
return 0;
}
32 changes: 0 additions & 32 deletions examples/app_pipeline/src/main.xc

This file was deleted.

12 changes: 6 additions & 6 deletions examples/app_pipeline/src/pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include "pipeline_state.h"

void pipeline_tile0_init(pipeline_state_tile0_t *state) {
memset(state, 0, sizeof(pipeline_state_tile0_t));
void pipeline_thread0_init(pipeline_state_thread0_t *state) {
memset(state, 0, sizeof(pipeline_state_thread0_t));

// Initialise AEC, DE, ADEC stages
aec_conf_t aec_de_mode_conf, aec_non_de_mode_conf;
Expand Down Expand Up @@ -44,8 +44,8 @@ void pipeline_tile0_init(pipeline_state_tile0_t *state) {
stage1_init(&state->stage_1_state, &aec_de_mode_conf, &aec_non_de_mode_conf, &adec_conf);
}

void pipeline_tile1_init(pipeline_state_tile1_t *state) {
memset(state, 0, sizeof(pipeline_state_tile1_t));
void pipeline_thread1_init(pipeline_state_thread1_t *state) {
memset(state, 0, sizeof(pipeline_state_thread1_t));

// Initialise IC, VNR
ic_init(&state->ic_state);
Expand All @@ -58,7 +58,7 @@ void pipeline_tile1_init(pipeline_state_tile1_t *state) {
agc_init(&state->agc_state, &agc_conf_asr);
}

void pipeline_process_frame_tile0(pipeline_state_tile0_t *state,
void pipeline_process_frame_thread0(pipeline_state_thread0_t *state,
int32_t (*input_y_data)[AP_FRAME_ADVANCE],
int32_t (*input_x_data)[AP_FRAME_ADVANCE],
int32_t (*output_data)[AP_FRAME_ADVANCE],
Expand All @@ -79,7 +79,7 @@ void pipeline_process_frame_tile0(pipeline_state_tile0_t *state,
memcpy(md_output, &md, sizeof(pipeline_metadata_t));
}

void pipeline_process_frame_tile1(pipeline_state_tile1_t *state, pipeline_metadata_t *md_input,
void pipeline_process_frame_thread1(pipeline_state_thread1_t *state, pipeline_metadata_t *md_input,
int32_t (*input_data)[AP_FRAME_ADVANCE],
int32_t output_data[AP_FRAME_ADVANCE])
{
Expand Down
4 changes: 2 additions & 2 deletions examples/app_pipeline/src/pipeline_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef struct {
typedef struct {
// Stage1 - AEC, DE, ADEC
stage1_t DWORD_ALIGNED stage_1_state;
} pipeline_state_tile0_t;
} pipeline_state_thread0_t;

typedef struct {
// IC, VNR
Expand All @@ -26,6 +26,6 @@ typedef struct {
ns_state_t DWORD_ALIGNED ns_state;
// AGC
agc_state_t agc_state;
} pipeline_state_tile1_t;
} pipeline_state_thread1_t;

#endif
6 changes: 5 additions & 1 deletion examples/app_vnr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_vnr)

set(APP_HW_TARGET XK-EVK-XU316)
if(DEFINED XCORE_TARGET)
set(APP_HW_TARGET ${XCORE_TARGET})
else()
set(APP_HW_TARGET XK-EVK-XU316)
endif()

if(NOT BUILD_NATIVE)
set(APP_COMPILER_FLAGS -report)
Expand Down
21 changes: 11 additions & 10 deletions lib_voice/lib_build_info.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
set(LIB_NAME lib_voice)
set(LIB_VERSION 1.0.0)
set(LIB_DEPENDENT_MODULES "lib_xcore_math(2.4.1)")
set(LIB_DEPENDENT_MODULES "lib_xcore_math(lib_voice_fixes)")

set(LIB_COMPILER_FLAGS
-g
-Os
-DHEADROOM_CHECK=0)

if(BUILD_NATIVE)
list(APPEND LIB_COMPILER_FLAGS
-D__xtflm_conf_h_exists__
-DNN_USE_REF
)
endif()
# if(BUILD_NATIVE)
# list(APPEND LIB_COMPILER_FLAGS
# -D__xtflm_conf_h_exists__
# -DNN_USE_REF
# )
# endif()

set(LIB_CXX_SRCS "")
set(lib_ASM_SRCS "")
include(${CMAKE_CURRENT_LIST_DIR}/vnr_model.cmake)
file(RELATIVE_PATH MODEL_OUT_DIR_REL ${CMAKE_CURRENT_LIST_DIR} ${MODEL_OUT_DIR})

Expand Down Expand Up @@ -70,7 +71,7 @@ foreach(target ${APP_BUILD_TARGETS})

# Link aitools with the targets
target_link_libraries(${target} PRIVATE tflite_micro)
if(BUILD_NATIVE)
target_compile_features(${target} PRIVATE cxx_std_11)
endif()
# if(BUILD_NATIVE)
# target_compile_features(${target} PRIVATE cxx_std_11)
# endif()
endforeach()
4 changes: 2 additions & 2 deletions lib_voice/src/aec/aec_process_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum e_fft {Y_FFT, X_FFT, ERROR_FFT};
#define REF_ACTIVE_THRESHOLD_dB (-60) // Reference input level above which it is considered active
#define REF_ACTIVE_THRESHOLD f64_to_float_s32(pow(10, REF_ACTIVE_THRESHOLD_dB/20.0))

#ifdef __XS3A__
#if defined(__XS3A__) || defined(__VX4B__)
#include <xcore/parallel.h>
DECLARE_JOB(calc_time_domain_ema_energy_task, (const aec_par_tasks_and_channels_t*, aec_filter_state_t *, int32_t*, int, int, enum e_td_ema));
DECLARE_JOB(fft_task, (const aec_par_tasks_and_channels_t*, aec_filter_state_t*, aec_filter_state_t*, int, int, enum e_fft));
Expand Down Expand Up @@ -273,7 +273,7 @@ void filter_adapt_task(const aec_par_tasks_t *s, aec_filter_state_t *main_state,
}
}

#ifdef __XS3A__
#if defined(__XS3A__) || defined(__VX4B__)

#define PAR_THREADS_PJOBS(FUNC, ARR, NUM_THREADS, ...) \
do { \
Expand Down
13 changes: 10 additions & 3 deletions lib_voice/vnr_model.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ execute_process(
)

# Add tflite_micro
set(XMOS_AITOOLSLIB_PATH_CMAKE "${XMOS_AITOOLSLIB_PATH}/buildfiles/aitoolslib.cmake")
if (APP_BUILD_ARCH STREQUAL "xs3a")
set(XMOS_AITOOLSLIB_PATH_CMAKE "${XMOS_AITOOLSLIB_PATH}/buildfiles/aitoolslib.cmake")
set(MODEL_TH 0.50)
set(ARCH_STR "XS3A")
elseif (APP_BUILD_ARCH STREQUAL "vx4b")
set(XMOS_AITOOLSLIB_PATH_CMAKE "${CMAKE_CURRENT_LIST_DIR}/../new_ai_tools/libxtflitemicro.cmake")
set(MODEL_TH 2)
set(ARCH_STR "VX4A")
endif()

if(XMOS_AITOOLSLIB_PATH STREQUAL "")
message(FATAL_ERROR "Path to XMOS AI tools NOT found")
Expand All @@ -38,12 +46,11 @@ set(MODEL_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/src.autogen/vnr_model/)
set(MODEL_IN_PATH ${CMAKE_CURRENT_LIST_DIR}/src/vnr/model/trained_model.tflite)
set(MODEL_OUT_PATH ${MODEL_OUT_DIR}/trained_model_xcore.tflite)
set(MODEL_N_CORES 1)
set(MODEL_TH 0.50)

file(MAKE_DIRECTORY ${MODEL_OUT_DIR})

add_custom_command(
OUTPUT ${MODEL_OUT_PATH}.cpp ${MODEL_OUT_PATH}.h ${MODEL_OUT_PATH}
COMMAND xcore-opt ${MODEL_IN_PATH} -tc ${MODEL_N_CORES} -o ${MODEL_OUT_PATH} --xcore-conv-err-threshold ${MODEL_TH}
COMMAND xcore-opt ${MODEL_IN_PATH} -tc ${MODEL_N_CORES} -o ${MODEL_OUT_PATH} --xcore-conv-err-threshold ${MODEL_TH} --xcore-target-arch=${ARCH_STR}
DEPENDS ${MODEL_IN_PATH}
)
18 changes: 18 additions & 0 deletions new_ai_tools/libxtflitemicro.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(XMOS_AITOOLSLIB_DEFINITIONS
"TF_LITE_STATIC_MEMORY"
"TF_LITE_STRIP_ERROR_STRINGS"
"XCORE"
"NO_INTERPRETER"
)

set(XMOS_AITOOLSLIB_LIBRARIES "${CMAKE_CURRENT_LIST_DIR}/libxtflitemicro_vx4a.a")
set(XMOS_AITOOLSLIB_INCLUDES "${XMOS_AITOOLSLIB_PATH}/include")


# list(APPEND APP_COMPILER_FLAGS
# -Wfptrgroup
# -ffunction-sections
# -fdata-sections
# -Wl,--gc-sections
# -D__VX4A__=1
# )
Binary file added new_ai_tools/libxtflitemicro_vx4a.a
Binary file not shown.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# python_version 3.11
# pip_version 25.*

xmos-ai-tools==1.4.2
xmos-ai-tools==1.4.3.dev18
7 changes: 6 additions & 1 deletion tests/lib_aec/aec_unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(aec_unit_tests)

set(APP_HW_TARGET XK-EVK-XU316)
if(DEFINED XCORE_TARGET)
set(APP_HW_TARGET ${XCORE_TARGET})
else()
set(APP_HW_TARGET XK-EVK-XU316)
endif()

set(XMOS_SANDBOX_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../../)
include(${XMOS_SANDBOX_DIR}/lib_voice/tests/etc/build_options.cmake)

Expand Down
Loading