Daily bump.
[official-gcc.git] / libgomp / config / gcn / target.c
blob1d4a23cb8d204c9042ffb58adce68befa03df5d3
1 /* Copyright (C) 2017-2024 Free Software Foundation, Inc.
2 Contributed by Mentor Embedded.
4 This file is part of the GNU Offloading and Multi Processing Library
5 (libgomp).
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.
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.
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.
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/>. */
26 #include "libgomp.h"
27 #include "libgomp-gcn.h"
28 #include <limits.h>
30 extern volatile struct gomp_offload_icvs GOMP_ADDITIONAL_ICVS;
32 bool
33 GOMP_teams4 (unsigned int num_teams_lower, unsigned int num_teams_upper,
34 unsigned int thread_limit, bool first)
36 if (!first)
37 return false;
38 if (thread_limit)
40 struct gomp_task_icv *icv = gomp_icv (true);
41 icv->thread_limit_var
42 = thread_limit > INT_MAX ? UINT_MAX : thread_limit;
44 unsigned int num_workgroups, workgroup_id;
45 num_workgroups = __builtin_gcn_dim_size (0);
46 workgroup_id = __builtin_gcn_dim_pos (0);
47 /* FIXME: If num_teams_lower > num_workgroups, we want to loop
48 multiple times at least for some workgroups. */
49 (void) num_teams_lower;
50 if (!num_teams_upper || num_teams_upper >= num_workgroups)
51 num_teams_upper = ((GOMP_ADDITIONAL_ICVS.nteams > 0
52 && num_workgroups > GOMP_ADDITIONAL_ICVS.nteams)
53 ? GOMP_ADDITIONAL_ICVS.nteams : num_workgroups);
54 else if (workgroup_id >= num_teams_upper)
55 return false;
56 gomp_num_teams_var = num_teams_upper - 1;
57 return true;
60 int
61 omp_pause_resource (omp_pause_resource_t kind, int device_num)
63 (void) kind;
64 (void) device_num;
65 return -1;
68 int
69 omp_pause_resource_all (omp_pause_resource_t kind)
71 (void) kind;
72 return -1;
75 ialias (omp_pause_resource)
76 ialias (omp_pause_resource_all)
78 void
79 GOMP_target_ext (int device, void (*fn) (void *), size_t mapnum,
80 void **hostaddrs, size_t *sizes, unsigned short *kinds,
81 unsigned int flags, void **depend, void **args)
83 (void) flags;
84 (void) depend;
85 (void) args;
87 if (device != GOMP_DEVICE_HOST_FALLBACK || fn == NULL)
88 return;
90 /* The output data is at ((void*) kernargs)[2]. */
91 register void **kernargs = (void**) __builtin_gcn_kernarg_ptr ();
92 struct output *data = (struct output *) kernargs[2];
93 /* Reserve one slot. */
94 unsigned int index = __atomic_fetch_add (&data->next_output, 1,
95 __ATOMIC_ACQUIRE);
97 if ((unsigned int) (index + 1) < data->consumed)
98 abort (); /* Overflow. */
100 /* Spinlock while the host catches up. */
101 if (index >= 1024)
102 while (__atomic_load_n (&data->consumed, __ATOMIC_ACQUIRE)
103 <= (index - 1024))
104 asm ("s_sleep 64");
106 unsigned int slot = index % 1024;
107 data->queue[slot].value_u64[0] = (uint64_t) fn;
108 data->queue[slot].value_u64[1] = (uint64_t) mapnum;
109 data->queue[slot].value_u64[2] = (uint64_t) hostaddrs;
110 data->queue[slot].value_u64[3] = (uint64_t) sizes;
111 data->queue[slot].value_u64[4] = (uint64_t) kinds;
112 data->queue[slot].value_u64[5] = (uint64_t) GOMP_ADDITIONAL_ICVS.device_num;
114 data->queue[slot].type = 4; /* Reverse offload. */
115 __atomic_store_n (&data->queue[slot].written, 1, __ATOMIC_RELEASE);
117 /* Spinlock while the host catches up. */
118 while (__atomic_load_n (&data->queue[slot].written, __ATOMIC_ACQUIRE) != 0)
119 asm ("s_sleep 64");
122 void
123 GOMP_target_data_ext (int device, size_t mapnum, void **hostaddrs,
124 size_t *sizes, unsigned short *kinds)
126 (void) device;
127 (void) mapnum;
128 (void) hostaddrs;
129 (void) sizes;
130 (void) kinds;
131 __builtin_unreachable ();
134 void
135 GOMP_target_end_data (void)
137 __builtin_unreachable ();
140 void
141 GOMP_target_update_ext (int device, size_t mapnum, void **hostaddrs,
142 size_t *sizes, unsigned short *kinds,
143 unsigned int flags, void **depend)
145 (void) device;
146 (void) mapnum;
147 (void) hostaddrs;
148 (void) sizes;
149 (void) kinds;
150 (void) flags;
151 (void) depend;
152 __builtin_unreachable ();
155 void
156 GOMP_target_enter_exit_data (int device, size_t mapnum, void **hostaddrs,
157 size_t *sizes, unsigned short *kinds,
158 unsigned int flags, void **depend)
160 (void) device;
161 (void) mapnum;
162 (void) hostaddrs;
163 (void) sizes;
164 (void) kinds;
165 (void) flags;
166 (void) depend;
167 __builtin_unreachable ();