diff mbox series

Fix 'char' initialization, copy, check in 'libgomp.oacc-fortran/acc-memcpy.f90' (was: [patch] OpenACC: Add Fortran routines acc_{alloc,free,hostptr,deviceptr,memcpy_{to,from}_device*})

Message ID 87y1at5615.fsf@euler.schwinge.ddns.net
State New
Headers show
Series Fix 'char' initialization, copy, check in 'libgomp.oacc-fortran/acc-memcpy.f90' (was: [patch] OpenACC: Add Fortran routines acc_{alloc,free,hostptr,deviceptr,memcpy_{to,from}_device*}) | expand

Commit Message

Thomas Schwinge March 8, 2024, 11:15 a.m. UTC
Hi Tobias!

On 2024-02-19T22:36:51+0100, Tobias Burnus <tburnus@baylibre.com> wrote:
> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90

OK to push
"Fix 'char' initialization, copy, check in 'libgomp.oacc-fortran/acc-memcpy.f90'",
see attached?


Grüße
 Thomas


> @@ -0,0 +1,47 @@
> +! { dg-do run }
> +! { dg-skip-if "" { *-*-* } { "*" } { "-DACC_MEM_SHARED=0" } }
> +
> +! based on libgomp.oacc-c-c++-common/lib-60.c
> +
> +program main
> +  use openacc
> +  use iso_fortran_env
> +  use iso_c_binding
> +  implicit none (type, external)
> +  integer(int8), allocatable :: char(:)
> +  type(c_ptr) :: dptr
> +  integer(c_intptr_t) :: i
> +  integer(int8) :: j
> +
> +  allocate(char(-128:127))
> +  do i = -128, 127
> +    char(j) = int (j, int8)
> +  end do
> +
> +  dptr = acc_malloc (256_c_size_t)
> +  call acc_memcpy_to_device (dptr, char, 255_c_size_t)
> +
> +  do i = 0, 255
> +    if (acc_is_present (transfer (transfer(char, i) + i, dptr), 1)) &
> +      stop 1
> +  end do
> +
> +  char = 0_int8
> +
> +  call acc_memcpy_from_device (char, dptr, 256_c_size_t)
> +
> +  do i = -128, 127
> +    char(i) = int (j, int8)
> +    if (char(i) /= j) &
> +      stop 2
> +  end do
> +
> +  do i = 0, 255
> +    if (acc_is_present (transfer (transfer(char, i) + i, dptr), 1)) &
> +      stop 3
> +  end do
> +
> +  call acc_free (dptr)
> +
> +  deallocate (char)
> +end

Comments

Tobias Burnus March 8, 2024, 4:26 p.m. UTC | #1
Hi Thomas,

Am 08.03.24 um 12:15 schrieb Thomas Schwinge:
> OK to push
> "Fix 'char' initialization, copy, check in 'libgomp.oacc-fortran/acc-memcpy.f90'",
> see attached?

OK.

I think there was some remaining code around the problem that 
HUGE(1_int8) = 127 and '-128_int8' is invalid because in Fortran, that's 
'unary_minus(128_int8)', which is not valid as 128 exceeds HUGE(1_int8),

Which the remaining bits code tried to solve (i.e. -127:127 vs. 
-128:127) but seemingly failed to do so consistently.

Thanks!

Tobias
diff mbox series

Patch

From 7ea60a544353fa9ff0760e11db53332195eebad4 Mon Sep 17 00:00:00 2001
From: Thomas Schwinge <tschwinge@baylibre.com>
Date: Wed, 6 Mar 2024 23:18:08 +0100
Subject: [PATCH] Fix 'char' initialization, copy, check in
 'libgomp.oacc-fortran/acc-memcpy.f90'
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Our dear friend '-Wuninitialized' reported:

    [...]/libgomp.oacc-fortran/acc-memcpy.f90:18:27:

       18 |     char(j) = int (j, int8)
          |                           ^
    Warning: ‘j’ may be used uninitialized [-Wmaybe-uninitialized]
    [...]/libgomp.oacc-fortran/acc-memcpy.f90:14:20:

       14 |   integer(int8) :: j
          |                    ^
    note: ‘j’ was declared here

..., but actually there were other issues.

	libgomp/
	* testsuite/libgomp.oacc-fortran/acc-memcpy.f90: Fix 'char'
	initialization, copy, check.
---
 libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90 | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90 b/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90
index 670dc50ff07..844d08a4661 100644
--- a/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90
+++ b/libgomp/testsuite/libgomp.oacc-fortran/acc-memcpy.f90
@@ -11,15 +11,14 @@  program main
   integer(int8), allocatable :: char(:)
   type(c_ptr) :: dptr
   integer(c_intptr_t) :: i
-  integer(int8) :: j
 
   allocate(char(-128:127))
   do i = -128, 127
-    char(j) = int (j, int8)
+    char(i) = int (i, int8)
   end do
 
   dptr = acc_malloc (256_c_size_t)
-  call acc_memcpy_to_device (dptr, char, 255_c_size_t)
+  call acc_memcpy_to_device (dptr, char, 256_c_size_t)
 
   do i = 0, 255
     if (acc_is_present (transfer (transfer(char, i) + i, dptr), 1)) &
@@ -31,8 +30,7 @@  program main
   call acc_memcpy_from_device (char, dptr, 256_c_size_t)
 
   do i = -128, 127
-    char(i) = int (j, int8)
-    if (char(i) /= j) &
+    if (char(i) /= i) &
       stop 2
   end do
 
-- 
2.34.1