Skip to content
Permalink
Browse files

Use aligned malloc instead of malloc in unit tests.

  • Loading branch information...
agopikrishna13 committed Jun 4, 2019
1 parent e5d4ebe commit 14ea300b4f5906f1e92df5d632c7dd4f961e1b6e
Showing with 35 additions and 18 deletions.
  1. +14 −0 test/EbUnitTest.h
  2. +9 −8 test/ForwardtransformTests.cc
  3. +12 −10 test/InversetransformTests.cc
@@ -23,4 +23,18 @@ extern const char eb_unit_test_result_str[2][25];
}
#endif

#ifdef _MSC_VER
#define TEST_ALLIGN_MALLOC(type, pointer, n_elements) \
pointer = (type) _aligned_malloc(n_elements, ALVALUE); \

#define TEST_ALLIGN_FREE(pointer) _aligned_free(pointer);

#else
#define TEST_ALLIGN_MALLOC(type, pointer, n_elements) \
posix_memalign((void**)(&(pointer)), ALVALUE, n_elements); \

#define TEST_ALLIGN_FREE(pointer) free(pointer);

#endif

#endif // EbUnitTest_h
@@ -4,6 +4,7 @@
#include "aom_dsp_rtcd.h"
#include "EbTransforms.h"
#include "EbUnitTestUtility.h"
#include "EbUnitTest.h"
#include <immintrin.h>

typedef void(*av1_frwd_txfm_func)(int16_t *input, int32_t *coeff, uint32_t stride, TxType tx_type, uint8_t bitDepth);
@@ -15,28 +16,28 @@ int tx_64[] = { 0 , 9 };
int bitDepth[] = { 8, 10, 12 };

static void init_data(int16_t **input, int16_t **input_opt, uint32_t input_stride) {
*input = (int16_t*)malloc(sizeof(**input) * MAX_SB_SIZE * input_stride);
*input_opt = (int16_t*)malloc(sizeof(**input_opt) * MAX_SB_SIZE * input_stride);
TEST_ALLIGN_MALLOC(int16_t*, *input, sizeof(int16_t) * MAX_SB_SIZE * input_stride);
TEST_ALLIGN_MALLOC(int16_t*, *input_opt, sizeof(int16_t) * MAX_SB_SIZE * input_stride);
memset(*input, 0, MAX_SB_SIZE * input_stride);
memset(*input_opt, 0, MAX_SB_SIZE * input_stride);
eb_buf_random_s16(*input, MAX_SB_SIZE * input_stride);
memcpy(*input_opt, *input, sizeof(**input) * MAX_SB_SIZE * input_stride);
}

static void uninit_data(int16_t *input, int16_t *input_opt) {
free(input);
free(input_opt);
TEST_ALLIGN_FREE(input);
TEST_ALLIGN_FREE(input_opt);
}

static void uninit_coeff(int32_t *coeff, int32_t *coeff_opt) {
free(coeff);
free(coeff_opt);
TEST_ALLIGN_FREE(coeff);
TEST_ALLIGN_FREE(coeff_opt);
}

static void init_coeff(int32_t **coeff, int32_t **coeff_opt, uint32_t *stride) {
*stride = eb_create_random_aligned_stride(MAX_SB_SIZE, 64);
*coeff = (int32_t*)malloc(sizeof(**coeff) * MAX_SB_SIZE * *stride);
*coeff_opt = (int32_t*)malloc(sizeof(**coeff_opt) * MAX_SB_SIZE * *stride);
TEST_ALLIGN_MALLOC(int32_t*, *coeff, sizeof(int32_t) * MAX_SB_SIZE * *stride);
TEST_ALLIGN_MALLOC(int32_t*, *coeff_opt, sizeof(int32_t) * MAX_SB_SIZE * *stride);
}

TEST(ForwardTransformTest, av1_frwd_txfm_kernels)
@@ -2,6 +2,7 @@
#include "EbDefinitions.h"
#include "aom_dsp_rtcd.h"
#include "EbUnitTestUtility.h"
#include "EbUnitTest.h"

typedef void (*av1_inv_txfm_highbd_func)(const int32_t *coeff, uint16_t *output,int32_t stride, TxType tx_type, int32_t bd);
typedef void (*av1_inv_txfm2d_highbd_rect_func)(const int32_t *input, uint16_t *output, int32_t stride, TxType tx_type, TxSize tx_size, int32_t eob, int32_t bd);
@@ -17,8 +18,8 @@ int bd[] = { 10, 12};

static void init_data(int32_t **input, int32_t **input_opt, int32_t *input_stride) {
*input_stride = eb_create_random_aligned_stride(MAX_SB_SIZE, 64);
*input = (int32_t*)malloc(sizeof(**input) * MAX_SB_SIZE * *input_stride);
*input_opt = (int32_t*)malloc(sizeof(**input_opt) * MAX_SB_SIZE * *input_stride);
TEST_ALLIGN_MALLOC(int32_t*, *input, sizeof(int32_t) * MAX_SB_SIZE * *input_stride);
TEST_ALLIGN_MALLOC(int32_t*, *input_opt, sizeof(int32_t) * MAX_SB_SIZE * *input_stride);
memset(*input, 0, MAX_SB_SIZE * *input_stride);
memset(*input_opt, 0, MAX_SB_SIZE * *input_stride);
eb_buf_random_s32(*input, MAX_SB_SIZE * *input_stride);
@@ -27,27 +28,28 @@ static void init_data(int32_t **input, int32_t **input_opt, int32_t *input_strid

static void init_data_with_max(int32_t **input, int32_t **input_opt, int32_t *input_stride) {
*input_stride = eb_create_random_aligned_stride(MAX_SB_SIZE, 64);
*input = (int32_t*)malloc(sizeof(**input) * MAX_SB_SIZE * *input_stride);
*input_opt = (int32_t*)malloc(sizeof(**input_opt) * MAX_SB_SIZE * *input_stride);
TEST_ALLIGN_MALLOC(int32_t*, *input, sizeof(int32_t) * MAX_SB_SIZE * *input_stride);
TEST_ALLIGN_MALLOC(int32_t*, *input_opt, sizeof(int32_t) * MAX_SB_SIZE * *input_stride);
memset(*input, 0, MAX_SB_SIZE * *input_stride);
memset(*input_opt, 0, MAX_SB_SIZE * *input_stride);
eb_buf_random_s32_with_max(*input, MAX_SB_SIZE * *input_stride, 1023);
memcpy(*input_opt, *input, sizeof(**input) * MAX_SB_SIZE * *input_stride);
}

static void uninit_data(int32_t *coeff, int32_t *coeff_opt,int32_t *stride) {
free(coeff);
free(coeff_opt);
(void)stride;
TEST_ALLIGN_FREE(coeff);
TEST_ALLIGN_FREE(coeff_opt);
}

static void uninit_output(uint16_t *output, uint16_t *output_opt) {
free(output);
free(output_opt);
TEST_ALLIGN_FREE(output);
TEST_ALLIGN_FREE(output_opt);
}

static void init_output(uint16_t **output,uint16_t **output_opt,int32_t num) {
*output = (uint16_t*)malloc(sizeof(**output) * MAX_SB_SIZE * num);
*output_opt = (uint16_t*)malloc(sizeof(**output) * MAX_SB_SIZE * num);
TEST_ALLIGN_MALLOC(uint16_t*, *output, sizeof(uint16_t) * MAX_SB_SIZE * num);
TEST_ALLIGN_MALLOC(uint16_t*, *output_opt, sizeof(uint16_t) * MAX_SB_SIZE * num);
eb_buf_random_u16(*output, MAX_SB_SIZE * num);
memcpy(*output_opt, *output, sizeof(**output) * MAX_SB_SIZE * num);
}

0 comments on commit 14ea300

Please sign in to comment.
You can’t perform that action at this time.