-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[OpenMP][clang] Set num_threads 'strict' to unsupported on GPUs #160659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2703,7 +2703,8 @@ llvm::Value *CGOpenMPRuntime::emitForNext(CodeGenFunction &CGF, | |
| } | ||
|
|
||
| llvm::Value *CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF, | ||
| const Expr *Message) { | ||
| const Expr *Message, | ||
| SourceLocation Loc) { | ||
| if (!Message) | ||
| return llvm::ConstantPointerNull::get(CGF.VoidPtrTy); | ||
| return CGF.EmitScalarExpr(Message); | ||
|
|
@@ -2713,11 +2714,13 @@ llvm::Value * | |
| CGOpenMPRuntime::emitMessageClause(CodeGenFunction &CGF, | ||
| const OMPMessageClause *MessageClause) { | ||
| return emitMessageClause( | ||
| CGF, MessageClause ? MessageClause->getMessageString() : nullptr); | ||
| CGF, MessageClause ? MessageClause->getMessageString() : nullptr, | ||
| MessageClause->getBeginLoc()); | ||
| } | ||
|
|
||
| llvm::Value * | ||
| CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity) { | ||
| CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity, | ||
| SourceLocation Loc) { | ||
| // OpenMP 6.0, 10.4: "If no severity clause is specified then the effect is | ||
| // as if sev-level is fatal." | ||
| return llvm::ConstantInt::get(CGM.Int32Ty, | ||
|
|
@@ -2727,13 +2730,15 @@ CGOpenMPRuntime::emitSeverityClause(OpenMPSeverityClauseKind Severity) { | |
| llvm::Value * | ||
| CGOpenMPRuntime::emitSeverityClause(const OMPSeverityClause *SeverityClause) { | ||
| return emitSeverityClause(SeverityClause ? SeverityClause->getSeverityKind() | ||
| : OMPC_SEVERITY_unknown); | ||
| : OMPC_SEVERITY_unknown, | ||
| SeverityClause->getBeginLoc()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You perform a nullptr check the first time dereferencing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| void CGOpenMPRuntime::emitNumThreadsClause( | ||
| CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc, | ||
| OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity, | ||
| const Expr *Message) { | ||
| SourceLocation SeverityLoc, const Expr *Message, | ||
| SourceLocation MessageLoc) { | ||
| if (!CGF.HaveInsertPoint()) | ||
| return; | ||
| llvm::SmallVector<llvm::Value *, 4> Args( | ||
|
|
@@ -2745,8 +2750,8 @@ void CGOpenMPRuntime::emitNumThreadsClause( | |
| RuntimeFunction FnID = OMPRTL___kmpc_push_num_threads; | ||
| if (Modifier == OMPC_NUMTHREADS_strict) { | ||
| FnID = OMPRTL___kmpc_push_num_threads_strict; | ||
| Args.push_back(emitSeverityClause(Severity)); | ||
| Args.push_back(emitMessageClause(CGF, Message)); | ||
| Args.push_back(emitSeverityClause(Severity, SeverityLoc)); | ||
| Args.push_back(emitMessageClause(CGF, Message, MessageLoc)); | ||
| } | ||
| CGF.EmitRuntimeCall( | ||
| OMPBuilder.getOrCreateRuntimeFunction(CGM.getModule(), FnID), Args); | ||
|
|
@@ -12263,7 +12268,8 @@ llvm::Value *CGOpenMPSIMDRuntime::emitForNext(CodeGenFunction &CGF, | |
| void CGOpenMPSIMDRuntime::emitNumThreadsClause( | ||
| CodeGenFunction &CGF, llvm::Value *NumThreads, SourceLocation Loc, | ||
| OpenMPNumThreadsClauseModifier Modifier, OpenMPSeverityClauseKind Severity, | ||
| const Expr *Message) { | ||
| SourceLocation SeverityLoc, const Expr *Message, | ||
| SourceLocation MessageLoc) { | ||
| llvm_unreachable("Not supported in SIMD-only mode"); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // RUN: %clang_cc1 -DF1 -verify -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-ppc.bc | ||
| // RUN: %clang_cc1 -DF1 -DTARGET -verify -fopenmp -fopenmp-version=60 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host-ppc.bc -o /dev/null | ||
| // RUN: %clang_cc1 -DF2 -verify -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-ppc.bc | ||
| // RUN: %clang_cc1 -DF2 -DTARGET -verify -fopenmp -fopenmp-version=60 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host-ppc.bc -o /dev/null | ||
| // RUN: %clang_cc1 -DF3 -verify -fopenmp -fopenmp-version=60 -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host-ppc.bc | ||
| // RUN: %clang_cc1 -DF3 -DTARGET -verify -fopenmp -fopenmp-version=60 -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host-ppc.bc -o /dev/null | ||
|
|
||
| #ifndef TARGET | ||
| // expected-no-diagnostics | ||
| #endif | ||
|
|
||
| #ifdef F3 | ||
| template<typename tx> | ||
| tx ftemplate(int n) { | ||
| tx a = 0; | ||
|
|
||
| #ifdef TARGET | ||
| // expected-error@+2 {{modifier 'strict' is currently not supported on a GPU for the 'num_threads' clause}} | ||
| #endif | ||
| #pragma omp parallel num_threads(strict: tx(20)) severity(fatal) message("msg") | ||
| { | ||
| } | ||
|
|
||
| short b = 1; | ||
| #ifdef TARGET | ||
| // expected-error@+2 {{modifier 'strict' is currently not supported on a GPU for the 'num_threads' clause}} | ||
| #endif | ||
| #pragma omp parallel num_threads(strict: b) severity(warning) message("msg") | ||
| { | ||
| a += b; | ||
| } | ||
|
|
||
| return a; | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef F2 | ||
| static | ||
| int fstatic(int n) { | ||
|
|
||
| #ifdef TARGET | ||
| // expected-error@+2 {{modifier 'strict' is currently not supported on a GPU for the 'num_threads' clause}} | ||
| #endif | ||
| #pragma omp target parallel num_threads(strict: n) message("msg") | ||
| { | ||
| } | ||
|
|
||
| #ifdef TARGET | ||
| // expected-error@+2 {{modifier 'strict' is currently not supported on a GPU for the 'num_threads' clause}} | ||
| #endif | ||
| #pragma omp target parallel num_threads(strict: 32+n) severity(warning) | ||
| { | ||
| } | ||
|
|
||
| return n+1; | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef F1 | ||
| struct S1 { | ||
| double a; | ||
|
|
||
| int r1(int n){ | ||
| int b = 1; | ||
|
|
||
| #ifdef TARGET | ||
| // expected-error@+2 {{modifier 'strict' is currently not supported on a GPU for the 'num_threads' clause}} | ||
| #endif | ||
| #pragma omp parallel num_threads(strict: n-b) severity(warning) message("msg") | ||
| { | ||
| this->a = (double)b + 1.5; | ||
| } | ||
|
|
||
| #ifdef TARGET | ||
| // expected-error@+2 {{modifier 'strict' is currently not supported on a GPU for the 'num_threads' clause}} | ||
| #endif | ||
| #pragma omp parallel num_threads(strict: 1024) severity(fatal) | ||
| { | ||
| this->a = 2.5; | ||
| } | ||
|
|
||
| return (int)a; | ||
| } | ||
| }; | ||
| #endif | ||
|
|
||
| int bar(int n){ | ||
| int a = 0; | ||
|
|
||
| #ifdef F1 | ||
| #pragma omp target | ||
| { | ||
| S1 S; | ||
| a += S.r1(n); | ||
| } | ||
| #endif | ||
|
|
||
| #ifdef F2 | ||
| a += fstatic(n); | ||
| #endif | ||
|
|
||
| #ifdef F3 | ||
| #pragma omp target | ||
| a += ftemplate<int>(n); | ||
| #endif | ||
|
|
||
| return a; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ro-i you deferrence
MessageClauseafter a nullptr check in the first time but unconditionally dereference right afterward. One of these has to be a bug.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#164767