OnlineBodySchemaAdaptation  2.0
Cuda_Gl.cu
1 /*
2  * Copyright: (C) 2017 VisLab, Institute for Systems and Robotics,
3  * Instituto Superior Técnico, Universidade de Lisboa, Lisbon, Portugal
4  * Author: Pedro Vicente <pvicente@isr.tecnico.ulisboa.pt>
5  * CopyPolicy: Released under the terms of the GNU GPL v3.0.
6  *
7  */
8 
9 #include <helper_cuda.h>
10 
11 
12 texture<float4, 2, cudaReadModeElementType> inTex;
13 
14 __global__ void CuDeviceArrayCopyFromTexture( float3* dst, int dstStep, int width, int height )
15 {
16  int x = blockIdx.x * blockDim.x + threadIdx.x;
17  int y = blockIdx.y * blockDim.y + threadIdx.y;
18 
19  if ( x > width || y > height ) return;
20 
21  float4 res = tex2D(inTex, x, y);
22  float3* row_y = (float3*)((char*)dst + y * dstStep);
23  row_y[x] = make_float3(res.x, res.y, res.z);
24 }
25 // round up n/m
26 inline int iDivUp(int n, int m)
27 {
28  return (n + m - 1) / m;
29 }
30 
31 extern "C" void DeviceArrayCopyFromTexture( float3* dst, int dstStep, int width, int height )
32 {
33  dim3 threads( 64, 1 );
34  dim3 grid = dim3( iDivUp( width, threads.x ), height/threads.y );
35  CuDeviceArrayCopyFromTexture <<< grid, threads >>> ( dst, dstStep, width, height );
36 }
37 
38 extern "C" void BindToTexture( cudaArray *cuArr )
39 {
40  checkCudaErrors( cudaBindTextureToArray( inTex, cuArr ) );
41 }