@@ -17,18 +17,24 @@ using namespace std;
1717
1818device_prop_t::device_prop_t ( )
1919{
20+ int currentDevice;
2021 cudaError_t err;
2122
23+ err = cudaGetDevice ( ¤tDevice );
24+ POP_CUDA_FATAL_TEST ( err, " Cannot get the current CUDA device" );
25+
2226 err = cudaGetDeviceCount ( &_num_devices );
2327 POP_CUDA_FATAL_TEST ( err, " Cannot count devices" );
2428
29+ _properties.resize (_num_devices);
30+
2531 for ( int n=0 ; n<_num_devices; n++ ) {
26- cudaDeviceProp* p;
27- _properties.push_back ( p = new cudaDeviceProp );
28- err = cudaGetDeviceProperties ( p, n );
32+ _properties[n] = new cudaDeviceProp;
33+ err = cudaGetDeviceProperties ( _properties[n], n );
2934 POP_CUDA_FATAL_TEST ( err, " Cannot get properties for a device" );
3035 }
31- err = cudaSetDevice ( 0 );
36+
37+ err = cudaSetDevice ( currentDevice );
3238 POP_CUDA_FATAL_TEST ( err, " Cannot set device 0" );
3339}
3440
@@ -86,5 +92,221 @@ device_prop_t::~device_prop_t( )
8692 }
8793}
8894
95+ bool device_prop_t::checkLimit_2DtexLinear ( int & width, int & height, bool printWarn ) const
96+ {
97+ bool returnSuccess = true ;
98+ int currentDevice;
99+ cudaError_t err;
100+
101+ err = cudaGetDevice ( ¤tDevice );
102+ if ( err != cudaSuccess )
103+ {
104+ POP_CUDA_WARN ( err, " Cannot get current CUDA device" );
105+ return true ;
106+ }
107+
108+ if ( currentDevice >= _properties.size () )
109+ {
110+ POP_WARN ( " CUDA device was not registered at program start" );
111+ return true ;
112+ }
113+
114+ const cudaDeviceProp* ptr = _properties[currentDevice];
115+ if ( width > ptr->maxTexture2DLayered [0 ] )
116+ {
117+ if ( printWarn )
118+ {
119+ std::cerr << __FILE__ << " :" << __LINE__
120+ << " : CUDA device " << currentDevice << std::endl
121+ << " does not support 2D linear textures " << width
122+ << " pixels wide." << endl;
123+ }
124+ width = ptr->maxTexture2DLayered [0 ];
125+ returnSuccess = false ;
126+ }
127+ if ( height > ptr->maxTexture2DLayered [1 ] )
128+ {
129+ if ( returnSuccess && printWarn )
130+ {
131+ std::cerr << __FILE__ << " :" << __LINE__
132+ << " : CUDA device " << currentDevice << std::endl
133+ << " does not support 2D linear textures " << height
134+ << " pixels high." << endl;
135+ }
136+ height = ptr->maxTexture2DLayered [1 ];
137+ returnSuccess = false ;
138+ }
139+
140+ return returnSuccess;
141+ }
142+
143+ bool device_prop_t::checkLimit_2DtexArray ( int & width, int & height, bool printWarn ) const
144+ {
145+ bool returnSuccess = true ;
146+ int currentDevice;
147+ cudaError_t err;
148+
149+ err = cudaGetDevice ( ¤tDevice );
150+ if ( err != cudaSuccess )
151+ {
152+ POP_CUDA_WARN ( err, " Cannot get current CUDA device" );
153+ return true ;
154+ }
155+
156+ if ( currentDevice >= _properties.size () )
157+ {
158+ POP_WARN ( " CUDA device was not registered at program start" );
159+ return true ;
160+ }
161+
162+ const cudaDeviceProp* ptr = _properties[currentDevice];
163+ if ( width > ptr->maxTexture2D [0 ] )
164+ {
165+ if ( printWarn )
166+ {
167+ std::cerr << __FILE__ << " :" << __LINE__
168+ << " : CUDA device " << currentDevice << std::endl
169+ << " does not support 2D array textures " << width
170+ << " pixels wide." << endl;
171+ }
172+ width = ptr->maxTexture2D [0 ];
173+ returnSuccess = false ;
174+ }
175+ if ( height > ptr->maxTexture2D [1 ] )
176+ {
177+ if ( returnSuccess && printWarn )
178+ {
179+ std::cerr << __FILE__ << " :" << __LINE__
180+ << " : CUDA device " << currentDevice << std::endl
181+ << " does not support 2D array textures " << height
182+ << " pixels high." << endl;
183+ }
184+ height = ptr->maxTexture2D [1 ];
185+ returnSuccess = false ;
186+ }
187+
188+ return returnSuccess;
189+ }
190+
191+ bool device_prop_t::checkLimit_2DtexLayered ( int & width, int & height, int & layers, bool printWarn ) const
192+ {
193+ bool returnSuccess = true ;
194+ int currentDevice;
195+ cudaError_t err;
196+
197+ err = cudaGetDevice ( ¤tDevice );
198+ if ( err != cudaSuccess )
199+ {
200+ POP_CUDA_WARN ( err, " Cannot get current CUDA device" );
201+ return true ;
202+ }
203+
204+ if ( currentDevice >= _properties.size () )
205+ {
206+ POP_WARN ( " CUDA device was not registered at program start" );
207+ return true ;
208+ }
209+
210+ const cudaDeviceProp* ptr = _properties[currentDevice];
211+ if ( width > ptr->maxTexture2DLayered [0 ] )
212+ {
213+ if ( printWarn )
214+ {
215+ std::cerr << __FILE__ << " :" << __LINE__
216+ << " : CUDA device " << currentDevice << std::endl
217+ << " does not support 2D array textures " << width
218+ << " pixels wide." << endl;
219+ }
220+ width = ptr->maxTexture2DLayered [0 ];
221+ returnSuccess = false ;
222+ }
223+ if ( height > ptr->maxTexture2DLayered [1 ] )
224+ {
225+ if ( returnSuccess && printWarn )
226+ {
227+ std::cerr << __FILE__ << " :" << __LINE__
228+ << " : CUDA device " << currentDevice << std::endl
229+ << " does not support 2D array textures " << height
230+ << " pixels high." << endl;
231+ }
232+ height = ptr->maxTexture2DLayered [1 ];
233+ returnSuccess = false ;
234+ }
235+ if ( layers > ptr->maxTexture2DLayered [2 ] )
236+ {
237+ if ( returnSuccess && printWarn )
238+ {
239+ std::cerr << __FILE__ << " :" << __LINE__
240+ << " : CUDA device " << currentDevice << std::endl
241+ << " does not support 2D array textures " << layers
242+ << " pixels deep." << endl;
243+ }
244+ layers = ptr->maxTexture2DLayered [2 ];
245+ returnSuccess = false ;
246+ }
247+
248+ return returnSuccess;
249+ }
250+
251+ bool device_prop_t::checkLimit_2DsurfLayered ( int & width, int & height, int & layers, bool printWarn ) const
252+ {
253+ bool returnSuccess = true ;
254+ int currentDevice;
255+ cudaError_t err;
256+
257+ err = cudaGetDevice ( ¤tDevice );
258+ if ( err != cudaSuccess )
259+ {
260+ POP_CUDA_WARN ( err, " Cannot get current CUDA device" );
261+ return true ;
262+ }
263+
264+ if ( currentDevice >= _properties.size () )
265+ {
266+ POP_WARN ( " CUDA device was not registered at program start" );
267+ return true ;
268+ }
269+
270+ const cudaDeviceProp* ptr = _properties[currentDevice];
271+ if ( width > ptr->maxSurface2DLayered [0 ] )
272+ {
273+ if ( printWarn )
274+ {
275+ std::cerr << __FILE__ << " :" << __LINE__
276+ << " : CUDA device " << currentDevice << std::endl
277+ << " does not support layered 2D surfaces " << width
278+ << " bytes wide." << endl;
279+ }
280+ width = ptr->maxSurface2DLayered [0 ];
281+ returnSuccess = false ;
282+ }
283+ if ( height > ptr->maxSurface2DLayered [1 ] )
284+ {
285+ if ( returnSuccess && printWarn )
286+ {
287+ std::cerr << __FILE__ << " :" << __LINE__
288+ << " : CUDA device " << currentDevice << std::endl
289+ << " does not support layered 2D surfaces " << height
290+ << " pixels high." << endl;
291+ }
292+ height = ptr->maxSurface2DLayered [1 ];
293+ returnSuccess = false ;
294+ }
295+ if ( layers > ptr->maxSurface2DLayered [2 ] )
296+ {
297+ if ( returnSuccess && printWarn )
298+ {
299+ std::cerr << __FILE__ << " :" << __LINE__
300+ << " : CUDA device " << currentDevice << std::endl
301+ << " does not support layered 2D surfaces " << layers
302+ << " pixels deep." << endl;
303+ }
304+ layers = ptr->maxSurface2DLayered [2 ];
305+ returnSuccess = false ;
306+ }
307+
308+ return returnSuccess;
309+ }
310+
89311}}
90312
0 commit comments