Skip to content

Commit 075683d

Browse files
author
Henry Jin
committed
more uses_allocators update
1 parent 08859e6 commit 075683d

File tree

6 files changed

+51
-35
lines changed

6 files changed

+51
-35
lines changed

History.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ \section{Changes from 5.2 to 5.2.1}
1818
\item Added the following examples for the 5.2 features:
1919
\begin{itemize}
2020
\item \scode{uses_allocators} clause for the use of allocators in
21-
\code{target} regions (\specref{sec:allocators})
21+
\code{target} regions (\specref{sec:allocators})
2222
\end{itemize}
2323
\item Added the following examples for the 5.1 features:
2424
\begin{itemize}
2525
\item The \scode{inoutset} dependence type (\specref{subsec:task_concurrent_depend})
2626
\item Atomic compare and capture (\specref{sec:cas})
2727
\end{itemize}
28-
\item Added other examples:
28+
\item Added the following examples for the 5.0 features:
2929
\begin{itemize}
3030
\item \code{declare}~\code{target} directive with \scode{device_type(nohost)}
3131
clause (\specref{subsec:declare_target_device_type})

devices/sources/declare_target.7.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ void foo_onhost();
1414

1515
#pragma omp declare variant(foo_onhost) match(device={kind(host)})
1616
void foo(){
17-
// device specific computation
17+
//device specific computation
1818
}
1919

2020
void foo_onhost(){
@@ -24,8 +24,8 @@ void foo_onhost(){
2424
int main(){
2525
#pragma omp target teams
2626
{
27-
foo(); // calls foo() on target device
28-
// or foo_onhost() in case of host fallback
27+
foo(); //calls foo() on target device or
28+
//foo_onhost() in case of host fallback
2929
}
3030
return 0;
3131

devices/sources/declare_target.7.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ program main
2222

2323
use subs
2424
!$omp target
25-
call foo ! calls foo() on device
26-
! or foo_onhost() in case of host fallback
25+
call foo !calls foo() on device or
26+
!foo_onhost() in case of host fallback
2727
!$omp end target
2828

2929
end program

memory_model/allocators.tex

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,21 +156,18 @@ \section{Memory Allocators}
156156
An allocator is initialized for the \scode{target} region in the \scode{uses_allocators} clause,
157157
and the traits specified in \splc{cgroup_traits} are included by the \scode{traits} modifier.
158158

159-
As shown above, the \scode{uses_allocators} clause creates a new allocator for the
160-
\scode{target} region, and uses only traits specified in the clause with a modifier.
161159
In CASE 3, the \splc{cgroup_alloc} variable is initialized on the host with traits
162-
and a memory space. However, these are ignored by the \scode{uses_allocators} clause,
163-
because a new allocator is initialized, and has no traits specified within the clause.
160+
and a memory space. However, these are ignored by the \scode{uses_allocators} clause
161+
and a new allocator for the \scode{target} region is initialized with default traits.
164162

165163
\cexample[5.2]{allocators}{5}
166164
\ffreeexample[5.2]{allocators}{5}
167165

168-
The following example shows how to make an allocator, defined on the host, available in a \scode{target} region.
166+
\index{dynamic_allocators clause@\scode{dynamic_allocators} clause}
167+
\index{clauses!dynamic_allocators@\scode{dynamic_allocators}}
169168

170-
When the \scode{requires} directive is specified with a \scode{dynamic_allocators}
171-
clause, allocators initialized on the host can be used in a \scode{target} region
172-
without specifying a \scode{uses_allocators} clause. This applies to predefined
173-
allocators and user-defined allocators.
169+
The following example shows how to make an allocator available in a \scode{target} region
170+
without specifying a \scode{uses_allocators} clause.
174171

175172
In CASE 1, the predefined \scode{omp_cgroup_mem_alloc} allocator is used in the \scode{target}
176173
region as in CASE 1 of the previous example, but without specifying a \scode{uses_allocators} clause.
@@ -179,9 +176,14 @@ \section{Memory Allocators}
179176
restrictions on allocator usage in \scode{target} regions.
180177

181178
CASE 2 also uses the \scode{dynamic_allocators} clause to remove allocator
182-
restrictions in the \scode{target} region. Here, an allocator initialized
183-
on the host is used for target array allocations of an \scode{allocate} clause.
184-
179+
restrictions in \scode{target} regions. Here, an allocator is initialized
180+
by calling the \scode{omp_init_allocator} routine in the \code{target} region.
181+
The allocator is then used for the allocations of array \plc{xbuf} in
182+
an \scode{allocate} clause of the \code{target}~\code{teams} construct
183+
for each team and destroyed after its use.
184+
The use of separate \code{target} regions is needed here since
185+
no statement is allowed between a \code{target} directive and
186+
its nested \code{teams} construct.
185187

186188
\cexample[5.2]{allocators}{6}
187189
\ffreeexample[5.2]{allocators}{6}

memory_model/sources/allocators.6.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
int calc(int i, int j) { return i*j;}
1414
#pragma omp declare target(calc)
1515

16-
1716
int main()
1817
{
1918
#define N 256
2019
int sum;
2120
int xbuf[N];
2221

23-
omp_allocator_handle_t cgroup_alloc;
22+
static omp_allocator_handle_t cgroup_alloc;
23+
#pragma omp declare target(cgroup_alloc)
2424
const omp_alloctrait_t cgroup_traits[1] =
2525
{{omp_atk_access, omp_atv_cgroup}};
2626

@@ -50,11 +50,14 @@ int main()
5050

5151
for (int i = 0; i < N; i++) { xbuf[i] = 0; }
5252

53-
cgroup_alloc = omp_init_allocator(
54-
omp_default_mem_space, 1, cgroup_traits);
53+
// initializes the allocator in target region
54+
#pragma omp target
55+
cgroup_alloc = omp_init_allocator(
56+
omp_default_mem_space, 1, cgroup_traits);
5557

56-
// WARNING: cgroup_alloc is in undefined state on target device!
57-
#pragma omp target teams reduction(+:xbuf) thread_limit(N) \
58+
// uses the initialized allocator
59+
#pragma omp target
60+
#pragma omp teams reduction(+:xbuf) thread_limit(N) \
5861
allocate(cgroup_alloc:xbuf) num_teams(4)
5962
{
6063
#pragma omp parallel for
@@ -63,7 +66,9 @@ int main()
6366
}
6467
}
6568

66-
omp_destroy_allocator(cgroup_alloc);
69+
// destroys the allocator after its use
70+
#pragma omp target
71+
omp_destroy_allocator(cgroup_alloc);
6772

6873
sum = 0;
6974
#pragma omp parallel for reduction(+:sum)

memory_model/sources/allocators.6.f90

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ program main
2525

2626
!$omp requires dynamic_allocators
2727

28-
integer( omp_allocator_handle_kind ) :: cgroup_alloc
29-
type(omp_alloctrait),parameter :: cgroup_traits(1)= &
28+
integer(omp_allocator_handle_kind),save :: cgroup_alloc
29+
!$omp declare target(cgroup_alloc)
30+
type(omp_alloctrait),parameter :: cgroup_traits(1)= &
3031
[omp_alloctrait(omp_atk_access,omp_atv_cgroup)]
3132

3233
!*** CASE 1: ***!
@@ -55,21 +56,29 @@ program main
5556

5657
do i=1,N; xbuf(i)=0; end do
5758

58-
cgroup_alloc = omp_init_allocator(omp_default_mem_space, 1, &
59-
cgroup_traits)
59+
!! initializes allocator in the target region
60+
!$omp target
61+
cgroup_alloc = omp_init_allocator(omp_default_mem_space, 1, &
62+
cgroup_traits)
63+
!$omp end target
6064

61-
!! WARNING: cgroup_alloc is in undefined state on target device!
62-
!$omp target teams reduction(+:xbuf) thread_limit(N) &
63-
!$omp& allocate(cgroup_alloc:xbuf) num_teams(4)
65+
!! uses the initialized allocator
66+
!$omp target
67+
!$omp teams reduction(+:xbuf) thread_limit(N) &
68+
!$omp& allocate(cgroup_alloc:xbuf) num_teams(4)
6469

6570
!$omp parallel do
6671
do i = 1,N
6772
xbuf(i) = xbuf(i) + calc(i,omp_get_team_num())
6873
enddo
6974

70-
!$omp end target teams
75+
!$omp end teams
76+
!$omp end target
7177

72-
call omp_destroy_allocator(cgroup_alloc)
78+
!! destroys the allocator after its use
79+
!$omp target
80+
call omp_destroy_allocator(cgroup_alloc)
81+
!$omp end target
7382

7483
sum = 0
7584
!$omp parallel do reduction(+:sum)

0 commit comments

Comments
 (0)