text
stringlengths
129
1.02k
or was added to the data clauses, new attach anddetach clauses were added, and matchingacc_attach andacc_detach runtime API routines were added; see Sections 264, 2712-2713 and 3229 The Intel Coprocessor Offload Interface target and API routine sec tions were removed from the Section A Recommendations for Implementers, since Intel no longer produ ces this prod- uct 113 Changes from Version 26 to 2 The_OPENACC value was updated to 201811 The specification allows for hosts that share some memory with the device but n ot all memory The wording in the text now discusses whether local thread data is in share d memory (memory shared between the local thread and the device) or discrete memory (local thread memory that is not shared with the device), instead of shared-memory devices and non -shared memory devices See Sections 13 Memory Model and 26 Data Environment The text was clarified to allow an implementation that treats a multicore CPU as a devic e, either an additional device or the only device Thereadonly
mber a nd configuration of gangs of workers and vector length may be different for each kernel If theasync clause does not appear, there is an implicit barrier at the end of the kerne ls region, and the local thread execution will not proceed until the entire sequence o f kernels has completed execution Thecopy ,copyin ,copyout ,create ,no_create ,present ,deviceptr , andattach data clauses are described in Section 27 Data Clauses The device_type clause is described in Section 24 Device-Specific Clauses Implicitly determined data attributes are d escribed in Sec- tion 262 Restrictions are described in Section 254 254 Compute Construct Restrictions The following restrictions apply to all compute constructs: A program may not branch into or out of a compute construct Only theasync ,wait ,num_gangs ,num_workers , andvector_length clauses may follow a device_type clause At most one ifclause may appear In Fortran, the condition must evaluate to a scalar logica l value; in C or C++, the condition must evaluate to
have completed Errors Anacc_error_invalid_async error is issued if wait_arg is not a valid async- argument value Anacc_error_device_unavailable error is issued if dev_num is not a valid device number See Section 522 3210 acc wait Summary Theacc_wait routines wait for completion of all associated asynchronous operations o n a single specified async queue or on all async queues on the current device o r on a specified device Format C or C++: void acc_wait(int wait_arg); void acc_wait_device(int wait_arg, int dev_num); void acc_wait_all(void); void acc_wait_all_device(int dev_num); Fortran: subroutine acc_wait(wait_arg) subroutine acc_wait_device(wait_arg, dev_num) subroutine acc_wait_all() subroutine acc_wait_all_device(dev_num) integer(acc_handle_kind) :: wait_arg integer :: dev_num Description A call to an acc_wait routine is functionally equivalent to a wait directive as follows, see Sec- tion 2163: acc_wait to await(wait_arg) directive acc_wait_device to await(devnum:dev_num,queues:wait_arg) directive
, the host thread may orchestrate the execution by allocating memory o n the accelerator de- vice, initiating data transfer, sending the code to the accelerator, passing a rguments to the compute region, queuing the accelerator code, waiting for completion, transferrin g results back to the host, and deallocating memory In most cases, the host can queue a sequence o f operations to be executed on a device, one after the other Most current accelerators and many multicore CPUs support two or three levels of parallelism Most accelerators and multicore CPUs support coarse-grain parallelism, which is fully parallel exe- cution across execution units There may be limited support for synchroniz ation across coarse-grain parallel operations Many accelerators and some CPUs also support fin e-grain parallelism, often implemented as multiple threads of execution within a single execution unit, which are typically rapidly switched on the execution unit to tolerate long latency memory operations Finally, most accelerator
Only the read and write of the location designated by xare performed mutually atomically The evaluation of expr orexpr-list need not be atomic with respect to the read or write of the location designated by x Anatomic construct with the capture clause forces an atomic update of the location designated byxusing the designated operator or intrinsic while also capturing the original or final value of the location designated by xwith respect to the atomic update The original or final value of the location designated by xis written into the location designated by vdepending on the form of the atomic construct structured block or statements following the usual language sema ntics Only the read and write of the location designated by xare performed mutually atomically Neither the evaluation of expr orexpr-list , nor the write to the location designated by v,need to be atomic with respect to the read or write of the location designated by x For all forms of the atomic construct, any combination of two or more of these
n Section 216 and count is a nonneg- ative integer indicating the array length If there is no dev_num argument, it is treated as if dev_num is the current device number Otherwise, dev_num must be a valid device number of the current device type A call to any of these routines returns an inde xiassociated with await_arg[i] that is not acc_async_sync and meets the conditions that would evalu- ateacc_async_test_device(wait_arg[i], dev_num) totrue If all the elements in wait_arg are equal to acc_async_sync orcount is equal to 0, these routines return -1 Otherwise, the return value is an integer in the range of 0≤i<count in C or C++ and 1≤i≤count in Fortran Errors Anacc_error_invalid_argument error is issued if count is a negative number Anacc_error_invalid_async error is issued if any element encountered in wait_arg is not a valid async-argument value Anacc_error_device_unavailable error is issued if dev_num is not a valid device number See Section 522 3213 acc getdefault async Summary Theacc_get_default_async
d from acc_malloc oracc_deviceptr The behavior of the acc_memcpy_device routines is: Ifbytes is zero, no action is taken Ifdata_dev_dest anddata_dev_src have the same value, no action is taken If the memory regions referred to by data_dev_dest anddata_dev_src overlap, the behavior is undefined If the data referred to by data_dev_src ordata_dev_dest is not accessible by the current device, the behavior is undefined Otherwise, bytes bytes of data at data_dev_src in the current device memory are copied todata_dev_dest in the current device memory The_async version of this routine will perform the data transfers asynchronously o n the async queue associated with async_arg The routine may return before the data has been transferred; see Section 216 Asynchronous Behavior for more details The synchro nous versions will not return until the data has been completely transferred Errors Anacc_error_invalid_null_pointer error is issued if data_dev_dest or data_dev_src is a null pointer and bytes is nonzero Anacc_e
ry as necessary Some accelerators implement a weak memory model In particular, they do not su pport memory coherence between operations executed by different threads; even on the same execution unit, mem- ory coherence is only guaranteed when the memory operations are separ ated by an explicit memory fence Otherwise, if one thread updates a memory location and another rea ds the same location, or two threads store a value to the same location, the hardware may not guarante e the same result for each execution While a compiler can detect some potential errors of this natu re, it is nonetheless possible to write a compute region that produces inconsistent numerical res ults Similarly, some accelerators implement a weak memory model for memory shared be tween the host and the accelerator, or memory shared between multiple accelerators Programmers need to be very careful that the program uses appropriate synchronization to ensure that an assignment or modification by a thread on any device to data in shared memory
uted in parallel across the gangs The dim argument is not allowed An argument with no keyword or with the num keyword is allowed only when the num_gangs does not appear on the kernels construct If an argument with no keyword or an argument after the num keyword appears, it specifies how many gangs to use to execute the iterations of this loop The region of a loop with the gang clause may not contain another loop with a gang clause unless within a nested compute region The scheduling of loop iterations to gangs is not specified unless the static modifier appears as an argument If the static modifier appears with an integer expression, that expression is used as a chunk size If the static modifier appears with an asterisk, the implementation will select a chunk size The iterations are divided into chunks of the selected chunk size, and the chunks are assigned to gangs starting with gang zero and continuing in round-robin fa shion Two gang loops in the same parallel region with the same number of iterations, and with
the pointer When the device pointer target is deallocated, the pointer in device memory sho uld be restored to the host value, so it can be safely copied back to host memory A detach action updates the pointer in device memory to have the same value as the corresponding pointer in lo cal memory; see Section 272 The attach anddetach actions are performed by the copy ,copyin ,copyout , create ,attach , anddetach data clauses (Sections 274-2713), and the acc_attach and acc_detach runtime API routines (Section 3229) The attach anddetach actions use attachment counters to determine when the pointer in device memory needs to be updated; s ee Section 268 265 Data Construct Summary Thedata construct defines vars to be allocated in the current device memory for the duration of the region, whether data should be copied from local memory to the current device memory upon region entry, and copied from device memory to local memory upon region ex it Syntax In C and C++, the syntax of the OpenACC data construct is #pragma
gh environment variables and through calls to OpenACC API r outines The program can retrieve values through calls to OpenACC API routines The ICVs are: acc-current-device-type-var - controls which type of device is used acc-current-device-num-var - controls which device of the selected type is used acc-default-async-var - controls which asynchronous queue is used when none appears in an async clause 231 Modifying and Retrieving ICV Values The following table shows environment variables or procedures to modify th e values of the internal control variables, and procedures to retrieve the values: ICV Ways to modify values Way to retrieve value acc-current-device-type-var acc_set_device_type acc_get_device_type set device_type init device_type ACC_DEVICE_TYPE acc-current-device-num-var acc_set_device_num acc_get_device_num set device_num init device_num ACC_DEVICE_NUM acc-default-async-var acc_set_default_async acc_get_default_async set default_async The initial values are implementation-defined After initial
then the original directive is nonconforming The supported device types are implementation-defined Depending on the imp lementation and the compiling environment, an implementation may support only a single device type, or may support multiple device types but only one at a time, or may support multiple device types in a single compilation A device architecture name may be generic, such as a vendor, or more spe cific, such as a partic- ular generation of device; see Appendix A Recommendations for Implementer s for recommended names When compiling for a particular device, the implementation will use the claus es associated with thedevice_type clause that specifies the most specific architecture name that applies for this device; clauses associated with any other device_type clause are ignored In this context, the asterisk is the least specific architecture name Syntax The syntax of the device_type clause is device_type( *) device_type( device-type-list ) Thedevice_type clause may be abbreviated to dtype /triangl
roperty will return 0 and acc_get_property_string will return a null pointer (in C or C++) or a blank string (in Fortran) in the following cases: If device type dev_type is not supported or no device of dev_type is available If the value of dev_num is not a valid device number for device type dev_type If the value of property is not one of the known values for that query routine, or that property has no value for the specified device 327 acc init Summary Theacc_init andacc_init_device routines initialize the runtime for the specified device type and device number This can be used to isolate any initialization cost from the computational cost, such as when collecting performance statistics Format C or C++: void acc_init(acc_device_t dev_type); void acc_init_device(int dev_num, acc_device_t dev_type ); Fortran: subroutine acc_init(dev_type) subroutine acc_init_device(dev_num, dev_type) integer :: dev_num integer(acc_device_kind) :: dev_type Description A call toacc_init oracc_init_device is functionally eq
in the current device memory and not in local memory The host may n ot be able to access variables in a device_resident clause The accelerator data lifetime of global variables or common blocks that appear in a device_resident clause is the entire execution of the program In Fortran, if the variable has the Fortran allocatable attribute, the memory for the variable will be allocated in and deallocated from the current device memory when the hos t thread executes anallocate ordeallocate statement for that variable, if the current device is a non-shared memory device If the variable has the Fortran pointer attribute, it may be allocated or deallocated by the host in the current device memory, or may appear on the left hand sid e of a pointer assignment statement, if the right hand side variable itself appears in a device_resident clause In Fortran, the argument to a device_resident clause may be a common block name enclosed in slashes; in this case, all declarations of the common block must have a matchin g de
arg appears as an actual argument in a procedure call in a compute construc t or an accelerator routine, and the associated dummy argument subarg also has the optional attribute, then PRESENT(subarg) returns the same value as PRESENT(subarg) would when executed on the host 2172 Do Concurrent Construct This section refers to the Fortran doconcurrent construct that is a form of doconstruct When doconcurrent appears without a loop construct in a kernels construct it is treated as if it is annotated with loop auto If it appears in a parallel construct or an accelerator routine then it is treated as if it is annotated with loop independent 3 Runtime Library This chapter describes the OpenACC runtime library routines that are availa ble for use by program- mers Use of these routines may limit portability to systems that do not support the OpenACC API Conditional compilation using the _OPENACC preprocessor variable may preserve portability This chapter has two sections: Runtime library definitions Runtime libra
clause behaves as follows: At entry to a region, the structured reference counter is used On an enterdata directive, the dynamic reference counter is used Ifvaris present and is not a null pointer, a present increment action with the appropriate reference counter is performed Ifvaris not present, a copyin action with the appropriate reference counter is performed Ifvaris a pointer reference, an attach action is performed At exit from the region: If the structured reference counter for varis zero, no action is taken Otherwise, a detach action is performed if varis a pointer reference, and a present decrement action with the structured reference counter is performed if varis not a null pointer If both structured and dynamic reference counters are zero, a delete action is performed If the optional readonly modifier appears, then the implementation may assume that the data referenced by var-list is never written to within the applicable region The errors in Section 273 Data Clause Errors may be issue
attributes may appear in a data clause that overrides the imp licit attribute Variables with explicitly determined data attributes are those which appear in a da ta clause on a data construct, a compute construct, or a declare directive See Section A33 for recommended diagnostics related to data attributes OpenACC supports systems with accelerators that have discrete memory fro m the host, systems with accelerators that share memory with the host, as well as systems where an accelerator shares some memory with the host but also has some discrete memory that is not shared w ith the host In the first case, no data is in shared memory In the second case, all data is in shared memory In the third case, some data may be in shared memory and some data may be in discr ete memory, although a single array or aggregate data structure must be allocated comple tely in shared or discrete memory When a nested OpenACC construct is executed on the device, the d efault target device for that construct is the same device on wh
urrent-device-num-var for the cur- rent thread If there are no devices of device type dev_type or if device type dev_type is not supported, this routine returns -1 326 acc getproperty Summary Theacc_get_property andacc_get_property_string routines return the value of a device-property for the specified device Format C or C++: size_t acc_get_property(int dev_num, acc_device_t dev_type, acc_device_property_t property); const char*acc_get_property_string(int dev_num, acc_device_t dev_type, acc_device_property_t property); Fortran: function acc_get_property(dev_num, dev_type, property) subroutine acc_get_property_string(dev_num, dev_type, & property, string) integer, value :: dev_num integer(acc_device_kind), value :: dev_type integer(acc_device_property_kind), value :: property integer(c_size_t) :: acc_get_property character *(*) :: string Description Theacc_get_property andacc_get_property_string routines return the value of the property dev_num anddev_type specify the device being queried If dev_type has the v
by the compiler The implementatio n may use a different value than specified based on limitations imposed by the target arch itecture 2513 private clause Theprivate clause is allowed on the parallel andserial constructs; it declares that a copy of each item on the list will be created for each gang in all dimensions Restrictions See Section 2171 Optional Arguments for discussion of Fortran optional a rguments in private clauses 2514 firstprivate clause Thefirstprivate clause is allowed on the parallel andserial constructs; it declares that a copy of each item on the list will be created for each gang, and that the co py will be initialized with the value of that item on the local thread when a parallel orserial construct is encountered Restrictions See Section 2171 Optional Arguments for discussion of Fortran optional a rguments in firstprivate clauses 2515 reduction clause Thereduction clause is allowed on the parallel andserial constructs It specifies a reduction operator and one or more vars It implies cop
point in the execution of the program Calls may appear in the library itself, during the processing o f an event The OpenACC runtime must allow for this case, where the callback list for an even t is modified while that event is being processed Dynamic Registration and Unregistration Calls toacc_register andacc_unregister may occur at any point in the application A callback routine can be registered or unregistered from a callback routin e, either the same routine or another routine, for a different event or the same event for which th e callback was invoked If a callback routine is registered for an event while that event is being proce ssed, then the new callback routine will be added to the tail of the list of callback routines for this event So me events (the _end ) events process the callback routines in reverse order, from the tail to th e head For those events, adding a new callback routine will not cause the new routine to be inv oked for this instance of the event The other events process the callbac
tive At least one copyout ,delete , ordetach clause must appear on an exitdata direc- tive if clause Theifclause is optional; when there is no ifclause, the compiler will generate code to allocate or deallocate space in the current device memory and move data from and to loca l memory When an ifclause appears, the program will conditionally allocate or deallocate device memory and move data to and/or from device memory When the condition in theifclause evaluates to false , no device memory will be allocated or deallocated, and no data will be moved When thecondition evaluates to true, the data will be allocated or deallocated and moved as specified async clause Theasync clause is optional; see Section 216 Asynchronous Behavior for more info rmation wait clause Thewait clause is optional; see Section 216 Asynchronous Behavior for more infor mation finalize clause Thefinalize clause is allowed on the exitdata directive and is optional When no finalize clause appears, the exit data directive will decrement the
t starts at the routine directive #pragma acc routine(f) gang void scopeB() { #pragma acc parallel f();// conforming } void f() {} // conforming C++ classes permit forward references from member function bodies to o ther members de- clared later For example, immediately within classA below,g’s scope does not start until afterf’s definition Nevertheless, within f’s body,gis in scope throughout The same is true forg’sroutine directive Thus, f’s call togis conforming class A { void f() { #pragma acc parallel g();// conforming } #pragma acc routine gang void g(); }; In some places, C++ classes do not permit forward references For e xample, in the return type of a member function, a member typedef that is declared later is not in scope L ikewise,g’s definition below is not fully within the scope of g’sroutine directive even though its body is, so its definition is nonconforming class A { #pragma acc routine(f) gang void f() {} // conforming void g() {} // nonconforming #pragma acc routine(g) gang }; The C++ scope
ost, wh en collecting performance statistics If no device type appears all devices will be initialize d Aninit directive may be used in place of a call to the acc_init oracc_init_device runtime API routine, as described in Section 327 Syntax In C and C++, the syntax of the init directive is: #pragma acc init [clause-list ]new-line In Fortran the syntax of the init directive is: !$acc init [clause-list ] where clause is one of the following: device_type( device-type-list ) device_num( int-expr) if( condition) device type clause Thedevice_type clause specifies the type of device that is to be initialized in the runtime If the device_type clause appears, then the acc-current-device-type-var for the current thread is set to the argument value If no device_num clause appears then all devices of this type are initialized device num clause Thedevice_num clause specifies the device id to be initialized If the device_num clause appears, then the acc-current-device-num-var for the current thread is set to the argument v
each array element of the array or subarray individually I f the reduction varis a com- posite variable, the reduction operation is logically equivalent to applying tha t reduction operation to each member of the composite variable individually If a variable is involved in a reduction that spans multiple nested loops where tw o or more of those loops have associated loop directives, a reduction clause containing that variable must appear on each of those loop directives Restrictions Avarin areduction clause must be a scalar variable name, an aggregate variable name, an array element, or a subarray (refer to Section 271) Reduction clauses on nested constructs for the same reduction varmust have the same reduc- tion operator Every varin areduction clause appearing on an orphaned loop construct must be private The restrictions for a reduction clause on a compute construct listed in in Section 25 reduction clause also apply to a reduction clause on a loop construct See Section 2171 Optional Arguments for di
eans that code within the parallel region, but outside of a loop construct with gang-level worksharing, will be executed redu ndantly by all gangs One worker in each gang begins executing the code in the structured block of the construct Note: Unless there is a loop construct within the parallel region, all gangs will execute all the code within the region redundantly If theasync clause does not appear, there is an implicit barrier at the end of the accele rator parallel region, and the execution of the local thread will not proceed until all gan gs have reached the end of the parallel region Thecopy ,copyin ,copyout ,create ,no_create ,present ,deviceptr , andattach data clauses are described in Section 27 Data Clauses The private andfirstprivate clauses are described in Sections 2513 and Sections 2514 The device_type clause is de- scribed in Section 24 Device-Specific Clauses Implicitly determined data attribu tes are described in Section 262 Restrictions are described in Section 254 252 Serial Construct Sum
re specified using special comments that are identifie d by a unique sentinel Compilers will typically ignore OpenACC directives if support is disabled or n ot provided 21 Directive Format In C and C++, OpenACC directives are specified with the #pragma mechanism The syntax of an OpenACC directive is: #pragma acc directive-name [clause-list ]new-line Each directive starts with #pragma acc The remainder of the directive follows the C and C++ conventions for pragmas Whitespace may be used before and after the #; whitespace may be required to separate words in a directive Preprocessing tokens follow ing the#pragma acc are subject to macro replacement Directives are case-sensitive In Fortran, OpenACC directives are specified in free-form source fi les as !$acc directive-name [clause-list ] The comment prefix ( !) may appear in any column, but may only be preceded by whitespace (spac es and tabs) The sentinel ( !$acc ) must appear as a single word, with no intervening whitespace Line length, whitespace, and continuation
ed or disabled from a callback routine, either the same routine or another routine, for a different event or the same event for which the callback was invoked If a callback routine is enabled for an event wh ile that event is being processed, then the new callback routine will be immediately enabled If it app ears on the list of callback routines closer to the head (for _end events) or closer to the tail (for other events), that newly-enabled callback routine will be invoked for this instance of this even t, unless it is disabled or unregistered before that callback is reached If a callback routine is disabled for an event while that event is being proc essed, that callback routine is immediately disabled For any event, if that callback routine had not yet bee n invoked for this in- stance of the event, it will not be invoked, unless it is enabled before that callback routine is reached in the list of callbacks for this event If all callbacks for an event are disa bled while that event is being processed, or
is used when there is an error condition issued from code executing on the device acc_error_device_init is used for any error initializing a device acc_error_device_shutdown is used for any error shutting down a device acc_error_device_unavailable is used when there is an error where the se- lected device is unavailable acc_error_device_type_unavailable is used when there is an error where no device of the selected device type is available or is supported acc_error_wrong_device_type is used when there is an error related to the device type, such as a mismatch between the device type for which a compute co nstruct was compiled and the device available at runtime acc_error_out_of_memory is used when the program tries to allocate more mem- ory on the device than is available acc_error_not_present is used for an error related to data not being present at runtime acc_error_partly_present is used for an error related to part of the data being present but not being completely present at runtime a
immediate detach action on the pointer referred to by ptr_addr ; see Section 272 These routines may issue a data transfer from local memory to device memory The_async ver- sions of these routines will perform the data transfers asynchronously on the async queue associated withasync_arg These routines may return before the data has been transferred; see Section 2 for more details The synchronous versions will not return until the data h as been completely trans- ferred Errors Anacc_error_invalid_null_pointer error is issued if ptr_addr is a null pointer Anacc_error_invalid_async error is issued if async_arg is not a valid async- argument value See Section 522 3230 acc memcpy d2d Summary Theacc_memcpy_d2d routines copy the contents of an array on one device to an array on the same or a different device without updating the value on the host Format C or C++: void acc_memcpy_d2d(h_void *data_arg_dest, h_void*data_arg_src, size_t bytes, int dev_num_dest, int dev_num_src); void acc_memcpy_d2d_async(h_void *data_
e code on the device 519 Enqueue Data Update (Upload and Download) Thedata update profiling event names are acc_ev_enqueue_upload_start acc_ev_enqueue_upload_end acc_ev_enqueue_download_start acc_ev_enqueue_download_end The_start events are triggered just before each upload (data copy from local memo ry to device memory) operation is or download (data copy from device memory to local memor y) operation is enqueued for execution on a device The corresponding _end events are triggered just after each upload or download operation is enqueued Note: Measuring the time between the start and end update callbacks is often unlikely to be useful, since it will only measure the time to manage the enqueue operation, not the time to pe rform the actual upload or download When the action that generates a data update event was generated explicitly by the application code theimplicit field in the event structure will be set to 0 When the data allocation event is triggered because of a variable or array with implicitly-determin
o one whenever the pointer is attached to new target address, and incremented whenever an attach action for that pointer is performed for the same target address The attachment counter is decremented whenever a detach action occurs for the pointer, and the pointer is detached when the attachment counter reaches zero This is described in more detail in Section 272 Data Clause Ac tions A pointer in device memory can be assigned a device address in two ways Th e pointer can be attached to a device address due to data clauses or API routines, as desc ribed in Section 27 Data Clause Actions, or the pointer can be assigned in a compute region exec uted on that device Unspecified behavior may result if both ways are used for the same pointer Pointer members of structs, classes, or derived types in device or host me mory can be overwritten due to update directives or API routines It is the user’s responsibility to e nsure that the pointers have the appropriate values before or after the data movement in either dire c
om device Summary Theacc_memcpy_from_device routine copies data from device memory to local memory Format C or C++: void acc_memcpy_from_device(h_void *data_host_dest, d_void*data_dev_src, size_t bytes); void acc_memcpy_from_device_async(h_void *data_host_dest, d_void*data_dev_src, size_t bytes, int async_arg); Fortran: subroutine acc_memcpy_from_device(data_host_dest, data_dev_src, bytes) subroutine acc_memcpy_from_device_async(data_host_de st, data_dev_src, bytes, async_arg) type(*),dimension( *) :: data_host_dest type(c_ptr), value :: data_dev_src integer(c_size_t), value :: bytes integer(acc_handle_kind), value :: async_arg Description Theacc_memcpy_from_device routine copies bytes bytes of data from the device address indata_dev_src to the local address in data_host_dest data_dev_src must be an address accessible from the current device, such as an address re turned from acc_malloc or acc_deviceptr , or an address in shared memory The behavior of the acc_memcpy_from_device routines is: Ifbytes is zero,
argument value Anacc_error_device_unavailable error is issued if dev_num is not a valid device number See Section 522 3211 acc wait async Summary Theacc_wait_async routines enqueue a wait operation on one async queue of the current device or a specified device for the operations previously enqueued on a single specified async queue or on all other async queues Format C or C++: void acc_wait_async(int wait_arg, int async_arg); void acc_wait_device_async(int wait_arg, int async_arg, int dev_num); void acc_wait_all_async(int async_arg); void acc_wait_all_device_async(int async_arg, int dev_n um); Fortran: subroutine acc_wait_async(wait_arg, async_arg) subroutine acc_wait_device_async(wait_arg, async_arg, dev_num) subroutine acc_wait_all_async(async_arg) subroutine acc_wait_all_device_async(async_arg, dev_n um) integer(acc_handle_kind) :: wait_arg, async_arg integer :: dev_num Description A call to an acc_wait_async routine is functionally equivalent to a waitasync(async_arg) directive as follows, see Section 21
dimens ions For instance, after entering a loop partitioned for gang-level work-sharing at dimensio n 3, the program will be in GP3, GR2, GR1 mode When only one worker is active, in any gang-level execution mode, the pr ogram is in worker-single mode (WS mode) When only one vector lane is active, the program is in vector-single mode (VS mode) If a gang reaches a loop or loop nest marked for worker-le vel work-sharing, the gang transitions to worker-partitioned mode (WP mode), which activates all the workers of the gang The iterations of the loop or loops are partitioned across the workers of this gan g If the same loop is marked for both gang-partitioning in dimension dand worker-partitioning, then the iterations of the loop are spread across all the workers of all the gangs of dimension d If a worker reaches a loop or loop nest marked for vector-level work-sharing, the worker will tra nsition to vector-partitioned mode (VP mode) Similar to WP mode, the transition to VP mode activates all the vector lanes of
pointer otherwise For events that are neither _start or_end events, this field will be a null pointer Data Events For a data event, as noted in the event descriptions, the second argument will be a pointer to the acc_data_event_info struct typedef struct acc_data_event_info { acc_event_t event_type; int valid_bytes; acc_construct_t parent_construct; int implicit; void*tool_info; const char *var_name; size_t bytes; const void *host_ptr; const void *device_ptr; }acc_data_event_info; The fields specific for a data event are: acc_event_tevent_type - The event type that triggered this callback The events that use theacc_data_event_info struct are: acc_ev_enqueue_upload_start acc_ev_enqueue_upload_end acc_ev_enqueue_download_start acc_ev_enqueue_download_end acc_ev_create acc_ev_delete acc_ev_alloc acc_ev_free constchar *var_name - A pointer to null-terminated string containing the name of the variable for which this event is triggered, if known, or a null pointer if not If the library wants to save the variable nam
rules apply to the directive line In itial directive lines must have whitespace after the sentinel Continued directive lines must have an ampersand ( &) as the last nonblank character on the line, prior to any comment placed in the dire ctive Continuation directive lines must begin with the sentinel (possibly preceded by whitespac e) and may have an ampersand as the first non-whitespace character after the sentinel Comme nts may appear on the same line as a directive, starting with an exclamation point and extending to the en d of the line If the first nonblank character after the sentinel is an exclamation point, the line is ignored In Fortran fixed-form source files, OpenACC directives are specifie d as one of !$acc directive-name [clause-list ] c$acc directive-name [clause-list ] *$acc directive-name [clause-list ] The sentinel ( !$acc ,c$acc , or*$acc ) must occupy columns 1-5 Fixed form line length, whitespace, continuation, and column rules apply to the directive line Initial d irective lines must have a sp
t of one or more integer expressions, and a var-list is a comma-separated list of one or more vars The one exception isclause-list , which is a list of one or more clauses optionally separated by commas #pragma acc directive-name [clause-list ]new-line For C/C++, unless otherwise specified, each expression inside of the Op enACC clauses and direc- tive arguments must be a valid assignment-expression This avoids ambiguity between the comma operator and comma-separated list items In this spec, a do loop (in italics) is the doconstruct as defined by the Fortran standard The do-stmt of thedoconstruct must conform to one of the following forms: do [label] do-var = lb, ub [, incr] do concurrent [label] concurrent-header [concurrent-locality] Thedo-var is a variable name and the lb, ub, incr are scalar integer expressions A doconcurrent is treated as if defining a loop for each index in the concurrent-header An italicized true is used for a condition that evaluates to nonzero in C or C++, or true in Fortran An italic
lback from a thread T2 while it’s still processing a callback, from the same event type or from a different ev ent type, from another thread T1 Theacc_callback_info struct has a thread_id field, which the runtime must set to a unique value for each host thread If the tool library uses dynamic callback registration and unregistration, or callback disabling and enabling, recall that unregistering or disabling an event callback from o ne thread will unregister or disable that callback for all threads, and registering or enabling an even t callback from any thread will register or enable it for all threads If two or more threads register the same callback for the same event, the behavior is the same as if one thread registered that callback multiple times; see Section 541 Multiple Callbacks The acc_unregister routine must be called as many times asacc_register for that callback/event pair in order to totally unregister it If two threads register two different callback routines for the same event, unless the ord e
Any data clause on the compute construct, a lexically containing data construct, or a visible declare directive Exposed variable access : Any access to the data or address of a variable at a point within the compute construct where the variable is not private to a scope lexically enc losed within the compute construct Note: In the argument of C’s sizeof operator, the appearance of a variable is not an exposed access because neither its data nor its address is accessed In the argu ment of areduction clause on an enclosed loop construct, the appearance of a variable that is not otherwise privatized is an exposed access to the original variable On a compute or combined construct, if a variable appears in a reduction clause but no other data clause, it is treated as if it also appears in a copy clause Otherwise, for any variable, the compiler will implicitly determine its data attribute on a compute construct if all of the follo wing conditions are met: There is no default(none) clause visible at the compute c
issued; see Sections 2161 and 2162 See Section 522 256 if clause Theifclause is optional When the condition in theifclause evaluates to true, the region will execute on the current device When the condition in theifclause evaluates to false , the local thread will execute the region 257 self clause Theself clause is optional Theself clause may have a single condition-argument If the condition-argument is not present it is assumed to evaluate to true When both an ifclause and a self clause appear and the condition in theifclause evaluates to false , theself clause has no effect When the condition evaluates to true, the region will execute on the local device When the condition in theself clause evaluates to false , the region will execute on the current device 258 async clause Theasync clause is optional; see Section 216 Asynchronous Behavior for more info rmation 259 wait clause Thewait clause is optional; see Section 216 Asynchronous Behavior for more infor mation 2510 num gangs clause Thenum_gangs clause
as if it app ears in ano_create clause on the current construct If the variable is defined as global or fi le or function static, it must appear in a declare directive 263 Data Regions and Data Lifetimes Data in shared memory is accessible from the current device as well as to the local thread Such data is available to the accelerator for the lifetime of the variable Data not in sha red memory must be copied to and from device memory using data constructs, clauses, and A PI routines A data lifetime is the duration from when the data is first made available to the accelerator until it becomes unavailable For data in shared memory, the data lifetime begins when the data is a llocated and ends when it is deallocated; for statically allocated data, the data lifetime begins w hen the program begins and does not end For data not in shared memory, the data lifetime beg ins when it is made present and ends when it is no longer present There are four types of data regions When the program encounters a data construct, it
In the case of combined directives, the outermost construct of the combined con struct should be specified as theparent_construct If the event was emitted as the result of the application making a call to the runtime api, the value will be acc_construct_runtime_api typedef enum acc_construct_t { acc_construct_parallel = 0, acc_construct_serial = acc_construct_kernels = 1, acc_construct_loop = 2, acc_construct_data = 3, acc_construct_enter_data = 4, acc_construct_exit_data = 5, acc_construct_host_data = 6, acc_construct_atomic = 7, acc_construct_declare = 8, acc_construct_init = 9, acc_construct_shutdown = 10, acc_construct_set = 11, acc_construct_update = 12, acc_construct_routine = 13, acc_construct_wait = 14, acc_construct_runtime_api = 15, }acc_construct_t; 523 Third Argument: API-Specific Information The third argument is a pointer to the acc_api_info struct type, shown here typedef struct acc_api_info { acc_device_api device_api; int valid_bytes; acc_device_t device_type; int vendor; const void *device_
to an acc_create API routine (Section 3218) See those sections for details Acreate action for a varoccurs only when varis not already present in device memory Acreate action for a var: allocates device memory for var; and sets the structured or dynamic reference counter to one Copyin Action Acopyin action is one of the actions that may be performed for a copy (Section 276) or copyin (Section 277) clause, or for a call to an acc_copyin API routine (Section 3218) See those sections for details Acopyin action for a varoccurs only when varis not already present in device memory Acopyin action for a var: allocates device memory for var; initiates a copy of the data for varfrom the local thread memory to the corresponding device memory; and sets the structured or dynamic reference counter to one The data copy may complete asynchronously, depending on other clauses on the directive Copyout Action Acopyout action is one of the actions that may be performed for a copy (Section 276) or copyout (Section 278) clau
vice memory for var Attach Action Anattach action is one of the actions that may be performed for a present (Section 275), copy (Section 276), copyin (Section 277), copyout (Section 278), create (Section 279), no_create (Section 2710), or attach (Section 2711) clause, or for a call to an acc_attach API routine (Section 3229) See those sections for details Anattach action for a varoccurs only when varis a pointer reference If the pointer varis in shared memory or is not present in the current device memory, or if the address to which varpoints is not present in the current device memory, no action is taken If the attachment counter forvaris nonzero and the pointer in device memory already points to the device copy of the data in var, the attachment counter for the pointer varis incremented Otherwise, the pointer in device memory is attached to the device copy of the data by initiating an update for the pointer in device memory to point to the device copy of the data and setting the attachment counter for the p
acc_register_library , passing the addresses of the reg- istration routines acc_callback_register andacc_callback_unregister , in case that routine comes from a dynamic library In the third argument it passes the address of the lookup routineacc_prof_lookup to obtain the addresses of inquiry functions No inquiry functions are defined in this profiling interface, but we preserve this argument for future support of sampling- based tools Typically, the OpenACC runtime will include a weak definition of acc_register_library , which does nothing and which will be called when there is no tools library In th is case, the library can save the addresses of these routines and/or make registration calls to r egister any appropriate callbacks The prototype for acc_register_library is: extern void acc_register_library (acc_prof_reg reg, acc_prof_reg unreg, acc_prof_lookup_func lookup); The first two arguments of this routine are of type: typedef void ( *acc_prof_reg) (acc_event_t event_type, acc_callback cb, acc_register_t i
oss implementations and interoperability with other accelerator API s 18 References Each language version inherits the limitations that remain in previous versions o f the language in this list American National Standard Programming Language C , ANSI X3159-1989 (ANSI C) ISO/IEC 9899:1999, Information Technology – Programming Languages – C , (C99) ISO/IEC 9899:2011, Information Technology – Programming Languages – C , (C11) The use of the following C11 features may result in unspecified behavior Threads Thread-local storage Parallel memory model Atomic ISO/IEC 9899:2018, Information Technology – Programming Languages – C , (C18) The use of the following C18 features may result in unspecified behavior Thread related features ISO/IEC 14882:1998, Information Technology – Programming Languages – C++ ISO/IEC 14882:2011, Information Technology – Programming Languages – C++ , (C++11) The use of the following C++11 features may result in unspecified behavio r Extern templates copy and rethrow except
library that will be invoked in the normal case where there is no LD_PRELOAD setting If an implementation only supports static linking, or if the application is linked without dynamic library support, this feature will not be av ailable Bash: export LD_PRELOAD=/home/user/lib/myprofso /myapp or LD_PRELOAD=/home/user/lib/myprofso /myapp C-shell: setenv LD_PRELOAD /home/user/lib/myprofso /myapp The sequence of events is: 1 The operating system loader loads the library specified in LD_PRELOAD 2 The call to acc_register_library in the OpenACC runtime is resolved to the routine in the loaded tools library 3 OpenACC runtime calls the acc_register_library routine in that library 4 Youracc_register_library routine calls acc_callback_register for each event to be monitored 5acc_callback_register records the callback routines 6 The program runs, and your callback routines are invoked at the ap propriate events In this mode, only a single tools library is supported, since only one acc_register_library initialization rou
c variables are not supported in functions to wh ich aroutine directive applies In Fortran, variables with the save attribute, either explicitly or implicitly, are not supported in subprograms to which a routine directive applies A call to a procedure with a nohost clause must not appear in a compute construct that is compiled for the host See examples below If a call to a procedure with a nohost clause appears in another procedure but outside any compute construct, that other procedure must also have a nohost clause A call to a procedure with a gang(dim: d)clause must appear in code that is executed ingang-redundant mode in all dimensions dand lower For instance, a procedure with a gang(dim:2) clause may not be called from within a loop that has a gang(dim:1) or agang(dim:2) clause The user needs to ensure that a call to a procedure with a gang(dim: d)clause, when present in a region executing in GRe orGPe mode with e>d and called by a gang along dimension e, is executed by all of its corresponding gang
pended to the tail of the callback list for that event Unregistering A matching call to acc_callback_unregister will remove that routine from the list of call- back routines for that event acc_callback_register(acc_ev_enqueue_upload_start, prof_data, acc_reg); // prof_data is on the callback list for acc_ev_enqueue_upload_start acc_callback_unregister(acc_ev_enqueue_upload_start , prof_data, acc_reg); // prof_data is removed from the callback list // foracc_ev_enqueue_upload_start Each entry on the callback list must also have a refcount This keeps track of how many times this routine was added to this event’s callback list If a routine is registered ntimes, it must be unregistered ntimes before it is removed from the list Note that if a routine is registered multiple times for the same event, its refcount will be incremented with each registration, but it will only be invoked once for each event instance 542 Disabling and Enabling Callbacks A callback routine may be temporarily disabled on the callback l
ot_host , andacc_device_current For other val- ues, look at the appropriate files included with the implementation, or read the do cumentation for the implementation The value acc_device_default will never be returned by any function; its use as an argument will tell the runtime library to use the default device type f or that implemen- tation 32 Runtime Library Routines In this section, for the C and C++ prototypes, pointers are typed h_void*ord_void*to desig- nate a host memory address or device memory address, when these calls ar e executed on the host, as if the following definitions were included: #define h_void void #define d_void void Many Fortran API bindings defined in this section rely on types defined in Fo rtran’siso_c_binding module It is implied that the iso_c_binding module is used in these bindings, even if not ex- plicitly stated in the format section for that routine Restrictions Except foracc_on_device , these routines are only available on the host 321 acc getnum devices Summary Theacc_get_nu
ne directive for the procedure must include the nohost clause If the data ap- pears in alink clause, that data must have an active accelerator data lifetime by virtue of ap pearing in a data clause for a data construct, compute construct, or enterdata directive 216 Asynchronous Behavior This section describes the async clause, thewait clause, thewait directive, and the behavior of programs that use asynchronous data movement, compute regions, and as ynchronous API routines In this section and throughout the specification, the term async-argument means a nonnegative scalar integer expression ( intfor C or C++, integer for Fortran), or one of the special values acc_async_noval oracc_async_sync , as defined in the C header file and the Fortran openacc module The special values are negative values, so as not to conflict with a user-specified nonnegative async-argument An async-argument is used inasync clauses,wait clauses,wait directives, and as an argument to various runtime routines Theasync-value of an async-argum
urrent 291 collapse clause Thecollapse clause is used to specify how many nested loops are associated with the loop construct The argument to the collapse clause must be a constant positive integer expression If nocollapse clause appears, only the immediately following loop is associated with the loop construct If more than one loop is associated with the loop construct, the iterations of all the associated loops are all scheduled according to the rest of the clauses The trip count fo r all loops associated with thecollapse clause must be computable and invariant in all the loops The particular intege r type used to compute the trip count for the collapsed loops is implementation define d However, the integer type used for the trip count has at least the precision of each loop variable of the associated loops It is implementation-defined whether a gang ,worker orvector clause on the construct is ap- plied to each loop, or to the linearized iteration space The associated loops are the nnested loops that immedia
tion or automatic offloading, or paralle lizing across multiple accelerators of the same type, or across multiple accelerators of diffe rent types, these pos- sibilities are not addressed in this document 12 Execution Model The execution model targeted by OpenACC API-enabled implementations is hos t-directed execu- tion with an attached parallel accelerator, such as a GPU, or a multicore host with a host thread that initiates parallel execution on the multiple cores, thus treating the multicore CPU itself as a device Much of a user application executes on a host thread Compute intensive r egions are offloaded to an accelerator or executed on the multiple host cores under control of a hos t thread A device, either an attached accelerator or the multicore CPU, executes parallel regions , which typically contain work-sharing loops, kernels regions, which typically contain one or more loops that may be exe- cuted as kernels, or serial regions, which are blocks of sequential code Even in accelerator-targeted regions
is created for each gang in all dimensions and shared across the set of thr eads associated with all the vector lanes of all the workers of that gang Restrictions See Section 2171 Optional Arguments for discussion of Fortran optional a rguments in private clauses /triangledownsld /triangledownsld Examples In the example below, tmp is private to each worker of every gang but shared across all the vector lanes of a worker !$acc parallel !$acc loop gang do k = 1, n !$acc loop worker private(tmp) do j = 1, n !a single vector lane in each gang and worker assigns to tmp tmp = b(j,k) + c(j,k) !$acc loop vector do i = 1, n !all vector lanes use the result of the above update to tmp a(i,j,k) = a(i,j,k) + tmp/div enddo enddo enddo !$acc end parallel In the example below, tmp is private to each gang in every dimension !$acc parallel num_gangs(3,50,150) !$acc loop gang(dim:3) do k = 1, n !$acc loop gang(dim:2) private(tmp) do j = 1, n !all gangs along dimension 1 execute in gang redundant mode a nd !assign to tmp wh
launch additional compute regions, allowing for nested parallelism In that case, the OpenACC directives may be executed by a host thread or a device thread This specification uses the term local thread orlocal memory to mean the thread that executes the directive, or the memory associated with that thread , whether that thread executes on the host or on the accelerator The specification uses the ter mlocal device to mean the device on which the local thread is executing Most accelerators can operate asynchronously with respect to the hos t thread Such devices have one or more activity queues The host thread will enqueue operations onto the device activity queues, such as data transfers and procedure execution After enqueuing the operation, the host thread can continue execution while the device operates independently and asynchro nously The host thread may query the device activity queue(s) and wait for all the operations in a q ueue to complete Operations on a single device activity queue will complete before
scussion of Fortran optional a rguments in reduction clauses See Section 262 Variables with Implicitly Determined Data Attributes for a restriction re- quiring certain loop reduction variables to have explicit data clauses on their parent compute constructs Areduction clause may not appear on a loop directive that has a gang clause with a dim: argument whose value is greater than 1 Areduction clause may not appear on a loop directive that has a gang clause and is within a compute construct that has a num_gangs clause with more than one explicit argument /triangledownsld /triangledownsld Examples xis not private at the loop directive below, so its reduction normally updates xat the end of the parallel region, where gangs synchronize When possible, the imp lementation might choose to partially update xat the loop exit instead, or fully if num_gangs(1) were added to theparallel directive However, portable applications cannot rely on such early up - dates, so accesses to xare undefined within the parallel reg
lerator 264 Data Structures with Pointers This section describes the behavior of data structures that contain pointer s A pointer may be a C or C++ pointer (eg, float*), a Fortran pointer or array pointer (eg, real, pointer, dimension(:) ), or a Fortran allocatable (eg, real,allocatable,dimension(:) ) When a data object is copied to device memory, the values are copied exactly If the data is a data structure that includes a pointer, or is just a pointer, the pointer value copie d to device memory will be the host pointer value If the pointer target object is also allocated in o r copied to device memory, the pointer itself needs to be updated with the device address of the tar get object before dereferencing the pointer in device memory Anattach action updates the pointer in device memory to point to the device copy of the data that the host pointer targets; see Section 272 For Fortran array pointer s and allocatable arrays, this includes copying any associated descriptor (dope vector) to the devic e copy of
e strongly rec- ommended to use the names in this section The first subsection describes dev ices, such as NVIDIA GPUs The second subsection describes additional API routines for tar get platforms, such as CUDA and OpenCL The third subsection lists several recommended options for imp lementations A1 Target Devices A11 NVIDIA GPU Targets This section gives recommendations for implementations that target NVIDIA GP U devices Accelerator Device Type These implementations should use the name acc_device_nvidia for theacc_device_t type or return values from OpenACC Runtime API routines ACC DEVICE TYPE An implementation should use the case-insensitive name nvidia for the environment variable ACC_DEVICE_TYPE device type clause argument An implementation should use the case-insensitive name nvidia as the argument to the device_type clause A12 AMD GPU Targets This section gives recommendations for implementations that target AMD GPUs Accelerator Device Type These implementations should use the name acc_device_radeon for
the worker The iterations of the loop or loops will be partitioned across the v ector lanes using vector or SIMD operations Again, a single loop may be marked for one, two, or all three of gang, worker, and vector parallelism, and the iterations of that loop will be spread across th e gangs, workers, and vector lanes as appropriate The program starts executing with a single initial host thread, identified by a p rogram counter and its stack The initial host thread may spawn additional host threads, using O penACC or another mechanism, such as with the OpenMP API On a device, a single vector lane of a single worker of a single gang is called a device thread When executing on an accelerator, a parallel execution context is created on the accelerator and may contain many such threads The user should not attempt to implement barrier synchronization, critical se ctions, or locks across any of gang, worker, or vector parallelism The execution model allows fo r an implementation that executes some gangs to completi
xpr is not a valid device number or that device is not available Anacc_error_device_shutdown error is issued if there is an error shutting down the device See Section 522 2143 Set Directive Summary Theset directive provides a means to modify internal control variables using direc tives Each form of theset directive is functionally equivalent to a matching runtime API routine Syntax In C and C++, the syntax of the set directive is: #pragma acc set [clause-list ]new-line In Fortran the syntax of the set directive is: !$acc set [clause-list ] where clause is one of the following default_async( int-expr) device_num( int-expr) device_type( device-type-list ) if( condition) default async clause Thedefault_async clause specifies the asynchronous queue that should be used if no que ue ap- pears and changes the value of acc-default-async-var for the current thread to the argument value If the value is acc_async_default , the value of acc-default-async-var will revert to the ini- tial value, which is implementation-de
edownsld /triangledownsld Examples On the following directive, worker appears as a device-specific clause for devices of type foo, butgang appears as a default clause and so applies to all device types, including foo #pragma acc loop gang device_type(foo) worker The first directive below is identical to the previous directive except that loop is replaced withroutine Unlikeloop ,routine does not permit gang to appear with worker , but both apply for device type foo, so the directive is nonconforming The second directive below is conforming because gang there applies to all device types except foo // nonconforming: gang and worker not permitted together #pragma acc routine gang device_type(foo) worker // conforming: gang and worker for different device types #pragma acc routine device_type(foo) worker \ device_type( *) gang On the directive below, the value of num_gangs is4for device type foo, but it is2for all other device types, including bar That is,foo has a device-specific num_gangs clause, so the defau
for more information 215 Procedure Calls in Compute Regions This section describes how routines are compiled for an accelerator and h ow procedure calls are compiled in compute regions See Section 2171 Optional Arguments for discus sion of Fortran optional arguments in procedure calls inside compute regions 2151 Routine Directive Summary Theroutine directive is used to tell the compiler to compile the definition for a procedure, su ch as a function or C++ lambda, for an accelerator as well as for the host Th eroutine directive is also used to tell the compiler the attributes of the procedure when called on the a ccelerator Syntax In C and C++, the syntax of the routine directive is: #pragma acc routine clause-list new-line #pragma acc routine( name)clause-list new-line In C and C++, the routine directive without a name may appear immediately before a function definition, a function prototype, or a C++ lambda and applies to the function or C++ lambda The routine directive with a name may appear anywhere that a
ed data attribu tes or otherwise implicitly by the compiler the implicit field in the event structure will be set to 1 5110 Wait Thewait profiling event names are acc_ev_wait_start acc_ev_wait_end Anacc_ev_wait_start event will be triggered for each relevant queue before the local threa d waits for that queue to be empty A acc_ev_wait_end event will be triggered for each relevant queue after the local thread has determined that the queue is empty Wait events occur when the local thread and a device synchronize, eithe r due to await directive or by a wait clause on a synchronous data construct, compute construct, or enter data ,exit data , orupdate directive For wait events triggered by an explicit synchronous wait directive orwait clause, the implicit field in the event structure will be 0 For all other wait events, the implicit field in the event structure will be 1 The OpenACC runtime need not trigger wait events for queues that have not been used in the program, and need not trigger wait events for queues th
ent is acc_async_sync ifasync-argument has a value equal to the special value acc_async_sync , the value of acc-default-async-var ifasync-argument has a value equal to the special value acc_async_noval , the value of the async-argument , if it is nonnegative, implementation-defined, otherwise Theasync-value is used to select the activity queue to which the clause or directive or API ro utine refers The properties of the current device and the implementation will dete rmine how many actual activity queues are supported, and how the async-value is mapped onto the actual activity queues Two asynchronous operations on the same device with the same async-value will be enqueued onto the same activity queue, and therefore will be executed on the device in the order they are encountered by the local thread Two asynchronous operations with dif ferent async-values may be enqueued onto different activity queues, and therefore may be execu ted on the device in either order or concurrently relative to each other If th
dynamic reference counters for vars appearing in copyout anddelete clauses, and will decrement the attachment counters for point- ers appearing in detach clauses If a finalize clause appears, the exitdata directive will set the dynamic reference counters to zero for vars appearing in copyout anddelete clauses, and will set the attachment counters to zero for pointers appearing in detach clauses Errors See Section 273 for errors due to data clauses See Sections 2161 and 2162 for errors due to async orwait clauses 267 Reference Counters When device memory is allocated for data not in shared memory due to data claus es or OpenACC API routine calls, the OpenACC implementation keeps track of that section of de vice memory and its relationship to the corresponding data in host memory Each section of device memory is associated with two reference counters per device, a structured reference counter and a dynamic reference counter The structured and dynamic reference counters are used to determine when to allocate o
ion outside the loop int x = 0; #pragma acc parallel copy(x) { // gang-shared x undefined #pragma acc loop gang worker vector reduction(+:x) for (int i = 0; i < I; ++i) x += 1; // vector-private x modified // gang-shared x undefined }// gang-shared x updated for gang/worker/vector reduction // x = I xis private at each of the innermost two loop directives below, so each of their reductions updatesxat the loop’s exit However, xis not private at the outer loop directive, so its reduction updates xby the end of the parallel region instead int x = 0; #pragma acc parallel copy(x) { // gang-shared x undefined #pragma acc loop gang reduction(+:x) for (int i = 0; i < I; ++i) { #pragma acc loop worker reduction(+:x) for (int j = 0; j < J; ++j) { #pragma acc loop vector reduction(+:x) for (int k = 0; k < K; ++k) { x += 1; // vector-private x modified }// worker-private x updated for vector reduction }// gang-private x updated for worker reduction } // gang-shared x undefined }// gang-shared x updated for gang reducti
the OpenACC runtime shuts down, either bec ause all devices have been shutdown by calls to the acc_shutdown API routine, or at the end of the program 512 Device Initialization and Shutdown Thedevice initialization profiling event names are acc_ev_device_init_start acc_ev_device_init_end These events are triggered when a device is being initialized by the OpenACC runtime This may be when the program starts, or may be later during execution when the progra m reaches an acc_init call or an OpenACC construct The acc_ev_device_init_start is triggered before device initialization starts and acc_ev_device_init_end after initialization is complete Thedevice shutdown profiling event names are acc_ev_device_shutdown_start acc_ev_device_shutdown_end These events are triggered when a device is shut down, most likely by a ca ll to the OpenACC acc_shutdown API routine The acc_ev_device_shutdown_start is triggered before the device shutdown process starts and acc_ev_device_shutdown_end after the device shut- down is complet
81, async queue, async-argument , 88, asynchronous execution, 11, atomic construct, attach action, 45, attach clause, attachment counter, auto clause, portability, autoscoping, barrier synchronization, 11, 32, 34, bind clause, block construct, cache directive, capture clause, collapse clause, common block, 45, 73, 74, compiler options, 156 5709compute construct, compute region, construct, atomic , compute, data , 40, host_data , kernels , 33, kernelsloop , parallel , 31, parallelloop , serial , 32, serialloop , copy clause, 39, copyin action, copyin clause, copyout action, copyout clause, create action, create clause, 53, CUDA, 11, 12, 147, 153, data attribute explicitly determined, implicitly determined, predetermined, 37, data clause, visible, 38, data construct, 40, data lifetime, data region, 40, implicit, data-independent loop construct, declare directive, default clause, 37, visible, 38, default(none) clause, default(present), delete action, delete clause, detach action, 45, immediate, detach clause, d
ng-private y modified }// gang-shared x and y updated for gang reduction // x = I; y = I * /trianglesolid /trianglesolid 210 Cache Directive Summary Thecache directive may appear at the top of (inside of) a loop It specifies array e lements or subarrays that should be fetched into the highest level of the cache for the body of the loop Syntax In C and C++, the syntax of the cache directive is #pragma acc cache( [readonly: ]var-list)new-line In Fortran, the syntax of the cache directive is !$acc cache( [readonly: ]var-list) Avarin acache directive must be a single array element or a simple subarray In C and C++ , a simple subarray is an array name followed by an extended array range s pecification in brackets, with start and length, such as arr[ lower:length] where the lower bound is a constant, loop invariant, or the for loop variable plus or minus a constant or loop invariant, and the length is a constant In Fortran, a simple subarray is an array name followed by a comma-separa ted list of range specifi- catio
*acc_callback) (acc_callback_info *,acc_event_info *,acc_api_info *); The third argument is an enum type: typedef enum acc_register_t { acc_reg = 0, acc_toggle = 1, acc_toggle_per_thread = }acc_register_t; This is usually acc_reg , but see Section 542 Disabling and Enabling Callbacks for cases where different values are used An example of registering callbacks for launch, upload, and download ev ents is: acc_callback_register(acc_ev_enqueue_launch_start, prof_launch, acc_reg); acc_callback_register(acc_ev_enqueue_upload_start, prof_data, acc_reg); acc_callback_register(acc_ev_enqueue_download_start , prof_data, acc_reg); As shown in this example, the same routine ( prof_data ) can be registered for multiple events The routine can use the event_type field in the acc_callback_info structure to determine for what event it was invoked The names acc_prof_register andacc_prof_unregister are preserved for backward compatibility with previous versions of OpenACC 531 Library Registration The OpenACC runtime will invoke
hen executing accelerator regions The value of this environment variable mus t be a nonnegative integer between zero and the number of devices of the desired type attached to the h ost If the value is greater than or equal to the number of devices attached, the behavior is imple mentation-defined Example: setenv ACC_DEVICE_NUM export ACC_DEVICE_NUM= 43 ACC PROFLIB TheACC_PROFLIB environment variable specifies the profiling library More details about the evaluation at runtime is given in section 533 Runtime Dynamic Library Loading Example: setenv ACC_PROFLIB /path/to/proflib/libaccprofso export ACC_PROFLIB=/path/to/proflib/libaccprofso 5 Profiling and Error Callback Interface This chapter describes the OpenACC interface for runtime callback routine s These routines may be provided by the programmer or by a tool or library developer Calls to these routines are triggered during the application execution at specific OpenACC events There are tw o classes of events, profiling events and error events Profiling events can
tains, may contain, or may call another pr ocedure that contains a loop with a gang clause associated with dimension dor less worker clause Theworker clause specifies that the procedure contains, may contain, or may call ano ther pro- cedure that contains a loop with a worker clause, but does not contain nor does it call another procedure that contains a loop with the gang clause A loop in this procedure with an auto clause may be selected by the compiler to execute in worker orvector mode A call to this procedure must appear in code that is executed in worker-single mode, though it may be in gang-redundant organg-partitioned mode For instance, a procedure with a routineworker directive may be called from within a loop that has the gang clause, but not from within a loop that has the worker clause vector clause Thevector clause specifies that the procedure contains, may contain, or may call ano ther pro- cedure that contains a loop with the vector clause, but does not contain nor does it call another procedure
on before starting to execute other gangs T his means that trying to implement synchronization between gangs is likely to fail In particular, a bar rier across gangs cannot be implemented in a portable fashion, since all gangs may not ever be active at the same time Similarly, the execution model allows for an implementation that executes some work ers within a gang or vector lanes within a worker to completion before starting other work ers or vector lanes, or for some workers or vector lanes to be suspended until other worker s or vector lanes complete This means that trying to implement synchronization across workers or vecto r lanes is likely to fail In particular, implementing a barrier or critical section across workers or v ector lanes using atomic operations and a busy-wait loop may never succeed, since the schedule r may suspend the worker or vector lane that owns the lock, and the worker or vector lane waiting on the lo ck can never complete Some devices, such as a multicore CPU, may also create and
ype – a derived type in Fortran, or a struct orunion type in C, or a class , struct , orunion type in C++ (This is different from the use of the term composite data type in the C and C++ languages) Composite variable – a variable of composite datatype In Fortran, a composite variable must not have allocatable or pointer attributes Compute construct – aparallel construct ,serial construct , orkernels construct Compute intensity – for a given loop, region, or program unit, the ratio of the number of arith metic operations performed on computed data divided by the number of memory tran sfers required to move that data between two levels of a memory hierarchy Compute region – aparallel region ,serial region , orkernels region Construct – a directive and the associated statement, loop, or structured block, if any CUDA – the CUDA environment from NVIDIA, a C-like programming environment us ed to ex- plicitly control and program an NVIDIA GPU Current device – the device represented by the acc-current-device-type
ive-name For C and C++, new-line means the newline character at the end of a line: #pragma acc directive-name new-line Optional syntax is enclosed in square brackets; an option that may be repe ated more than once is followed by ellipses: #pragma acc directive-name [clause [[,]clause ] ] new-line In this spec, a var(in italics) is one of the following: a variable name (a scalar, array, or composite variable name); a subarray specification with subscript ranges; an array element; a member of a composite variable; a common block name between slashes Not all options are allowed in all clauses; the allowable options are clarified f or each use of the term var Unnamed common blocks (blank commons) are not permitted and common blocks o f the same name must be of the same size in all scoping units as required by the Fortran sta ndard To simplify the specification and convey appropriate constraint information, apqr-list is a comma- separated list of pqritems For example, an int-expr-list is a comma-separated lis
ion defines the number of workers within each gang that will be active after a gang transitions from worker-single mode to worker-partitioned mode If the clause does not appear, an implementation-defined default will be used; the default value ma y be 1, and may be different for each parallel construct or for each kernel created for a kernels construct The implementation may use a different value than specified based on limitations imposed by the target architecture 2512 vector length clause Thevector_length clause is allowed on the parallel andkernels constructs The value of the integer expression defines the number of vector lanes that will be ac tive after a worker transi- tions from vector-single mode to vector-partitioned mode This clause determin es the vector length to use for vector or SIMD operations If the clause does not appear, a n implementation-defined default will be used This vector length will be used for loop constructs an notated with the vector clause, as well as loops automatically vectorized
552 OpenACC Events During Event Processing 553 Multiple Host Threads 6 Glossary A Recommendations for Implementers A1 Target Devices A11 NVIDIA GPU Targets A12 AMD GPU Targets A13 Multicore Host CPU Target A2 API Routines for Target Platforms A21 NVIDIA CUDA Platform A22 OpenCL Target Platform A3 Recommended Options and Diagnostics A31 C Pointer in Present clause A32 Nonconforming Applications and Implementations A33 Automatic Data Attributes A34 Routine Directive with a Name 1 Introduction This document describes the compiler directives, library routines, and en vironment variables that collectively define the OpenACCTMApplication Programming Interface
e 513 Enter Data and Exit Data Theenter data profiling event names are acc_ev_enter_data_start acc_ev_enter_data_end These events are triggered at enterdata directives, entry to data constructs, and entry to implicit data regions such as those generated by compute constructs The acc_ev_enter_data_start event is triggered before any data allocation ,data update , orwait events that are associated with that directive or region entry, and the acc_ev_enter_data_end is triggered after those events Theexit data profiling event names are acc_ev_exit_data_start acc_ev_exit_data_end These events are triggered at exit data directives, exit from data constructs, and exit from implicit data regions The acc_ev_exit_data_start event is triggered before any data deallocation ,data update , or wait events associated with that directive or region exit, and the acc_ev_exit_data_end event is triggered after those events When the construct that triggers an enter data orexit data event was generated implicitly by the compiler the i
outines copy the data to that device memory Format C or C++: d_void*acc_copyin(h_void *data_arg, size_t bytes); d_void*acc_create(h_void *data_arg, size_t bytes); void acc_copyin_async(h_void *data_arg, size_t bytes, int async_arg); void acc_create_async(h_void *data_arg, size_t bytes, int async_arg); Fortran: subroutine acc_copyin(data_arg [, bytes ]) subroutine acc_create(data_arg [, bytes ]) subroutine acc_copyin_async(data_arg [, bytes ], async_arg) subroutine acc_create_async(data_arg [, bytes ], async_arg) type(*), dimension() :: data_arg integer :: bytes integer(acc_handle_kind) :: async_arg Description A call to an acc_copyin oracc_create routine is similar to an enterdata directive with acopyin orcreate clause, respectively, as described in Sections 277 and 279, except th at noattach action is performed for a pointer reference In C/C++, data_arg is a pointer to the data, andbytes specifies the data size in bytes; the associated data section starts at the address indata_arg and continues for bytes
handle; const void *context_handle; const void *async_handle; }acc_api_info; The fields are described below: acc_device_api device_api - The API in use for this device The data type is the enumeration acc_device_api , which is described later in this section intvalid_bytes - The number of valid bytes in this struct See the discussion above in Section 521 First Argument: General Information acc_device_tdevice_type - The device type; the datatype is acc_device_t , de- fined inopenacch intvendor - An identifier to identify the OpenACC vendor; contact your vendor to dete r- mine the value used by that vendor’s runtime constvoid *device_handle - If applicable, this will be a pointer to the API-specific device information constvoid *context_handle - If applicable, this will be a pointer to the API-specific context information const void *async_handle - If applicable, this will be a pointer to the API-specific async queue information According to the value of device_api a library can cast the pointers of the field
loops, and the element loops will all be inside the tileloops If thevector clause appears on the loop construct, the vector clause is applied to the element loops If the gang clause appears on the loop construct, the gang clause is applied to the tile loops If the worker clause appears on the loop construct, the worker clause is applied to the element loops if no vector clause appears, and to the tileloops otherwise 299 device type clause Thedevice_type clause is described in Section 24 Device-Specific Clauses 2910 private clause Theprivate clause on a loop construct specifies that a copy of each item in var-list will be created If the body of the loop is executed in vector-partitioned mode, a copy of the item is created for each thread associated with each vector lane If the body of the loop is executed in worker- partitioned vector-single mode, a copy of the item is created for each worker and shared across th e set of threads associated with all the vector lanes of that worker Otherw ise, a copy of the item
plementa tion of this tools interface must also be thread-safe All threads use the same set of c allbacks for all events, so registering a callback from one thread will cause all threads to execute tha t callback This means that managing the callback lists for each event must be protected from multiple simultan eous updates This includes adding a callback to the tail of the callback list for an event, remo ving a callback from the list for an event, and incrementing or decrementing the refcount for a callback routine for an event In addition, one thread may register, unregister, enable, or disable a callb ack for an event while another thread is processing the callback list for that event asynchron ously The exact behavior may be dependent on the implementation, but some behaviors are expected and o thers are disallowed In the following examples, there are three callbacks, A, B, and C, register ed for event E in that order, where callbacks A and B are enabled and callback C is temporarily d isabled Thread T1
routine returns the value of acc-default-async-var for the cur- rent thread Format C or C++: int acc_get_default_async(void); Fortran: function acc_get_default_async() integer(acc_handle_kind) :: acc_get_default_async Description Theacc_get_default_async routine returns the value of acc-default-async-var for the cur- rent thread, which is the asynchronous queue used when an async clause appears without an async-argument or with the value acc_async_noval 3214 acc setdefault async Summary Theacc_set_default_async routine tells the runtime which asynchronous queue to use when anasync clause appears with no queue argument Format C or C++: void acc_set_default_async(int async_arg); Fortran: subroutine acc_set_default_async(async_arg) integer(acc_handle_kind) :: async_arg Description A call toacc_set_default_async is functionally equivalent to a setdefault_async(async_arg) directive, as described in Section 2143 This acc_set_default_async routine tells the runtime to place any directives with an async clause tha
_arg is a null pointer and bytes is nonzero Anacc_error_not_present error is issued if the data section is not in shared memory and is not present in the current device memory Anacc_error_invalid_data_section error is issued if data_arg is an array sec- tion that is not contiguous (in Fortran) Anacc_error_partly_present error is issued if part of the data section is already present in the current device memory but all of the data section is not Anacc_error_invalid_async error is issued if async_arg is not a valid async- argument value See Section 522 3220 acc update device and acc update self Summary Theacc_update_device andacc_update_self routines test to see if the argument is in shared memory; if not, the argument must be present in the current device memory, and the routines update the data in device memory from the corresponding local memory ( acc_update_device ) or update the data in local memory from the corresponding device memory ( acc_update_self ) Format C or C++: void acc_update_device(h_void
ointer varto one If the pointer is a null pointer, the pointer in device memory is updated to have the same value The update may complete asynchronously, depending on other clauses on the directive The implementation schedules pointer updates after any data copie s due to copyin actions that are performed for the same directive Detach Action Adetach action is one of the actions that may be performed for a present (Section 275), copy (Section 276), copyin (Section 277), copyout (Section 278), create (Section 279), no_create (Section 2710), delete (Section 2711), or detach (Section 2711) clause, or for a call to an acc_detach API routine (Section 3229) See those sections for details Adetach action for a varoccurs only when varis a pointer reference If the pointer varis in shared memory or is not present in the current device memory, or if the attachment counter forvarfor the pointer is zero, no action is taken Otherwise, the attachment counter for the pointer varis decremented If the attachment counter is decre
down, which effectively s ets structured and dynamic reference counters to zero Format C or C++: void acc_shutdown(acc_device_t dev_type); void acc_shutdown_device(int dev_num, acc_device_t dev_ type); Fortran: subroutine acc_shutdown(dev_type) subroutine acc_shutdown_device(dev_num, dev_type) integer :: dev_num integer(acc_device_kind) :: dev_type Description A call toacc_shutdown oracc_shutdown_device is functionally equivalent to a shutdown directive, with matching dev_type anddev_num arguments, as described in Section 2142 dev_type must be one of the defined accelerator types dev_num must be a valid device number of the device type dev_type acc_shutdown routine disconnects the program from all devices of device type dev_type Theacc_shutdown_device routine disconnects the program from dev_num of typedev_type Any data that is present in the memory of a device that is shut down is immediately deallocated Restrictions This routine may not be called while a compute region is executing on a device of type dev
be used by tools f or profile or trace data collection Currently, this interface does not support tools that employ asy nchronous sampling Error events can be used to release resources or cleanly shut down a large parallel application when the OpenACC runtime detects an error condition from which it cannot recov er This is specifically for error handling, not for error recovery There is no support p rovided for restarting or retrying an OpenACC program, construct, or API routine after an error condition has been detected and an error callback routine has been called In this chapter, the term runtime refers to the OpenACC runtime library The term library refers to the routines invoked at specified events by the OpenACC runtime There are three steps for interfacing a library to the runtime The first step is to write the library callback routines Section 51 Events describes the supported runtime even ts and the order in which callbacks to the callback routines will occur Section 52 Callbacks Signature describes th
r and bytes is nonzero Anacc_error_invalid_async error is issued if async_arg is not a valid async- argument value See Section 522 3228 acc memcpy device Summary Theacc_memcpy_device routine copies data from one memory location to another memory location on the current device Format C or C++: void acc_memcpy_device(d_void *data_dev_dest, d_void*data_dev_src, size_t bytes); void acc_memcpy_device_async(d_void *data_dev_dest, d_void*data_dev_src, size_t bytes, int async_arg); Fortran: subroutine acc_memcpy_device(data_dev_dest, data_dev_src, bytes); subroutine acc_memcpy_device_async(data_dev_dest, data_dev_src, bytes, async_arg); type(c_ptr), value :: data_dev_dest type(c_ptr), value :: data_dev_src integer(c_size_t), value :: bytes integer(acc_handle_kind), value :: async_arg Description Theacc_memcpy_device routine copies bytes bytes of data from the device address in data_dev_src to the device address in data_dev_dest Both addresses must be addresses in the current device memory, such as would be returne
acc_is_present acc_memcpy_to_device ,acc_memcpy_from_device acc_update_device ,acc_update_self defined behavior with multiple host threads, such as with OpenMP recommendations for specific implementations clarified that no arguments are allowed on the vector clause in a parallel region 110 Corrections in the August 2013 document corrected the atomiccapture syntax for C/C++ fixed the name of the acc_wait andacc_wait_all procedures fixed description of the acc_hostptr procedure 111 Changes from Version 20 to 2 The_OPENACC value was updated to 201510 ; see Section 22 Conditional Compilation Thenum_gangs ,num_workers , andvector_length clauses are now allowed on the kernels construct; see Section 253 Kernels Construct Reduction on C++ class members, array elements, and struct elements are ex plicitly disal- lowed; see Section 2515 reduction clause Reference counting is now used to manage the correspondence and lifetime of device data; see Section 267 Reference Counters The behavior of the exitdata d
truct A kernels region is a structured block which is compiled for the accelerator The code in the kernels region will be d ivided by the compiler into a sequence of kernels; typically each loop nest will become a single ker nel A kernels region may require space in device memory to be allocated and data to be copied from lo cal memory to device memory upon region entry, and data to be copied from device memory to local memory and space in device memory to be deallocated upon exit Level of parallelism – a possible level of parallelism, which in OpenACC is gang, worker, vector , or sequential One or more of gang, worker, and vector parallelism may ap pear on a loop con- struct Sequential execution corresponds to no parallelism The gang ,worker ,vector , and seq clauses specify the level of parallelism for a loop Local device – the device where the local thread executes Local memory – the memory associated with the local thread Local thread – the host thread or the accelerator thread that executes an OpenACC d
tine will get resolved by the dynamic loader 535 Application-Controlled Initialization An alternative to default initialization is to have the application itself call the library initialization routine, which then calls acc_callback_register for each appropriate event The library may be statically linked to the application or your application may dynamically load the lib rary The sequence of events is: 1 Your application calls the library initialization routine 2 The library initialization routine calls acc_callback_register for each event to be monitored 3acc_callback_register records the callback routines 4 The program runs, and your callback routines are invoked at the ap propriate events In this mode, multiple tools libraries can be supported, with each library initialization routine in- voked by the application 54 Registering Event Callbacks This section describes how to register and unregister callbacks, temporar ily disabling and enabling callbacks, the behavior of dynamic registration and unregistrati
r execution on the current device Syntax In C and C++, the syntax of the OpenACC kernels construct is #pragma acc kernels [clause-list ]new-line structured block and in Fortran, the syntax is !$acc kernels [clause-list ] structured block !$acc end kernels or !$acc kernels [clause-list ] block construct [!$acc end kernels ] where clause is one of the following: async [(int-expr)] wait [(int-expr-list )] num_gangs( int-expr) num_workers( int-expr) vector_length( int-expr) device_type( device-type-list ) if( condition) self [(condition)] copy( var-list) copyin( [readonly: ]var-list) copyout( [zero: ]var-list) create( [zero: ]var-list) no_create( var-list) present( var-list) deviceptr( var-list) attach( var-list) default( none | present ) Description The compiler will split the code in the kernels region into a sequence of accele rator kernels Typi- cally, each loop nest will be a distinct kernel When the program encounte rs akernels construct, it will launch the sequence of kernels in order on the device The nu
*apiinfo) { acc_data_event_info *datainfo; datainfo = (acc_data_event_info *)eventinfo; switch( datainfo->event_type ) { case acc_ev_enqueue_upload_start : } } Multiple Callbacks Multiple callback routines can be registered on the same event: acc_callback_register(acc_ev_enqueue_upload_start, prof_data, acc_reg); acc_callback_register(acc_ev_enqueue_upload_start, prof_up, acc_reg); For most events, the callbacks will be invoked in the order in which they are r egistered However, endevents, named acc_ev__end , invoke callbacks in the reverse order Essentially, each event has an ordered list of callback routines A new callback routine is a ppended to the tail of the list for that event For most events, that list is traversed from the head to th e tail, but for endevents, the list is traversed from the tail to the head If a callback is registered, then later unregistered, then later still registere d again, the second regis- tration is considered to be a new callback, and the callback routine will then be ap
for the current thread to tell the program what type of device will be used to run th e next compute region, if one has been selected The device type may have been selected by the pro gram with a runtime API call or a directive, by an environment variable, or by the default behav ior of the implementation; see the table in Section 231 Restrictions If the device type has not yet been selected, the value acc_device_none may be returned 324 acc setdevice num Summary Theacc_set_device_num routine tells the runtime which device to use and sets the value of acc-current-device-num-var Format C or C++: void acc_set_device_num(int dev_num, acc_device_t dev_t ype); Fortran: subroutine acc_set_device_num(dev_num, dev_type) integer :: dev_num integer(acc_device_kind) :: dev_type Description A call toacc_set_device_num is functionally equivalent to a setdevice_type(dev_type) device_num(dev_num) directive, as described in Section 2143 This routine tells the runtime which device to use among those available of the given
grams, which can pass arguments b y name See Section 32 Replaced composite variable by aggregate variable in reduction ,default , andprivate clauses and in implicitly determined data attributes; the new wording also includes F ortran character and allocatable/pointer variables See glossary in Section 6 116 Changes from Version 31 to 3 Updated_OPENACC value to202111 Modified specification to comply with INCITS standard for inclusive terminolog y The text was changed to state that certain runtime errors, when detected, r esult in a call to the current runtime error callback routines See Section 15 An ambiguity issue with the C/C++ comma operator was resolved See Section 16 The terms true andfalse were defined and used throughout to shorten the descriptions See Section 16 Implicitly determined data attributes on compute constructs were clarified See Se ction 262 Clarified that the default(none) clause applies to scalar variables See Section 262 Theasync ,wait , anddevice_type clauses may be specified on dat
ment for varwill deallocate memory from both local memory as well as the current device memory, for a non-shared memory device, and the d ynamic reference counter will be set to zero If the structured reference counter is not z ero, a runtime error is issued In Fortran, if a variable varinvar-list has the Fortran pointer attribute, then it may appear on the left hand side of a pointer assignment statement, if the right hand side variab le itself appears in a create clause Errors In Fortran, an acc_error_present error is issued at a deallocate statement if the struc- tured reference counter is not zero See Section 522 2133 link clause Thelink clause is used for large global host static data that is referenced within an accelerator routine and that should have a dynamic data lifetime on the device The link clause specifies that only a global link for the named variables should be statically created in accele rator memory The host data structure remains statically allocated and globally available The dev ice dat
creates a data region When the program encounters a compute construct with explicit data clause s or with implicit data allocation added by the compiler, it creates a data region that has a duration o f the compute construct When the program enters a procedure, it creates an implicit data region tha t has a duration of the procedure That is, the implicit data region is created when the procedure is called, and exited when the program returns from that procedure invocation There is also an imp licit data region associated with the execution of the program itself The implicit program data region has a duration of the execution of the program In addition to data regions, a program may create and delete data on the acce lerator using enter data andexit data directives or using runtime API routines When the program executes anenter data directive, or executes a call to a runtime API acc_copyin oracc_create routine, each varon the directive or the variable on the runtime API argument list will be made live on acce
reats auto asseq, the gangs redundantly compute arr’s maximum, but the combined result is still arr’s maximum Either way, because xis not private at the loop directive, the reduction updates xby the end of the parallel region int x = 0; const int *arr =/*array of I values */; #pragma acc parallel copy(x) { // gang-shared x undefined #pragma acc loop auto gang reduction(max:x) for (int i = 0; i < I; ++i) { // complex loop body x = x < arr[i] ? arr[i] : x; // gang- or loop-private // x modified } // gang-shared x undefined }// gang-shared x updated for gang or gang/seq reduction // x = arr maximum The following example is the same as the previous one except that the reductio n operator is now+ While gang-partitioned mode sums the elements of arr once, gang-redundant mode sums them once per gang, producing a result many times arr’s sum This example shows that, for some reduction operators, combining auto ,gang , andreduction is typically non-portable int x = 0; const int *arr =/*array of I values */; #pragma ac
stem issues The default error callback routine may print an error message and halt p rogram execution The ap- plication can register one or more additional error callback routines, to allow a failing application to release resources or to cleanly shut down a large parallel runtime with many threads and processes See Chapter 5 Profiling and Error Callback Interface The error callba ck mechanism is not intended for error recovery There is no support for restarting or retrying a n OpenACC program, construct, or API routine after an error condition has been detected and an error callb ack routine has been called 16 Conventions used in this document Some terms are used in this specification that conflict with their usage as define d in the base lan- guages When there is potential confusion, the term will appear in the Gloss ary Keywords and punctuation that are part of the actual specification will ap pear in typewriter font: #pragma acc Italic font is used where a keyword or other name must be used: #pragma acc direct
n 522 274 deviceptr clause Thedeviceptr clause may appear on structured data and compute constructs and declare directives Thedeviceptr clause is used to declare that the pointers in var-list are device pointers, so the data need not be allocated or moved between the host and device for this po inter In C and C++, the vars invar-list must be pointer variables In Fortran, the vars invar-list must be dummy arguments (arrays or scalars), and may not have the Fortranpointer ,allocatable , orvalue attributes For data in shared memory, host pointers are the same as device pointers, s o this clause has no effect 275 present clause Thepresent clause may appear on structured data and compute constructs and declare di- rectives The present clause specifies that vars invar-list are in shared memory or are already present in the current device memory due to data regions or data lifetimes that contain the construct on which the present clause appears For each varinvar-list , ifvaris in shared memory, no action is taken; if