Home | History | Annotate | Line # | Download | only in gdb.rocm
      1 /* This testcase is part of GDB, the GNU debugger.
      2 
      3    Copyright 2021-2024 Free Software Foundation, Inc.
      4 
      5    This program is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation; either version 3 of the License, or
      8    (at your option) any later version.
      9 
     10    This program is distributed in the hope that it will be useful,
     11    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13    GNU General Public License for more details.
     14 
     15    You should have received a copy of the GNU General Public License
     16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     17 
     18 #include <hip/hip_runtime.h>
     19 #include <unistd.h>
     20 
     21 #define CHECK(cmd)                                                           \
     22   {                                                                          \
     23     hipError_t error = cmd;                                                  \
     24     if (error != hipSuccess)                                                 \
     25       {                                                                      \
     26 	fprintf (stderr, "error: '%s'(%d) at %s:%d\n",                       \
     27 		 hipGetErrorString (error), error, __FILE__, __LINE__);      \
     28 	exit (EXIT_FAILURE);                                                 \
     29       }                                                                      \
     30   }
     31 
     32 __global__ static void
     33 kernel1 ()
     34 {}
     35 
     36 __device__ static void
     37 break_here_execer ()
     38 {
     39 }
     40 
     41 __global__ static void
     42 kernel2 ()
     43 {
     44   break_here_execer ();
     45 }
     46 
     47 int
     48 main ()
     49 {
     50   /* Launch a first kernel to make sure the runtime is active by the time we
     51      call fork.  */
     52   kernel1<<<1, 1>>> ();
     53 
     54   /* fork + exec while the runtime is active.  */
     55   if (FORK () == 0)
     56     {
     57       int ret = execl (EXECEE, EXECEE, NULL);
     58       perror ("exec");
     59       abort ();
     60     }
     61 
     62   kernel2<<<1, 1>>> ();
     63 
     64   CHECK (hipDeviceSynchronize ());
     65   return 0;
     66 }
     67