texture_binder.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <kfusion/safe_call.hpp>
5 
6 namespace kfusion
7 {
8  namespace cuda
9  {
11  {
12  public:
13  template<class T, enum cudaTextureReadMode readMode>
14  TextureBinder(const DeviceArray2D<T>& arr, const struct texture<T, 2, readMode>& tex) : texref(&tex)
15  {
16  cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
17  cudaSafeCall( cudaBindTexture2D(0, tex, arr.ptr(), desc, arr.cols(), arr.rows(), arr.step()) );
18  }
19 
20  template<class T, enum cudaTextureReadMode readMode>
21  TextureBinder(const DeviceArray<T>& arr, const struct texture<T, 1, readMode> &tex) : texref(&tex)
22  {
23  cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
24  cudaSafeCall( cudaBindTexture(0, tex, arr.ptr(), desc, arr.sizeBytes()) );
25  }
26 
27  template<class T, enum cudaTextureReadMode readMode>
28  TextureBinder(const PtrStepSz<T>& arr, const struct texture<T, 2, readMode>& tex) : texref(&tex)
29  {
30  cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
31  cudaSafeCall( cudaBindTexture2D(0, tex, arr.data, desc, arr.cols, arr.rows, arr.step) );
32  }
33 
34  template<class A, class T, enum cudaTextureReadMode readMode>
35  TextureBinder(const A& arr, const struct texture<T, 2, readMode>& tex, const cudaChannelFormatDesc& desc) : texref(&tex)
36  {
37  cudaSafeCall( cudaBindTexture2D(0, tex, arr.data, desc, arr.cols, arr.rows, arr.step) );
38  }
39 
40  template<class T, enum cudaTextureReadMode readMode>
41  TextureBinder(const PtrSz<T>& arr, const struct texture<T, 1, readMode> &tex) : texref(&tex)
42  {
43  cudaChannelFormatDesc desc = cudaCreateChannelDesc<T>();
44  cudaSafeCall( cudaBindTexture(0, tex, arr.data, desc, arr.size * arr.elemSize()) );
45  }
46 
48  {
49  cudaSafeCall( cudaUnbindTexture(texref) );
50  }
51  private:
52  const struct textureReference *texref;
53  };
54  }
55 
56  namespace device
57  {
59  }
60 }
size_t step
stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! ...
TextureBinder(const DeviceArray< T > &arr, const struct texture< T, 1, readMode > &tex)
size_t step() const
Returns stride between two consecutive rows in bytes for internal buffer. Step is stored always and e...
T * ptr(int y=0)
Returns pointer to given row in internal buffer.
int rows() const
Returns number of rows.
TextureBinder(const A &arr, const struct texture< T, 2, readMode > &tex, const cudaChannelFormatDesc &desc)
#define cudaSafeCall(expr)
Definition: safe_call.hpp:16
T * ptr()
Returns pointer for internal buffer in GPU memory.
DeviceArray2D class
DeviceArray class
TextureBinder(const PtrStepSz< T > &arr, const struct texture< T, 2, readMode > &tex)
TextureBinder(const PtrSz< T > &arr, const struct texture< T, 1, readMode > &tex)
__kf_hdevice__ size_t elemSize() const
Utility.
Definition: capture.hpp:8
const struct textureReference * texref
int cols() const
Returns number of elements in each row.
TextureBinder(const DeviceArray2D< T > &arr, const struct texture< T, 2, readMode > &tex)


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:09