Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions clang/lib/DPCT/AnalysisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7512,11 +7512,32 @@ void FreeQueriesInfo::printImmediateText(llvm::raw_ostream &OS, const Node *S,
return Info->printImmediateText(OS, S->getBeginLoc(), K);
}

#ifdef DPCT_DEBUG_BUILD
llvm::errs() << "Can not get FreeQueriesInfo for this FunctionDecl\n";
assert(0);
#endif // DPCT_DEBUG_BUILD

auto DFI = DeviceFunctionDecl::LinkRedecls(FD);
if (!DFI)
return;
auto Index = DpctGlobalInfo::getCudaKernelDimDFIIndexThenInc();
DpctGlobalInfo::insertCudaKernelDimDFIMap(Index, DFI);
switch (K) {
case FreeQueriesKind::NdItem: {
OS << MapNames::getClNamespace()
<< "ext::oneapi::this_work_item::get_nd_item<{{NEEDREPLACEG" +
std::to_string(Index) + "}}>()";
break;
}
case FreeQueriesKind::Group: {
OS << MapNames::getClNamespace()
<< "ext::oneapi::this_work_item::get_work_group<{{NEEDREPLACEG" +
std::to_string(Index) + "}}>()";
break;
}
case FreeQueriesKind::SubGroup: {
OS << MapNames::getClNamespace()
<< "ext::oneapi::this_work_item::get_sub_group()";
break;
}
default:
llvm_unreachable("Unexpected FreeQueriesKind");
}
Comment thread
zhiweij1 marked this conversation as resolved.
Outdated
} else {
if (auto DFI = DeviceFunctionDecl::LinkRedecls(FD))
DFI->setItem();
Expand Down
13 changes: 13 additions & 0 deletions clang/test/dpct/with_this_nd_item.cu
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,16 @@ int main() {

test3<<<32,32>>>();
}

struct TEST4 {
// CHECK: TEST4(int a) : thread_idx(sycl::ext::oneapi::this_work_item::get_nd_item<1>().get_local_id(0)) {}
__device__ TEST4(int a) : thread_idx(threadIdx.x) {}
int thread_idx;
};

// CHECK: int test5(const int ct, int numLane = 0) {
// CHECK-NEXT: if (!numLane) numLane = sycl::ext::oneapi::this_work_item::get_sub_group().get_local_range().get(0);
__device__ int test5(const int ct, const int numLane = warpSize) {
int r = ct * numLane;
return r;
}