diff options
author | Shilei Tian <tianshilei1992@gmail.com> | 2021-10-16 12:58:11 -0400 |
---|---|---|
committer | Shilei Tian <tianshilei1992@gmail.com> | 2021-10-16 12:58:29 -0400 |
commit | 2c941fa2f9b9a93b42bdddc810a817b02a937b55 (patch) | |
tree | a44b85ac189df92734b183405cf6c746d827a30d | |
parent | 85b87179f4820592894d2d1da699794edf9ad6b6 (diff) | |
download | llvm-2c941fa2f9b9a93b42bdddc810a817b02a937b55.zip llvm-2c941fa2f9b9a93b42bdddc810a817b02a937b55.tar.gz llvm-2c941fa2f9b9a93b42bdddc810a817b02a937b55.tar.bz2 |
[OpenMP][deviceRTLs] Fix wrong return value of `__kmpc_is_spmd_exec_mode`
D110279 introduced a bug to the device runtime. In `__kmpc_parallel_51`, we detect
whether we are already in parallel region by `__kmpc_parallel_level() > __kmpc_is_spmd_exec_mode()`.
It is based on the assumption that:
- In SPMD mode, parallel level is initialized to 1.
- In generic mode, parallel level is initialized to 0.
- `__kmpc_is_spmd_exec_mode` returns `1` for SPMD mode, 0 otherwise.
Because the return value type of `__kmpc_is_spmd_exec_mode` is `int8_t`, there
was an implicit cast from `bool` to `int8_t`. We can make sure it is either 0 or
1 since C++14. In D110279, the return value is the result of an `and` operation,
which is 2 in SPMD mode. This breaks the assumption in `__kmpc_parallel_51`.
Reviewed By: carlo.bertolli, dpalermo
Differential Revision: https://reviews.llvm.org/D111905
-rw-r--r-- | openmp/libomptarget/deviceRTLs/common/src/omptarget.cu | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu index 78bd5d7..d0be541 100644 --- a/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu +++ b/openmp/libomptarget/deviceRTLs/common/src/omptarget.cu @@ -160,8 +160,12 @@ static void __kmpc_spmd_kernel_deinit(bool RequiresFullRuntime) { } // Return true if the current target region is executed in SPMD mode. +// NOTE: This function has to return 1 for SPMD mode, and 0 for generic mode. +// That's because `__kmpc_parallel_51` checks if it's already in parallel region +// by comparision between the parallel level and the return value of this +// function. EXTERN int8_t __kmpc_is_spmd_exec_mode() { - return execution_param & OMP_TGT_EXEC_MODE_SPMD; + return (execution_param & OMP_TGT_EXEC_MODE_SPMD) == OMP_TGT_EXEC_MODE_SPMD; } EXTERN int8_t __kmpc_is_generic_main_thread(kmp_int32 Tid) { |