Skip to content

Commit

Permalink
[SYCLomatic] Migrate cublasHandle_t to dpct::queue_ptr (#354)
Browse files Browse the repository at this point in the history
Signed-off-by: Jiang, Zhiwei <[email protected]>
  • Loading branch information
zhiweij1 authored Nov 16, 2022
1 parent dcdce3d commit a0758d6
Show file tree
Hide file tree
Showing 44 changed files with 97 additions and 89 deletions.
18 changes: 9 additions & 9 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ void TypeInDeclRule::registerMatcher(MatchFinder &MF) {
"cudaError", "curandStatus", "cublasStatus", "CUstream",
"CUstream_st", "thrust::complex", "thrust::device_vector",
"thrust::device_ptr", "thrust::device_reference",
"thrust::host_vector", "cublasHandle_t",
"thrust::host_vector", "cublasHandle_t",
"CUevent_st", "__half", "half", "__half2", "half2",
"cudaMemoryAdvise", "cudaError_enum", "cudaDeviceProp",
"cudaPitchedPtr", "thrust::counting_iterator",
Expand Down Expand Up @@ -3238,11 +3238,11 @@ void TypeInDeclRule::runRule(const MatchFinder::MatchResult &Result) {
const FunctionDecl *FD = DpctGlobalInfo::findAncestor<FunctionDecl>(TL);
if (FD &&
(FD->hasAttr<CUDADeviceAttr>() || FD->hasAttr<CUDAGlobalAttr>())) {
if (TL->getType().getAsString().find("cublasHandle_t") !=
std::string::npos)
if (DpctGlobalInfo::getUnqualifiedTypeName(TL->getType()) == "cublasHandle_t") {
report(BeginLoc, Diagnostics::HANDLE_IN_DEVICE, false, TypeStr);
return;
}
}

if (VarD) {
DD = VarD;
} else if (FieldD) {
Expand Down Expand Up @@ -11684,7 +11684,7 @@ void MemoryMigrationRule::registerMatcher(MatchFinder &MF) {
"cuMemcpyDtoD_v2", "cuMemAllocPitch_v2", "cuMemPrefetchAsync",
"cuMemFree_v2", "cuDeviceTotalMem_v2", "cuMemHostGetFlags",
"cuMemHostRegister_v2", "cuMemHostUnregister",
"cuMemcpy", "cuMemcpyAsync");
"cuMemcpy", "cuMemcpyAsync");
};

MF.addMatcher(callExpr(allOf(callee(functionDecl(memoryAPI())), parentStmt()))
Expand Down Expand Up @@ -11772,8 +11772,8 @@ void MemoryMigrationRule::runRule(const MatchFinder::MatchResult &Result) {
Name.compare("cuMemHostRegister_v2") &&
Name.compare("cudaHostGetFlags") &&
Name.compare("cuMemHostGetFlags") &&
Name.compare("cuMemcpy") &&
Name.compare("cuMemcpyAsync")) {
Name.compare("cuMemcpy") &&
Name.compare("cuMemcpyAsync")) {
report(C->getBeginLoc(), Diagnostics::NOERROR_RETURN_COMMA_OP, false);
insertAroundStmt(C, "(", ", 0)");
} else if (IsAssigned && !Name.compare("cudaMemAdvise") &&
Expand Down Expand Up @@ -11911,8 +11911,8 @@ MemoryMigrationRule::MemoryMigrationRule() {
{"cuMemGetInfo_v2", &MemoryMigrationRule::miscMigration},
{"cudaMemGetInfo", &MemoryMigrationRule::miscMigration},
{"cuDeviceTotalMem_v2", &MemoryMigrationRule::miscMigration},
{"cuMemcpy", &MemoryMigrationRule::memcpyMigration},
{"cuMemcpyAsync", &MemoryMigrationRule::memcpyMigration}};
{"cuMemcpy", &MemoryMigrationRule::memcpyMigration},
{"cuMemcpyAsync", &MemoryMigrationRule::memcpyMigration}};

for (auto &P : Dispatcher)
MigrationDispatcher[P.first] =
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/DPCT/MapNames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ void MapNames::setExplicitNamespaceMap() {
{"ushort3", std::make_shared<TypeNameRule>(getClNamespace() + "ushort3")},
{"ushort4", std::make_shared<TypeNameRule>(getClNamespace() + "ushort4")},
{"cublasHandle_t",
std::make_shared<TypeNameRule>(getClNamespace() + "queue*")},
std::make_shared<TypeNameRule>(getDpctNamespace() + "queue_ptr",
HelperFeatureEnum::Device_typedef_queue_ptr)},
{"cublasStatus_t", std::make_shared<TypeNameRule>("int")},
{"cublasStatus", std::make_shared<TypeNameRule>("int")},
{"cublasGemmAlgo_t", std::make_shared<TypeNameRule>("int")},
Expand Down
11 changes: 9 additions & 2 deletions clang/test/dpct/cublas-create-Sgemm-destroy.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ cublasStatus_t bar (cublasStatus_t s){
return s;
}

// CHECK: extern sycl::queue* handle2;
// CHECK: extern dpct::queue_ptr handle2;
extern cublasHandle_t handle2;

// CHECK: int foo2(dpct::library_data_t DT) try {
int foo2(cudaDataType DT) {
// CHECK: dpct::device_ext &dev_ct1 = dpct::get_current_device();
// CHECK-NEXT: sycl::queue &q_ct1 = dev_ct1.default_queue();
// CHECK: int status;
// CHECK-NEXT: sycl::queue* handle;
// CHECK-NEXT: dpct::queue_ptr handle;
// CHECK-NEXT: handle = &q_ct1;
// CHECK-NEXT: /*
// CHECK-NEXT: DPCT1003:{{[0-9]+}}: Migrated API does not return error code. (*, 0) is inserted. You may need to rewrite this code.
Expand Down Expand Up @@ -294,3 +294,10 @@ void foo4() {
cublasCdgmm(handle, CUBLAS_SIDE_LEFT, 2, 2, a_c, 2, x_c, 1, c_c, 2);
cublasZdgmm(handle, CUBLAS_SIDE_LEFT, 2, 2, a_z, 2, x_z, 1, c_z, 2);
}

void foo() {
//CHECK:const dpct::queue_ptr h_c = nullptr;
//CHECK-NEXT:dpct::queue_ptr h = h_c;
const cublasHandle_t h_c = nullptr;
cublasHandle_t h = h_c;
}
2 changes: 1 addition & 1 deletion clang/test/dpct/cublasLegacyHelper.cu
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main() {

// CHECK: int a = sizeof(int);
// CHECK-NEXT: a = sizeof(int);
// CHECK-NEXT: a = sizeof(cl::sycl::queue*);
// CHECK-NEXT: a = sizeof(dpct::queue_ptr);
// CHECK-NEXT: a = sizeof(cl::sycl::float2);
// CHECK-NEXT: a = sizeof(cl::sycl::double2);
int a = sizeof(cublasStatus);
Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/cublasReturnType.cu
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cublasStatus_t foo(int m, int n) {
return CUBLAS_STATUS_SUCCESS;
}

// CHECK: sycl::queue* foo1(int m) {
// CHECK: dpct::queue_ptr foo1(int m) {
cublasHandle_t foo1(int m) {
return 0;
}
Expand Down
66 changes: 33 additions & 33 deletions clang/test/dpct/datatypes_test_part2.cu
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ cudaEvent_t &&var4 = std::move(var1);
}

{
// CHECK: sycl::queue* var1;
// CHECK-NEXT: sycl::queue* *var2;
// CHECK-NEXT: sycl::queue* &var3 = var1;
// CHECK-NEXT: sycl::queue* &&var4 = std::move(var1);
// CHECK: dpct::queue_ptr var1;
// CHECK-NEXT: dpct::queue_ptr *var2;
// CHECK-NEXT: dpct::queue_ptr &var3 = var1;
// CHECK-NEXT: dpct::queue_ptr &&var4 = std::move(var1);
cublasHandle_t var1;
cublasHandle_t *var2;
cublasHandle_t &var3 = var1;
Expand Down Expand Up @@ -274,8 +274,8 @@ void case_2(void) {
}

{
// CHECK: new sycl::queue*();
// CHECK-NEXT: new sycl::queue* *();
// CHECK: new dpct::queue_ptr();
// CHECK-NEXT: new dpct::queue_ptr *();
new cublasHandle_t();
new cublasHandle_t *();
}
Expand Down Expand Up @@ -420,9 +420,9 @@ cudaEvent_t foo12();
cudaEvent_t *foo13();
cudaEvent_t &foo14();

// CHECK: sycl::queue* foo15();
// CHECK-NEXT: sycl::queue* *foo16();
// CHECK-NEXT: sycl::queue* &foo17();
// CHECK: dpct::queue_ptr foo15();
// CHECK-NEXT: dpct::queue_ptr *foo16();
// CHECK-NEXT: dpct::queue_ptr &foo17();
cublasHandle_t foo15();
cublasHandle_t *foo16();
cublasHandle_t &foo17();
Expand Down Expand Up @@ -570,10 +570,10 @@ template <> struct S<cudaEvent_t *> {};
template <> struct S<cudaEvent_t &> {};
template <> struct S<cudaEvent_t &&> {};

// CHECK: template <> struct S<sycl::queue*> {};
// CHECK-NEXT: template <> struct S<sycl::queue* *> {};
// CHECK-NEXT: template <> struct S<sycl::queue* &> {};
// CHECK-NEXT: template <> struct S<sycl::queue* &&> {};
// CHECK: template <> struct S<dpct::queue_ptr> {};
// CHECK-NEXT: template <> struct S<dpct::queue_ptr *> {};
// CHECK-NEXT: template <> struct S<dpct::queue_ptr &> {};
// CHECK-NEXT: template <> struct S<dpct::queue_ptr &&> {};
template <> struct S<cublasHandle_t> {};
template <> struct S<cublasHandle_t *> {};
template <> struct S<cublasHandle_t &> {};
Expand Down Expand Up @@ -747,10 +747,10 @@ template_foo<cudaEvent_t *>();
template_foo<cudaEvent_t &>();
template_foo<cudaEvent_t &&>();

// CHECK: template_foo<sycl::queue*>();
// CHECK-NEXT: template_foo<sycl::queue* *>();
// CHECK-NEXT: template_foo<sycl::queue* &>();
// CHECK-NEXT: template_foo<sycl::queue* &&>();
// CHECK: template_foo<dpct::queue_ptr>();
// CHECK-NEXT: template_foo<dpct::queue_ptr *>();
// CHECK-NEXT: template_foo<dpct::queue_ptr &>();
// CHECK-NEXT: template_foo<dpct::queue_ptr &&>();
template_foo<cublasHandle_t>();
template_foo<cublasHandle_t *>();
template_foo<cublasHandle_t &>();
Expand Down Expand Up @@ -940,10 +940,10 @@ using UT17 = cudaEvent_t *;
using UT18 = cudaEvent_t &;
using UT19 = cudaEvent_t &&;

// CHECK: using UT20 = sycl::queue*;
// CHECK-NEXT: using UT21 = sycl::queue* *;
// CHECK-NEXT: using UT22 = sycl::queue* &;
// CHECK-NEXT: using UT23 = sycl::queue* &&;
// CHECK: using UT20 = dpct::queue_ptr;
// CHECK-NEXT: using UT21 = dpct::queue_ptr *;
// CHECK-NEXT: using UT22 = dpct::queue_ptr &;
// CHECK-NEXT: using UT23 = dpct::queue_ptr &&;
using UT20 = cublasHandle_t;
using UT21 = cublasHandle_t *;
using UT22 = cublasHandle_t &;
Expand Down Expand Up @@ -1132,10 +1132,10 @@ typedef cudaEvent_t* T17;
typedef cudaEvent_t& T18;
typedef cudaEvent_t&& T19;

// CHECK: typedef sycl::queue* T20;
// CHECK-NEXT: typedef sycl::queue** T21;
// CHECK-NEXT: typedef sycl::queue*& T22;
// CHECK-NEXT: typedef sycl::queue*&& T23;
// CHECK: typedef dpct::queue_ptr T20;
// CHECK-NEXT: typedef dpct::queue_ptr* T21;
// CHECK-NEXT: typedef dpct::queue_ptr& T22;
// CHECK-NEXT: typedef dpct::queue_ptr&& T23;
typedef cublasHandle_t T20;
typedef cublasHandle_t* T21;
typedef cublasHandle_t& T22;
Expand Down Expand Up @@ -1384,19 +1384,19 @@ __device__ void foo_t(){
// CHECK: /*
// CHECK-NEXT: DPCT1021:{{[0-9]+}}: Migration of cublasHandle_t in __global__ or __device__ function is not supported. You may need to redesign the code.
// CHECK-NEXT: */
// CHECK-NEXT: #define T8_20 sycl::queue*
// CHECK-NEXT: #define T8_20 cublasHandle_t
// CHECK-NEXT: /*
// CHECK-NEXT: DPCT1021:{{[0-9]+}}: Migration of cublasHandle_t in __global__ or __device__ function is not supported. You may need to redesign the code.
// CHECK-NEXT: */
// CHECK-NEXT: #define T8_21 sycl::queue* *
// CHECK-NEXT: #define T8_21 cublasHandle_t *
// CHECK-NEXT: /*
// CHECK-NEXT: DPCT1021:{{[0-9]+}}: Migration of cublasHandle_t in __global__ or __device__ function is not supported. You may need to redesign the code.
// CHECK-NEXT: */
// CHECK-NEXT: #define T8_22 sycl::queue* &
// CHECK-NEXT: #define T8_22 cublasHandle_t &
// CHECK-NEXT: /*
// CHECK-NEXT: DPCT1021:{{[0-9]+}}: Migration of cublasHandle_t in __global__ or __device__ function is not supported. You may need to redesign the code.
// CHECK-NEXT: */
// CHECK-NEXT: #define T8_23 sycl::queue* &&
// CHECK-NEXT: #define T8_23 cublasHandle_t &&
// CHECK-NEXT: T8_20 a1;
// CHECK-NEXT: T8_21 a2;
// CHECK-NEXT: T8_22 a3=a1;
Expand Down Expand Up @@ -1744,10 +1744,10 @@ template <> void foo2(cudaEvent_t){}
template <> void foo3(cudaEvent_t){}
template <> void foo4(cudaEvent_t){}

// CHECK: template <> void foo1(sycl::queue*){}
// CHECK-NEXT: template <> void foo2(sycl::queue*){}
// CHECK-NEXT: template <> void foo3(sycl::queue*){}
// CHECK-NEXT: template <> void foo4(sycl::queue*){}
// CHECK: template <> void foo1(dpct::queue_ptr){}
// CHECK-NEXT: template <> void foo2(dpct::queue_ptr){}
// CHECK-NEXT: template <> void foo3(dpct::queue_ptr){}
// CHECK-NEXT: template <> void foo4(dpct::queue_ptr){}
template <> void foo1(cublasHandle_t){}
template <> void foo2(cublasHandle_t){}
template <> void foo3(cublasHandle_t){}
Expand Down
8 changes: 4 additions & 4 deletions clang/test/dpct/nestedqueue.cu
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ __host__ __device__ void foo1(){
// CHECK: /*
// CHECK-NEXT: DPCT1021:{{[0-9]+}}: Migration of cublasHandle_t in __global__ or __device__ function is not supported. You may need to redesign the code.
// CHECK-NEXT: */
// CHECK-NEXT: sycl::queue* handle;
// CHECK-NEXT: cublasHandle_t handle;
cublasHandle_t handle;
int n=1;
float* x_S=0;
Expand All @@ -26,7 +26,7 @@ __device__ void foo2(){
// CHECK: /*
// CHECK-NEXT: DPCT1021:{{[0-9]+}}: Migration of cublasHandle_t in __global__ or __device__ function is not supported. You may need to redesign the code.
// CHECK-NEXT: */
// CHECK-NEXT: sycl::queue* handle;
// CHECK-NEXT: cublasHandle_t handle;
cublasHandle_t handle;
int n=1;
float* x_S=0;
Expand All @@ -43,7 +43,7 @@ __global__ void foo3(){
// CHECK: /*
// CHECK-NEXT: DPCT1021:{{[0-9]+}}: Migration of cublasHandle_t in __global__ or __device__ function is not supported. You may need to redesign the code.
// CHECK-NEXT: */
// CHECK-NEXT: sycl::queue* handle;
// CHECK-NEXT: cublasHandle_t handle;
cublasHandle_t handle;
int n=1;
float* x_S=0;
Expand All @@ -57,7 +57,7 @@ __global__ void foo3(){
}

__host__ void foo4(){
// CHECK: sycl::queue* handle;
// CHECK: dpct::queue_ptr handle;
cublasHandle_t handle;
int n=1;
float* x_S=0;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test1.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test1_out/api_test1.dp.cpp --match-full-lines %s -check-prefix=CODE
// RUN: rm -rf %T/BlasUtils/api_test1_out

// FEATURE_NUMBER: 22
// FEATURE_NUMBER: 23

// CODE: // AAA
// CODE-NEXT:#include <sycl/sycl.hpp>
Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test10.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test10_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test10_out

// CHECK: 36
// CHECK: 37

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test11.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test11_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test11_out

// CHECK: 23
// CHECK: 24

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test12.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test12_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test12_out

// CHECK: 17
// CHECK: 18

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test13.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test13_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test13_out

// CHECK: 17
// CHECK: 18

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test14.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test14_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test14_out

// CHECK: 31
// CHECK: 32

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test15.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test15_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test15_out

// CHECK: 23
// CHECK: 24

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test16.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test16_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test16_out

// CHECK: 23
// CHECK: 24

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test17.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test17_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test17_out

// CHECK: 38
// CHECK: 39

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test18.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test18_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test18_out

// CHECK: 16
// CHECK: 17

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test19.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test19_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test19_out

// CHECK: 23
// CHECK: 24

#include "cublas_v2.h"

Expand Down
2 changes: 1 addition & 1 deletion clang/test/dpct/test_api_level/BlasUtils/api_test20.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// RUN: FileCheck --input-file %T/BlasUtils/api_test20_out/count.txt --match-full-lines %s
// RUN: rm -rf %T/BlasUtils/api_test20_out

// CHECK: 23
// CHECK: 24

#include "cublas_v2.h"

Expand Down
Loading

0 comments on commit a0758d6

Please sign in to comment.