Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCLomatic] Add a dummy function to migrate API like getErrorStr/getErrorName #2412

Open
wants to merge 11 commits into
base: SYCLomatic
Choose a base branch
from
12 changes: 6 additions & 6 deletions clang/lib/DPCT/APINamesCUBLAS.inc
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,12 @@ GELS_BATCHED(cublasCgelsBatched)
GELS_BATCHED(cublasZgelsBatched)
#undef GELS_BATCHED

WARNING_FACTORY_ENTRY(
"cublasGetStatusString",
TOSTRING_FACTORY_ENTRY("cublasGetStatusString",
LITERAL("\"<Placeholder string>\"")),
Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED,
ARG("The call was replaced by a placeholder string"))
WARNING_FACTORY_ENTRY("cublasGetStatusString",
CALL_FACTORY_ENTRY("cublasGetStatusString",
CALL(MapNames::getDpctNamespace() +
"get_error_string_dummy",
ARG_WC(0))),
Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY)

#define GEMM_EX(NAME, COMPUTE_TYPE) \
ASSIGNABLE_FACTORY(FEATURE_REQUEST_FACTORY( \
Expand Down
24 changes: 12 additions & 12 deletions clang/lib/DPCT/APINamesCUSPARSE.inc
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,18 @@ ASSIGNABLE_FACTORY(CALL_FACTORY_ENTRY(
"cusparseSpMV", CALL(MapNames::getLibraryHelperNamespace() + "sparse::spmv",
MEMBER_CALL(ARG(0), true, "get_queue"), ARG(1), ARG(2),
ARG(3), ARG(4), ARG(5), ARG(6), ARG(7))))
WARNING_FACTORY_ENTRY(
"cusparseGetErrorString",
TOSTRING_FACTORY_ENTRY("cusparseGetErrorString",
LITERAL("\"<Placeholder string>\"")),
Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED,
ARG("The call was replaced by a placeholder string"))
WARNING_FACTORY_ENTRY(
"cusparseGetErrorName",
TOSTRING_FACTORY_ENTRY("cusparseGetErrorName",
LITERAL("\"<Placeholder string>\"")),
Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED,
ARG("The call was replaced by a placeholder string"))
WARNING_FACTORY_ENTRY("cusparseGetErrorString",
CALL_FACTORY_ENTRY("cusparseGetErrorString",
CALL(MapNames::getDpctNamespace() +
"get_error_string_dummy",
ARG_WC(0))),
Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY)
WARNING_FACTORY_ENTRY("cusparseGetErrorName",
CALL_FACTORY_ENTRY("cusparseGetErrorName",
CALL(MapNames::getDpctNamespace() +
"get_error_string_dummy",
ARG_WC(0))),
Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY)

ASSIGNABLE_FACTORY(
CALL_FACTORY_ENTRY("cusparseSpGEMM_createDescr",
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/DPCT/APINamesDriver.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ WARNING_FACTORY_ENTRY(
"cuGetErrorString",
ASSIGNABLE_FACTORY(
ASSIGN_FACTORY_ENTRY("cuGetErrorString", DEREF(1),
ARG("\"<Placeholder string>\""))),
Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED,
ARG("The call was replaced by a placeholder string"))
CALL(MapNames::getDpctNamespace() + "get_error_string_dummy", ARG_WC(0)))),
Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY)

FEATURE_REQUEST_FACTORY(
HelperFeatureEnum::device_ext,
Expand Down
34 changes: 16 additions & 18 deletions clang/lib/DPCT/APINamesErrorHandling.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@

WARNING_FACTORY_ENTRY(
"cudnnGetErrorString",
TOSTRING_FACTORY_ENTRY("cudnnGetErrorString",
LITERAL("\"<Placeholder string>\"")),
Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED,
ARG("The call was replaced by a placeholder string"))

CALL_FACTORY_ENTRY("cudnnGetErrorString",
CALL(MapNames::getDpctNamespace() + "get_error_string_dummy",
ARG_WC(0))),
Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY)
WARNING_FACTORY_ENTRY(
"cudaGetErrorString",
TOSTRING_FACTORY_ENTRY("cudaGetErrorString",
LITERAL("\"<Placeholder string>\"")),
Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED,
ARG("The call was replaced by a placeholder string"))

CALL_FACTORY_ENTRY("cudaGetErrorString",
CALL(MapNames::getDpctNamespace() + "get_error_string_dummy",
ARG_WC(0))),
Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY)
WARNING_FACTORY_ENTRY(
"cudaGetErrorName",
TOSTRING_FACTORY_ENTRY("cudaGetErrorName",
LITERAL("\"<Placeholder string>\"")),
Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED,
ARG("The call was replaced by a placeholder string"))
CALL_FACTORY_ENTRY("cudaGetErrorName",
CALL(MapNames::getDpctNamespace() + "get_error_string_dummy",
ARG_WC(0))),
Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY)

CONDITIONAL_FACTORY_ENTRY(
checkIsCallExprOnly(),
Expand Down Expand Up @@ -53,10 +51,10 @@ CONDITIONAL_FACTORY_ENTRY(

WARNING_FACTORY_ENTRY(
"ncclGetErrorString",
TOSTRING_FACTORY_ENTRY("cublasGetStatusString",
LITERAL("\"<Placeholder string>\"")),
Diagnostics::TRNA_WARNING_ERROR_HANDLING_API_COMMENTED,
ARG("The call was replaced by a placeholder string"))
CALL_FACTORY_ENTRY("ncclGetErrorString",
CALL(MapNames::getDpctNamespace() + "get_error_string_dummy",
ARG_WC(0))),
Diagnostics::ERROR_HANDLING_API_REPLACED_BY_DUMMY)

CONDITIONAL_FACTORY_ENTRY(
checkIsCallExprOnly(),
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/DPCT/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ std::unordered_set<int> APIQueryNeedReportWarningIDSet = {
// More IDs may need to be added, like: 1007, 1028, 1030, 1031, 1037,
// 1051, 1053, 1067, 1069, 1076, 1082, 1090, 1107.
1008, // API_NOT_MIGRATED_SYCL_UNDEF
1009, // TRNA_WARNING_ERROR_HANDLING_API_COMMENTED
1009, // ERROR_HANDLING_API_REPLACED_BY_DUMMY
1014, // STREAM_FLAG_PRIORITY_NOT_SUPPORTED
1023, // MASK_UNSUPPORTED
1029, // DEVICE_LIMIT_NOT_SUPPORTED
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/DPCT/Diagnostics.inc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ DEF_WARNING(API_NOT_MIGRATED, 1007, HIGH_LEVEL, "Migration of %0 is not supporte
DEF_COMMENT(API_NOT_MIGRATED, 1007, HIGH_LEVEL, "Migration of {0} is not supported.")
DEF_WARNING(API_NOT_MIGRATED_SYCL_UNDEF, 1008, HIGH_LEVEL, "%0 function is not defined in SYCL. This is a hardware-specific feature. Consult with your hardware vendor to find a replacement.")
DEF_COMMENT(API_NOT_MIGRATED_SYCL_UNDEF, 1008, HIGH_LEVEL, "{0} function is not defined in SYCL. This is a hardware-specific feature. Consult with your hardware vendor to find a replacement.")
DEF_WARNING(TRNA_WARNING_ERROR_HANDLING_API_COMMENTED, 1009, LOW_LEVEL, "SYCL uses exceptions to report errors and does not use the error codes. %0. You need to rewrite this code.")
DEF_COMMENT(TRNA_WARNING_ERROR_HANDLING_API_COMMENTED, 1009, LOW_LEVEL, "SYCL uses exceptions to report errors and does not use the error codes. {0}. You need to rewrite this code.")
DEF_WARNING(ERROR_HANDLING_API_REPLACED_BY_DUMMY, 1009, LOW_LEVEL, "SYCL reports errors using exceptions and does not use error codes. Please replace the \"get_error_string_dummy(...)\" with a real error-handling function.")
DEF_COMMENT(ERROR_HANDLING_API_REPLACED_BY_DUMMY, 1009, LOW_LEVEL, "SYCL reports errors using exceptions and does not use error codes. Please replace the \"get_error_string_dummy(...)\" with a real error-handling function.")
DEF_WARNING(TRNA_WARNING_ERROR_HANDLING_API_REPLACED_0, 1010, LOW_LEVEL, "SYCL uses exceptions to report errors and does not use the error codes. The call was replaced with 0. You need to rewrite this code.")
DEF_COMMENT(TRNA_WARNING_ERROR_HANDLING_API_REPLACED_0, 1010, LOW_LEVEL, "SYCL uses exceptions to report errors and does not use the error codes. The call was replaced with 0. You need to rewrite this code.")
DEF_WARNING(TRNA_WARNING_OVERLOADED_API_FOUND, 1011, LOW_LEVEL, "The tool detected overloaded operators for built-in vector types, which may conflict with the SYCL 2020 standard operators (see 4.14.2.1 Vec interface). The tool inserted a namespace to avoid the conflict. Use SYCL 2020 standard operators instead.")
Expand Down
6 changes: 6 additions & 0 deletions clang/lib/DPCT/ExprAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,12 @@ void ExprAnalysis::analyzeExpr(const DeclRefExpr *DRE) {
REPLACE_ENUM(MapNames::SPBLASEnumsMap);
REPLACE_ENUM(MapNames::CUBEnumsMap);
#undef REPLACE_ENUM
std::string TypeName = DpctGlobalInfo::getTypeName(ECD->getType());
if (TypeName == "cublasStatus_t" || TypeName == "cusparseStatus_t" ||
TypeName == "cudaError_enum" || TypeName == "cudnnStatus_t" ||
TypeName == "cudaError" || TypeName == "ncclResult_t") {
addReplacement(DRE, toString(ECD->getInitVal(), 10));
}
}
} else if (auto VD = dyn_cast<VarDecl>(DRE->getDecl())) {
if (RefString == "warpSize" &&
Expand Down
10 changes: 9 additions & 1 deletion clang/runtime/dpct-rt/include/dpct/dpct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,17 @@ template <int Arg> class dpct_kernel_scalar;

#define DPCT_COMPATIBILITY_TEMP (900)

namespace dpct{
namespace dpct {
enum error_code { success = 0, default_error = 999 };
/// A dummy function introduced to assist auto migration.
/// The SYCLomatic user should replace it with a real error-handling function.
/// SYCL reports errors using exceptions and does not use error codes.
inline const char *get_error_string_dummy(int ec) {
(void)ec;
return "<FIXME: Placeholder>"; // Return the error string for the error code
// ec.
}
} // namespace dpct

#define DPCT_CHECK_ERROR(expr) \
[&]() { \
Expand Down
19 changes: 17 additions & 2 deletions clang/test/dpct/cublas_115.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

void foo1(cublasStatus_t s) {
//CHECK:/*
//CHECK-NEXT:DPCT1009:{{[0-9]+}}: SYCL uses exceptions to report errors and does not use the error codes. The call was replaced by a placeholder string. You need to rewrite this code.
//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:printf("Error string: %s", "<Placeholder string>");
//CHECK-NEXT:printf("Error string: %s", dpct::get_error_string_dummy(s));
printf("Error string: %s", cublasGetStatusString(s));
cublasHandle_t handle;
void *workspace;
Expand All @@ -22,6 +22,21 @@ void foo1(cublasStatus_t s) {
cublasSetWorkspace(handle, workspace, size);
}

//CHECK:void foo11(int err) {
//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: dpct::get_error_string_dummy(err);
//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: dpct::get_error_string_dummy({{[0-9]+}});
//CHECK-NEXT:}
void foo11(cublasStatus_t err) {
cublasGetStatusString(err);
cublasGetStatusString(CUBLAS_STATUS_NOT_INITIALIZED);
}

//CHECK:void foo2(dpct::compute_type &a) {
//CHECK-NEXT: a = dpct::compute_type::f16;
//CHECK-NEXT: a = dpct::compute_type::f16_standard;
Expand Down
Loading
Loading