Skip to content

Commit

Permalink
Migration support for CUDA driver error APIs and cudaErrorr_enum
Browse files Browse the repository at this point in the history
Signed-off-by: Teja Alaghari <[email protected]>
  • Loading branch information
TejaX-Alaghari committed Dec 14, 2023
1 parent 62f84ef commit 434e15d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
4 changes: 4 additions & 0 deletions clang/lib/DPCT/APINames.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 16 additions & 0 deletions clang/lib/DPCT/APINamesErrorHandling.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand Down
12 changes: 10 additions & 2 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3475,6 +3475,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));
}

Expand Down Expand Up @@ -6250,7 +6255,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",
Expand Down Expand Up @@ -6560,7 +6566,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();
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/DPCT/MapNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void MapNames::setExplicitNamespaceMap() {
{"cudaError",
std::make_shared<TypeNameRule>(getDpctNamespace() + "err0",
HelperFeatureEnum::device_ext)},
{"cudaError_enum",
std::make_shared<TypeNameRule>(getDpctNamespace() + "error_code",
HelperFeatureEnum::device_ext)},
{"CUjit_option", std::make_shared<TypeNameRule>("int")},
{"CUresult", std::make_shared<TypeNameRule>("int")},
{"CUcontext", std::make_shared<TypeNameRule>("int")},
Expand Down Expand Up @@ -890,6 +893,11 @@ void MapNames::setExplicitNamespaceMap() {
{"cudaDevAttrConcurrentManagedAccess",
std::make_shared<EnumNameRule>(
"get_info<sycl::info::device::usm_shared_allocations>")},
// enum cudaError_enum Type
{"cudaErrorInvalidConfiguration",
std::make_shared<EnumNameRule>(
getDpctNamespace() + "default_error",
HelperFeatureEnum::device_ext)},
// enum Memcpy Kind
{"cudaMemcpyHostToHost",
std::make_shared<EnumNameRule>(getDpctNamespace() + "host_to_host")},
Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,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";
Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/error-handling-constants.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions clang/test/dpct/types001.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 434e15d

Please sign in to comment.