Skip to content

Commit

Permalink
Adding some functions back in that seem to be a copy/paste error (#1373)
Browse files Browse the repository at this point in the history
Authors:
  - Corey J. Nolet (https://github.com/cjnolet)

Approvers:
  - Ben Frederickson (https://github.com/benfred)

URL: #1373
  • Loading branch information
cjnolet authored Mar 24, 2023
1 parent 9389108 commit f4c7f1f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 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,30 @@ 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);
}
}

/**
* @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

0 comments on commit f4c7f1f

Please sign in to comment.