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

Adding some functions back in that seem to be a copy/paste error #1373

Merged
Merged
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
37 changes: 37 additions & 0 deletions cpp/include/raft/util/cuda_dev_essentials.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,41 @@ DI int laneId()
return id;
}

/** Device function to apply the input lambda across threads in the grid */
template <int ItemsPerThread, typename L>
DI void forEach(int num, L lambda)
{
int idx = (blockDim.x * blockIdx.x) + threadIdx.x;
const int numThreads = blockDim.x * gridDim.x;
#pragma unroll
for (int itr = 0; itr < ItemsPerThread; ++itr, idx += numThreads) {
if (idx < num) lambda(idx, itr);
}
}

/** number of threads per warp */
static const int WarpSize = 32;

/** get the laneId of the current thread */
DI int laneId()
{
int id;
asm("mov.s32 %0, %%laneid;" : "=r"(id));
return id;
}

/**
* @brief Swap two values
* @tparam T the datatype of the values
* @param a first input
* @param b second input
*/
template <typename T>
HDI void swapVals(T& a, T& b)
{
T tmp = a;
a = b;
b = tmp;
}

} // namespace raft