Skip to content

Commit 08859e6

Browse files
author
Henry Jin
committed
declare target with device_type(nohost)
1 parent 03b9a00 commit 08859e6

File tree

5 files changed

+89
-3
lines changed

5 files changed

+89
-3
lines changed

History.tex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ \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}
@@ -27,6 +27,8 @@ \section{Changes from 5.2 to 5.2.1}
2727
\end{itemize}
2828
\item Added other examples:
2929
\begin{itemize}
30+
\item \code{declare}~\code{target} directive with \scode{device_type(nohost)}
31+
clause (\specref{subsec:declare_target_device_type})
3032
\item \scode{omp_pause_resource} and \scode{omp_pause_resource_all}
3133
routines (\specref{sec:pause_resource})
3234
\end{itemize}

devices/declare_target.tex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,25 @@ \subsection{Declare Target Directive with \code{link} Clause}
246246
\cexample[5.1]{declare_target}{6}
247247
\ffreeexample[4.5]{declare_target}{6}
248248

249+
250+
\subsection{Declare Target Directive with \code{device\_type} Clause}
251+
\label{subsec:declare_target_device_type}
252+
253+
\index{directives!declare target@\code{declare}~\code{target}}
254+
\index{declare target directive@\code{declare}~\code{target} directive}
255+
256+
\index{directives!begin declare target@\code{begin}~\code{declare}~\code{target}}
257+
\index{begin declare target directive@\code{begin}~\code{declare}~\code{target} directive}
258+
259+
\index{clauses!device_type@\code{device\_type}}
260+
\index{device_type clause@\code{device\_type} clause}
261+
262+
The \code{declare}~\code{target} directives apply to procedures to ensure that they can be executed or accessed on a device.
263+
The \code{device\_type} clause specifies whether a version of the procedure or variable should be made available on the host, device or both.
264+
This example uses \code{nohost} for a procedure \plc{foo}. Only a device version of the procedure \plc{foo} is made available.
265+
If the variant function \plc{foo\_onhost} is not specified for the host fallback execution, the call to \plc{foo} from the \code{target} region will result in a link time error due to the code generated for host execution of the target region.
266+
This is because host symbol for the device routine \plc{foo} marked as \code{nohost} is not required to be present in the host environment.
267+
268+
\cexample[5.2]{declare_target}{7}
269+
\ffreeexample[5.2]{declare_target}{7}
270+

devices/sources/declare_target.7.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @@name: declare_target.7
3+
* @@type: C
4+
* @@operation: link
5+
* @@expect: success
6+
* @@version: omp_5.2
7+
*/
8+
#include <stdio.h>
9+
10+
void foo();
11+
void foo_onhost();
12+
13+
#pragma omp declare target enter(foo) device_type(nohost)
14+
15+
#pragma omp declare variant(foo_onhost) match(device={kind(host)})
16+
void foo(){
17+
// device specific computation
18+
}
19+
20+
void foo_onhost(){
21+
printf("On host\n");
22+
}
23+
24+
int main(){
25+
#pragma omp target teams
26+
{
27+
foo(); // calls foo() on target device
28+
// or foo_onhost() in case of host fallback
29+
}
30+
return 0;
31+
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
! @@name: declare_target.7
2+
! @@type: F-free
3+
! @@operation: link
4+
! @@expect: success
5+
! @@version: omp_5.2
6+
module subs
7+
8+
contains
9+
subroutine foo()
10+
!$omp declare target enter(foo) device_type(nohost)
11+
!$omp declare variant(foo_onhost) match(device={kind(host)})
12+
! device specific computation
13+
end subroutine
14+
15+
subroutine foo_onhost()
16+
print *,' On host.'
17+
end subroutine
18+
19+
end module
20+
21+
program main
22+
23+
use subs
24+
!$omp target
25+
call foo ! calls foo() on device
26+
! or foo_onhost() in case of host fallback
27+
!$omp end target
28+
29+
end program

tasking/sources/tasking.8.f

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ module example
77
integer tp
88
!$omp threadprivate(tp)
99
integer var
10-
contains
10+
end module
11+
1112
subroutine work
13+
use example
1214
!$omp parallel
1315
! do work here
1416
!$omp task
@@ -21,4 +23,3 @@ subroutine work
2123
!$omp end task
2224
!$omp end parallel
2325
end subroutine
24-
end module

0 commit comments

Comments
 (0)