ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
gpu_mat_prng.cu
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "mvs/gpu_mat_prng.h"
9 
10 namespace colmap {
11 namespace mvs {
12 namespace {
13 
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;
17 
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;
21 
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));
25  }
26 }
27 
28 } // namespace
29 
30 GpuMatPRNG::GpuMatPRNG(const int width, const int height)
31  : GpuMat(width, height) {
32  InitRandomStateKernel<<<gridSize_, blockSize_>>>(*this);
33 }
34 
35 } // namespace mvs
36 } // namespace colmap