|
1 | 1 | \cchapter{Data Environment}{data_environment} |
2 | 2 | \label{chap:data_environment} |
3 | | -The OpenMP \plc{data environment} contains data attributes of variables and |
4 | | -objects. Many constructs (such as \kcode{parallel}, \kcode{simd}, \kcode{task}) |
5 | | -accept clauses to control \plc{data-sharing} attributes |
6 | | -of referenced variables in the construct, where \plc{data-sharing} applies to |
7 | | -whether the attribute of the variable is \plc{shared}, |
8 | | -is \plc{private} storage, or has special operational characteristics |
9 | | -(as found in the \kcode{firstprivate}, \kcode{lastprivate}, \kcode{linear}, or \kcode{reduction} clause). |
| 3 | +An OpenMP \emph{data environment} is defined by a set of variables or objects |
| 4 | +and their \emph{data-environment attributes}. Data-environment attributes can |
| 5 | +be divided into \emph{data-sharing attributes} and \emph{data-mapping |
| 6 | +attributes}. |
10 | 7 |
|
11 | | -The data environment for a device (distinguished as a \plc{device data environment}) |
12 | | -is controlled on the host by \plc{data-mapping} attributes, which determine the |
13 | | -relationship of the data on the host, the \plc{original} data, and the data on the |
14 | | -device, the \plc{corresponding} data. |
| 8 | +Many constructs (such as \kcode{parallel}, \kcode{simd}, \kcode{task}) |
| 9 | +accept clauses to control data-sharing attributes of referenced variables in |
| 10 | +the construct, where data-sharing applies to whether the attribute of the |
| 11 | +variable is \emph{shared} or \emph{private}, in addition to other special |
| 12 | +operational characteristics of private (as indicated by the |
| 13 | +\kcode{firstprivate}, \kcode{lastprivate}, \kcode{linear}, or \kcode{reduction} |
| 14 | +clause). |
| 15 | + |
| 16 | +Variables and objects in the data environment for a target device |
| 17 | +(distinguished as a device data environment) have \emph{data-mapping |
| 18 | +attributes} that are controlled by data-mapping constructs (such as |
| 19 | +\kcode{target} or \kcode{target_data}), which determine the relationship of the |
| 20 | +data on the host (the \emph{original} data) and the data on the device (the |
| 21 | +\emph{corresponding} data). |
15 | 22 |
|
16 | 23 | \bigskip |
17 | 24 | DATA-SHARING ATTRIBUTES |
18 | 25 |
|
19 | | -Data-sharing attributes of variables can be classified as being \plc{predetermined}, |
20 | | -\plc{explicitly determined} or \plc{implicitly determined}. |
| 26 | +Data-sharing attributes of variables can be classified as being \emph{predetermined}, |
| 27 | +\emph{explicitly determined} or \emph{implicitly determined}. |
21 | 28 |
|
22 | 29 | Certain variables and objects have predetermined attributes. |
23 | 30 | A commonly found case is the loop iteration variable in associated loops |
24 | | -of a \kcode{for} or \kcode{do} construct. It has a private data-sharing attribute. |
25 | | -Variables with predetermined data-sharing attributes cannot be listed in a data-sharing clause; but there are some |
26 | | -exceptions (mainly concerning loop iteration variables). |
| 31 | +of a \kcode{for} or \kcode{do} construct. It has a private data-sharing |
| 32 | +attribute. Certain declarative directives can also be used to define variables |
| 33 | +as having special predetermined data-sharing attributes including \emph{threadprivate}, |
| 34 | +\emph{groupprivate}, and \emph{device-local}. Variables with predetermined |
| 35 | +data-sharing attributes cannot usually be listed in a data-sharing clause, but there |
| 36 | +are some exceptions (mainly concerning loop iteration variables). |
27 | 37 |
|
28 | 38 | Variables with explicitly determined data-sharing attributes are those that are |
29 | | -referenced in a given construct and are listed in a data-sharing attribute |
| 39 | +referenced in a given construct and are listed in a data-sharing |
30 | 40 | clause on the construct. Some of the common data-sharing clauses are: |
31 | 41 | \kcode{shared}, \kcode{private}, \kcode{firstprivate}, \kcode{lastprivate}, |
32 | 42 | \kcode{linear}, and \kcode{reduction}. % Are these all of them? |
|
38 | 48 | For a complete list of variables and objects with predetermined and |
39 | 49 | implicitly determined attributes, please refer to the |
40 | 50 | \docref{Data-sharing Attribute Rules for Variables Referenced in a Construct} |
41 | | -subsection of the OpenMP Specifications document. |
| 51 | +subsection of the OpenMP Specification document. |
42 | 52 |
|
43 | 53 | \bigskip |
44 | 54 | DATA-MAPPING ATTRIBUTES |
45 | 55 |
|
46 | | -The \kcode{map} clause on a device construct explicitly specifies how the list items in |
47 | | -the clause are mapped from the encountering task's data environment (on the host) |
48 | | -to the corresponding item in the device data environment (on the device). |
49 | | -The common \plc{list items} are arrays, array sections, scalars, pointers, and |
50 | | -structure elements (members). |
51 | | - |
52 | | -Procedures and global variables have predetermined data mapping if they appear |
53 | | -within the list or block of a \kcode{declare target} directive. Also, a C/C++ pointer |
54 | | -is mapped as a zero-length array section, as is a C++ variable that is a reference to a pointer. |
55 | | -% Waiting for response from Eric on this. |
| 56 | +A data-mapping attribute determines the manner in which a variable or object is |
| 57 | +mapped from a data environment of a task (typically on the host device) to a |
| 58 | +device data environment on a different device. The specification of list items |
| 59 | +in a \kcode{map} clause is the main mechanism for controlling the data-mapping |
| 60 | +attributes of data in a device data environment. These list items may include |
| 61 | +variables, including array and structure elements, array sections, as well as |
| 62 | +more general lvalue expressions in C/C++ (such as a dereferenced expression of |
| 63 | +pointer type). |
56 | 64 |
|
57 | | -Without explicit mapping, non-scalar and non-pointer variables within the scope of the \kcode{target} |
58 | | -construct are implicitly mapped with a \plc{map-type} of \kcode{tofrom}. |
59 | | -Without explicit mapping, scalar variables within the scope of the \kcode{target} |
60 | | -construct are not mapped, but have an implicit firstprivate data-sharing |
61 | | -attribute. (That is, the value of the original variable is given to a private |
62 | | -variable of the same name on the device.) This behavior can be changed with |
63 | | -the \kcode{defaultmap} clause. |
| 65 | +If a \kcode{map} clause is not explicitly specified for a variable that is |
| 66 | +referenced in a \kcode{target} construct, that variable may still have an |
| 67 | +\emph{implicit} data-mapping attribute (as if it had appeared in a \kcode{map} |
| 68 | +clause). For example, the use of a declare target directive or |
| 69 | +\kcode{defaultmap} clause can result in a variable having an implicit |
| 70 | +data-mapping attribute. Additionally, list items that appear in certain |
| 71 | +data-sharing clauses (e.g., \kcode{reduction}) on a compound target construct |
| 72 | +can imply a data-mapping attribute. Also, non-scalar variables referenced |
| 73 | +inside a \kcode{target} construct that do not otherwise have a predetermined or |
| 74 | +explicit data-sharing or data-mapping attribute will typically be implicitly |
| 75 | +mapped by default, in contrast to scalar variables which are typically given |
| 76 | +an implicit firstprivate attribute (these default implicit attributes can be |
| 77 | +changed with the use of the \kcode{defaultmap} clause). For a complete set of |
| 78 | +rules for implicit data-mapping attributes, refer to the |
| 79 | +\docref{Implicit Data-Mapping Attribute Rules} |
| 80 | +subsection of the OpenMP Specification document. |
64 | 81 |
|
65 | | -The \kcode{map} clause can appear on \kcode{target}, \kcode{target data} and |
66 | | -\kcode{target enter/exit data} constructs. The operations of creation and |
67 | | -removal of device storage as well as assignment of the original list item |
68 | | -values to the corresponding list items may be complicated when the list |
69 | | -item appears on multiple constructs or when the host and device storage |
70 | | -is shared. In these cases the item's reference count, the number of times |
71 | | -it has been referenced (increment by 1 on entry and decrement by 1 on exit) in nested (structured) |
72 | | -map regions and/or accumulative (unstructured) mappings, determines the operation. |
73 | | -Details of the \kcode{map} clause and reference count operation are specified |
74 | | -in the \docref{\kcode{map} Clause} subsection of the OpenMP Specifications document. |
| 82 | +The \kcode{map} clause can appear on data-mapping constructs (specifically, |
| 83 | +\kcode{target}, \kcode{target_data}, \kcode{target_enter_data} and |
| 84 | +\kcode{target_exit_data}). The operations of creation and removal of corresponding |
| 85 | +storage as well as assignment of the original list item values to the |
| 86 | +corresponding list items may be complicated when the list item appears on |
| 87 | +multiple constructs that are executed concurrently. To accomodate this, a |
| 88 | +reference count is maintained to determine which of those operations are |
| 89 | +needed. This can help ensure that corresponding storage is not removed on |
| 90 | +completion of one construct while another construct that has mapped the same |
| 91 | +data still requires it, as well as elide data transfers between devices in |
| 92 | +cases where corresponding storage is not being created or removed (though this |
| 93 | +can be overridden with use of modifiers such as \kcode{delete} or |
| 94 | +\kcode{always}). Details of the \kcode{map} clause and reference count |
| 95 | +operations are specified in the \docref{\kcode{map} Clause} subsection of the |
| 96 | +OpenMP Specification document. |
75 | 97 |
|
76 | 98 |
|
77 | 99 | %===== Examples Sections ===== |
78 | 100 | \input{data_environment/threadprivate} |
| 101 | +\input{data_environment/groupprivate} |
79 | 102 | \input{data_environment/default_none} |
80 | 103 | \input{data_environment/private} |
81 | 104 | \input{data_environment/fort_loopvar} |
|
0 commit comments