From 393f9b017ce3c7192ef18839211e6958b2b926e2 Mon Sep 17 00:00:00 2001 From: Teja Alaghari Date: Tue, 14 Nov 2023 17:00:19 +0800 Subject: [PATCH] Migration support for cud driver error APIs and cudaErrorr_enum Signed-off-by: Teja Alaghari --- clang/lib/DPCT/APINames.inc | 4 ++++ clang/lib/DPCT/APINamesErrorHandling.inc | 16 ++++++++++++++++ clang/lib/DPCT/ASTTraversal.cpp | 12 ++++++++++-- clang/lib/DPCT/MapNames.cpp | 8 ++++++++ clang/test/dpct/cpp_test.cpp | 2 +- clang/test/dpct/error-handling-constants.cu | 2 +- clang/test/dpct/types001.cu | 4 ++-- 7 files changed, 42 insertions(+), 6 deletions(-) diff --git a/clang/lib/DPCT/APINames.inc b/clang/lib/DPCT/APINames.inc index e838f2bdcaa0..d339d36b4236 100644 --- a/clang/lib/DPCT/APINames.inc +++ b/clang/lib/DPCT/APINames.inc @@ -84,6 +84,10 @@ ENTRY(cudaGetErrorString, cudaGetErrorString, true, NO_FLAG, P0, "Successful") ENTRY(cudaGetLastError, cudaGetLastError, true, NO_FLAG, P0, "DPCT1010") ENTRY(cudaPeekAtLastError, cudaPeekAtLastError, true, NO_FLAG, P0, "DPCT1026/DPCT1027") +// error handling functions of driver API +ENTRY(cuGetErrorName, cuGetErrorName, true, NO_FLAG, P0, "Successful") +ENTRY(cuGetErrorString, cuGetErrorString, true, NO_FLAG, P0, "Successful") + // stream management functions of API ENTRY(cudaCtxResetPersistingL2Cache, cudaCtxResetPersistingL2Cache, true, NO_FLAG, P7, "DPCT1026/DPCT1027") ENTRY(cudaStreamAddCallback, cudaStreamAddCallback, true, NO_FLAG, P0, "Successful") diff --git a/clang/lib/DPCT/APINamesErrorHandling.inc b/clang/lib/DPCT/APINamesErrorHandling.inc index e346869b5c31..2fab7df8eeea 100644 --- a/clang/lib/DPCT/APINamesErrorHandling.inc +++ b/clang/lib/DPCT/APINamesErrorHandling.inc @@ -22,6 +22,14 @@ WARNING_FACTORY_ENTRY( "\"cudaGetErrorString is not supported\"/*", "*/"), Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED) +WARNING_FACTORY_ENTRY( + "cuGetErrorString", + INSERT_AROUND_FACTORY(CALL_FACTORY_ENTRY("cuGetErrorString", + CALL("cuGetErrorString", + ARG_WC(0), ARG_WC(1))), + "\"cuGetErrorString is not supported\"/*", "*/"), + Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED) + WARNING_FACTORY_ENTRY( "cudaGetErrorName", INSERT_AROUND_FACTORY(CALL_FACTORY_ENTRY("cudaGetErrorName", @@ -30,6 +38,14 @@ WARNING_FACTORY_ENTRY( "\"cudaGetErrorName is not supported\"/*", "*/"), Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED) +WARNING_FACTORY_ENTRY( + "cuGetErrorName", + INSERT_AROUND_FACTORY(CALL_FACTORY_ENTRY("cuGetErrorName", + CALL("cuGetErrorName", + ARG_WC(0), ARG_WC(1))), + "\"cuGetErrorName is not supported\"/*", "*/"), + Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED) + CONDITIONAL_FACTORY_ENTRY( checkIsCallExprOnly(), WARNING_FACTORY_ENTRY( diff --git a/clang/lib/DPCT/ASTTraversal.cpp b/clang/lib/DPCT/ASTTraversal.cpp index 8ef2bb29db65..20d9df631f20 100644 --- a/clang/lib/DPCT/ASTTraversal.cpp +++ b/clang/lib/DPCT/ASTTraversal.cpp @@ -3413,6 +3413,11 @@ void ErrorConstantsRule::runRule(const MatchFinder::MatchResult &Result) { } } + auto Search = EnumConstantRule::EnumNamesMap.find(EC->getDeclName().getAsString()); + if (Search != EnumConstantRule::EnumNamesMap.end()) { + Repl = Search->second->NewName; + } + emplaceTransformation(new ReplaceStmt(DE, Repl)); } @@ -6261,7 +6266,8 @@ void FunctionCallRule::registerMatcher(MatchFinder &MF) { "cudaDeviceGetAttribute", "cudaDeviceGetP2PAttribute", "cudaDeviceGetPCIBusId", "cudaGetDevice", "cudaDeviceSetLimit", "cudaGetLastError", "cudaPeekAtLastError", "cudaDeviceSynchronize", - "cudaThreadSynchronize", "cudnnGetErrorString", "cudaGetErrorString", "cudaGetErrorName", + "cudaThreadSynchronize", "cudnnGetErrorString", "cudaGetErrorString", + "cuGetErrorString", "cudaGetErrorName", "cuGetErrorName", "cudaDeviceSetCacheConfig", "cudaDeviceGetCacheConfig", "clock", "cudaOccupancyMaxPotentialBlockSize", "cudaThreadSetLimit", "cudaFuncSetCacheConfig", "cudaThreadExit", "cudaDeviceGetLimit", @@ -6571,7 +6577,9 @@ void FunctionCallRule::runRule(const MatchFinder::MatchResult &Result) { } else if (FuncName == "cudaGetLastError" || FuncName == "cudaPeekAtLastError" || FuncName == "cudaGetErrorString" || - FuncName == "cudaGetErrorName") { + FuncName == "cuGetErrorString" || + FuncName == "cudaGetErrorName" || + FuncName == "cuGetErrorName") { ExprAnalysis EA(CE); emplaceTransformation(EA.getReplacement()); EA.applyAllSubExprRepl(); diff --git a/clang/lib/DPCT/MapNames.cpp b/clang/lib/DPCT/MapNames.cpp index 51b238d1462d..072a40ebcc63 100644 --- a/clang/lib/DPCT/MapNames.cpp +++ b/clang/lib/DPCT/MapNames.cpp @@ -102,6 +102,9 @@ void MapNames::setExplicitNamespaceMap() { {"cudaError", std::make_shared(getDpctNamespace() + "err0", HelperFeatureEnum::device_ext)}, + {"cudaError_enum", + std::make_shared(getDpctNamespace() + "error_code", + HelperFeatureEnum::device_ext)}, {"CUjit_option", std::make_shared("int")}, {"CUresult", std::make_shared("int")}, {"CUcontext", std::make_shared("int")}, @@ -914,6 +917,11 @@ void MapNames::setExplicitNamespaceMap() { {"cudaDevAttrConcurrentManagedAccess", std::make_shared( "get_info")}, + // enum cudaError_enum Type + {"cudaErrorInvalidConfiguration", + std::make_shared( + getDpctNamespace() + "default_error", + HelperFeatureEnum::device_ext)}, // enum Memcpy Kind {"cudaMemcpyHostToHost", std::make_shared( getDpctNamespace() + "host_to_host")}, diff --git a/clang/test/dpct/cpp_test.cpp b/clang/test/dpct/cpp_test.cpp index 646772f163dc..a2cb3d79f8c5 100644 --- a/clang/test/dpct/cpp_test.cpp +++ b/clang/test/dpct/cpp_test.cpp @@ -187,7 +187,7 @@ void test_simple_ifs() { // CHECK-NEXT: return "cudaErrorLaunchOutOfResources"; // CHECK-NEXT: case {{[0-9]+}}: // CHECK-NEXT: return "cudaErrorInvalidDeviceFunction"; -// CHECK-NEXT: case 9: +// CHECK-NEXT: case dpct::default_error: // CHECK-NEXT: return "cudaErrorInvalidConfiguration"; // CHECK-NEXT: case {{[0-9]+}}: // CHECK-NEXT: return "cudaErrorInvalidDevice"; diff --git a/clang/test/dpct/error-handling-constants.cu b/clang/test/dpct/error-handling-constants.cu index e85df4a37d61..ce766c913e37 100644 --- a/clang/test/dpct/error-handling-constants.cu +++ b/clang/test/dpct/error-handling-constants.cu @@ -27,7 +27,7 @@ // CHECK-NEXT: return "cudaErrorLaunchOutOfResources"; // CHECK-NEXT: case {{[0-9]+}}: // CHECK-NEXT: return "cudaErrorInvalidDeviceFunction"; -// CHECK-NEXT: case 9: +// CHECK-NEXT: case dpct::default_error: // CHECK-NEXT: return "cudaErrorInvalidConfiguration"; // CHECK-NEXT: case {{[0-9]+}}: // CHECK-NEXT: return "cudaErrorInvalidDevice"; diff --git a/clang/test/dpct/types001.cu b/clang/test/dpct/types001.cu index 8278ef2c8ae1..3bcff1d7281f 100644 --- a/clang/test/dpct/types001.cu +++ b/clang/test/dpct/types001.cu @@ -318,8 +318,8 @@ int main(int argc, char **argv) { a = sizeof(fftresult); a = sizeof fftresult; - //CHECK:cudaError_enum error_enum; - //CHECK-NEXT:a = sizeof(cudaError_enum); + //CHECK:dpct::error_code error_enum; + //CHECK-NEXT:a = sizeof(dpct::error_code); //CHECK-NEXT:a = sizeof(error_enum); //CHECK-NEXT:a = sizeof error_enum; cudaError_enum error_enum;