-
Notifications
You must be signed in to change notification settings - Fork 42
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
rocRAND: random numbers inside kernel function #54
Comments
Hi, for this you can use the rocRAND device API. For example: #include <hip/hip_runtime.h>
#include <rocrand/rocrand_kernel.h>
__global__
void test() {
uint tid = blockDim.x * blockIdx.x + threadIdx.x;
rocrand_state_xorwow state;
rocrand_init(123, tid, 0, &state);
for (int i = 0; i < 3; ++i) {
const auto value = rocrand(&state);
printf("thread %d, index %u: %u\n", tid, i, value);
}
}
int main() {
test<<<dim3(1), dim3(32)>>>();
hipDeviceSynchronize();
} After compiling as follows (assuming you have rocRAND installed in its default installation location):
When executed, it prints something like
You can find the other rocrand device functions in the rocRAND API docs, under 'Device Functions'. On a side note, if you're using modulo for integers, beware of modulo bias: The first |
Thank you! |
I'm completely new to GPGPU. I was looking at the rocRAND documentation and I have no idea how to use it. Is there any plans to add some examples in the rocRAND API docs, just like your example? |
Yep agreed, those those should be expanded a little. |
Tracking a) new example request and b) rocRAND documentation improvements internally. |
I'm doing a project using ROCm and I'm needing to get some random numbers inside a kernel function.
Really simple example:
How can I create this function?
Right now, just as a placeholder I'm creating a big vector on cpu and write every single position with a random number that comes from C rand() function. Then I hipMemcpy it from host to the device. This vector is really big and I'm basically wasting a lot of my vram just to hold this vector.
The text was updated successfully, but these errors were encountered: