about summary refs log tree commit diff
path: root/sysdeps/x86_64/fpu/bench-libmvec-skeleton.c
diff options
context:
space:
mode:
authorSunil K Pandey <skpgkp2@gmail.com>2021-11-05 00:56:47 -0700
committerSunil K Pandey <skpgkp2@gmail.com>2021-11-16 11:37:39 -0800
commita43c0b5483da4c5e3796af309864cb44256c02db (patch)
treea902af371c47da07212dc1022d8e9a39f83f7769 /sysdeps/x86_64/fpu/bench-libmvec-skeleton.c
parentd8c2e8e0439b715918ee69b70aab4d222c17e2ca (diff)
downloadglibc-a43c0b5483da4c5e3796af309864cb44256c02db.tar.gz
glibc-a43c0b5483da4c5e3796af309864cb44256c02db.tar.xz
glibc-a43c0b5483da4c5e3796af309864cb44256c02db.zip
x86-64: Create microbenchmark infrastructure for libmvec
Add python script to generate libmvec microbenchmark from the input
values for each libmvec function using skeleton benchmark template.

Creates double and float benchmarks with vector length 1, 2, 4, 8,
and 16 for each libmvec function.  Vector length 1 corresponds to
scalar version of function and is included for vector function perf
comparison.

Co-authored-by: Haochen Jiang <haochen.jiang@intel.com>
Reviewed-by: H.J. Lu <hjl.tools@gmail.com>
Diffstat (limited to 'sysdeps/x86_64/fpu/bench-libmvec-skeleton.c')
-rw-r--r--sysdeps/x86_64/fpu/bench-libmvec-skeleton.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/sysdeps/x86_64/fpu/bench-libmvec-skeleton.c b/sysdeps/x86_64/fpu/bench-libmvec-skeleton.c
new file mode 100644
index 0000000000..ee025594a5
--- /dev/null
+++ b/sysdeps/x86_64/fpu/bench-libmvec-skeleton.c
@@ -0,0 +1,103 @@
+/* Skeleton for libmvec benchmark programs.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <string.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <time.h>
+#include <inttypes.h>
+#include <bench-timing.h>
+#include <json-lib.h>
+#include <bench-util.h>
+#include <math-tests-arch.h>
+
+#include <bench-util.c>
+#define D_ITERS 10000
+
+int
+main (int argc, char **argv)
+{
+  unsigned long i, k;
+  timing_t start, end;
+  json_ctx_t json_ctx;
+
+#if defined REQUIRE_AVX
+  if (!CPU_FEATURE_ACTIVE (AVX))
+    {
+      printf ("AVX not supported.\n");
+      return 0;
+    }
+#elif defined REQUIRE_AVX2
+  if (!CPU_FEATURE_ACTIVE (AVX2))
+    {
+      printf ("AVX2 not supported.\n");
+      return 0;
+    }
+#elif defined REQUIRE_AVX512F
+  if (!CPU_FEATURE_ACTIVE (AVX512F))
+    {
+      printf ("AVX512F not supported.\n");
+      return 0;
+    }
+#endif
+
+  bench_start ();
+
+#ifdef BENCH_INIT
+  BENCH_INIT ();
+#endif
+
+  json_init (&json_ctx, 2, stdout);
+
+  /* Begin function.  */
+  json_attr_object_begin (&json_ctx, FUNCNAME);
+
+  for (int v = 0; v < NUM_VARIANTS; v++)
+    {
+      double d_total_time = 0;
+      timing_t cur;
+      for (k = 0; k < D_ITERS; k++)
+	{
+	  TIMING_NOW (start);
+	  for (i = 0; i < NUM_SAMPLES (v); i++)
+	    BENCH_FUNC (v, i);
+	  TIMING_NOW (end);
+
+	  TIMING_DIFF (cur, start, end);
+
+	  TIMING_ACCUM (d_total_time, cur);
+	}
+      double d_total_data_set = D_ITERS * NUM_SAMPLES (v) * STRIDE;
+
+      /* Begin variant.  */
+      json_attr_object_begin (&json_ctx, VARIANT (v));
+
+      json_attr_double (&json_ctx, "duration", d_total_time);
+      json_attr_double (&json_ctx, "iterations", d_total_data_set);
+      json_attr_double (&json_ctx, "mean", d_total_time / d_total_data_set);
+
+      /* End variant.  */
+      json_attr_object_end (&json_ctx);
+    }
+
+  /* End function.  */
+  json_attr_object_end (&json_ctx);
+
+  return 0;
+}