OpenMP: Handle 'device_type(host)' on 'target'
OpenMP 'target' directive with 'device_type(host)' now correctly prevents offload code generation.
The OpenMP runtime now correctly handles the device_type(host) clause on target directives by ensuring that no offload code is generated for the outlined region. This clause is also honored for implicit declare target directives. Code executed under this clause runs as if device(omp_initial_device) was specified, ensuring correct behavior even when offloading is mandatory.
In Details
When an OpenMP target construct is annotated with device_type(host), the outlined device-side code should not be generated. This commit modifies expand_omp_target to pass device(omp_initial_device) semantics to the outlining process for such cases. Additionally, omp_discover_declare_target_tgt_fn_r and omp_discover_declare_target_fn_r are updated to prevent implicit declare target declarations from being added to regions that specify device_type(host). This ensures that regions marked as host-only do not trigger offload generation.
- OpenMP
- A standardized API for shared-memory parallel programming. It consists of compiler directives, library routines, and environment variables.
- target directive
- An OpenMP directive (
#pragma omp target) that specifies a region of code to be executed on a target device, distinct from the host CPU. - device_type(host)
- A clause for OpenMP directives that explicitly indicates the code should run on the host CPU, not an accelerator device.
- declare target
- An OpenMP directive that marks functions or variables for compilation and execution on a target device, even if they are called or accessed from the host code.
- offload
- The process of transferring computation and data to an accelerator device (like a GPU or coprocessor) for execution.