mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 19:24:06 +00:00
Merge branch 'simd-tests'
This commit is contained in:
commit
c0eef0adfb
|
@ -59,6 +59,18 @@ static const kvz_pixel pic_data[64] = {
|
|||
|
||||
static kvz_picture *g_pic = 0;
|
||||
static kvz_picture *g_ref = 0;
|
||||
static kvz_picture *g_big_pic = 0;
|
||||
static kvz_picture *g_big_ref = 0;
|
||||
static kvz_picture *g_64x64_zero = 0;
|
||||
static kvz_picture *g_64x64_max = 0;
|
||||
|
||||
static struct sad_test_env_t {
|
||||
int width;
|
||||
int height;
|
||||
void * tested_func;
|
||||
const strategy_t * strategy;
|
||||
char msg[255];
|
||||
} sad_test_env;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// SETUP, TEARDOWN AND HELPER FUNCTIONS
|
||||
|
@ -73,12 +85,34 @@ static void setup_tests()
|
|||
for (int i = 0; i < 64; ++i) {
|
||||
g_ref->y[i] = ref_data[i] + 48;
|
||||
}
|
||||
|
||||
g_big_pic = kvz_image_alloc(KVZ_CSP_420, 64, 64);
|
||||
for (int i = 0; i < 64*64; ++i) {
|
||||
g_big_pic->y[i] = (i*i / 32 + i) % 255;
|
||||
//g_big_pic->y[i] = i % 255;
|
||||
}
|
||||
|
||||
g_big_ref = kvz_image_alloc(KVZ_CSP_420, 64, 64);
|
||||
for (int i = 0; i < 64 * 64; ++i) {
|
||||
g_big_ref->y[i] = (i*i / 16 + i) % 255;
|
||||
//g_big_ref->y[i] = (i / 2) % 255;
|
||||
}
|
||||
|
||||
g_64x64_zero = kvz_image_alloc(KVZ_CSP_420, 64, 64);
|
||||
memset(g_64x64_zero->y, 0, 64 * 64 * sizeof(kvz_pixel));
|
||||
|
||||
g_64x64_max = kvz_image_alloc(KVZ_CSP_420, 64, 64);
|
||||
memset(g_64x64_max->y, PIXEL_MAX, 64 * 64 * sizeof(kvz_pixel));
|
||||
}
|
||||
|
||||
static void tear_down_tests()
|
||||
{
|
||||
kvz_image_free(g_pic);
|
||||
kvz_image_free(g_ref);
|
||||
kvz_image_free(g_big_pic);
|
||||
kvz_image_free(g_big_ref);
|
||||
kvz_image_free(g_64x64_zero);
|
||||
kvz_image_free(g_64x64_max);
|
||||
}
|
||||
|
||||
|
||||
|
@ -224,11 +258,66 @@ TEST test_bottomright_out(void)
|
|||
PASS();
|
||||
}
|
||||
|
||||
static unsigned simple_sad(const kvz_pixel* buf1, const kvz_pixel* buf2, unsigned stride,
|
||||
unsigned width, unsigned height)
|
||||
{
|
||||
unsigned sum = 0;
|
||||
for (unsigned y = 0; y < height; ++y) {
|
||||
for (unsigned x = 0; x < width; ++x) {
|
||||
sum += abs((int)buf1[y * stride + x] - (int)buf2[y * stride + x]);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
struct sad_test_env_t {
|
||||
kvz_picture *g_pic;
|
||||
kvz_picture *g_ref;
|
||||
};
|
||||
TEST test_reg_sad(void)
|
||||
{
|
||||
unsigned width = sad_test_env.width;
|
||||
unsigned height = sad_test_env.height;
|
||||
unsigned stride = 64;
|
||||
|
||||
unsigned correct_result = simple_sad(g_big_pic->y, g_big_ref->y, stride, width, height);
|
||||
|
||||
unsigned(*tested_func)(const kvz_pixel *, const kvz_pixel *, int, int, unsigned, unsigned) = sad_test_env.tested_func;
|
||||
unsigned result = tested_func(g_big_pic->y, g_big_ref->y, width, height, stride, stride);
|
||||
|
||||
sprintf(sad_test_env.msg, "%s(%ux%u):%s",
|
||||
sad_test_env.strategy->type,
|
||||
width,
|
||||
height,
|
||||
sad_test_env.strategy->strategy_name);
|
||||
|
||||
if (result != correct_result) {
|
||||
FAILm(sad_test_env.msg);
|
||||
}
|
||||
|
||||
PASSm(sad_test_env.msg);
|
||||
}
|
||||
|
||||
|
||||
TEST test_reg_sad_overflow(void)
|
||||
{
|
||||
unsigned width = sad_test_env.width;
|
||||
unsigned height = sad_test_env.height;
|
||||
unsigned stride = 64;
|
||||
|
||||
unsigned correct_result = simple_sad(g_64x64_zero->y, g_64x64_max->y, stride, width, height);
|
||||
|
||||
unsigned(*tested_func)(const kvz_pixel *, const kvz_pixel *, int, int, unsigned, unsigned) = sad_test_env.tested_func;
|
||||
unsigned result = tested_func(g_64x64_zero->y, g_64x64_max->y, width, height, stride, stride);
|
||||
|
||||
sprintf(sad_test_env.msg, "overflow %s(%ux%u):%s",
|
||||
sad_test_env.strategy->type,
|
||||
width,
|
||||
height,
|
||||
sad_test_env.strategy->strategy_name);
|
||||
|
||||
if (result != correct_result) {
|
||||
FAILm(sad_test_env.msg);
|
||||
}
|
||||
|
||||
PASSm(sad_test_env.msg);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -272,6 +361,29 @@ SUITE(sad_tests)
|
|||
RUN_TEST(test_bottomleft_out);
|
||||
RUN_TEST(test_bottom_out);
|
||||
RUN_TEST(test_bottomright_out);
|
||||
|
||||
struct dimension {
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
static const struct dimension tested_dims[] = {
|
||||
// Square motion partitions
|
||||
{64, 64}, {32, 32}, {16, 16}, {8, 8},
|
||||
// Symmetric motion partitions
|
||||
{64, 32}, {32, 64}, {32, 16}, {16, 32}, {16, 8}, {8, 16}, {8, 4}, {4, 8},
|
||||
// Asymmetric motion partitions
|
||||
{48, 16}, {16, 48}, {24, 16}, {16, 24}, {12, 4}, {4, 12}
|
||||
};
|
||||
|
||||
sad_test_env.tested_func = strategies.strategies[i].fptr;
|
||||
sad_test_env.strategy = &strategies.strategies[i];
|
||||
int num_dim_tests = sizeof(tested_dims) / sizeof(tested_dims[0]);
|
||||
for (int dim_test = 0; dim_test < num_dim_tests; ++dim_test) {
|
||||
sad_test_env.width = tested_dims[dim_test].width;
|
||||
sad_test_env.height = tested_dims[dim_test].height;
|
||||
RUN_TEST(test_reg_sad);
|
||||
RUN_TEST(test_reg_sad_overflow);
|
||||
}
|
||||
}
|
||||
|
||||
tear_down_tests();
|
||||
|
|
|
@ -126,8 +126,50 @@ TEST test_intra_speed(const int width)
|
|||
KVZ_GET_TIME(&clock_now)
|
||||
}
|
||||
|
||||
double test_time = TIME_PER_TEST + KVZ_CLOCK_T_AS_DOUBLE(clock_now) - test_end;
|
||||
sprintf(test_env.msg, "%.3fM x %s:%s",
|
||||
(double)call_cnt / 1000000.0,
|
||||
(double)call_cnt / 1000000.0 / test_time,
|
||||
test_env.strategy->type,
|
||||
test_env.strategy->strategy_name);
|
||||
PASSm(test_env.msg);
|
||||
}
|
||||
|
||||
|
||||
TEST test_intra_dual_speed(const int width)
|
||||
{
|
||||
const int size = width * width;
|
||||
uint64_t call_cnt = 0;
|
||||
KVZ_CLOCK_T clock_now;
|
||||
KVZ_GET_TIME(&clock_now);
|
||||
double test_end = KVZ_CLOCK_T_AS_DOUBLE(clock_now) + TIME_PER_TEST;
|
||||
|
||||
// Loop until time allocated for test has passed.
|
||||
for (unsigned i = 0;
|
||||
test_end > KVZ_CLOCK_T_AS_DOUBLE(clock_now);
|
||||
++i)
|
||||
{
|
||||
int test = i % NUM_TESTS;
|
||||
uint64_t sum = 0;
|
||||
for (int offset = 0; offset < NUM_CHUNKS * 64 * 64; offset += NUM_CHUNKS * size) {
|
||||
// Compare the first chunk against the 35 other chunks to simulate real usage.
|
||||
kvz_pixel * buf1 = &bufs[test][offset];
|
||||
for (int chunk = 0; chunk < NUM_CHUNKS; chunk += 2) {
|
||||
cost_pixel_nxn_multi_func *tested_func = test_env.tested_func;
|
||||
const kvz_pixel *buf_pair[2] = { &bufs[test][chunk * size + offset], &bufs[test][(chunk + 1) * size + offset] };
|
||||
unsigned costs[2] = { 0, 0 };
|
||||
tested_func((pred_buffer)buf_pair, buf1, 2, costs);
|
||||
sum += costs[0] + costs[1];
|
||||
++call_cnt;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(sum > 0);
|
||||
KVZ_GET_TIME(&clock_now)
|
||||
}
|
||||
|
||||
double test_time = TIME_PER_TEST + KVZ_CLOCK_T_AS_DOUBLE(clock_now) - test_end;
|
||||
sprintf(test_env.msg, "%.3fM x %s:%s",
|
||||
(double)call_cnt / 1000000.0 / test_time,
|
||||
test_env.strategy->type,
|
||||
test_env.strategy->strategy_name);
|
||||
PASSm(test_env.msg);
|
||||
|
@ -170,8 +212,9 @@ TEST test_inter_speed(const int width)
|
|||
KVZ_GET_TIME(&clock_now)
|
||||
}
|
||||
|
||||
double test_time = TIME_PER_TEST + KVZ_CLOCK_T_AS_DOUBLE(clock_now) - test_end;
|
||||
sprintf(test_env.msg, "%.3fM x %s(%ix%i):%s",
|
||||
(double)call_cnt / 1000000.0,
|
||||
(double)call_cnt / 1000000.0 / test_time,
|
||||
test_env.strategy->type,
|
||||
width,
|
||||
width,
|
||||
|
@ -221,8 +264,9 @@ TEST dct_speed(const int width)
|
|||
KVZ_GET_TIME(&clock_now)
|
||||
}
|
||||
|
||||
double test_time = TIME_PER_TEST + KVZ_CLOCK_T_AS_DOUBLE(clock_now) - test_end;
|
||||
sprintf(test_env.msg, "%.3fM x %s:%s",
|
||||
(double)call_cnt / 1000000.0,
|
||||
(double)call_cnt / 1000000.0 / test_time,
|
||||
test_env.strategy->type,
|
||||
test_env.strategy->strategy_name);
|
||||
PASSm(test_env.msg);
|
||||
|
@ -236,6 +280,13 @@ TEST intra_sad(void)
|
|||
}
|
||||
|
||||
|
||||
TEST intra_sad_dual(void)
|
||||
{
|
||||
const int width = 1 << test_env.log_width;
|
||||
return test_intra_dual_speed(width);
|
||||
}
|
||||
|
||||
|
||||
TEST intra_satd(void)
|
||||
{
|
||||
const int width = 1 << test_env.log_width;
|
||||
|
@ -243,6 +294,13 @@ TEST intra_satd(void)
|
|||
}
|
||||
|
||||
|
||||
TEST intra_satd_dual(void)
|
||||
{
|
||||
const int width = 1 << test_env.log_width;
|
||||
return test_intra_dual_speed(width);
|
||||
}
|
||||
|
||||
|
||||
TEST inter_sad(void)
|
||||
{
|
||||
const int width = 1 << test_env.log_width;
|
||||
|
@ -279,47 +337,17 @@ SUITE(speed_tests)
|
|||
for (unsigned i = 0; i < strategies.count; ++i) {
|
||||
const strategy_t * strategy = &strategies.strategies[i];
|
||||
|
||||
// Select buffer width according to function name for intra cost functions.
|
||||
if (strcmp(strategy->type, "sad_4x4") == 0) {
|
||||
// Select buffer width according to function name.
|
||||
if (strstr(strategy->type, "_4x4")) {
|
||||
test_env.log_width = 2;
|
||||
} else if (strcmp(strategy->type, "sad_8x8") == 0) {
|
||||
} else if (strstr(strategy->type, "_8x8")) {
|
||||
test_env.log_width = 3;
|
||||
} else if (strcmp(strategy->type, "sad_16x16") == 0) {
|
||||
} else if (strstr(strategy->type, "_16x16")) {
|
||||
test_env.log_width = 4;
|
||||
} else if (strcmp(strategy->type, "sad_32x32") == 0) {
|
||||
} else if (strstr(strategy->type, "_32x32")) {
|
||||
test_env.log_width = 5;
|
||||
} else if (strcmp(strategy->type, "sad_64x64") == 0) {
|
||||
} else if (strstr(strategy->type, "_64x64")) {
|
||||
test_env.log_width = 6;
|
||||
} else if (strcmp(strategy->type, "satd_4x4") == 0) {
|
||||
test_env.log_width = 2;
|
||||
} else if (strcmp(strategy->type, "satd_8x8") == 0) {
|
||||
test_env.log_width = 3;
|
||||
} else if (strcmp(strategy->type, "satd_16x16") == 0) {
|
||||
test_env.log_width = 4;
|
||||
} else if (strcmp(strategy->type, "satd_32x32") == 0) {
|
||||
test_env.log_width = 5;
|
||||
} else if (strcmp(strategy->type, "satd_64x64") == 0) {
|
||||
test_env.log_width = 6;
|
||||
} else if (strcmp(strategy->type, "dct_4x4") == 0) {
|
||||
test_env.log_width = 2;
|
||||
} else if (strcmp(strategy->type, "dct_8x8") == 0) {
|
||||
test_env.log_width = 3;
|
||||
} else if (strcmp(strategy->type, "dct_16x16") == 0) {
|
||||
test_env.log_width = 4;
|
||||
} else if (strcmp(strategy->type, "dct_32x32") == 0) {
|
||||
test_env.log_width = 5;
|
||||
} else if (strcmp(strategy->type, "idct_4x4") == 0) {
|
||||
test_env.log_width = 2;
|
||||
} else if (strcmp(strategy->type, "idct_8x8") == 0) {
|
||||
test_env.log_width = 3;
|
||||
} else if (strcmp(strategy->type, "idct_16x16") == 0) {
|
||||
test_env.log_width = 4;
|
||||
} else if (strcmp(strategy->type, "idct_32x32") == 0) {
|
||||
test_env.log_width = 5;
|
||||
} else if (strcmp(strategy->type, "fast_forward_dst_4x4") == 0) {
|
||||
test_env.log_width = 2;
|
||||
} else if (strcmp(strategy->type, "fast_inverse_dst_4x4") == 0) {
|
||||
test_env.log_width = 2;
|
||||
} else {
|
||||
test_env.log_width = 0;
|
||||
}
|
||||
|
@ -329,10 +357,18 @@ SUITE(speed_tests)
|
|||
|
||||
// Call different tests depending on type of function.
|
||||
// This allows for selecting a subset of tests with -t parameter.
|
||||
if (strncmp(strategy->type, "satd_", 5) == 0) {
|
||||
RUN_TEST(intra_satd);
|
||||
if (strncmp(strategy->type, "satd_", 5) == 0 && strcmp(strategy->type, "satd_any_size") != 0) {
|
||||
if (strlen(strategy->type) <= 10) {
|
||||
RUN_TEST(intra_satd);
|
||||
} else if (strstr(strategy->type, "_dual")) {
|
||||
RUN_TEST(intra_satd_dual);
|
||||
}
|
||||
} else if (strncmp(strategy->type, "sad_", 4) == 0) {
|
||||
RUN_TEST(intra_sad);
|
||||
if (strlen(strategy->type) <= 9) {
|
||||
RUN_TEST(intra_sad);
|
||||
} else if (strstr(strategy->type, "_dual")) {
|
||||
RUN_TEST(intra_sad_dual);
|
||||
}
|
||||
} else if (strcmp(strategy->type, "reg_sad") == 0) {
|
||||
// Call reg_sad with all the sizes it is actually called with.
|
||||
for (int width = 3; width <= 6; ++width) {
|
||||
|
|
Loading…
Reference in a new issue