Skip to content

Commit 1cff868

Browse files
authored
[SYCLomaitic]Refine EnumConstantRule implementation. (#2842)
Signed-off-by: Chen, Sheng S <sheng.s.chen@intel.com> Signed-off-by: Chen <sheng.s.chen@intel.com>
1 parent b293e4f commit 1cff868

File tree

10 files changed

+51
-96
lines changed

10 files changed

+51
-96
lines changed

clang/lib/DPCT/RuleInfra/MapNames.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,8 +1118,6 @@ void MapNames::setExplicitNamespaceMap(
11181118
? getClNamespace() +
11191119
"ext::oneapi::experimental::queue_state::recording"
11201120
: "cudaStreamCaptureStatusActive")},
1121-
{"cudaStreamCaptureStatusInvalidated",
1122-
std::make_shared<EnumNameRule>("cudaStreamCaptureStatusInvalidated")},
11231121
// enum cudaGraphNodeType
11241122
{"cudaGraphNodeTypeKernel",
11251123
std::make_shared<EnumNameRule>(
@@ -1602,6 +1600,21 @@ void MapNames::setExplicitNamespaceMap(
16021600
{"CUSOLVER_EIG_RANGE_I",
16031601
std::make_shared<EnumNameRule>("oneapi::mkl::rangev::indices")},
16041602
{"ncclSuccess", std::make_shared<EnumNameRule>("0")},
1603+
{"CUDNN_STATUS_SUCCESS", std::make_shared<EnumNameRule>("0")},
1604+
{"CUDNN_BATCHNORM_PER_ACTIVATION", std::make_shared<EnumNameRule>("")},
1605+
{"CUDNN_NORM_PER_ACTIVATION", std::make_shared<EnumNameRule>("")},
1606+
{"CUSOLVER_EIG_MODE_VECTOR", std::make_shared<EnumNameRule>("")},
1607+
{"CUSOLVER_EIG_TYPE_1", std::make_shared<EnumNameRule>("")},
1608+
{"CUSOLVER_ALG_1", std::make_shared<EnumNameRule>("1")},
1609+
{"CUSOLVER_STATUS_SUCCESS", std::make_shared<EnumNameRule>("0")},
1610+
{"CUSOLVER_STATUS_NOT_INITIALIZED",
1611+
std::make_shared<EnumNameRule>("1")},
1612+
{"CUSOLVER_STATUS_ALLOC_FAILED", std::make_shared<EnumNameRule>("2")},
1613+
{"CUSOLVER_STATUS_INVALID_VALUE", std::make_shared<EnumNameRule>("3")},
1614+
{"CUSOLVER_STATUS_ARCH_MISMATCH", std::make_shared<EnumNameRule>("4")},
1615+
{"CUSOLVER_STATUS_MAPPING_ERROR", std::make_shared<EnumNameRule>("5")},
1616+
{"CUSOLVER_STATUS_EXECUTION_FAILED", std::make_shared<EnumNameRule>("6")},
1617+
{"CUSOLVER_STATUS_INTERNAL_ERROR", std::make_shared<EnumNameRule>("7")},
16051618
// enum cudaGraphicsMapFlags
16061619
{"cudaGraphicsMapFlagsNone", std::make_shared<EnumNameRule>("0")},
16071620
{"cudaGraphicsMapFlagsReadOnly", std::make_shared<EnumNameRule>("0")},

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 19 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -955,15 +955,6 @@ void TypeInDeclRule::runRule(const MatchFinder::MatchResult &Result) {
955955
return;
956956
}
957957

958-
if (CanonicalTypeStr == "cudaGraphicsRegisterFlags" ||
959-
CanonicalTypeStr == "cudaGraphicsMapFlags") {
960-
if (!DpctGlobalInfo::useExtBindlessImages()) {
961-
report(TL->getBeginLoc(), Diagnostics::TRY_EXPERIMENTAL_FEATURE, false,
962-
CanonicalTypeStr,
963-
"--use-experimental-features=bindless_images");
964-
}
965-
}
966-
967958
if (CanonicalTypeStr == "CUdevice_P2PAttribute") {
968959
if (!DpctGlobalInfo::usePeerAccess()) {
969960
report(TL->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false,
@@ -1958,7 +1949,9 @@ void EnumConstantRule::registerMatcher(MatchFinder &MF) {
19581949
"cufftType", "cudaMemoryType", "CUctx_flags_enum",
19591950
"CUpointer_attribute_enum", "CUmemorytype_enum",
19601951
"cudaGraphicsMapFlags", "cudaGraphicsRegisterFlags",
1961-
"cudaGraphNodeType", "CUdevice_P2PAttribute_enum"))),
1952+
"cudaGraphNodeType", "CUdevice_P2PAttribute_enum",
1953+
"cudaExternalMemoryHandleType",
1954+
"cudaExternalSemaphoreHandleType"))),
19621955
matchesName("CUDNN_.*"), matchesName("CUSOLVER_.*")))))
19631956
.bind("EnumConstant"),
19641957
this);
@@ -2019,51 +2012,27 @@ void EnumConstantRule::runRule(const MatchFinder::MatchResult &Result) {
20192012
if (!E)
20202013
return;
20212014
std::string EnumName = E->getNameInfo().getName().getAsString();
2022-
if (EnumName == "cudaStreamCaptureStatusInvalidated" ||
2023-
EnumName == "cudaExternalMemoryHandleTypeOpaqueWin32Kmt" ||
2024-
EnumName == "cudaExternalMemoryHandleTypeD3D12Heap" ||
2025-
EnumName == "cudaExternalMemoryHandleTypeD3D11Resource" ||
2026-
EnumName == "cudaExternalMemoryHandleTypeD3D11ResourceKmt" ||
2027-
EnumName == "cudaExternalMemoryHandleTypeNvSciBuf" ||
2028-
EnumName == "cudaExternalSemaphoreHandleTypeOpaqueWin32Kmt" ||
2029-
EnumName == "cudaExternalSemaphoreHandleTypeD3D11Fence" ||
2030-
EnumName == "cudaExternalSemaphoreHandleTypeNvSciSync" ||
2031-
EnumName == "cudaExternalSemaphoreHandleTypeKeyedMutex" ||
2032-
EnumName == "cudaExternalSemaphoreHandleTypeKeyedMutexKmt" ||
2033-
EnumName == "cudaExternalSemaphoreHandleTypeTimelineSemaphoreFd" ||
2034-
EnumName == "cudaExternalSemaphoreHandleTypeTimelineSemaphoreWin32" ||
2035-
EnumName == "cudaGraphNodeTypeWaitEvent" ||
2036-
EnumName == "cudaGraphNodeTypeEventRecord" ||
2037-
EnumName == "cudaGraphNodeTypeExtSemaphoreSignal" ||
2038-
EnumName == "cudaGraphNodeTypeExtSemaphoreWait" ||
2039-
EnumName == "cudaGraphNodeTypeMemAlloc" ||
2040-
EnumName == "cudaGraphNodeTypeMemFree" ||
2041-
EnumName == "cudaGraphNodeTypeConditional" ||
2042-
EnumName == "CU_DEVICE_P2P_ATTRIBUTE_PERFORMANCE_RANK") {
2043-
report(E->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false, EnumName);
2044-
return;
2045-
} else if (EnumName == "cudaComputeModeDefault" ||
2046-
EnumName == "cudaComputeModeExclusive" ||
2047-
EnumName == "cudaComputeModeProhibited" ||
2048-
EnumName == "cudaComputeModeExclusiveProcess") {
2015+
2016+
if (EnumName == "cudaComputeModeDefault" ||
2017+
EnumName == "cudaComputeModeExclusive" ||
2018+
EnumName == "cudaComputeModeProhibited" ||
2019+
EnumName == "cudaComputeModeExclusiveProcess") {
20492020
handleComputeMode(EnumName, E);
20502021
return;
20512022
} else if ((EnumName == "cudaStreamCaptureStatusActive" ||
2052-
EnumName == "cudaStreamCaptureStatusNone") &&
2023+
EnumName == "cudaStreamCaptureStatusNone" ||
2024+
EnumName == "cudaGraphNodeTypeKernel" ||
2025+
EnumName == "cudaGraphNodeTypeMemcpy" ||
2026+
EnumName == "cudaGraphNodeTypeMemset" ||
2027+
EnumName == "cudaGraphNodeTypeHost" ||
2028+
EnumName == "cudaGraphNodeTypeGraph" ||
2029+
EnumName == "cudaGraphNodeTypeEmpty") &&
20532030
!DpctGlobalInfo::useExtGraph()) {
20542031
report(E->getBeginLoc(), Diagnostics::TRY_EXPERIMENTAL_FEATURE, false,
20552032
EnumName, "--use-experimental-features=graph");
20562033
return;
20572034
} else if (!DpctGlobalInfo::useExtBindlessImages() &&
2058-
(EnumName == "cudaGraphicsRegisterFlagsNone" ||
2059-
EnumName == "cudaGraphicsRegisterFlagsReadOnly" ||
2060-
EnumName == "cudaGraphicsRegisterFlagsWriteDiscard" ||
2061-
EnumName == "cudaGraphicsRegisterFlagsSurfaceLoadStore" ||
2062-
EnumName == "cudaGraphicsRegisterFlagsTextureGather" ||
2063-
EnumName == "cudaGraphicsMapFlagsNone" ||
2064-
EnumName == "cudaGraphicsMapFlagsReadOnly" ||
2065-
EnumName == "cudaGraphicsMapFlagsWriteDiscard" ||
2066-
EnumName == "cudaExternalMemoryHandleTypeOpaqueFd" ||
2035+
(EnumName == "cudaExternalMemoryHandleTypeOpaqueFd" ||
20672036
EnumName == "cudaExternalMemoryHandleTypeOpaqueWin32" ||
20682037
EnumName == "cudaExternalMemoryHandleTypeD3D12Resource" ||
20692038
EnumName == "cudaExternalSemaphoreHandleTypeOpaqueFd" ||
@@ -2072,16 +2041,6 @@ void EnumConstantRule::runRule(const MatchFinder::MatchResult &Result) {
20722041
report(E->getBeginLoc(), Diagnostics::TRY_EXPERIMENTAL_FEATURE, false,
20732042
EnumName, "--use-experimental-features=bindless_images");
20742043
return;
2075-
} else if (!DpctGlobalInfo::useExtGraph() &&
2076-
(EnumName == "cudaGraphNodeTypeKernel" ||
2077-
EnumName == "cudaGraphNodeTypeMemcpy" ||
2078-
EnumName == "cudaGraphNodeTypeMemset" ||
2079-
EnumName == "cudaGraphNodeTypeHost" ||
2080-
EnumName == "cudaGraphNodeTypeGraph" ||
2081-
EnumName == "cudaGraphNodeTypeEmpty")) {
2082-
report(E->getBeginLoc(), Diagnostics::TRY_EXPERIMENTAL_FEATURE, false,
2083-
EnumName, "--use-experimental-features=graph");
2084-
return;
20852044
} else if (auto ET = dyn_cast<EnumType>(E->getType())) {
20862045
if (auto ETD = ET->getDecl()) {
20872046
auto EnumTypeName = ETD->getName().str();
@@ -2108,7 +2067,9 @@ void EnumConstantRule::runRule(const MatchFinder::MatchResult &Result) {
21082067
}
21092068

21102069
auto Search = MapNames::EnumNamesMap.find(EnumName);
2111-
if (Search == MapNames::EnumNamesMap.end()) {
2070+
if (Search == MapNames::EnumNamesMap.end() ||
2071+
Search->second->NewName == EnumName) {
2072+
report(E->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false, EnumName);
21122073
return;
21132074
}
21142075
if (auto ET = dyn_cast<EnumType>(E->getType())) {

clang/lib/DPCT/RulesLang/RulesLangGraphicsInterop.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ void GraphicsInteropRule::registerMatcher(ast_matchers::MatchFinder &MF) {
4343
.bind("extResMember"),
4444
this);
4545

46-
MF.addMatcher(declRefExpr(to(enumConstantDecl(hasType(enumDecl(hasAnyName(
47-
"cudaExternalMemoryHandleType",
48-
"cudaExternalSemaphoreHandleType"))))))
49-
.bind("extResEnum"),
50-
this);
51-
5246
auto graphicsInteropAPI = [&]() {
5347
return hasAnyName(
5448
"cudaGraphicsD3D11RegisterResource", "cudaGraphicsResourceSetMapFlags",
@@ -232,18 +226,6 @@ void GraphicsInteropRule::runRule(
232226
ExprAnalysis EA(CE);
233227
emplaceTransformation(EA.getReplacement());
234228
EA.applyAllSubExprRepl();
235-
} else if (auto DRE = getNodeAsType<DeclRefExpr>(Result, "extResEnum")) {
236-
if (auto ECD = dyn_cast<EnumConstantDecl>(DRE->getDecl())) {
237-
std::string EnumName = ECD->getName().str();
238-
requestHelperFeatureForEnumNames(EnumName);
239-
if (MapNames::replaceName(MapNames::EnumNamesMap, EnumName)) {
240-
emplaceTransformation(new ReplaceStmt(DRE, EnumName));
241-
} else {
242-
report(DRE->getBeginLoc(), Diagnostics::API_NOT_MIGRATED, false,
243-
EnumName);
244-
return;
245-
}
246-
}
247229
}
248230
}
249231

clang/test/dpct/cudaGraphics_default_option.cu

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,10 @@ int main() {
1818
cudaArray_t* array;
1919
size_t size;
2020

21-
// CHECK: /*
22-
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphicsRegisterFlags is not supported, please try to remigrate with option: --use-experimental-features=bindless_images.
23-
// CHECK-NEXT: */
24-
// CHECK: /*
25-
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphicsRegisterFlagsNone is not supported, please try to remigrate with option: --use-experimental-features=bindless_images.
26-
// CHECK-NEXT: */
21+
// CHECK: int regFlags = 0;
2722
cudaGraphicsRegisterFlags regFlags = cudaGraphicsRegisterFlagsNone;
2823

29-
// CHECK: /*
30-
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphicsMapFlags is not supported, please try to remigrate with option: --use-experimental-features=bindless_images.
31-
// CHECK-NEXT: */
32-
// CHECK: /*
33-
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphicsMapFlagsNone is not supported, please try to remigrate with option: --use-experimental-features=bindless_images.
34-
// CHECK-NEXT: */
24+
// CHECK: int mapFlags = 0;
3525
cudaGraphicsMapFlags mapFlags = cudaGraphicsMapFlagsNone;
3626
// CHECK: /*
3727
// CHECK-NEXT: DPCT1026:{{[0-9]+}}: The call to cudaGraphicsResourceSetMapFlags was removed because this functionality is deprecated in DX12 and hence is not supported in SYCL.

clang/test/dpct/cudaGraphics_default_option_win.cu

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ int main() {
1515
// CHECK-NEXT: */
1616
cudaGraphicsResource_t resource, *resources;
1717

18-
// CHECK: /*
19-
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphicsRegisterFlags is not supported, please try to remigrate with option: --use-experimental-features=bindless_images.
20-
// CHECK-NEXT: */
21-
// CHECK: /*
22-
// CHECK-NEXT: DPCT1119:{{[0-9]+}}: Migration of cudaGraphicsRegisterFlagsNone is not supported, please try to remigrate with option: --use-experimental-features=bindless_images.
23-
// CHECK-NEXT: */
2418
cudaGraphicsRegisterFlags regFlags = cudaGraphicsRegisterFlagsNone;
2519

2620
ID3D11Resource* pD3DResource;

clang/test/dpct/cudnn-get-error-string.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const char *test_function(cudnnStatus_t status) {
5858
//CHECK-NEXT: /*
5959
//CHECK-NEXT: DPCT1009:{{[0-9]+}}: SYCL reports errors using exceptions and does not use error codes. Please replace the "get_error_string_dummy(...)" with a real error-handling function.
6060
//CHECK-NEXT: */
61+
//CHECK-NEXT: /*
62+
//CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of CUDNN_STATUS_NOT_INITIALIZED is not supported.
63+
//CHECK-NEXT: */
6164
//CHECK-NEXT: dpct::get_error_string_dummy({{[0-9]+}});
6265
//CHECK-NEXT:}
6366
void foo(cudnnStatus_t err) {

clang/test/dpct/driver-mem-syclcompat.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ int main(){
262262
// CHECK-NEXT: DPCT1131:{{[0-9]+}}: The migration of "CUarray" is not currently supported with SYCLcompat. Please adjust the code manually.
263263
// CHECK-NEXT: */
264264
// CHECK-NEXT: CUarray ca;
265+
// CHECK-NEXT: /*
266+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of CU_MEMORYTYPE_ARRAY is not supported.
267+
// CHECK-NEXT: */
265268
// CHECK-NEXT: cpy2.to.image = ca;
266269
// CHECK-NEXT: cpy2.to.pitched.set_pitch(5);
267270
// CHECK-NEXT: cpy2.to.pitched.set_y(4);

clang/test/dpct/driver-mem-usm-none.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ int main(){
215215
// CHECK: dpct::memcpy_parameter cpy2;
216216
// CHECK-EMPTY:
217217
// CHECK-NEXT: dpct::image_matrix_p ca;
218+
// CHECK: /*
219+
// CHECK-NEXT: DPCT1007:22: Migration of CU_MEMORYTYPE_ARRAY is not supported.
220+
// CHECK-NEXT: */
218221
// CHECK-NEXT: cpy2.to.image = ca;
219222
// CHECK-NEXT: cpy2.to.pitched.set_pitch(5);
220223
// CHECK-NEXT: cpy2.to.pitched.set_y(4);

clang/test/dpct/driver-mem.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ int main(){
264264
// CHECK: dpct::memcpy_parameter cpy2;
265265
// CHECK-EMPTY:
266266
// CHECK-NEXT: dpct::image_matrix_p ca;
267+
// CHECK-NEXT: /*
268+
// CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of CU_MEMORYTYPE_ARRAY is not supported.
269+
// CHECK-NEXT: */
267270
// CHECK-NEXT: cpy2.to.image = ca;
268271
// CHECK-NEXT: cpy2.to.pitched.set_pitch(5);
269272
// CHECK-NEXT: cpy2.to.pitched.set_y(4);

clang/test/dpct/manual_migrate_inroot/foo/api_is_inroot.cu

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ int main() {
2424
//CHECK:int a1 = cudnnAAA();
2525
//CHECK-NEXT:cudnnFooType b1;
2626
//CHECK-NEXT:cudnnFooEnum c1;
27+
//CHECK-NEXT: /*
28+
//CHECK-NEXT: DPCT1007:{{[0-9]+}}: Migration of CUDNN_FOO_VAL is not supported.
29+
//CHECK-NEXT: */
2730
//CHECK-NEXT:if(b1 == CUDNN_FOO_VAL){
2831
//CHECK-NEXT:}
2932
//CHECK-NEXT:cudnnCLASS d1;

0 commit comments

Comments
 (0)