From 657aa8f1e9c7120f3709de1572c9ce75f0b40311 Mon Sep 17 00:00:00 2001 From: Deepak Raj H R Date: Wed, 15 Jan 2025 23:31:02 +0800 Subject: [PATCH 1/3] Add support for cuGetErrorName --- clang/lib/DPCT/RulesLang/APINamesDriver.inc | 7 +++++++ clang/lib/DPCT/RulesLang/RulesLang.cpp | 3 ++- clang/lib/DPCT/SrcAPI/APINames.inc | 2 +- clang/test/dpct/cuda-get-error-string.cu | 12 ++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/clang/lib/DPCT/RulesLang/APINamesDriver.inc b/clang/lib/DPCT/RulesLang/APINamesDriver.inc index ad858b9cd2fa..14c9ba434808 100644 --- a/clang/lib/DPCT/RulesLang/APINamesDriver.inc +++ b/clang/lib/DPCT/RulesLang/APINamesDriver.inc @@ -15,6 +15,13 @@ WARNING_FACTORY_ENTRY( CALL(MapNames::getDpctNamespace() + "get_error_string_dummy", ARG_WC(0)))), Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY) +WARNING_FACTORY_ENTRY( + "cuGetErrorName", + ASSIGNABLE_FACTORY( + ASSIGN_FACTORY_ENTRY("cuGetErrorName", DEREF(1), + CALL(MapNames::getDpctNamespace() + "get_error_string_dummy", ARG_WC(0)))), + Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY) + FEATURE_REQUEST_FACTORY( HelperFeatureEnum::device_ext, ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY( diff --git a/clang/lib/DPCT/RulesLang/RulesLang.cpp b/clang/lib/DPCT/RulesLang/RulesLang.cpp index 75580e75d595..52d2e64b6903 100644 --- a/clang/lib/DPCT/RulesLang/RulesLang.cpp +++ b/clang/lib/DPCT/RulesLang/RulesLang.cpp @@ -8201,7 +8201,8 @@ void DriverDeviceAPIRule::registerMatcher(ast_matchers::MatchFinder &MF) { return hasAnyName( "cuDeviceGet", "cuDeviceComputeCapability", "cuDriverGetVersion", "cuDeviceGetCount", "cuDeviceGetAttribute", "cuDeviceGetName", - "cuDeviceGetUuid", "cuDeviceGetUuid_v2", "cuGetErrorString"); + "cuDeviceGetUuid", "cuDeviceGetUuid_v2", "cuGetErrorString", + "cuGetErrorName"); }; MF.addMatcher( diff --git a/clang/lib/DPCT/SrcAPI/APINames.inc b/clang/lib/DPCT/SrcAPI/APINames.inc index fed15b19b817..c7819604a33e 100644 --- a/clang/lib/DPCT/SrcAPI/APINames.inc +++ b/clang/lib/DPCT/SrcAPI/APINames.inc @@ -1536,7 +1536,7 @@ ENTRY(__match_any_sync, __match_any_sync, true, NO_FLAG, P4, "comment") ENTRY(__match_all_sync, __match_all_sync, true, NO_FLAG, P4, "comment") // Error Handling -ENTRY(cuGetErrorName, cuGetErrorName, false, NO_FLAG, P4, "comment") +ENTRY(cuGetErrorName, cuGetErrorName, true, NO_FLAG, P4, "Successful") ENTRY(cuGetErrorString, cuGetErrorString, true, NO_FLAG, P4, "comment") // Initialization diff --git a/clang/test/dpct/cuda-get-error-string.cu b/clang/test/dpct/cuda-get-error-string.cu index a489aac8c0c2..646ce8dbaca5 100644 --- a/clang/test/dpct/cuda-get-error-string.cu +++ b/clang/test/dpct/cuda-get-error-string.cu @@ -137,6 +137,18 @@ const char *test_function() { //CHECK-NEXT: err_s = dpct::get_error_string_dummy(e); cuGetErrorString(e, &err_s); +//CHECK: /* +//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. +//CHECK-NEXT: */ +//CHECK-NEXT: err_s = dpct::get_error_string_dummy(e); + cuGetErrorName(e, &err_s); + +//CHECK-NEXT: /* +//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. +//CHECK-NEXT: */ +//CHECK-NEXT: c = dpct::get_error_string_dummy({{[0-9]+}}); + cuGetErrorName(CUDA_ERROR_OUT_OF_MEMORY, &err_s); + //CHECK:/* //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. //CHECK-NEXT:*/ From b446bfd04c19288362fbf2fcd346f1e457308e87 Mon Sep 17 00:00:00 2001 From: Deepak Raj H R Date: Wed, 15 Jan 2025 23:38:34 +0800 Subject: [PATCH 2/3] Format code --- clang/lib/DPCT/RulesLang/RulesLang.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/clang/lib/DPCT/RulesLang/RulesLang.cpp b/clang/lib/DPCT/RulesLang/RulesLang.cpp index 52d2e64b6903..fb640c33d4b8 100644 --- a/clang/lib/DPCT/RulesLang/RulesLang.cpp +++ b/clang/lib/DPCT/RulesLang/RulesLang.cpp @@ -8198,11 +8198,11 @@ void DriverModuleAPIRule::runRule( void DriverDeviceAPIRule::registerMatcher(ast_matchers::MatchFinder &MF) { auto DriverDeviceAPI = [&]() { - return hasAnyName( - "cuDeviceGet", "cuDeviceComputeCapability", "cuDriverGetVersion", - "cuDeviceGetCount", "cuDeviceGetAttribute", "cuDeviceGetName", - "cuDeviceGetUuid", "cuDeviceGetUuid_v2", "cuGetErrorString", - "cuGetErrorName"); + return hasAnyName("cuDeviceGet", "cuDeviceComputeCapability", + "cuDriverGetVersion", "cuDeviceGetCount", + "cuDeviceGetAttribute", "cuDeviceGetName", + "cuDeviceGetUuid", "cuDeviceGetUuid_v2", + "cuGetErrorString", "cuGetErrorName"); }; MF.addMatcher( From 7986febb742fa8e484643bb61e9abac2b04601d5 Mon Sep 17 00:00:00 2001 From: Deepak Raj H R Date: Thu, 16 Jan 2025 13:36:13 +0800 Subject: [PATCH 3/3] Fix lit check --- clang/test/dpct/cuda-get-error-string.cu | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/dpct/cuda-get-error-string.cu b/clang/test/dpct/cuda-get-error-string.cu index 646ce8dbaca5..4bfd1fa63dc5 100644 --- a/clang/test/dpct/cuda-get-error-string.cu +++ b/clang/test/dpct/cuda-get-error-string.cu @@ -143,10 +143,10 @@ const char *test_function() { //CHECK-NEXT: err_s = dpct::get_error_string_dummy(e); cuGetErrorName(e, &err_s); -//CHECK-NEXT: /* +//CHECK: /* //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. //CHECK-NEXT: */ -//CHECK-NEXT: c = dpct::get_error_string_dummy({{[0-9]+}}); +//CHECK-NEXT: err_s = dpct::get_error_string_dummy({{[0-9]+}}); cuGetErrorName(CUDA_ERROR_OUT_OF_MEMORY, &err_s); //CHECK:/*