Skip to content

Commit

Permalink
Integer ADM : Review changes Netflix#1
Browse files Browse the repository at this point in the history
- Code modification based on understanding from MotionScore and VIF review
- Addition of function macros for code consolidation
- Performance optimsations with modifications of integer arithmetic logic
  • Loading branch information
IttiamVijayakumarGR committed May 15, 2020
1 parent fef1c8f commit 96055a7
Show file tree
Hide file tree
Showing 4 changed files with 1,415 additions and 1,768 deletions.
144 changes: 101 additions & 43 deletions libvmaf/src/feature/integer_adm.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,97 @@
#define NUM_BUFS_ADM 30
#endif

static inline void *init_dwt_band(adm_dwt_band_t *band, char *data_top, size_t stride)
{
band->band_a = (int16_t *)data_top; data_top += stride;
band->band_h = (int16_t *)data_top; data_top += stride;
band->band_v = (int16_t *)data_top; data_top += stride;
band->band_d = (int16_t *)data_top; data_top += stride;
return data_top;
}

static inline void *init_index(int32_t **index, char *data_top, size_t stride)
{
index[0] = (int32_t *)data_top; data_top += stride;
index[1] = (int32_t *)data_top; data_top += stride;
index[2] = (int32_t *)data_top; data_top += stride;
index[3] = (int32_t *)data_top; data_top += stride;
return data_top;
}

static inline void *i4_init_dwt_band(i4_adm_dwt_band_t *band, char *data_top, size_t stride)
{
band->band_a = (int32_t *)data_top; data_top += stride;
band->band_h = (int32_t *)data_top; data_top += stride;
band->band_v = (int32_t *)data_top; data_top += stride;
band->band_d = (int32_t *)data_top; data_top += stride;
return data_top;
}

static inline void *init_dwt_band_hvd(adm_dwt_band_t *band, char *data_top, size_t stride)
{
band->band_a = NULL;
band->band_h = (int16_t *)data_top; data_top += stride;
band->band_v = (int16_t *)data_top; data_top += stride;
band->band_d = (int16_t *)data_top; data_top += stride;
return data_top;
}

static inline void *i4_init_dwt_band_hvd(i4_adm_dwt_band_t *band, char *data_top, size_t stride)
{
band->band_a = NULL;
band->band_h = (int32_t *)data_top; data_top += stride;
band->band_v = (int32_t *)data_top; data_top += stride;
band->band_d = (int32_t *)data_top; data_top += stride;
return data_top;
}

static int init(VmafFeatureExtractor *fex, enum VmafPixelFormat pix_fmt,
unsigned bpc, unsigned w, unsigned h)
{
Integer_AdmState *s = fex->priv;

s->integer_stride = ALIGN_CEIL(w * sizeof(int32_t));
s->ind_size_x = ALIGN_CEIL(((w + 1) / 2) * sizeof(int32_t));
s->ind_size_y = ALIGN_CEIL(((h + 1) / 2) * sizeof(int32_t));
s->buf_sz_one = s->ind_size_x * ((h + 1) / 2);

s->data_buf = aligned_malloc(s->buf_sz_one * NUM_BUFS_ADM, MAX_ALIGN);
if (!s->data_buf) goto free_ref;
s->tmp_ref = aligned_malloc(s->integer_stride * 4, MAX_ALIGN);
if (!s->tmp_ref) goto free_ref;
s->buf_x_orig = aligned_malloc(s->ind_size_x * 4, MAX_ALIGN);
if (!s->buf_x_orig) goto free_ref;
s->buf_y_orig = aligned_malloc(s->ind_size_y * 4, MAX_ALIGN);
if (!s->buf_y_orig) goto free_ref;
AdmState *s = fex->priv;

s->integer_stride = ALIGN_CEIL(w * sizeof(int32_t));
s->buf.ind_size_x = ALIGN_CEIL(((w + 1) / 2) * sizeof(int32_t));
s->buf.ind_size_y = ALIGN_CEIL(((h + 1) / 2) * sizeof(int32_t));
size_t buf_sz_one = s->buf.ind_size_x * ((h + 1) / 2);

s->buf.data_buf = aligned_malloc(buf_sz_one * NUM_BUFS_ADM, MAX_ALIGN);
if (!s->buf.data_buf) goto free_ref;
s->buf.tmp_ref = aligned_malloc(s->integer_stride * 4, MAX_ALIGN);
if (!s->buf.tmp_ref) goto free_ref;
s->buf.buf_x_orig = aligned_malloc(s->buf.ind_size_x * 4, MAX_ALIGN);
if (!s->buf.buf_x_orig) goto free_ref;
s->buf.buf_y_orig = aligned_malloc(s->buf.ind_size_y * 4, MAX_ALIGN);
if (!s->buf.buf_y_orig) goto free_ref;

void *data_top = s->buf.data_buf;
data_top = init_dwt_band(&s->buf.ref_dwt2, data_top, buf_sz_one / 2);
data_top = init_dwt_band(&s->buf.dis_dwt2, data_top, buf_sz_one / 2);
data_top = init_dwt_band_hvd(&s->buf.decouple_r, data_top, buf_sz_one / 2);
data_top = init_dwt_band_hvd(&s->buf.decouple_a, data_top, buf_sz_one / 2);
data_top = init_dwt_band_hvd(&s->buf.csf_a, data_top, buf_sz_one / 2);
data_top = init_dwt_band_hvd(&s->buf.csf_f, data_top, buf_sz_one / 2);

data_top = i4_init_dwt_band(&s->buf.i4_ref_dwt2, data_top, buf_sz_one);
data_top = i4_init_dwt_band(&s->buf.i4_dis_dwt2, data_top, buf_sz_one);
data_top = i4_init_dwt_band_hvd(&s->buf.i4_decouple_r, data_top, buf_sz_one);
data_top = i4_init_dwt_band_hvd(&s->buf.i4_decouple_a, data_top, buf_sz_one);
data_top = i4_init_dwt_band_hvd(&s->buf.i4_csf_a, data_top, buf_sz_one);
data_top = i4_init_dwt_band_hvd(&s->buf.i4_csf_f, data_top, buf_sz_one);

void *ind_buf_y = s->buf.buf_y_orig;
init_index(s->buf.ind_y, ind_buf_y, s->buf.ind_size_y);
void *ind_buf_x = s->buf.buf_x_orig;
init_index(s->buf.ind_x, ind_buf_x, s->buf.ind_size_x);

return 0;

free_ref:
if (s->data_buf) aligned_free(s->data_buf);
if (s->tmp_ref) aligned_free(s->tmp_ref);
if (s->buf_x_orig) aligned_free(s->buf_x_orig);
if (s->buf_y_orig) aligned_free(s->buf_y_orig);
if (s->buf.data_buf) aligned_free(s->buf.data_buf);
if (s->buf.tmp_ref) aligned_free(s->buf.tmp_ref);
if (s->buf.buf_x_orig) aligned_free(s->buf.buf_x_orig);
if (s->buf.buf_y_orig) aligned_free(s->buf.buf_y_orig);

return -ENOMEM;
}
Expand All @@ -65,38 +130,31 @@ static int extract(VmafFeatureExtractor *fex,
VmafPicture *ref_pic, VmafPicture *dist_pic,
unsigned index, VmafFeatureCollector *feature_collector)
{
Integer_AdmState *s = fex->priv;
AdmState *s = fex->priv;
int err = 0;

double score, score_num, score_den;
double score;
double scores[8];

ptrdiff_t integer_stride = ref_pic->bpc == 8 ? ref_pic->stride[0] << 2 : ref_pic->stride[0] << 1;
integer_compute_adm(ref_pic, dist_pic, &score, scores, ADM_BORDER_FACTOR, s->buf);

//the stride pass to integer_compute_adm is in multiple of sizeof(uint32_t)
err = integer_compute_adm(ref_pic->data[0], dist_pic->data[0], ref_pic->w[0], ref_pic->h[0],
integer_stride, integer_stride, &score, &score_num,
&score_den, scores, ADM_BORDER_FACTOR, ref_pic->bpc, s);
if (err) return err;

err = vmaf_feature_collector_append(feature_collector,
err |= vmaf_feature_collector_append(feature_collector,
"'VMAF_feature_adm2_integer_score'",
score, index);
if (err) return err;

err = vmaf_feature_collector_append(feature_collector,
err |= vmaf_feature_collector_append(feature_collector,
"integer_adm_scale0",
scores[0] / scores[1], index);
if (err) return err;
err = vmaf_feature_collector_append(feature_collector,

err |= vmaf_feature_collector_append(feature_collector,
"integer_adm_scale1",
scores[2] / scores[3], index);
if (err) return err;
err = vmaf_feature_collector_append(feature_collector,

err |= vmaf_feature_collector_append(feature_collector,
"integer_adm_scale2",
scores[4] / scores[5], index);
if (err) return err;
err = vmaf_feature_collector_append(feature_collector,

err |= vmaf_feature_collector_append(feature_collector,
"integer_adm_scale3",
scores[6] / scores[7], index);
if (err) return err;
Expand All @@ -106,12 +164,12 @@ static int extract(VmafFeatureExtractor *fex,

static int close(VmafFeatureExtractor *fex)
{
Integer_AdmState *s = fex->priv;
AdmState *s = fex->priv;

if (s->data_buf) aligned_free(s->data_buf);
if (s->tmp_ref) aligned_free(s->tmp_ref);
if (s->buf_x_orig) aligned_free(s->buf_x_orig);
if (s->buf_y_orig) aligned_free(s->buf_y_orig);
if (s->buf.data_buf) aligned_free(s->buf.data_buf);
if (s->buf.tmp_ref) aligned_free(s->buf.tmp_ref);
if (s->buf.buf_x_orig) aligned_free(s->buf.buf_x_orig);
if (s->buf.buf_y_orig) aligned_free(s->buf.buf_y_orig);

return 0;
}
Expand All @@ -128,6 +186,6 @@ VmafFeatureExtractor vmaf_fex_integer_adm = {
.init = init,
.extract = extract,
.close = close,
.priv_size = sizeof(Integer_AdmState),
.priv_size = sizeof(AdmState),
.provided_features = provided_features,
};
Loading

0 comments on commit 96055a7

Please sign in to comment.