test: Add alignment and misalignment to arrays
authorDavid Schleef <ds@schleef.org>
Wed, 18 Aug 2010 01:34:45 +0000 (18:34 -0700)
committerDavid Schleef <ds@schleef.org>
Wed, 18 Aug 2010 01:38:56 +0000 (18:38 -0700)
This causes most of the performance tests to slow down significantly,
but is a more realistic measurement of actual performance.

orc-test/orcarray.c
orc-test/orcarray.h
orc-test/orctest.c

index 4c21be2..552575a 100644 (file)
 #define isnan(x) _isnan(x)
 #endif
 
+#define ALIGNMENT 64
+#define MISALIGNMENT 0
+
 OrcArray *
-orc_array_new (int n, int m, int element_size)
+orc_array_new (int n, int m, int element_size, int misalignment)
 {
   OrcArray *ar;
+  void *data;
+  int ret;
 
   ar = malloc (sizeof(OrcArray));
   memset (ar, 0, sizeof(OrcArray));
@@ -31,10 +36,14 @@ orc_array_new (int n, int m, int element_size)
   ar->element_size = element_size;
 
   ar->stride = (n*element_size + EXTEND_STRIDE);
-  ar->alloc_len = ar->stride * (m+2*EXTEND_ROWS);
-  ar->alloc_data = malloc (ar->alloc_len);
+  ar->stride = (ar->stride + (ALIGNMENT-1)) & (~(ALIGNMENT-1));
+  ar->alloc_len = ar->stride * (m+2*EXTEND_ROWS) + (ALIGNMENT * element_size);
+
+  ret = posix_memalign (&data, ALIGNMENT, ar->alloc_len);
+  ar->alloc_data = data;
 
-  ar->data = ORC_PTR_OFFSET (ar->alloc_data, ar->stride * EXTEND_ROWS);
+  ar->data = ORC_PTR_OFFSET (ar->alloc_data,
+      ar->stride * EXTEND_ROWS + element_size * misalignment);
   
   return ar;
 }
index 6b26141..60d3d23 100644 (file)
@@ -20,7 +20,7 @@ struct _OrcArray {
   int alloc_len;
 };
 
-OrcArray *orc_array_new (int n, int m, int element_size);
+OrcArray *orc_array_new (int n, int m, int element_size, int misalignment);
 void orc_array_free (OrcArray *array);
 
 void orc_array_set_pattern (OrcArray *array, int value);
index 85e715f..bcf2b36 100644 (file)
@@ -508,6 +508,7 @@ orc_test_compare_output_full (OrcProgram *program, int flags)
   int acc_exec = 0, acc_emul = 0;
   int ret = ORC_TEST_OK;
   int bad = 0;
+  int misalignment;
 
   ORC_DEBUG ("got here");
 
@@ -547,17 +548,23 @@ orc_test_compare_output_full (OrcProgram *program, int flags)
   orc_executor_set_m (ex, m);
   ORC_DEBUG("size %d %d", ex->n, ex->params[ORC_VAR_A1]);
 
+  misalignment = 0;
   for(i=0;i<ORC_N_VARIABLES;i++){
     if (program->vars[i].name == NULL) continue;
 
     if (program->vars[i].vartype == ORC_VAR_TYPE_SRC) {
-      src[i-ORC_VAR_S1] = orc_array_new (n, m, program->vars[i].size);
+      src[i-ORC_VAR_S1] = orc_array_new (n, m, program->vars[i].size,
+          misalignment);
       orc_array_set_random (src[i-ORC_VAR_S1], &rand_context);
+      misalignment++;
     } else if (program->vars[i].vartype == ORC_VAR_TYPE_DEST) {
-      dest_exec[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size);
+      dest_exec[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size,
+          misalignment);
       orc_array_set_pattern (dest_exec[i], ORC_OOB_VALUE);
-      dest_emul[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size);
+      dest_emul[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size,
+          misalignment);
       orc_array_set_pattern (dest_emul[i], ORC_OOB_VALUE);
+      misalignment++;
     } else if (program->vars[i].vartype == ORC_VAR_TYPE_PARAM) {
       orc_executor_set_param (ex, i, 2);
     }
@@ -826,6 +833,7 @@ orc_test_performance_full (OrcProgram *program, int flags,
   OrcProfile prof;
   double ave, std;
   OrcTarget *target;
+  int misalignment;
 
   ORC_DEBUG ("got here");
 
@@ -864,17 +872,23 @@ orc_test_performance_full (OrcProgram *program, int flags,
   orc_executor_set_m (ex, m);
   ORC_DEBUG("size %d %d", ex->n, ex->params[ORC_VAR_A1]);
 
+  misalignment = 0;
   for(i=0;i<ORC_N_VARIABLES;i++){
     if (program->vars[i].name == NULL) continue;
 
     if (program->vars[i].vartype == ORC_VAR_TYPE_SRC) {
-      src[i-ORC_VAR_S1] = orc_array_new (n, m, program->vars[i].size);
+      src[i-ORC_VAR_S1] = orc_array_new (n, m, program->vars[i].size,
+          misalignment);
       orc_array_set_random (src[i-ORC_VAR_S1], &rand_context);
+      misalignment++;
     } else if (program->vars[i].vartype == ORC_VAR_TYPE_DEST) {
-      dest_exec[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size);
+      dest_exec[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size,
+          misalignment);
       orc_array_set_pattern (dest_exec[i], ORC_OOB_VALUE);
-      dest_emul[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size);
+      dest_emul[i-ORC_VAR_D1] = orc_array_new (n, m, program->vars[i].size,
+          misalignment);
       orc_array_set_pattern (dest_emul[i], ORC_OOB_VALUE);
+      misalignment++;
     } else if (program->vars[i].vartype == ORC_VAR_TYPE_PARAM) {
       orc_executor_set_param (ex, i, 2);
     }