Skip to content

Commit 5c8345d

Browse files
authored
[SYCLomatic] Match the typeAliasDecl for Cub Type, match template scan and reduce for block and warp. (#2887)
Signed-off-by: Chen, Sheng S <sheng.s.chen@intel.com>
1 parent a07bde6 commit 5c8345d

2 files changed

Lines changed: 53 additions & 5 deletions

File tree

clang/lib/DPCT/RulesLangLib/CUBAPIMigration.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -946,10 +946,14 @@ void CubRule::processCubDeclStmt(const DeclStmt *DS) {
946946
if (isTypeInAnalysisScope(ObjCanonicalType.getTypePtr())) {
947947
continue;
948948
} else if (ObjTypeStr.find("class cub::WarpScan") == 0 ||
949-
ObjTypeStr.find("class cub::WarpReduce") == 0) {
949+
ObjTypeStr.find("class cub::WarpReduce") == 0 ||
950+
ObjTypeStr.find("WarpScan<") == 0 ||
951+
ObjTypeStr.find("WarpReduce<") == 0) {
950952
Repl = DpctGlobalInfo::getSubGroup(DRE);
951953
} else if (ObjTypeStr.find("class cub::BlockScan") == 0 ||
952-
ObjTypeStr.find("class cub::BlockReduce") == 0) {
954+
ObjTypeStr.find("class cub::BlockReduce") == 0 ||
955+
ObjTypeStr.find("BlockScan<") == 0 ||
956+
ObjTypeStr.find("BlockReduce<") == 0) {
953957
Repl = DpctGlobalInfo::getGroup(DRE);
954958
} else {
955959
continue;
@@ -975,9 +979,12 @@ void CubRule::processCubTypeDefOrUsing(const TypedefNameDecl *TD) {
975979
std::string TypeName = TD->getNameAsString();
976980
auto &Context = dpct::DpctGlobalInfo::getContext();
977981
auto &SM = dpct::DpctGlobalInfo::getSourceManager();
978-
auto MyMatcher = compoundStmt(forEachDescendant(
979-
typeLoc(loc(qualType(hasDeclaration(typedefDecl(hasName(TypeName))))))
980-
.bind("typeLoc")));
982+
983+
auto MyMatcher = compoundStmt(
984+
forEachDescendant(typeLoc(loc(qualType(hasDeclaration(
985+
anyOf(typedefDecl(hasName(TypeName)),
986+
typeAliasDecl(hasName(TypeName)))))))
987+
.bind("typeLoc")));
981988
auto MatcherScope = DpctGlobalInfo::findAncestor<CompoundStmt>(TD);
982989
if (!MatcherScope)
983990
return;
@@ -1033,6 +1040,7 @@ void CubRule::processCubTypeDefOrUsing(const TypedefNameDecl *TD) {
10331040
}
10341041
}
10351042
}
1043+
10361044
if (DeleteFlag) {
10371045
emplaceTransformation(new ReplaceDecl(TD, ""));
10381046
} else {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// UNSUPPORTED: cuda-8.0, cuda-9.0, cuda-9.1, cuda-9.2, cuda-10.0, cuda-10.1, cuda-10.2
2+
// UNSUPPORTED: v8.0, v9.0, v9.1, v9.2, v10.0, v10.1, v10.2
3+
// RUN: dpct --format-range=none -in-root %S -out-root %T/type/fix_alias_bug %S/fix_alias_bug.cu --cuda-include-path="%cuda-path/include" -- -std=c++14 -x cuda --cuda-host-only
4+
// RUN: FileCheck --input-file %T/type/fix_alias_bug/fix_alias_bug.dp.cpp %s
5+
// RUN: %if build_lit %{icpx -c -fsycl %T/type/fix_alias_bug/fix_alias_bug.dp.cpp -o %T/type/fix_alias_bug/fix_alias_bug.dp.o %}
6+
7+
#include <cub/cub.cuh>
8+
#include <cuda.h>
9+
template <bool> struct warp_reduce;
10+
11+
template <> struct warp_reduce<true> {
12+
template <typename T, typename reducer_t>
13+
inline T operator()(const T &value_, bool all, const reducer_t &r) {
14+
// CHECK: using warp_reduce_t = sycl::sub_group;
15+
16+
using warp_reduce_t = cub::WarpReduce<T, 10>;
17+
18+
typename warp_reduce_t::TempStorage dummy_storage;
19+
// CHECK: warp_reduce_t warp_reduce(sycl::ext::oneapi::this_work_item::get_sub_group());
20+
21+
warp_reduce_t warp_reduce(dummy_storage);
22+
}
23+
};
24+
25+
template <> struct warp_reduce<false> {
26+
template <typename T, typename reducer_t>
27+
inline T operator()(const T &value_, bool all, const reducer_t &r) {
28+
// CHECK: using warp_reduce_t = sycl::sub_group;
29+
30+
using warp_reduce_t = cub::WarpReduce<T, 10>;
31+
32+
typename warp_reduce_t::TempStorage dummy_storage;
33+
// CHECK: warp_reduce_t warp_reduce(sycl::ext::oneapi::this_work_item::get_sub_group());
34+
warp_reduce_t warp_reduce(dummy_storage);
35+
}
36+
};
37+
int main() {
38+
int a, b;
39+
warp_reduce<true>()(a, true, b);
40+
}

0 commit comments

Comments
 (0)