r343492 - [OPENMP][NVPTX] Handle `requires datasharing` flag correctly with

Jonas Hahnfeld via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 1 09:47:33 PDT 2018


Does this fix an issue or is it just 'this looks incorrect'? 
__kmpc_data_sharing_push_stack has an extra case if the runtime is 
uninitialized, so AFAICS the initialization in __kmpc_spmd_kernel_init 
should not be needed.

If the runtime needs to be initialized Clang emits a call to 
__kmpc_data_sharing_init_stack_spmd which should setup the data 
structures.

Jonas

On 2018-10-01 18:20, Alexey Bataev via cfe-commits wrote:
> Author: abataev
> Date: Mon Oct  1 09:20:57 2018
> New Revision: 343492
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=343492&view=rev
> Log:
> [OPENMP][NVPTX] Handle `requires datasharing` flag correctly with
> lightweight runtime.
> 
> The datasharing flag must be set to `1` when executing SPMD-mode
> compatible directive with reduction|lastprivate clauses.
> 
> Modified:
>     cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
>     cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp
>     
> cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
> 
> cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=343492&r1=343491&r2=343492&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Mon Oct  1 09:20:57 
> 2018
> @@ -1207,6 +1207,10 @@ void CGOpenMPRuntimeNVPTX::emitSPMDKerne
>                                     IsOffloadEntry, CodeGen);
>  }
> 
> +static void
> +getDistributeLastprivateVars(const OMPExecutableDirective &D,
> +                             llvm::SmallVectorImpl<const ValueDecl *> 
> &Vars);
> +
>  void CGOpenMPRuntimeNVPTX::emitSPMDEntryHeader(
>      CodeGenFunction &CGF, EntryFunctionState &EST,
>      const OMPExecutableDirective &D) {
> @@ -1219,11 +1223,33 @@ void CGOpenMPRuntimeNVPTX::emitSPMDEntry
>    // Initialize the OMP state in the runtime; called by all active 
> threads.
>    bool RequiresFullRuntime = 
> CGM.getLangOpts().OpenMPCUDAForceFullRuntime ||
>                               
> !supportsLightweightRuntime(CGF.getContext(), D);
> +  // Check if we have inner distribute + lastprivate|reduction 
> clauses.
> +  bool RequiresDatasharing = RequiresFullRuntime;
> +  if (!RequiresDatasharing) {
> +    const OMPExecutableDirective *TD = &D;
> +    if (!isOpenMPTeamsDirective(TD->getDirectiveKind()) &&
> +        !isOpenMPParallelDirective(TD->getDirectiveKind())) {
> +      const Stmt *S = getSingleCompoundChild(
> +          
> TD->getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers(
> +              /*IgnoreCaptured=*/true));
> +      TD = cast<OMPExecutableDirective>(S);
> +    }
> +    if (!isOpenMPDistributeDirective(TD->getDirectiveKind()) &&
> +        !isOpenMPParallelDirective(TD->getDirectiveKind())) {
> +      const Stmt *S = getSingleCompoundChild(
> +          
> TD->getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers(
> +              /*IgnoreCaptured=*/true));
> +      TD = cast<OMPExecutableDirective>(S);
> +    }
> +    if (isOpenMPDistributeDirective(TD->getDirectiveKind()))
> +      RequiresDatasharing = 
> TD->hasClausesOfKind<OMPLastprivateClause>() ||
> +                            
> TD->hasClausesOfKind<OMPReductionClause>();
> +  }
>    llvm::Value *Args[] = {
>        getThreadLimit(CGF, /*IsInSPMDExecutionMode=*/true),
>        /*RequiresOMPRuntime=*/
>        Bld.getInt16(RequiresFullRuntime ? 1 : 0),
> -      /*RequiresDataSharing=*/Bld.getInt16(RequiresFullRuntime ? 1 : 
> 0)};
> +      /*RequiresDataSharing=*/Bld.getInt16(RequiresDatasharing ? 1 : 
> 0)};
>    CGF.EmitRuntimeCall(
>        createNVPTXRuntimeFunction(OMPRTL_NVPTX__kmpc_spmd_kernel_init), 
> Args);
> 
> 
> Modified: cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp?rev=343492&r1=343491&r2=343492&view=diff
> ==============================================================================
> --- cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp (original)
> +++ cfe/trunk/test/OpenMP/nvptx_SPMD_codegen.cpp Mon Oct  1 09:20:57 
> 2018
> @@ -40,7 +40,7 @@ void foo() {
>    for (int i = 0; i < 10; ++i)
>      ;
>  int a;
> -// CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0, i16 0)
> +// CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0, i16 1)
>  // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0, i16 0)
>  // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 0, i16 0)
>  // CHECK: call void @__kmpc_spmd_kernel_init(i32 {{.+}}, i16 1, i16 
> {{.+}})
> 
> Modified:
> cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp?rev=343492&r1=343491&r2=343492&view=diff
> ==============================================================================
> ---
> cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
> (original)
> +++
> cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
> Mon Oct  1 09:20:57 2018
> @@ -69,7 +69,7 @@ int bar(int n){
> 
>  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}_l32(
>  // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 
> @llvm.nvvm.read.ptx.sreg.ntid.x()
> -// CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
> i16 0, i16 0)
> +// CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
> i16 0, i16 1)
>  // CHECK: [[TEAM_ALLOC:%.+]] = call i8*
> @__kmpc_data_sharing_push_stack(i{{[0-9]+}} 4, i16 0)
>  // CHECK: [[BC:%.+]] = bitcast i8* [[TEAM_ALLOC]] to [[REC:%.+]]*
>  // CHECK: getelementptr inbounds [[REC]], [[REC]]* [[BC]],
> i{{[0-9]+}} 0, i{{[0-9]+}} 0
> 
> Modified:
> cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp?rev=343492&r1=343491&r2=343492&view=diff
> ==============================================================================
> ---
> cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
> (original)
> +++
> cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
> Mon Oct  1 09:20:57 2018
> @@ -64,7 +64,7 @@ int bar(int n){
> 
>  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+}}_l30(
>  // CHECK-DAG: [[THREAD_LIMIT:%.+]] = call i32 
> @llvm.nvvm.read.ptx.sreg.ntid.x()
> -// CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
> i16 0, i16 0)
> +// CHECK: call void @__kmpc_spmd_kernel_init(i32 [[THREAD_LIMIT]],
> i16 0, i16 1)
>  // CHECK: [[TEAM_ALLOC:%.+]] = call i8*
> @__kmpc_data_sharing_push_stack(i{{[0-9]+}} 4, i16 0)
>  // CHECK: [[BC:%.+]] = bitcast i8* [[TEAM_ALLOC]] to [[REC:%.+]]*
>  // CHECK: getelementptr inbounds [[REC]], [[REC]]* [[BC]],
> i{{[0-9]+}} 0, i{{[0-9]+}} 0
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list