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
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)
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
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/>. */
27 #include "libgomp-gcn.h"
30 extern volatile struct gomp_offload_icvs GOMP_ADDITIONAL_ICVS
;
33 GOMP_teams4 (unsigned int num_teams_lower
, unsigned int num_teams_upper
,
34 unsigned int thread_limit
, bool first
)
40 struct gomp_task_icv
*icv
= gomp_icv (true);
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
)
56 gomp_num_teams_var
= num_teams_upper
- 1;
61 omp_pause_resource (omp_pause_resource_t kind
, int device_num
)
69 omp_pause_resource_all (omp_pause_resource_t kind
)
75 ialias (omp_pause_resource
)
76 ialias (omp_pause_resource_all
)
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
)
87 if (device
!= GOMP_DEVICE_HOST_FALLBACK
|| fn
== NULL
)
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,
97 if ((unsigned int) (index
+ 1) < data
->consumed
)
98 abort (); /* Overflow. */
100 /* Spinlock while the host catches up. */
102 while (__atomic_load_n (&data
->consumed
, __ATOMIC_ACQUIRE
)
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)
123 GOMP_target_data_ext (int device
, size_t mapnum
, void **hostaddrs
,
124 size_t *sizes
, unsigned short *kinds
)
131 __builtin_unreachable ();
135 GOMP_target_end_data (void)
137 __builtin_unreachable ();
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
)
152 __builtin_unreachable ();
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
)
167 __builtin_unreachable ();