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] Fix unsuccessful compilation of dpct::load_kernel_library_mem due to failed argument cast #2525

Merged
merged 8 commits into from
Dec 2, 2024
4 changes: 2 additions & 2 deletions clang/lib/DPCT/RulesLang/APINamesDriver.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ FEATURE_REQUEST_FACTORY(
ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY("cuModuleLoadData", DEREF(0),
CALL(MapNames::getDpctNamespace() +
"load_kernel_library_mem",
ARG(1)))))
CAST_IF_NOT_SAME(makeLiteral("const char *"), ARG(1))))))

FEATURE_REQUEST_FACTORY(
HelperFeatureEnum::device_ext,
ASSIGNABLE_FACTORY(ASSIGN_FACTORY_ENTRY("cuModuleLoadDataEx", DEREF(0),
CALL(MapNames::getDpctNamespace() +
"load_kernel_library_mem",
ARG(1)))))
CAST_IF_NOT_SAME(makeLiteral("const char *"), ARG(1))))))

FEATURE_REQUEST_FACTORY(
HelperFeatureEnum::device_ext,
Expand Down
15 changes: 14 additions & 1 deletion clang/test/dpct/module_main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@ int main(){
//CHECK-NEXT: M = dpct::load_kernel_library_mem(Data.c_str());
cuModuleLoadData(&M, Data.c_str());

unsigned char *DataPtr;
//CHECK: /*
//CHECK-NEXT: DPCT1104:{{[0-9]+}}: 'DataPtr' should point to a dynamic library loaded in memory. The dynamic library should supply wrapped kernel functions.
//CHECK-NEXT: */
//CHECK-NEXT: M = dpct::load_kernel_library_mem((const char *)DataPtr);
cuModuleLoadData(&M, DataPtr);

//CHECK: /*
//CHECK-NEXT: DPCT1104:{{[0-9]+}}: 'Data.c_str()' should point to a dynamic library loaded in memory. The dynamic library should supply wrapped kernel functions.
//CHECK-NEXT: */
//CHECK-NEXT: M = dpct::load_kernel_library_mem(Data.c_str());
cuModuleLoadDataEx(&M, Data.c_str(), 0, NULL, NULL);

//CHECK: /*
//CHECK-NEXT: DPCT1104:{{[0-9]+}}: 'DataPtr' should point to a dynamic library loaded in memory. The dynamic library should supply wrapped kernel functions.
//CHECK-NEXT: */
//CHECK-NEXT: M = dpct::load_kernel_library_mem((const char *)DataPtr);
cuModuleLoadDataEx(&M, DataPtr, 0, NULL, NULL);

//CHECK: F = dpct::get_kernel_function(M, FunctionName.c_str());
cuModuleGetFunction(&F, M, FunctionName.c_str());

Expand Down Expand Up @@ -66,4 +79,4 @@ int main(){
}

return 0;
}
}
4 changes: 2 additions & 2 deletions clang/test/dpct/query_api_mapping/Driver/test.cu
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,15 @@
// CUMODULELOADDATA: CUDA API:
// CUMODULELOADDATA-NEXT: cuModuleLoadData(pm /*CUmodule **/, pData /*const void **/);
// CUMODULELOADDATA-NEXT: Is migrated to:
// CUMODULELOADDATA-NEXT: *pm = dpct::load_kernel_library_mem(pData);
// CUMODULELOADDATA-NEXT: *pm = dpct::load_kernel_library_mem((const char *)pData);

// RUN: dpct --cuda-include-path="%cuda-path/include" --query-api-mapping=cuModuleLoadDataEx | FileCheck %s -check-prefix=CUMODULELOADDATAEX
// CUMODULELOADDATAEX: CUDA API:
// CUMODULELOADDATAEX-NEXT: cuModuleLoadDataEx(pm /*CUmodule **/, pData /*const void **/,
// CUMODULELOADDATAEX-NEXT: u /*unsigned int*/, pOpt /*CUjit_option **/,
// CUMODULELOADDATAEX-NEXT: pOptVal /*void ***/);
// CUMODULELOADDATAEX-NEXT: Is migrated to:
// CUMODULELOADDATAEX-NEXT: *pm = dpct::load_kernel_library_mem(pData);
// CUMODULELOADDATAEX-NEXT: *pm = dpct::load_kernel_library_mem((const char *)pData);

// RUN: dpct --cuda-include-path="%cuda-path/include" --query-api-mapping=cuModuleUnload | FileCheck %s -check-prefix=CUMODULEUNLOAD
// CUMODULEUNLOAD: CUDA API:
Expand Down