Go to the documentation of this file.
42 #define DECL_TEXTURE_WRAPPER_CLASS(NAME, TYPE) \
43 texture<TYPE> NAME ## _tex; \
44 struct NAME ## _texture \
46 typedef TYPE value_type; \
47 typedef value_type reference; \
48 typedef const value_type* pointer; \
49 typedef uint32 difference_type; \
50 typedef std::random_access_iterator_tag iterator_category; \
52 NVBIO_FORCEINLINE NVBIO_DEVICE TYPE operator[] (const uint32 i) const; \
54 static NVBIO_FORCEINLINE NVBIO_HOST void bind(const uint32* NAME, uint32 size); \
56 static NVBIO_FORCEINLINE NVBIO_HOST void unbind(); \
59 #define INST_TEXTURE_WRAPPER_CLASS(NAME, TYPE) \
60 NVBIO_FORCEINLINE NVBIO_DEVICE TYPE NAME ## _texture::operator[] (const uint32 i) const \
62 return tex1Dfetch( NAME ## _tex, i ); \
64 NVBIO_FORCEINLINE NVBIO_HOST void NAME ## _texture::bind(const uint32* ptr, uint32 size) \
69 cudaChannelFormatDesc channel_desc = cudaCreateChannelDesc<TYPE>(); \
70 NAME ## _tex.normalized = false; \
71 NAME ## _tex.filterMode = cudaFilterModePoint; \
72 cudaBindTexture( 0, &NAME ## _tex, ptr, &channel_desc, size*sizeof(uint32) ); \
73 nvbio::cuda::check_error("NAME ## texture::bind"); \
75 NVBIO_FORCEINLINE NVBIO_HOST void NAME ## _texture::unbind() \
77 cudaUnbindTexture( &NAME ## _tex ); \
81 #define DECL_TEXTURE_SELECTOR_WRAPPER_CLASS(NAME, TYPE) \
82 texture<TYPE> NAME ## _tex1; \
83 texture<TYPE> NAME ## _tex2; \
84 struct NAME ## _texture_selector \
86 typedef TYPE value_type; \
87 typedef value_type reference; \
88 typedef const value_type* pointer; \
89 typedef uint32 difference_type; \
90 typedef std::random_access_iterator_tag iterator_category; \
92 NVBIO_FORCEINLINE NVBIO_HOST_DEVICE NAME ## _texture_selector(const uint32 sel) : m_sel(sel) {} \
94 NVBIO_FORCEINLINE NVBIO_DEVICE TYPE operator[] (const uint32 i) const; \
96 static NVBIO_FORCEINLINE NVBIO_HOST void bind(const uint32* ptr1, const uint32* ptr2, uint32 size); \
98 static NVBIO_FORCEINLINE NVBIO_HOST void unbind(); \
103 #define INST_TEXTURE_SELECTOR_WRAPPER_CLASS(NAME, TYPE) \
104 NVBIO_FORCEINLINE NVBIO_DEVICE TYPE NAME ## _texture_selector::operator[] (const uint32 i) const \
107 return tex1Dfetch( NAME ## _tex2, i ); \
109 return tex1Dfetch( NAME ## _tex1, i ); \
111 NVBIO_FORCEINLINE NVBIO_HOST void NAME ## _texture_selector::bind(const uint32* ptr1, const uint32* ptr2, uint32 size) \
113 cudaChannelFormatDesc channel_desc = cudaCreateChannelDesc<TYPE>(); \
114 NAME ## _tex1.normalized = false; \
115 NAME ## _tex1.filterMode = cudaFilterModePoint; \
116 NAME ## _tex2.normalized = false; \
117 NAME ## _tex2.filterMode = cudaFilterModePoint; \
118 if (ptr1) cudaBindTexture( 0, &NAME ## _tex1, ptr1, &channel_desc, size*sizeof(uint32) ); \
119 if (ptr2) cudaBindTexture( 0, &NAME ## _tex2, ptr2, &channel_desc, size*sizeof(uint32) ); \
120 nvbio::cuda::check_error("NAME ## texture_selector::bind"); \
122 NVBIO_FORCEINLINE NVBIO_HOST void NAME ## _texture_selector::unbind() \
124 cudaUnbindTexture( &NAME ## _tex1 ); \
125 cudaUnbindTexture( &NAME ## _tex2 ); \
129 #define TEXTURE_WRAPPER_LOG_WIDTH 14
130 #define TEXTURE_WRAPPER_WIDTH 16384
132 #define DECL_TEXTURE_WRAPPER_CLASS_2D(NAME, TYPE) \
133 texture<TYPE,2> NAME ## _tex_2d; \
134 struct NAME ## _texture_2d \
136 typedef TYPE value_type; \
137 typedef value_type reference; \
138 typedef const value_type* pointer; \
139 typedef uint32 difference_type; \
140 typedef std::random_access_iterator_tag iterator_category; \
142 NVBIO_FORCEINLINE NVBIO_DEVICE TYPE operator[] (const uint32 i) const; \
144 static NVBIO_FORCEINLINE NVBIO_HOST void bind(const uint32* NAME, uint32 size); \
146 static NVBIO_FORCEINLINE NVBIO_HOST void unbind(); \
149 #define INST_TEXTURE_WRAPPER_CLASS_2D(NAME, TYPE) \
150 NVBIO_FORCEINLINE NVBIO_DEVICE TYPE NAME ## _texture_2d::operator[] (const uint32 i) const \
152 return tex2D( NAME ## _tex_2d, i&(TEXTURE_WRAPPER_WIDTH-1u), i >> TEXTURE_WRAPPER_LOG_WIDTH ); \
154 NVBIO_FORCEINLINE NVBIO_HOST void NAME ## _texture_2d::bind(const uint32* ptr, uint32 size) \
159 cudaChannelFormatDesc channel_desc = cudaCreateChannelDesc<TYPE>(); \
160 NAME ## _tex_2d.normalized = false; \
161 NAME ## _tex_2d.filterMode = cudaFilterModePoint; \
163 const uint32 comps = sizeof(TYPE)/sizeof(uint32); \
164 const uint32 w = TEXTURE_WRAPPER_WIDTH; \
165 const uint32 h = (size/comps + w-1) / w; \
167 cudaBindTexture2D( 0, &NAME ## _tex_2d, ptr, &channel_desc, w, h, w*sizeof(TYPE) ); \
168 nvbio::cuda::check_error("NAME ## texture_2d::bind"); \
170 NVBIO_FORCEINLINE NVBIO_HOST void NAME ## _texture_2d::unbind() \
172 cudaUnbindTexture( &NAME ## _tex_2d ); \
175 #define DECL_TEXTURE_SELECTOR_WRAPPER_CLASS_2D(NAME, TYPE) \
176 texture<TYPE,2> NAME ## _tex1_2d; \
177 texture<TYPE,2> NAME ## _tex2_2d; \
178 struct NAME ## _texture_selector_2d \
180 typedef TYPE value_type; \
181 typedef value_type reference; \
182 typedef const value_type* pointer; \
183 typedef uint32 difference_type; \
184 typedef std::random_access_iterator_tag iterator_category; \
186 NVBIO_FORCEINLINE NVBIO_HOST_DEVICE NAME ## _texture_selector_2d(const uint32 sel) : m_sel(sel) {} \
188 NVBIO_FORCEINLINE NVBIO_DEVICE TYPE operator[] (const uint32 i) const; \
190 static NVBIO_FORCEINLINE NVBIO_HOST void bind(const uint32* ptr1, const uint32* ptr2, uint32 size); \
192 static NVBIO_FORCEINLINE NVBIO_HOST void unbind(); \
197 #define INST_TEXTURE_SELECTOR_WRAPPER_CLASS_2D(NAME, TYPE) \
198 NVBIO_FORCEINLINE NVBIO_DEVICE TYPE NAME ## _texture_selector_2d::operator[] (const uint32 i) const \
201 return tex2D( NAME ## _tex2_2d, i&(TEXTURE_WRAPPER_WIDTH-1u), i >> TEXTURE_WRAPPER_LOG_WIDTH ); \
203 return tex2D( NAME ## _tex1_2d, i&(TEXTURE_WRAPPER_WIDTH-1u), i >> TEXTURE_WRAPPER_LOG_WIDTH ); \
205 NVBIO_FORCEINLINE NVBIO_HOST void NAME ## _texture_selector_2d::bind(const uint32* ptr1, const uint32* ptr2, uint32 size) \
207 cudaChannelFormatDesc channel_desc = cudaCreateChannelDesc<TYPE>(); \
208 NAME ## _tex1_2d.normalized = false; \
209 NAME ## _tex1_2d.filterMode = cudaFilterModePoint; \
210 NAME ## _tex2_2d.normalized = false; \
211 NAME ## _tex2_2d.filterMode = cudaFilterModePoint; \
213 const uint32 comps = sizeof(TYPE)/sizeof(uint32); \
214 const uint32 w = TEXTURE_WRAPPER_WIDTH; \
215 const uint32 h = (size/comps + w-1) / w; \
217 if (ptr1) cudaBindTexture2D( 0, &NAME ## _tex1_2d, ptr1, &channel_desc, w, h, w*sizeof(TYPE) ); \
218 if (ptr2) cudaBindTexture2D( 0, &NAME ## _tex2_2d, ptr2, &channel_desc, w, h, w*sizeof(TYPE) ); \
219 nvbio::cuda::check_error("NAME ## texture_selector_2d::bind"); \
221 NVBIO_FORCEINLINE NVBIO_HOST void NAME ## _texture_selector_2d::unbind() \
223 cudaUnbindTexture( &NAME ## _tex1_2d ); \
224 cudaUnbindTexture( &NAME ## _tex2_2d ); \
229 #define DECL_TEXTURE_WRAPPER_CLASS(NAME, TYPE) \
230 struct NAME ## _texture \
232 static NVBIO_FORCEINLINE NVBIO_HOST void bind(const uint32* NAME, uint32 size) {} \
234 static NVBIO_FORCEINLINE NVBIO_HOST void unbind() {} \
237 #define INST_TEXTURE_WRAPPER_CLASS(NAME, TYPE)
239 #define DECL_TEXTURE_SELECTOR_WRAPPER_CLASS(NAME, TYPE) \
240 struct NAME ## _texture_selector \
242 static NVBIO_FORCEINLINE NVBIO_HOST void bind(const uint32* NAME, uint32 size) {} \
244 static NVBIO_FORCEINLINE NVBIO_HOST void unbind() {} \
247 #define INST_TEXTURE_SELECTOR_WRAPPER_CLASS(NAME, TYPE)
249 #define DECL_TEXTURE_WRAPPER_CLASS_2D(NAME, TYPE) \
250 struct NAME ## _texture_2d \
252 static NVBIO_FORCEINLINE NVBIO_HOST void bind(const uint32* NAME, uint32 size) {} \
254 static NVBIO_FORCEINLINE NVBIO_HOST void unbind() {} \
257 #define INST_TEXTURE_WRAPPER_CLASS_2D(NAME, TYPE)
259 #define DECL_TEXTURE_SELECTOR_WRAPPER_CLASS_2D(NAME, TYPE) \
260 struct NAME ## _texture_selector_2d \
262 static NVBIO_FORCEINLINE NVBIO_HOST void bind(const uint32* NAME, uint32 size) {} \
264 static NVBIO_FORCEINLINE NVBIO_HOST void unbind() {} \
267 #define INST_TEXTURE_SELECTOR_WRAPPER_CLASS_2D(NAME, TYPE)