From 5589bc875dc4971e25d028b8e2dce22ccc73c1ec Mon Sep 17 00:00:00 2001 From: Mamatha N Hosmane/RISC-V IP /SRI-Bangalore/Staff Engineer/Samsung Electronics Date: Mon, 23 Sep 2024 17:38:08 +0530 Subject: [PATCH 1/3] We are able to reproduce the issue https://github.com/mpeg5/xeve/issues/108 with the following build command: ``` cmake -DCMAKE_C_FLAGS="-mavx" .. make ``` Encode command: ``` ./xeve_app -i -o ``` Error message: ``` XEVE: eXtra-fast Essential Video Encoder Segmentation fault ``` On passing "-mavx2" as C_Flag (cmake -DCMAKE_C_FLAGS="-mavx" ..), it sets the flag for all files in the project, including the source C files. So, the compiler is creating optimizations which are not handled properly resulting in a segmentation fault. This PR fixes the issue by updating the CmakeLists.txt files. --- src_base/CMakeLists.txt | 3 +++ src_main/CMakeLists.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src_base/CMakeLists.txt b/src_base/CMakeLists.txt index 248af75..c172e05 100644 --- a/src_base/CMakeLists.txt +++ b/src_base/CMakeLists.txt @@ -86,6 +86,9 @@ elseif( UNIX OR MINGW ) if("${ARM}" STREQUAL "FALSE") set_property( SOURCE ${SSE} APPEND PROPERTY COMPILE_FLAGS "-msse4.1" ) set_property( SOURCE ${AVX} APPEND PROPERTY COMPILE_FLAGS " -mavx2" ) + + set_property( SOURCE ${LIB_BASE_SRC} APPEND PROPERTY COMPILE_FLAGS " -mno-avx2 -mno-avx" ) + endif() set_target_properties(${LIB_NAME_BASE}_dynamic PROPERTIES FOLDER lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) diff --git a/src_main/CMakeLists.txt b/src_main/CMakeLists.txt index 366a3c3..bea7637 100644 --- a/src_main/CMakeLists.txt +++ b/src_main/CMakeLists.txt @@ -97,6 +97,9 @@ elseif( UNIX OR MINGW ) if("${ARM}" STREQUAL "FALSE") set_property( SOURCE ${SSE} APPEND PROPERTY COMPILE_FLAGS "-msse4.1" ) set_property( SOURCE ${AVX} APPEND PROPERTY COMPILE_FLAGS " -mavx2" ) + + set_property( SOURCE ${LIB_BASE_SRC} APPEND PROPERTY COMPILE_FLAGS " -mno-avx2 -mno-avx" ) + set_property( SOURCE ${LIB_MAIN_SRC} APPEND PROPERTY COMPILE_FLAGS " -mno-avx2 -mno-avx" ) endif() set_target_properties(${LIB_NAME}_dynamic PROPERTIES FOLDER lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) From c059d6e3f29ce633c77285cb0969f5d12d09836f Mon Sep 17 00:00:00 2001 From: Neeraj Gadgil Date: Wed, 20 Nov 2024 19:04:05 +0530 Subject: [PATCH 2/3] Remove seg fault with -mavx in Linux OS * Shuffle struct member declaration in XEVE_CTX * Reorder instructions to introduce latency within `pintra_init_mt()` and `pinter_init_mt()` functions --- src_base/xeve_pinter.c | 21 ++++++++++----------- src_base/xeve_pintra.c | 5 ++++- src_base/xeve_type.h | 9 +++++---- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src_base/xeve_pinter.c b/src_base/xeve_pinter.c index 17bd3b5..8068d8f 100644 --- a/src_base/xeve_pinter.c +++ b/src_base/xeve_pinter.c @@ -1518,6 +1518,9 @@ static int pinter_init_mt(XEVE_CTX *ctx, int thread_idx) int size; pic = pi->pic_o = PIC_ORIG(ctx); + pi->refp = ctx->refp; + pi->slice_type = ctx->slice_type; + pi->o[Y_C] = pic->y; pi->o[U_C] = pic->u; pi->o[V_C] = pic->v; @@ -1527,6 +1530,12 @@ static int pinter_init_mt(XEVE_CTX *ctx, int thread_idx) pi->s_o[V_C] = pic->s_c; pic = pi->pic_m = PIC_MODE(ctx); + pi->map_mv = ctx->map_mv; + + pi->w_scu = ctx->w_scu; + size = sizeof(pel) * MAX_CU_DIM; + xeve_mset(pi->pred_buf, 0, size); + pi->m[Y_C] = pic->y; pi->m[U_C] = pic->u; pi->m[V_C] = pic->v; @@ -1534,17 +1543,7 @@ static int pinter_init_mt(XEVE_CTX *ctx, int thread_idx) pi->s_m[Y_C] = pic->s_l; pi->s_m[U_C] = pic->s_c; pi->s_m[V_C] = pic->s_c; - - pi->refp = ctx->refp; - pi->slice_type = ctx->slice_type; - - pi->map_mv = ctx->map_mv; - - pi->w_scu = ctx->w_scu; - - size = sizeof(pel) * MAX_CU_DIM; - xeve_mset(pi->pred_buf, 0, size); - + size = sizeof(s8) * PRED_NUM * REFP_NUM; xeve_mset(pi->refi, 0, size); diff --git a/src_base/xeve_pintra.c b/src_base/xeve_pintra.c index b48cb4e..461fdf0 100644 --- a/src_base/xeve_pintra.c +++ b/src_base/xeve_pintra.c @@ -39,6 +39,10 @@ int xeve_pintra_init_mt(XEVE_CTX * ctx, int tile_idx) pi = &ctx->pintra[tile_idx]; pic = pi->pic_o = PIC_ORIG(ctx); + + xeve_mset(&pi->slice_type, 0, sizeof(int)); + pi->slice_type = ctx->slice_type; + pi->o[Y_C] = pic->y; pi->o[U_C] = pic->u; pi->o[V_C] = pic->v; @@ -56,7 +60,6 @@ int xeve_pintra_init_mt(XEVE_CTX * ctx, int tile_idx) pi->s_m[U_C] = pic->s_c; pi->s_m[V_C] = pic->s_c; - pi->slice_type = ctx->slice_type; return XEVE_OK; } diff --git a/src_base/xeve_type.h b/src_base/xeve_type.h index 8cf5d98..33a7b1f 100644 --- a/src_base/xeve_type.h +++ b/src_base/xeve_type.h @@ -882,8 +882,6 @@ struct _XEVE_CTX /* cu data for current LCU */ XEVE_CU_DATA * map_cu_data; /* map for encoded motion vectors in SCU */ - s16 (* map_mv)[REFP_NUM][MV_D]; - /* map for encoded motion vectors in SCU */ s16 (* map_unrefined_mv)[REFP_NUM][MV_D]; /* map for reference indices */ s8 (* map_refi)[REFP_NUM]; @@ -953,12 +951,10 @@ struct _XEVE_CTX /* intra prediction functions */ int (*fn_pintra_init_mt)(XEVE_CTX * ctx, int tile_idx); int (*fn_pintra_init_lcu)(XEVE_CTX * ctx, XEVE_CORE * core); - double(*fn_pintra_analyze_cu)(XEVE_CTX *ctx, XEVE_CORE *core, int x, int y, int log2_cuw, int log2_cuh, XEVE_MODE *mi, s16 coef[N_C][MAX_CU_DIM], pel *rec[N_C], int s_rec[N_C]); int (*fn_pintra_set_complexity)(XEVE_CTX * ctx, int complexity); /* inter prediction functions */ int (*fn_pinter_init_mt)(XEVE_CTX * ctx, int tile_idx); int (*fn_pinter_init_lcu)(XEVE_CTX * ctx, XEVE_CORE * core); - double(*fn_pinter_analyze_cu)(XEVE_CTX *ctx, XEVE_CORE *core, int x, int y, int log2_cuw, int log2_cuh, XEVE_MODE *mi, s16 coef[N_C][MAX_CU_DIM], pel *rec[N_C], int s_rec[N_C]); int (*fn_pinter_set_complexity)(XEVE_CTX * ctx, int complexity); int (*fn_loop_filter)(XEVE_CTX * ctx, XEVE_CORE * core); /* entropy coding functions */ @@ -982,6 +978,9 @@ struct _XEVE_CTX void (*fn_deblock_tree)(XEVE_CTX * ctx, XEVE_PIC * pic, int x, int y, int cuw, int cuh, int cud, int cup, int is_hor_edge, TREE_CONS tree_cons, XEVE_CORE * core, int boundary_filtering); void (*fn_pic_flt)(XEVE_CTX * ctx, XEVE_IMGB * img); const XEVE_ITXB(*fn_itxb)[MAX_TR_LOG2]; + /* intra/inter analyze functions*/ + double(*fn_pintra_analyze_cu)(XEVE_CTX *ctx, XEVE_CORE *core, int x, int y, int log2_cuw, int log2_cuh, XEVE_MODE *mi, s16 coef[N_C][MAX_CU_DIM], pel *rec[N_C], int s_rec[N_C]); + double(*fn_pinter_analyze_cu)(XEVE_CTX *ctx, XEVE_CORE *core, int x, int y, int log2_cuw, int log2_cuh, XEVE_MODE *mi, s16 coef[N_C][MAX_CU_DIM], pel *rec[N_C], int s_rec[N_C]); /* platform specific data, if needed */ void * pf; @@ -996,6 +995,8 @@ struct _XEVE_CTX u8 tile_to_slice_map[XEVE_MAX_NUM_TILES_COL * XEVE_MAX_NUM_TILES_ROW]; u8 tiles_in_slice[XEVE_MAX_NUM_TILES_COL * XEVE_MAX_NUM_TILES_ROW]; u8 tile_order[XEVE_MAX_NUM_TILES_COL * XEVE_MAX_NUM_TILES_ROW]; + /* map for encoded motion vectors in SCU */ + s16 (* map_mv)[REFP_NUM][MV_D]; }; From 7b5cb21268ac1238cd53e8f3fe630bd5916a302e Mon Sep 17 00:00:00 2001 From: Neeraj Gadgil Date: Wed, 20 Nov 2024 19:15:35 +0530 Subject: [PATCH 3/3] Removed -mno-avx flags from CMakeLists --- src_base/CMakeLists.txt | 3 --- src_main/CMakeLists.txt | 3 --- 2 files changed, 6 deletions(-) diff --git a/src_base/CMakeLists.txt b/src_base/CMakeLists.txt index c172e05..248af75 100644 --- a/src_base/CMakeLists.txt +++ b/src_base/CMakeLists.txt @@ -86,9 +86,6 @@ elseif( UNIX OR MINGW ) if("${ARM}" STREQUAL "FALSE") set_property( SOURCE ${SSE} APPEND PROPERTY COMPILE_FLAGS "-msse4.1" ) set_property( SOURCE ${AVX} APPEND PROPERTY COMPILE_FLAGS " -mavx2" ) - - set_property( SOURCE ${LIB_BASE_SRC} APPEND PROPERTY COMPILE_FLAGS " -mno-avx2 -mno-avx" ) - endif() set_target_properties(${LIB_NAME_BASE}_dynamic PROPERTIES FOLDER lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) diff --git a/src_main/CMakeLists.txt b/src_main/CMakeLists.txt index bea7637..366a3c3 100644 --- a/src_main/CMakeLists.txt +++ b/src_main/CMakeLists.txt @@ -97,9 +97,6 @@ elseif( UNIX OR MINGW ) if("${ARM}" STREQUAL "FALSE") set_property( SOURCE ${SSE} APPEND PROPERTY COMPILE_FLAGS "-msse4.1" ) set_property( SOURCE ${AVX} APPEND PROPERTY COMPILE_FLAGS " -mavx2" ) - - set_property( SOURCE ${LIB_BASE_SRC} APPEND PROPERTY COMPILE_FLAGS " -mno-avx2 -mno-avx" ) - set_property( SOURCE ${LIB_MAIN_SRC} APPEND PROPERTY COMPILE_FLAGS " -mno-avx2 -mno-avx" ) endif() set_target_properties(${LIB_NAME}_dynamic PROPERTIES FOLDER lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)