1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
8 #include "mvs/gpu_mat_prng.h"
14 __global__ void InitRandomStateKernel(GpuMat<curandState> output) {
15 const size_t row = blockIdx.y * blockDim.y + threadIdx.y;
16 const size_t col = blockIdx.x * blockDim.x + threadIdx.x;
18 const size_t uniqueBlockIndex = blockIdx.y * gridDim.x + blockIdx.x;
19 const size_t id = uniqueBlockIndex * blockDim.y * blockDim.x +
20 threadIdx.y * blockDim.x + threadIdx.x;
22 // Each thread gets same seed, a different sequence number, no offset.
23 if (col < output.GetWidth() && row < output.GetHeight()) {
24 curand_init(id, 0, 0, &output.GetRef(row, col));
30 GpuMatPRNG::GpuMatPRNG(const int width, const int height)
31 : GpuMat(width, height) {
32 InitRandomStateKernel<<<gridSize_, blockSize_>>>(*this);