ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cuda_rotate.h
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 #pragma once
9 
10 #include <cuda_runtime.h>
11 
12 namespace colmap {
13 namespace mvs {
14 
15 // Rotate the input matrix by 90 degrees in counter-clockwise direction.
16 template <typename T>
17 void CudaRotate(const T* input,
18  T* output,
19  const int width,
20  const int height,
21  const int pitch_input,
22  const int pitch_output);
23 
25 // Implementation
27 
28 #ifdef __CUDACC__
29 
30 #define TILE_DIM_ROTATE 32
31 
32 namespace internal {
33 
34 template <typename T>
35 __global__ void CudaRotateKernel(T* output_data,
36  const T* input_data,
37  const int width,
38  const int height,
39  const int input_pitch,
40  const int output_pitch) {
41  int input_x = blockDim.x * blockIdx.x + threadIdx.x;
42  int input_y = blockDim.y * blockIdx.y + threadIdx.y;
43 
44  if (input_x >= width || input_y >= height) {
45  return;
46  }
47 
48  int output_x = input_y;
49  int output_y = width - 1 - input_x;
50 
51  *((T*)((char*)output_data + output_y * output_pitch) + output_x) =
52  *((T*)((char*)input_data + input_y * input_pitch) + input_x);
53 }
54 
55 } // namespace internal
56 
57 template <typename T>
58 void CudaRotate(const T* input,
59  T* output,
60  const int width,
61  const int height,
62  const int pitch_input,
63  const int pitch_output) {
64  dim3 block_dim(TILE_DIM_ROTATE, 1, 1);
65  dim3 grid_dim;
66  grid_dim.x = (width - 1) / TILE_DIM_ROTATE + 1;
67  grid_dim.y = height;
68 
69  internal::CudaRotateKernel<<<grid_dim, block_dim>>>(
70  output, input, width, height, pitch_input, pitch_output);
71 }
72 
73 #undef TILE_DIM_ROTATE
74 
75 #endif // __CUDACC__
76 
77 } // namespace mvs
78 } // namespace colmap
int width
int height
void CudaRotate(const T *input, T *output, const int width, const int height, const int pitch_input, const int pitch_output)