1 /* Copyright (C) 2013-2021 Free Software Foundation, Inc.
2    Contributed by Jakub Jelinek <jakub@redhat.com>.
3 
4    This file is part of the GNU Offloading and Multi Processing Library
5    (libgomp).
6 
7    Libgomp is free software; you can redistribute it and/or modify it
8    under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3, or (at your option)
10    any later version.
11 
12    Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
13    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14    FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15    more details.
16 
17    Under Section 7 of GPL version 3, you are granted additional
18    permissions described in the GCC Runtime Library Exception, version
19    3.1, as published by the Free Software Foundation.
20 
21    You should have received a copy of the GNU General Public License and
22    a copy of the GCC Runtime Library Exception along with this program;
23    see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24    <http://www.gnu.org/licenses/>.  */
25 
26 #include "libgomp.h"
27 #include <limits.h>
28 
29 extern int __gomp_team_num __attribute__((shared));
30 
31 bool
GOMP_teams4(unsigned int num_teams_lower,unsigned int num_teams_upper,unsigned int thread_limit,bool first)32 GOMP_teams4 (unsigned int num_teams_lower, unsigned int num_teams_upper,
33 	     unsigned int thread_limit, bool first)
34 {
35   unsigned int num_blocks, block_id;
36   asm ("mov.u32 %0, %%nctaid.x;" : "=r" (num_blocks));
37   if (!first)
38     {
39       unsigned int team_num;
40       if (num_blocks > gomp_num_teams_var)
41 	return false;
42       team_num = __gomp_team_num;
43       if (team_num > gomp_num_teams_var - num_blocks)
44 	return false;
45       __gomp_team_num = team_num + num_blocks;
46       return true;
47     }
48   if (thread_limit)
49     {
50       struct gomp_task_icv *icv = gomp_icv (true);
51       icv->thread_limit_var
52 	= thread_limit > INT_MAX ? UINT_MAX : thread_limit;
53     }
54   if (!num_teams_upper)
55     num_teams_upper = num_blocks;
56   else if (num_blocks < num_teams_lower)
57     num_teams_upper = num_teams_lower;
58   else if (num_blocks < num_teams_upper)
59     num_teams_upper = num_blocks;
60   asm ("mov.u32 %0, %%ctaid.x;" : "=r" (block_id));
61   if (block_id >= num_teams_upper)
62     return false;
63   __gomp_team_num = block_id;
64   gomp_num_teams_var = num_teams_upper - 1;
65   return true;
66 }
67 
68 int
omp_pause_resource(omp_pause_resource_t kind,int device_num)69 omp_pause_resource (omp_pause_resource_t kind, int device_num)
70 {
71   (void) kind;
72   (void) device_num;
73   return -1;
74 }
75 
76 int
omp_pause_resource_all(omp_pause_resource_t kind)77 omp_pause_resource_all (omp_pause_resource_t kind)
78 {
79   (void) kind;
80   return -1;
81 }
82 
83 ialias (omp_pause_resource)
ialias(omp_pause_resource_all)84 ialias (omp_pause_resource_all)
85 
86 void
87 GOMP_target_ext (int device, void (*fn) (void *), size_t mapnum,
88 		 void **hostaddrs, size_t *sizes, unsigned short *kinds,
89 		 unsigned int flags, void **depend, void **args)
90 {
91   (void) device;
92   (void) fn;
93   (void) mapnum;
94   (void) hostaddrs;
95   (void) sizes;
96   (void) kinds;
97   (void) flags;
98   (void) depend;
99   (void) args;
100   __builtin_unreachable ();
101 }
102 
103 void
GOMP_target_data_ext(int device,size_t mapnum,void ** hostaddrs,size_t * sizes,unsigned short * kinds)104 GOMP_target_data_ext (int device, size_t mapnum, void **hostaddrs,
105 		      size_t *sizes, unsigned short *kinds)
106 {
107   (void) device;
108   (void) mapnum;
109   (void) hostaddrs;
110   (void) sizes;
111   (void) kinds;
112   __builtin_unreachable ();
113 }
114 
115 void
GOMP_target_end_data(void)116 GOMP_target_end_data (void)
117 {
118   __builtin_unreachable ();
119 }
120 
121 void
GOMP_target_update_ext(int device,size_t mapnum,void ** hostaddrs,size_t * sizes,unsigned short * kinds,unsigned int flags,void ** depend)122 GOMP_target_update_ext (int device, size_t mapnum, void **hostaddrs,
123 			size_t *sizes, unsigned short *kinds,
124 			unsigned int flags, void **depend)
125 {
126   (void) device;
127   (void) mapnum;
128   (void) hostaddrs;
129   (void) sizes;
130   (void) kinds;
131   (void) flags;
132   (void) depend;
133   __builtin_unreachable ();
134 }
135 
136 void
GOMP_target_enter_exit_data(int device,size_t mapnum,void ** hostaddrs,size_t * sizes,unsigned short * kinds,unsigned int flags,void ** depend)137 GOMP_target_enter_exit_data (int device, size_t mapnum, void **hostaddrs,
138 			     size_t *sizes, unsigned short *kinds,
139 			     unsigned int flags, void **depend)
140 {
141   (void) device;
142   (void) mapnum;
143   (void) hostaddrs;
144   (void) sizes;
145   (void) kinds;
146   (void) flags;
147   (void) depend;
148   __builtin_unreachable ();
149 }
150