public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tejas Belagod <tejas.belagod@arm.com>
To: <gcc-patches@gcc.gnu.org>
Cc: Tejas Belagod <tejas.belagod@arm.com>,
	<richard.sandiford@arm.com>, <jakub@redhat.com>
Subject: [PATCH 02/11] AArch64: Add test cases for SVE types in OpenMP shared clause.
Date: Mon, 27 May 2024 10:36:17 +0530	[thread overview]
Message-ID: <20240527050626.3769230-3-tejas.belagod@arm.com> (raw)
In-Reply-To: <20240527050626.3769230-1-tejas.belagod@arm.com>

This patch tests various shared clauses with SVE types.  It also adds a test
scaffold to run OpenMP tests in under the gcc.target testsuite.

gcc/testsuite/ChangeLog:

	* gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp: New scaffold.
	* gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c: New test.
---
 .../aarch64/sve/omp/aarch64-sve-omp.exp       |  80 ++++++++
 .../gcc.target/aarch64/sve/omp/shared.c       | 186 ++++++++++++++++++
 2 files changed, 266 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp
 create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c

diff --git a/gcc/testsuite/gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp b/gcc/testsuite/gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp
new file mode 100644
index 00000000000..1997c80c334
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/omp/aarch64-sve-omp.exp
@@ -0,0 +1,80 @@
+# Copyright (C) 2006-2024 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't an AArch64 target.
+if {![istarget aarch64*-*-*] } then {
+  return
+}
+
+# Load support procs.
+load_lib gcc-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+if ![check_effective_target_fopenmp] {
+  return
+}
+
+proc omp_link_flags { } {
+    global ld_library_path
+    global TOOL_OPTIONS
+
+    set flags ""
+
+    if ![is_remote host] {
+	if [info exists TOOL_OPTIONS] {
+	    set gccpath "[get_multilibs ${TOOL_OPTIONS}]"
+	} else {
+	    set gccpath "[get_multilibs]"
+	}
+    }
+
+    if { $gccpath != "" } {
+      if [file exists "${gccpath}/libgomp/libgomp.spec"] {
+	  append flags "-B${gccpath}/libgomp/ -L${gccpath}/libgomp/.libs -I${gccpath}/libgomp/"
+	  append ld_library_path ":${gccpath}/libgomp/.libs"
+      }
+    } else {
+      global tool_root_dir
+
+      set libgomp [lookfor_file ${tool_root_dir} libgomp]
+      if { $libgomp != "" } {
+          append flags "-L${libgomp} -B${libgomp}"
+          append ld_library_path ":${libgomp}"
+      }
+    }
+
+    set_ld_library_path_env_vars
+
+    return "$flags"
+}
+
+if { [check_effective_target_aarch64_sve] } {
+    set sve_flags ""
+} else {
+    set sve_flags "-march=armv8.2-a+sve"
+}
+
+# Main loop.
+dg-runtest [lsort [find $srcdir/$subdir *.c]] "[omp_link_flags] $sve_flags -fopenmp" ""
+
+# All done.
+dg-finish
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c b/gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c
new file mode 100644
index 00000000000..3f380d95da4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/sve/omp/shared.c
@@ -0,0 +1,186 @@
+/* { dg-do run { target aarch64_sve256_hw } } */
+/* { dg-options "-msve-vector-bits=256 -std=gnu99 -fopenmp -O2 -fdump-tree-ompexp" } */
+
+#include <arm_sve.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+
+svint32_t
+__attribute__ ((noinline))
+explicit_shared (svint32_t a, svint32_t b, svbool_t p)
+{
+
+#pragma omp parallel shared (a, b, p) num_threads (1)
+  {
+    /* 'a', 'b' and 'p' are explicitly shared.  */
+    a = svadd_s32_z (p, a, b);
+  }
+
+#pragma omp parallel shared (a, b, p) num_threads (1)
+  {
+    a = svadd_s32_z (p, a, b);
+  }
+
+  return a;
+}
+
+svint32_t
+__attribute__ ((noinline))
+implicit_shared_default (svint32_t a, svint32_t b, svbool_t p)
+{
+
+#pragma omp parallel default (shared) num_threads (1)
+  {
+    /* 'a', 'b' and 'p' are implicitly shared.  */
+    a = svadd_s32_z (p, a, b);
+  }
+
+#pragma omp parallel default (shared) num_threads (1)
+  {
+    a = svadd_s32_z (p, a, b);
+  }
+
+  return a;
+}
+
+svint32_t
+__attribute__ ((noinline))
+implicit_shared_no_default (svint32_t a, svint32_t b, svbool_t p)
+{
+
+#pragma omp parallel num_threads (1)
+  {
+    /* 'a', 'b' and 'p' are implicitly shared without default clause.  */
+    a = svadd_s32_z (p, a, b);
+  }
+
+#pragma omp parallel num_threads (1)
+  {
+    a = svadd_s32_z (p, a, b);
+  }
+
+  return a;
+}
+
+svint32_t
+__attribute__ ((noinline))
+mix_shared (svint32_t b, svbool_t p)
+{
+
+  svint32_t a;
+  int32_t *m = (int32_t *)malloc (8 * sizeof (int32_t));
+  int i;
+
+#pragma omp parallel for
+  for (i = 0; i < 8; i++)
+    m[i] = i;
+
+#pragma omp parallel
+  {
+    /* 'm' is predetermined shared here.  'a' is implicitly shared here.  */
+    a = svld1_s32 (svptrue_b32 (), m);
+  }
+
+#pragma omp parallel num_threads (1)
+  {
+    /* 'a', 'b' and 'p' are implicitly shared here.  */
+    a = svadd_s32_z (p, a, b);
+  }
+
+#pragma omp parallel shared (a, b, p) num_threads (1)
+  {
+    /* 'a', 'b' and 'p' are explicitly shared here.  */
+    a = svadd_s32_z (p, a, b);
+  }
+
+  return a;
+}
+
+void
+__attribute__ ((noinline))
+predetermined_shared_static (bool x)
+{
+
+  int32_t *m = (int32_t *)malloc (8 * sizeof (int32_t));
+  int i;
+
+#pragma omp parallel for
+  /* 'm' is predetermined shared here.  */
+  for (i = 0; i < 8; i++)
+  {
+    m[i] = i;
+  }
+
+#pragma omp parallel
+  {
+    /* 'a' is predetermined shared here.  */
+    static int64_t n;
+    svint32_t a;
+    #pragma omp parallel
+    {
+      /* 'n' is predetermined shared here.  */
+      if (x)
+	{
+	  a = svld1_s32 (svptrue_b32 (), m);
+	  n = svaddv_s32 (svptrue_b32 (), a);
+	}
+      if (!x && n != 28)
+        __builtin_abort ();
+    }
+  }
+}
+
+svint32_t
+__attribute__ ((noinline))
+foo (svint32_t a, svint32_t b, svbool_t p)
+{
+  a = svadd_s32_z (p, a, b);
+  a = svadd_s32_z (p, a, b);
+  return a;
+}
+
+void compare_vec (svint32_t x, svint32_t y)
+{
+  svbool_t p = svnot_b_z (svptrue_b32 (), svcmpeq_s32 (svptrue_b32 (), x, y));
+
+  if (svptest_any (svptrue_b32 (), p))
+    __builtin_abort ();
+}
+
+int
+main ()
+{
+  svint32_t x = svindex_s32 (0 ,1);
+  svint32_t y = svindex_s32 (8, 1);
+  svint32_t a, b;
+  svbool_t p;
+
+  /* Implicit shared.  */
+  a = foo (x, y, p);
+  b = implicit_shared_default (x, y, p);
+  compare_vec (a, b);
+
+  /* Explicit shared.  */
+  a = foo (x ,y, p);
+  b = explicit_shared (x, y, p);
+  compare_vec (a, b);
+
+  /* Implicit shared with no default clause.  */
+  a = foo (x ,y, p);
+  b = implicit_shared_no_default (x, y, p);
+  compare_vec (a, b);
+
+  /* Mix shared.  */
+  a = foo (x ,y, p);
+  b = mix_shared (y, p);
+  compare_vec (a, b);
+
+  /* Predetermined shared.  */
+  predetermined_shared_static (true);
+  predetermined_shared_static (false);
+
+  return 0;
+}
+
+/* { dg-final { scan-tree-dump-times "value-expr: \*.omp_data_i->a" 10 "ompexp" } } */
-- 
2.25.1


  parent reply	other threads:[~2024-05-27  5:06 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27  5:06 [PATCH 00/11] AArch64/OpenMP: Test SVE ACLE types with various OpenMP constructs Tejas Belagod
2024-05-27  5:06 ` [PATCH 01/11] OpenMP/PolyInt: Pass poly-int structures by address to OMP libs Tejas Belagod
2024-05-30 12:58   ` Richard Sandiford
2024-05-31  6:30     ` Tejas Belagod
2024-05-31  7:45       ` Richard Sandiford
2024-05-31  8:01         ` Jakub Jelinek
2024-05-31  8:23           ` Richard Sandiford
2024-05-27  5:06 ` Tejas Belagod [this message]
2024-05-30 12:38   ` [PATCH 02/11] AArch64: Add test cases for SVE types in OpenMP shared clause Richard Sandiford
2024-05-31  7:01     ` Tejas Belagod
2024-05-27  5:06 ` [PATCH 03/11] AArch64: Diagnose OpenMP offloading when SVE types involved Tejas Belagod
2024-05-30 12:50   ` Richard Sandiford
2024-05-27  5:06 ` [PATCH 04/11] AArch64: Test OpenMP lastprivate clause for various constructs Tejas Belagod
2024-05-27  5:06 ` [PATCH 05/11] AArch64: Test OpenMP threadprivate clause on SVE type Tejas Belagod
2024-05-27  5:06 ` [PATCH 06/11] AArch64: Test OpenMP user-defined reductions with SVE types Tejas Belagod
2024-05-27  5:06 ` [PATCH 07/11] AArch64: Test OpenMP uniform clause on " Tejas Belagod
2024-05-27  5:06 ` [PATCH 08/11] AArch64: Test OpenMP simd aligned clause with " Tejas Belagod
2024-05-27  5:06 ` [PATCH 09/11] AArch64: Diagnose OpenMP linear clause for SVE type objects Tejas Belagod
2024-05-27  5:06 ` [PATCH 10/11] AArch64: Test OpenMP depend clause and its variations on SVE types Tejas Belagod
2024-05-27  5:06 ` [PATCH 11/11] AArch64: Diagnose SVE type objects when applied to OpenMP doacross clause Tejas Belagod
2024-05-30 12:58 ` [PATCH 00/11] AArch64/OpenMP: Test SVE ACLE types with various OpenMP constructs Richard Sandiford
2024-06-20  4:46 ` Tejas Belagod

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240527050626.3769230-3-tejas.belagod@arm.com \
    --to=tejas.belagod@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=richard.sandiford@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).