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
9 changes: 6 additions & 3 deletions libvmaf/src/feature/cuda/integer_adm/adm_dwt2.cu
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,18 @@ __device__ __forceinline__ void adm_dwt2_8_vert_hori_kernel(const T * d_picture,
break;
}

int32_t accum_lo = 0, accum_hi = 0;
/* normalizing is done for range from(0 to N) to (-N/2 to N/2).
* The low-pass offset goes in first: subtracted last, three
* 16-bit samples of 42456 or more take the sum past INT32_MAX
* on the way. */
int32_t accum_lo = -(params.dwt2_db2_coeffs_lo_sum * v_add_shift);
int32_t accum_hi = 0;
#pragma unroll
for (int i = 0;i< 4;++i) {
accum_lo += filter_lo[i] * u_s[i + 2 * item];
accum_hi += filter_hi[i] * u_s[i + 2 * item];
}

/* normalizing is done for range from(0 to N) to (-N/2 to N/2) */
accum_lo -= params.dwt2_db2_coeffs_lo_sum * v_add_shift;
accum_hi -= params.dwt2_db2_coeffs_hi_sum * v_add_shift;

s_tile[threadIdx.y * v_rows_per_thread + item][threadIdx.x] = make_short2((accum_lo + v_add_shift) >> v_shift, (accum_hi + v_add_shift) >> v_shift);
Expand Down
16 changes: 8 additions & 8 deletions libvmaf/src/feature/integer_adm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2561,15 +2561,15 @@ static void adm_dwt2_16_lo(const uint16_t *src, const adm_dwt_band_t *dst, AdmBu
uint16_t u_s2 = src[ind_y[2][i] * src_stride + j];
uint16_t u_s3 = src[ind_y[3][i] * src_stride + j];

accum = 0;
/* normalizing is done for range from(0 to N) to (-N/2 to N/2).
* The offset goes in first: subtracted last, three 16-bit samples
* of 42456 or more take the sum past INT32_MAX on the way. */
accum = -((int32_t)dwt2_db2_coeffs_lo_sum * add_shift_VP);
accum += (int32_t)filter_lo[0] * (int32_t)u_s0;
accum += (int32_t)filter_lo[1] * (int32_t)u_s1;
accum += (int32_t)filter_lo[2] * (int32_t)u_s2;
accum += (int32_t)filter_lo[3] * (int32_t)u_s3;

/* normalizing is done for range from(0 to N) to (-N/2 to N/2) */
accum -= (int32_t)dwt2_db2_coeffs_lo_sum * add_shift_VP;

tmplo[j] = (accum + add_shift_VP) >> shift_VP;
}

Expand Down Expand Up @@ -2621,15 +2621,15 @@ void adm_dwt2_16(const uint16_t *src, const adm_dwt_band_t *dst, AdmBuffer *buf,
uint16_t u_s2 = src[ind_y[2][i] * src_stride + j];
uint16_t u_s3 = src[ind_y[3][i] * src_stride + j];

accum = 0;
/* normalizing is done for range from(0 to N) to (-N/2 to N/2).
* The offset goes in first: subtracted last, three 16-bit samples
* of 42456 or more take the sum past INT32_MAX on the way. */
accum = -((int32_t)dwt2_db2_coeffs_lo_sum * add_shift_VP);
accum += (int32_t)filter_lo[0] * (int32_t)u_s0;
accum += (int32_t)filter_lo[1] * (int32_t)u_s1;
accum += (int32_t)filter_lo[2] * (int32_t)u_s2;
accum += (int32_t)filter_lo[3] * (int32_t)u_s3;

/* normalizing is done for range from(0 to N) to (-N/2 to N/2) */
accum -= (int32_t)dwt2_db2_coeffs_lo_sum * add_shift_VP;

tmplo[j] = (accum + add_shift_VP) >> shift_VP;

accum = 0;
Expand Down
8 changes: 4 additions & 4 deletions libvmaf/src/feature/x86/adm_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2937,15 +2937,15 @@ void adm_dwt2_16_avx2(const uint16_t *src, const adm_dwt_band_t *dst, AdmBuffer
uint16_t u_s2 = src[ind_y[2][i] * src_stride + j];
uint16_t u_s3 = src[ind_y[3][i] * src_stride + j];

accum = 0;
/* normalizing is done for range from(0 to N) to (-N/2 to N/2).
* The offset goes in first: subtracted last, three 16-bit samples
* of 42456 or more take the sum past INT32_MAX on the way. */
accum = -((int32_t)dwt2_db2_coeffs_lo_sum * add_shift_VP);
accum += (int32_t)filter_lo[0] * (int32_t)u_s0;
accum += (int32_t)filter_lo[1] * (int32_t)u_s1;
accum += (int32_t)filter_lo[2] * (int32_t)u_s2;
accum += (int32_t)filter_lo[3] * (int32_t)u_s3;

/* normalizing is done for range from(0 to N) to (-N/2 to N/2) */
accum -= (int32_t)dwt2_db2_coeffs_lo_sum * add_shift_VP;

tmplo[j] = (accum + add_shift_VP) >> shift_VP;

accum = 0;
Expand Down
8 changes: 4 additions & 4 deletions libvmaf/src/feature/x86/adm_avx512.c
Original file line number Diff line number Diff line change
Expand Up @@ -3080,15 +3080,15 @@ void adm_dwt2_16_avx512(const uint16_t *src, const adm_dwt_band_t *dst, AdmBuffe
uint16_t u_s2 = src[ind_y[2][i] * src_stride + j];
uint16_t u_s3 = src[ind_y[3][i] * src_stride + j];

accum = 0;
/* normalizing is done for range from(0 to N) to (-N/2 to N/2).
* The offset goes in first: subtracted last, three 16-bit samples
* of 42456 or more take the sum past INT32_MAX on the way. */
accum = -((int32_t)dwt2_db2_coeffs_lo_sum * add_shift_VP);
accum += (int32_t)filter_lo[0] * (int32_t)u_s0;
accum += (int32_t)filter_lo[1] * (int32_t)u_s1;
accum += (int32_t)filter_lo[2] * (int32_t)u_s2;
accum += (int32_t)filter_lo[3] * (int32_t)u_s3;

/* normalizing is done for range from(0 to N) to (-N/2 to N/2) */
accum -= (int32_t)dwt2_db2_coeffs_lo_sum * add_shift_VP;

tmplo[j] = (accum + add_shift_VP) >> shift_VP;

accum = 0;
Expand Down
104 changes: 104 additions & 0 deletions libvmaf/test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,109 @@ test_speed_filter = executable('test_speed_filter',
)
test('test_speed_filter', test_speed_filter)

# The vertical pass of adm_dwt2_16() used to add up filter taps in an int32_t
# in an order that overflows for samples of 42456 and above. Signed overflow
# wraps back to the right value on the usual targets, so the output is correct
# either way and only an instrumented build can tell. Build the three
# translation units that hold the code under test (integer_adm.c, x86/adm_avx2.c
# and x86/adm_avx512.c) with signed integer overflow trapping, for this test
# only: the other objects come from the regular build, minus the regular
# objects of those three files so no symbol is defined twice. Without compiler
# support for the check the test still compares against the 64-bit reference.
adm_dwt2_16_trap_args = ['-fsanitize=signed-integer-overflow',
'-fno-sanitize-recover=signed-integer-overflow']
adm_dwt2_16_trap = cc.has_multi_arguments(adm_dwt2_16_trap_args) and cc.links(
'int main(void) { return 0; }',
args : adm_dwt2_16_trap_args,
name : 'with signed integer overflow trapping',
)
adm_dwt2_16_link_args = []
adm_dwt2_16_objects = [
common_cuda_objects,
libvmaf_cpu_static_lib.extract_all_objects(recursive: true),
libsvm_static_lib.extract_all_objects(recursive: true),
]

if adm_dwt2_16_trap
adm_dwt2_16_link_args += adm_dwt2_16_trap_args
adm_dwt2_16_inc = [libvmaf_include, vmaf_include, include_directories('../src/cuda/')]

adm_dwt2_16_feature_sources = []
foreach src : libvmaf_feature_sources
if src != feature_src_dir + 'integer_adm.c'
adm_dwt2_16_feature_sources += src
endif
endforeach
adm_dwt2_16_trap_adm = static_library(
'adm_dwt2_16_trap_adm',
'../src/feature/integer_adm.c',
include_directories : adm_dwt2_16_inc,
dependencies : [thread_lib, stdatomic_dependency, cuda_dependency, builtin_clz_dependency],
c_args : adm_dwt2_16_trap_args,
)
adm_dwt2_16_objects += [
libvmaf_feature_static_lib.extract_objects(adm_dwt2_16_feature_sources),
adm_dwt2_16_trap_adm.extract_all_objects(recursive: true),
]

if is_asm_enabled and host_machine.cpu_family().startswith('x86')
adm_dwt2_16_avx2_sources = []
foreach src : x86_avx2_sources
if src != feature_src_dir + 'x86/adm_avx2.c'
adm_dwt2_16_avx2_sources += src
endif
endforeach
adm_dwt2_16_trap_avx2 = static_library(
'adm_dwt2_16_trap_avx2',
'../src/feature/x86/adm_avx2.c',
include_directories : vmaf_base_include,
c_args : avx2_cflags + vmaf_cflags_common + adm_dwt2_16_trap_args,
dependencies : [builtin_clz_dependency],
)
adm_dwt2_16_objects += [
x86_avx2_static_lib.extract_objects(adm_dwt2_16_avx2_sources),
adm_dwt2_16_trap_avx2.extract_all_objects(recursive: true),
]

if is_avx512_enabled and is_avx512_supported
adm_dwt2_16_avx512_sources = []
foreach src : x86_avx512_sources
if src != feature_src_dir + 'x86/adm_avx512.c'
adm_dwt2_16_avx512_sources += src
endif
endforeach
adm_dwt2_16_trap_avx512 = static_library(
'adm_dwt2_16_trap_avx512',
'../src/feature/x86/adm_avx512.c',
include_directories : vmaf_base_include,
c_args : avx512_cflags + vmaf_cflags_common + adm_dwt2_16_trap_args,
dependencies : [builtin_clz_dependency],
)
adm_dwt2_16_objects += [
x86_avx512_static_lib.extract_objects(adm_dwt2_16_avx512_sources),
adm_dwt2_16_trap_avx512.extract_all_objects(recursive: true),
]
endif
else
adm_dwt2_16_objects += platform_specific_cpu_objects
endif
else
adm_dwt2_16_objects += [
platform_specific_cpu_objects,
libvmaf_feature_static_lib.extract_all_objects(recursive: true),
]
endif

test_adm_dwt2_16 = executable('test_adm_dwt2_16',
['test.c', 'test_adm_dwt2_16.c', '../src/mem.c', '../src/picture.c', '../src/ref.c',
'../src/dict.c', '../src/opt.c', '../src/log.c', '../src/predict.c',
'../src/metadata_handler.c'],
include_directories : [libvmaf_inc, test_inc, include_directories('../src/')],
dependencies : [math_lib, stdatomic_dependency, thread_lib, cuda_dependency],
link_args : adm_dwt2_16_link_args,
objects : adm_dwt2_16_objects,
)

if float_enabled
test_vif_tools = executable('test_vif_tools',
['test.c', 'test_vif_tools.c'],
Expand Down Expand Up @@ -248,6 +351,7 @@ test('test_luminance_tools', test_luminance_tools)
test('test_cli_parse', test_cli_parse)
test('test_psnr', test_psnr)
test('test_framesync', test_framesync)
test('test_adm_dwt2_16', test_adm_dwt2_16)
test('test_propagate_metadata', test_propagate_metadata)
test('test_adm_csf', test_adm_csf)
test('test_barten_csf', test_barten_csf)
Expand Down
Loading