Skip to content

Commit 93238c6

Browse files
Added helper function for nvshmemx_init_attr
1 parent 6ff543f commit 93238c6

4 files changed

Lines changed: 28 additions & 105 deletions

File tree

clang/lib/DPCT/RulesSHMEM/APINamesNvshmem.inc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,13 @@
203203
FEATURE_REQUEST_FACTORY(HelperFeatureEnum::device_ext,
204204
CALL_FACTORY_ENTRY("nvshmem_init", CALL("ishmem_init")))
205205

206-
FEATURE_REQUEST_FACTORY(HelperFeatureEnum::device_ext,
207-
CALL_FACTORY_ENTRY("nvshmemx_init_attr",
208-
CALL("ishmemx_init_attr", ARG(1))))
206+
HEADER_INSERT_FACTORY(HeaderType::HT_DPCT_SHMEM_Utils,
207+
FEATURE_REQUEST_FACTORY(
208+
HelperFeatureEnum::device_ext,
209+
CALL_FACTORY_ENTRY("nvshmemx_init_attr",
210+
CALL(MapNames::getDpctNamespace() +
211+
"shmem::init_attr",
212+
ARG(0), ARG(1)))))
209213

210214
FEATURE_REQUEST_FACTORY(HelperFeatureEnum::device_ext,
211215
CALL_FACTORY_ENTRY("nvshmem_my_pe",

clang/lib/DPCT/RulesSHMEM/NVSHMEMAPIMigration.cpp

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -216,91 +216,6 @@ void clang::dpct::NVSHMEMRule::runRule(
216216

217217
EA.analyze(*TL);
218218
} else if (const CallExpr *CE = getNodeAsType<CallExpr>(Result, "call")) {
219-
auto &SM = DpctGlobalInfo::getSourceManager();
220-
auto LO = LangOptions();
221-
222-
std::string FuncName = "";
223-
const FunctionDecl *FD = CE->getDirectCallee();
224-
if (FD) {
225-
FuncName = FD->getNameInfo().getName().getAsString();
226-
}
227-
228-
if (!FuncName.empty()) {
229-
if (FuncName == "nvshmemx_init_attr") {
230-
// Get function arguments
231-
std::string NvshmemRT = "";
232-
std::string NvshmemInitRT = "";
233-
std::string AttrArg = "";
234-
235-
// Get the first argument's data
236-
const Expr *Arg0 = CE->getArg(0);
237-
238-
// Binary op on first argument is not supported
239-
if (dyn_cast<BinaryOperator>(Arg0->IgnoreImpCasts())) {
240-
report(CE->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false,
241-
FuncName);
242-
return;
243-
}
244-
245-
// Get first argument's init value
246-
if (auto DRE = dyn_cast<DeclRefExpr>(Arg0->IgnoreImpCasts())) {
247-
if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
248-
if (VD->hasInit()) {
249-
// get the init value from definition
250-
if (auto Init =
251-
dyn_cast<DeclRefExpr>(VD->getInit()->IgnoreImplicit())) {
252-
NvshmemInitRT = Init->getNameInfo().getName().getAsString();
253-
}
254-
}
255-
}
256-
}
257-
258-
// Get the first argument as string
259-
NvshmemRT = Lexer::getSourceText(
260-
CharSourceRange::getTokenRange(Arg0->getSourceRange()), SM, LO);
261-
262-
if (NvshmemRT == "0" || NvshmemInitRT == "0") {
263-
emplaceTransformation(new ReplaceStmt(CE, "ishmem_init()"));
264-
return;
265-
}
266-
267-
std::string IshmemRT = "";
268-
if (NvshmemRT == "NVSHMEMX_INIT_WITH_MPI_COMM") {
269-
IshmemRT = "ISHMEMX_RUNTIME_MPI";
270-
} else if (NvshmemRT == "NVSHMEMX_INIT_WITH_SHMEM") {
271-
IshmemRT = "ISHMEMX_RUNTIME_OPENSHMEM";
272-
}
273-
274-
if (NvshmemInitRT == "NVSHMEMX_INIT_WITH_MPI_COMM" ||
275-
NvshmemInitRT == "NVSHMEMX_INIT_WITH_SHMEM") {
276-
IshmemRT = "static_cast<ishmemx_runtime_type_t>(" + NvshmemRT + ")";
277-
}
278-
279-
// Get the second argument as string
280-
AttrArg = Lexer::getSourceText(
281-
CharSourceRange::getTokenRange(CE->getArg(1)->getSourceRange()), SM,
282-
LO);
283-
284-
if (IshmemRT.empty()) {
285-
report(CE->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false,
286-
FuncName);
287-
return;
288-
} else {
289-
auto IndentLoc = CE->getBeginLoc();
290-
if (IndentLoc.isMacroID())
291-
IndentLoc = SM.getExpansionLoc(IndentLoc);
292-
293-
std::string SetIshmemRT =
294-
"(" + AttrArg + ")->runtime = " + IshmemRT + ";";
295-
SetIshmemRT += getNL();
296-
SetIshmemRT += getIndent(IndentLoc, SM).str();
297-
298-
emplaceTransformation(
299-
new InsertBeforeStmt(CE, std::move(SetIshmemRT)));
300-
}
301-
}
302-
}
303-
304219
EA.analyze(CE);
305220
} else if (const DeclRefExpr *DRE =
306221
getNodeAsType<DeclRefExpr>(Result, "enumConstant")) {

clang/runtime/dpct-rt/include/dpct/shmem_utils.hpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@
1111

1212
namespace dpct::shmem {
1313

14-
/// Signal Operations
14+
/// Setup Operations
15+
/// Initialize Intel SHMEM runtime based on exisiting communicator in attributes
16+
/// \param [in] runtime_flags specifies the exisiting communicator
17+
/// \param [in] attr attributes of existing communicator
18+
void init_attr(unsigned runtime_flags, ishmemx_attr_t *attr) {
19+
if (runtime_flags == 0) {
20+
ishmem_init();
21+
} else {
22+
attr->runtime = static_cast<ishmemx_runtime_type_t>(runtime_flags);
23+
ishmemx_init_attr(attr);
24+
}
25+
}
26+
27+
/// Signal Operationss
1528
/// Update signal address with signal using signal operation
1629
/// \param [out] sig_addr Address of the signal to be updated
1730
/// \param [in] signal Value of the signal to update

clang/test/dpct/nvshmem/library_setup_exit_query.cu

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,21 @@ int main() {
5757
attr.args = args;
5858
#endif // NO_BUILD_TEST
5959

60-
// CHECK: (&attr)->runtime = ISHMEMX_RUNTIME_MPI;
61-
// CHECK-NEXT: ishmemx_init_attr(&attr);
60+
// CHECK: dpct::shmem::init_attr(ISHMEMX_RUNTIME_MPI, &attr);
61+
// CHECK-NEXT: dpct::shmem::init_attr(ISHMEMX_RUNTIME_OPENSHMEM, &attr);
62+
// CHECK-NEXT: dpct::shmem::init_attr(ISHMEMX_RUNTIME_MPI | ISHMEMX_RUNTIME_OPENSHMEM, &attr);
6263
nvshmemx_init_attr(NVSHMEMX_INIT_WITH_MPI_COMM, &attr);
63-
64-
#ifndef NO_BUILD_TEST
65-
// CHECK: /*
66-
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of nvshmemx_init_attr is not supported.
67-
// CHECK-NEXT: */
64+
nvshmemx_init_attr(NVSHMEMX_INIT_WITH_SHMEM, &attr);
6865
nvshmemx_init_attr(NVSHMEMX_INIT_WITH_MPI_COMM | NVSHMEMX_INIT_WITH_SHMEM, &attr);
69-
#endif // NO_BUILD_TEST
7066

7167
// CHECK: unsigned int rt = ISHMEMX_RUNTIME_MPI;
72-
// CHECK-NEXT: (&attr)->runtime = static_cast<ishmemx_runtime_type_t>(rt);
73-
// CHECK-NEXT: ishmemx_init_attr(&attr);
68+
// CHECK-NEXT: rt = ISHMEMX_RUNTIME_OPENSHMEM;
69+
// CHECK-NEXT: dpct::shmem::init_attr(rt, &attr);
7470
unsigned int rt = NVSHMEMX_INIT_WITH_MPI_COMM;
75-
nvshmemx_init_attr(rt, &attr);
76-
77-
// CHECK: rt = ISHMEMX_RUNTIME_OPENSHMEM;
78-
// CHECK-NEXT: (&attr)->runtime = static_cast<ishmemx_runtime_type_t>(rt);
79-
// CHECK-NEXT: ishmemx_init_attr(&attr);
8071
rt = NVSHMEMX_INIT_WITH_SHMEM;
8172
nvshmemx_init_attr(rt, &attr);
8273

83-
// CHECK: ishmem_init();
74+
// CHECK: dpct::shmem::init_attr(0, &attr);
8475
nvshmemx_init_attr(0, &attr);
8576

8677
// CHECK: ishmem_init();

0 commit comments

Comments
 (0)