Skip to content

Commit

Permalink
pre/postprocessor: unified subsample reporting
Browse files Browse the repository at this point in the history
\+ avoid potential division by zero in ther former fast version info
  • Loading branch information
MartinPulec committed Apr 9, 2024
1 parent b2bf09c commit 44ebd07
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 4 additions & 8 deletions src/gpujpeg_postprocessor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,9 @@ gpujpeg_preprocessor_select_decode_kernel(struct gpujpeg_coder* coder)

#define RETURN_KERNEL_IF(PIXEL_FORMAT, COLOR, COMP_COUNT, P1, P2, P3, P4, P5, P6, P7, P8) \
if ( sampling_factor == gpujpeg_make_sampling_factor(COMP_COUNT, P1, P2, P3, P4, P5, P6, P7, P8) ) { \
int max_h = max(P1, max(P3, P5)); \
int max_v = max(P2, max(P4, P6)); \
if ( coder->param.verbose >= 1 ) { \
printf("Using faster kernel for postprocessor (precompiled %dx%d, %dx%d, %dx%d).\n", max_h / P1, max_v / P2, max_h / P3, max_v / P4, max_h / P5, max_v / P6); \
print_kernel_configuration( \
"Using faster kernel for postprocessor (precompiled %dx%d, %dx%d, %dx%d, %dx%d).\n"); \
} \
RETURN_KERNEL_SWITCH(PIXEL_FORMAT, COLOR, P1, P2, P3, P4, P5, P6, P7, P8) \
}
Expand All @@ -267,11 +266,8 @@ gpujpeg_preprocessor_select_decode_kernel(struct gpujpeg_coder* coder)
else RETURN_KERNEL_IF(PIXEL_FORMAT, COLOR, 3, 1, 1, 2, 1, 2, 1, 0, 0) /* 4:2:2 */ \
else { \
if ( coder->param.verbose >= 0 ) { \
printf("Using slower kernel for postprocessor (dynamic %dx%d, %dx%d, %dx%d, %dx%d).\n", \
coder->component[0].sampling_factor.horizontal, coder->component[0].sampling_factor.vertical, \
coder->component[1].sampling_factor.horizontal, coder->component[1].sampling_factor.vertical, \
coder->component[2].sampling_factor.horizontal, coder->component[2].sampling_factor.vertical, \
coder->component[3].sampling_factor.horizontal, coder->component[3].sampling_factor.vertical); \
print_kernel_configuration( \
"Using slower kernel for postprocessor (dynamic %dx%d, %dx%d, %dx%d, %dx%d).\n"); \
} \
RETURN_KERNEL_SWITCH(PIXEL_FORMAT, COLOR, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC) \
} \
Expand Down
12 changes: 4 additions & 8 deletions src/gpujpeg_preprocessor.cu
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,9 @@ gpujpeg_preprocessor_select_encode_kernel(struct gpujpeg_coder* coder)

#define RETURN_KERNEL_IF(PIXEL_FORMAT, COLOR, COMP_COUNT, P1, P2, P3, P4, P5, P6, P7, P8) \
if ( sampling_factor == gpujpeg_make_sampling_factor(COMP_COUNT, P1, P2, P3, P4, P5, P6, P7, P8) ) { \
int max_h = max(P1, max(P3, P5)); \
int max_v = max(P2, max(P4, P6)); \
if ( coder->param.verbose >= 1 ) { \
printf("Using faster kernel for preprocessor (precompiled %dx%d, %dx%d, %dx%d).\n", max_h / P1, max_v / P2, max_h / P3, max_v / P4, max_h / P5, max_v / P6); \
print_kernel_configuration( \
"Using faster kernel for preprocessor (precompiled %dx%d, %dx%d, %dx%d, %dx%d).\n"); \
} \
RETURN_KERNEL_SWITCH(PIXEL_FORMAT, COLOR, P1, P2, P3, P4, P5, P6, P7, P8) \
}
Expand All @@ -246,11 +245,8 @@ gpujpeg_preprocessor_select_encode_kernel(struct gpujpeg_coder* coder)
else RETURN_KERNEL_IF(PIXEL_FORMAT, COLOR, 3, 1, 1, 2, 1, 2, 1, 0, 0) /* 4:2:2 */ \
else { \
if ( coder->param.verbose >= 0 ) { \
printf("Using slower kernel for preprocessor (dynamic %dx%d, %dx%d, %dx%d, %dx%d).\n", \
coder->component[0].sampling_factor.horizontal, coder->component[0].sampling_factor.vertical, \
coder->component[1].sampling_factor.horizontal, coder->component[1].sampling_factor.vertical, \
coder->component[2].sampling_factor.horizontal, coder->component[2].sampling_factor.vertical, \
coder->component[3].sampling_factor.horizontal, coder->component[3].sampling_factor.vertical); \
print_kernel_configuration( \
"Using slower kernel for preprocessor (dynamic %dx%d, %dx%d, %dx%d, %dx%d).\n"); \
} \
RETURN_KERNEL_SWITCH(PIXEL_FORMAT, COLOR, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, \
GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC, GPUJPEG_DYNAMIC) \
Expand Down
6 changes: 6 additions & 0 deletions src/gpujpeg_preprocessor_common.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ gpujpeg_preprocessor_make_sampling_factor_i(int comp_count, int numerator_h, int
comp4_h != 0 ? numerator_h / comp4_h : 0, comp4_v != 0 ? numerator_v / comp4_v : 0);
}

#define print_kernel_configuration(msg) \
printf(msg, coder->component[0].sampling_factor.horizontal, coder->component[0].sampling_factor.vertical, \
coder->component[1].sampling_factor.horizontal, coder->component[1].sampling_factor.vertical, \
coder->component[2].sampling_factor.horizontal, coder->component[2].sampling_factor.vertical, \
coder->component[3].sampling_factor.horizontal, coder->component[3].sampling_factor.vertical)

/* vi: set expandtab sw=4: */

0 comments on commit 44ebd07

Please sign in to comment.