Skip to content

Commit cbcc547

Browse files
authored
[SYCLomatic] Add __nv_half and __nv_half2 migration. (#2714)
Signed-off-by: Chen, Sheng S <sheng.s.chen@intel.com>
1 parent 93a7525 commit cbcc547

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

clang/lib/DPCT/RuleInfra/MapNames.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ void MapNames::setExplicitNamespaceMap(
327327
{"__half2", std::make_shared<TypeNameRule>(getClNamespace() + "half2")},
328328
{"half", std::make_shared<TypeNameRule>(getClNamespace() + "half")},
329329
{"half2", std::make_shared<TypeNameRule>(getClNamespace() + "half2")},
330+
{"__nv_half2", std::make_shared<TypeNameRule>(getClNamespace() + "half2")},
331+
{"__nv_half", std::make_shared<TypeNameRule>(getClNamespace() + "half")},
330332
{"cudaEvent_t",
331333
std::make_shared<TypeNameRule>(getDpctNamespace() + "event_ptr",
332334
HelperFeatureEnum::device_ext)},

clang/lib/DPCT/RulesLang/MapNamesLang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const std::map<std::string, int> MapNamesLang::VectorTypeMigratedTypeSizeMap{
9090
{"float3", 16}, {"float4", 16}, {"double1", 8},
9191
{"double2", 16}, {"double3", 32}, {"double4", 32},
9292
{"__half", 2}, {"__half2", 4}, {"__half_raw", 2},
93-
{"__half2_raw", 4}};
93+
{"__half2_raw", 4}, {"__nv_half", 2}, {"__nv_half2", 4}};
9494

9595
const std::map<clang::dpct::KernelArgType, int>
9696
MapNamesLang::KernelArgTypeSizeMap{

clang/lib/DPCT/RulesLang/MapNamesLang.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const std::string StringLiteralUnsupported{"UNSUPPORTED"};
2929
"ulonglong1", "longlong2", "ulonglong2", "longlong3", "ulonglong3", \
3030
"longlong4", "ulonglong4", "double1", "double2", "double3", "double4", \
3131
"__half", "__half2", "half", "half2", "__nv_bfloat16", "nv_bfloat16", \
32-
"__nv_bfloat162", "nv_bfloat162", "__half_raw", "__half2_raw"
32+
"__nv_bfloat162", "nv_bfloat162", "__half_raw", "__half2_raw", \
33+
"__nv_half2", "__nv_half"
3334

3435
/// Record mapping between names
3536
class MapNamesLang {

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ void TypeInDeclRule::registerMatcher(MatchFinder &MF) {
346346
"cublasLtMatmulHeuristicResult_t", "CUjit_target",
347347
"cublasLtMatrixTransformDesc_t", "cudaGraphicsMapFlags",
348348
"cudaGraphicsRegisterFlags", "cudaExternalMemoryHandleType",
349-
"CUstreamCallback", "cudaHostFn_t"))))))
349+
"CUstreamCallback", "cudaHostFn_t", "__nv_half2",
350+
"__nv_half"))))))
350351
.bind("cudaTypeDef"),
351352
this);
352353

@@ -1189,10 +1190,6 @@ void VectorTypeNamespaceRule::registerMatcher(MatchFinder &MF) {
11891190
.bind("vectorTypeTL"),
11901191
this);
11911192

1192-
MF.addMatcher(
1193-
cxxRecordDecl(isDirectlyDerivedFrom(hasAnyName(SUPPORTEDVECTORTYPENAMES)))
1194-
.bind("inheritanceType"),
1195-
this);
11961193

11971194
auto Vec3Types = [&]() {
11981195
return hasAnyName("char3", "uchar3", "short3", "ushort3", "int3", "uint3",
@@ -5034,8 +5031,9 @@ void DeviceFunctionDeclRule::registerMatcher(ast_matchers::MatchFinder &MF) {
50345031
this);
50355032

50365033
MF.addMatcher(typeLoc(hasAncestor(DeviceFunctionMatcher),
5037-
loc(qualType(hasDeclaration(namedDecl(hasAnyName(
5038-
"__half", "half", "__half2", "half2"))))))
5034+
loc(qualType(hasDeclaration(namedDecl(
5035+
hasAnyName("__half", "half", "__half2", "half2",
5036+
"__nv_half2", "__nv_half"))))))
50395037
.bind("fp16"),
50405038
this);
50415039

clang/test/dpct/types008.cu

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,23 @@
1818
void foo(){
1919
thrust::reverse_iterator<int *> d_tmp(0);
2020
}
21+
22+
void foo1() {
23+
//CHECK:sycl::half nv_h;
24+
//CHECK-NEXT:int a = sizeof(sycl::half);
25+
//CHECK-NEXT:a = sizeof(nv_h);
26+
//CHECK-NEXT:a = sizeof nv_h;
27+
__nv_half nv_h;
28+
int a = sizeof(__nv_half);
29+
a = sizeof(nv_h);
30+
a = sizeof nv_h;
31+
32+
//CHECK:sycl::half2 nv_h2;
33+
//CHECK-NEXT:a = sizeof(sycl::half2);
34+
//CHECK-NEXT:a = sizeof(nv_h2);
35+
//CHECK-NEXT:a = sizeof nv_h2;
36+
__nv_half2 nv_h2;
37+
a = sizeof(__nv_half2);
38+
a = sizeof(nv_h2);
39+
a = sizeof nv_h2;
40+
}

0 commit comments

Comments
 (0)