Point Cloud Library (PCL)
1.11.0
Main Page
Related Pages
Modules
Namespaces
Classes
common
include
pcl
cuda
cutil.h
1
/*
2
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
3
*
4
* Please refer to the NVIDIA end user license agreement (EULA) associated
5
* with this source code for terms and conditions that govern your use of
6
* this software. Any use, reproduction, disclosure, or distribution of
7
* this software and related documentation outside the terms of the EULA
8
* is strictly prohibited.
9
*
10
*/
11
12
/*
13
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
14
*
15
* Please refer to the NVIDIA end user license agreement (EULA) associated
16
* with this source code for terms and conditions that govern your use of
17
* this software. Any use, reproduction, disclosure, or distribution of
18
* this software and related documentation outside the terms of the EULA
19
* is strictly prohibited.
20
*
21
*/
22
23
24
/* CUda UTility Library */
25
26
#pragma once
27
28
#ifdef _WIN32
29
# pragma warning( disable : 4996 ) // disable deprecated warning
30
#endif
31
32
#include <stdio.h>
33
#include <stdlib.h>
34
35
#ifdef __cplusplus
36
extern
"C"
{
37
#endif
38
39
// helper typedefs for building DLL
40
#ifdef _WIN32
41
# ifdef BUILD_DLL
42
# define DLL_MAPPING __declspec(dllexport)
43
# else
44
# define DLL_MAPPING __declspec(dllimport)
45
# endif
46
#else
47
# define DLL_MAPPING
48
#endif
49
50
#ifdef _WIN32
51
#define CUTIL_API __stdcall
52
#else
53
#define CUTIL_API
54
#endif
55
56
////////////////////////////////////////////////////////////////////////////
57
//! CUT bool type
58
////////////////////////////////////////////////////////////////////////////
59
enum
CUTBoolean
60
{
61
CUTFalse = 0,
62
CUTTrue = 1
63
};
64
65
////////////////////////////////////////////////////////////////////////////
66
//! Deallocate memory allocated within Cutil
67
//! @param pointer to memory
68
////////////////////////////////////////////////////////////////////////////
69
DLL_MAPPING
70
void
CUTIL_API
71
cutFree(
void
* ptr);
72
73
////////////////////////////////////////////////////////////////////////////
74
//! Helper for bank conflict checking (should only be used with the
75
//! CUT_BANK_CHECKER macro)
76
//! @param tidx thread id in x dimension of block
77
//! @param tidy thread id in y dimension of block
78
//! @param tidz thread id in z dimension of block
79
//! @param bdimx block size in x dimension
80
//! @param bdimy block size in y dimension
81
//! @param bdimz block size in z dimension
82
//! @param file name of the source file where the access takes place
83
//! @param line line in the source file where the access takes place
84
//! @param aname name of the array which is accessed
85
//! @param index index into the array
86
////////////////////////////////////////////////////////////////////////////
87
DLL_MAPPING
88
void
CUTIL_API
89
cutCheckBankAccess(
unsigned
int
tidx,
unsigned
int
tidy,
unsigned
int
tidz,
90
unsigned
int
bdimx,
unsigned
int
bdimy,
91
unsigned
int
bdimz,
const
char
* file,
const
int
line,
92
const
char
* aname,
const
int
index);
93
94
////////////////////////////////////////////////////////////////////////////
95
//! Find the path for a filename
96
//! @return the path if succeeded, otherwise 0
97
//! @param filename name of the file
98
//! @param executablePath optional absolute path of the executable
99
////////////////////////////////////////////////////////////////////////////
100
DLL_MAPPING
101
char
* CUTIL_API
102
cutFindFilePath(
const
char
* filename,
const
char
* executablePath);
103
104
////////////////////////////////////////////////////////////////////////////
105
//! Read file \filename containing single precision floating point data
106
//! @return CUTTrue if reading the file succeeded, otherwise false
107
//! @param filename name of the source file
108
//! @param data uninitialized pointer, returned initialized and pointing to
109
//! the data read
110
//! @param len number of data elements in data, -1 on error
111
//! @note If a NULL pointer is passed to this function and it is
112
//! initialized within Cutil then cutFree() has to be used to
113
//! deallocate the memory
114
////////////////////////////////////////////////////////////////////////////
115
DLL_MAPPING
116
CUTBoolean CUTIL_API
117
cutReadFilef(
const
char
* filename,
float
** data,
unsigned
int
* len,
118
bool
verbose =
false
);
119
120
////////////////////////////////////////////////////////////////////////////
121
//! Read file \filename containing double precision floating point data
122
//! @return CUTTrue if reading the file succeeded, otherwise false
123
//! @param filename name of the source file
124
//! @param data uninitialized pointer, returned initialized and pointing to
125
//! the data read
126
//! @param len number of data elements in data, -1 on error
127
//! @note If a NULL pointer is passed to this function and it is
128
//! initialized within Cutil then cutFree() has to be used to
129
//! deallocate the memory
130
////////////////////////////////////////////////////////////////////////////
131
DLL_MAPPING
132
CUTBoolean CUTIL_API
133
cutReadFiled(
const
char
* filename,
double
** data,
unsigned
int
* len,
134
bool
verbose =
false
);
135
136
////////////////////////////////////////////////////////////////////////////
137
//! Read file \filename containing integer data
138
//! @return CUTTrue if reading the file succeeded, otherwise false
139
//! @param filename name of the source file
140
//! @param data uninitialized pointer, returned initialized and pointing to
141
//! the data read
142
//! @param len number of data elements in data, -1 on error
143
//! @note If a NULL pointer is passed to this function and it is
144
//! initialized within Cutil then cutFree() has to be used to
145
//! deallocate the memory
146
////////////////////////////////////////////////////////////////////////////
147
DLL_MAPPING
148
CUTBoolean CUTIL_API
149
cutReadFilei(
const
char
* filename,
int
** data,
unsigned
int
* len,
bool
verbose =
false
);
150
151
////////////////////////////////////////////////////////////////////////////
152
//! Read file \filename containing unsigned integer data
153
//! @return CUTTrue if reading the file succeeded, otherwise false
154
//! @param filename name of the source file
155
//! @param data uninitialized pointer, returned initialized and pointing to
156
//! the data read
157
//! @param len number of data elements in data, -1 on error
158
//! @note If a NULL pointer is passed to this function and it is
159
//! initialized within Cutil then cutFree() has to be used to
160
//! deallocate the memory
161
////////////////////////////////////////////////////////////////////////////
162
DLL_MAPPING
163
CUTBoolean CUTIL_API
164
cutReadFileui(
const
char
* filename,
unsigned
int
** data,
165
unsigned
int
* len,
bool
verbose =
false
);
166
167
////////////////////////////////////////////////////////////////////////////
168
//! Read file \filename containing char / byte data
169
//! @return CUTTrue if reading the file succeeded, otherwise false
170
//! @param filename name of the source file
171
//! @param data uninitialized pointer, returned initialized and pointing to
172
//! the data read
173
//! @param len number of data elements in data, -1 on error
174
//! @note If a NULL pointer is passed to this function and it is
175
//! initialized within Cutil then cutFree() has to be used to
176
//! deallocate the memory
177
////////////////////////////////////////////////////////////////////////////
178
DLL_MAPPING
179
CUTBoolean CUTIL_API
180
cutReadFileb(
const
char
* filename,
char
** data,
unsigned
int
* len,
181
bool
verbose =
false
);
182
183
////////////////////////////////////////////////////////////////////////////
184
//! Read file \filename containing unsigned char / byte data
185
//! @return CUTTrue if reading the file succeeded, otherwise false
186
//! @param filename name of the source file
187
//! @param data uninitialized pointer, returned initialized and pointing to
188
//! the data read
189
//! @param len number of data elements in data, -1 on error
190
//! @note If a NULL pointer is passed to this function and it is
191
//! initialized within Cutil then cutFree() has to be used to
192
//! deallocate the memory
193
////////////////////////////////////////////////////////////////////////////
194
DLL_MAPPING
195
CUTBoolean CUTIL_API
196
cutReadFileub(
const
char
* filename,
unsigned
char
** data,
197
unsigned
int
* len,
bool
verbose =
false
);
198
199
////////////////////////////////////////////////////////////////////////////
200
//! Write a data file \filename containing single precision floating point
201
//! data
202
//! @return CUTTrue if writing the file succeeded, otherwise false
203
//! @param filename name of the file to write
204
//! @param data pointer to data to write
205
//! @param len number of data elements in data, -1 on error
206
//! @param epsilon epsilon for comparison
207
////////////////////////////////////////////////////////////////////////////
208
DLL_MAPPING
209
CUTBoolean CUTIL_API
210
cutWriteFilef(
const
char
* filename,
const
float
* data,
unsigned
int
len,
211
const
float
epsilon,
bool
verbose =
false
);
212
213
////////////////////////////////////////////////////////////////////////////
214
//! Write a data file \filename containing double precision floating point
215
//! data
216
//! @return CUTTrue if writing the file succeeded, otherwise false
217
//! @param filename name of the file to write
218
//! @param data pointer to data to write
219
//! @param len number of data elements in data, -1 on error
220
//! @param epsilon epsilon for comparison
221
////////////////////////////////////////////////////////////////////////////
222
DLL_MAPPING
223
CUTBoolean CUTIL_API
224
cutWriteFiled(
const
char
* filename,
const
float
* data,
unsigned
int
len,
225
const
double
epsilon,
bool
verbose =
false
);
226
227
////////////////////////////////////////////////////////////////////////////
228
//! Write a data file \filename containing integer data
229
//! @return CUTTrue if writing the file succeeded, otherwise false
230
//! @param filename name of the file to write
231
//! @param data pointer to data to write
232
//! @param len number of data elements in data, -1 on error
233
////////////////////////////////////////////////////////////////////////////
234
DLL_MAPPING
235
CUTBoolean CUTIL_API
236
cutWriteFilei(
const
char
* filename,
const
int
* data,
unsigned
int
len,
237
bool
verbose =
false
);
238
239
////////////////////////////////////////////////////////////////////////////
240
//! Write a data file \filename containing unsigned integer data
241
//! @return CUTTrue if writing the file succeeded, otherwise false
242
//! @param filename name of the file to write
243
//! @param data pointer to data to write
244
//! @param len number of data elements in data, -1 on error
245
////////////////////////////////////////////////////////////////////////////
246
DLL_MAPPING
247
CUTBoolean CUTIL_API
248
cutWriteFileui(
const
char
* filename,
const
unsigned
int
* data,
249
unsigned
int
len,
bool
verbose =
false
);
250
251
////////////////////////////////////////////////////////////////////////////
252
//! Write a data file \filename containing char / byte data
253
//! @return CUTTrue if writing the file succeeded, otherwise false
254
//! @param filename name of the file to write
255
//! @param data pointer to data to write
256
//! @param len number of data elements in data, -1 on error
257
////////////////////////////////////////////////////////////////////////////
258
DLL_MAPPING
259
CUTBoolean CUTIL_API
260
cutWriteFileb(
const
char
* filename,
const
char
* data,
unsigned
int
len,
261
bool
verbose =
false
);
262
263
////////////////////////////////////////////////////////////////////////////
264
//! Write a data file \filename containing unsigned char / byte data
265
//! @return CUTTrue if writing the file succeeded, otherwise false
266
//! @param filename name of the file to write
267
//! @param data pointer to data to write
268
//! @param len number of data elements in data, -1 on error
269
////////////////////////////////////////////////////////////////////////////
270
DLL_MAPPING
271
CUTBoolean CUTIL_API
272
cutWriteFileub(
const
char
* filename,
const
unsigned
char
* data,
273
unsigned
int
len,
bool
verbose =
false
);
274
275
////////////////////////////////////////////////////////////////////////////
276
//! Load PGM image file (with unsigned char as data element type)
277
//! @return CUTTrue if reading the file succeeded, otherwise false
278
//! @param file name of the image file
279
//! @param data handle to the data read
280
//! @param w width of the image
281
//! @param h height of the image
282
//! @note If a NULL pointer is passed to this function and it is
283
//! initialized within Cutil then cutFree() has to be used to
284
//! deallocate the memory
285
////////////////////////////////////////////////////////////////////////////
286
DLL_MAPPING
287
CUTBoolean CUTIL_API
288
cutLoadPGMub(
const
char
* file,
unsigned
char
** data,
289
unsigned
int
*w,
unsigned
int
*h);
290
291
////////////////////////////////////////////////////////////////////////////
292
//! Load PPM image file (with unsigned char as data element type)
293
//! @return CUTTrue if reading the file succeeded, otherwise false
294
//! @param file name of the image file
295
//! @param data handle to the data read
296
//! @param w width of the image
297
//! @param h height of the image
298
////////////////////////////////////////////////////////////////////////////
299
DLL_MAPPING
300
CUTBoolean CUTIL_API
301
cutLoadPPMub(
const
char
* file,
unsigned
char
** data,
302
unsigned
int
*w,
unsigned
int
*h);
303
304
////////////////////////////////////////////////////////////////////////////
305
//! Load PPM image file (with unsigned char as data element type), padding
306
//! 4th component
307
//! @return CUTTrue if reading the file succeeded, otherwise false
308
//! @param file name of the image file
309
//! @param data handle to the data read
310
//! @param w width of the image
311
//! @param h height of the image
312
////////////////////////////////////////////////////////////////////////////
313
DLL_MAPPING
314
CUTBoolean CUTIL_API
315
cutLoadPPM4ub(
const
char
* file,
unsigned
char
** data,
316
unsigned
int
*w,
unsigned
int
*h);
317
318
////////////////////////////////////////////////////////////////////////////
319
//! Load PGM image file (with unsigned int as data element type)
320
//! @return CUTTrue if reading the file succeeded, otherwise false
321
//! @param file name of the image file
322
//! @param data handle to the data read
323
//! @param w width of the image
324
//! @param h height of the image
325
//! @note If a NULL pointer is passed to this function and it is
326
//! initialized within Cutil then cutFree() has to be used to
327
//! deallocate the memory
328
////////////////////////////////////////////////////////////////////////////
329
DLL_MAPPING
330
CUTBoolean CUTIL_API
331
cutLoadPGMi(
const
char
* file,
unsigned
int
** data,
332
unsigned
int
* w,
unsigned
int
* h);
333
334
////////////////////////////////////////////////////////////////////////////
335
//! Load PGM image file (with unsigned short as data element type)
336
//! @return CUTTrue if reading the file succeeded, otherwise false
337
//! @param file name of the image file
338
//! @param data handle to the data read
339
//! @param w width of the image
340
//! @param h height of the image
341
//! @note If a NULL pointer is passed to this function and it is
342
//! initialized within Cutil then cutFree() has to be used to
343
//! deallocate the memory
344
////////////////////////////////////////////////////////////////////////////
345
DLL_MAPPING
346
CUTBoolean CUTIL_API
347
cutLoadPGMs(
const
char
* file,
unsigned
short
** data,
348
unsigned
int
* w,
unsigned
int
* h);
349
350
////////////////////////////////////////////////////////////////////////////
351
//! Load PGM image file (with float as data element type)
352
//! @param file name of the image file
353
//! @param data handle to the data read
354
//! @param w width of the image
355
//! @param h height of the image
356
//! @note If a NULL pointer is passed to this function and it is
357
//! initialized within Cutil then cutFree() has to be used to
358
//! deallocate the memory
359
////////////////////////////////////////////////////////////////////////////
360
DLL_MAPPING
361
CUTBoolean CUTIL_API
362
cutLoadPGMf(
const
char
* file,
float
** data,
363
unsigned
int
* w,
unsigned
int
* h);
364
365
////////////////////////////////////////////////////////////////////////////
366
//! Save PGM image file (with unsigned char as data element type)
367
//! @param file name of the image file
368
//! @param data handle to the data read
369
//! @param w width of the image
370
//! @param h height of the image
371
////////////////////////////////////////////////////////////////////////////
372
DLL_MAPPING
373
CUTBoolean CUTIL_API
374
cutSavePGMub(
const
char
* file,
unsigned
char
* data,
375
unsigned
int
w,
unsigned
int
h);
376
377
////////////////////////////////////////////////////////////////////////////
378
//! Save PPM image file (with unsigned char as data element type)
379
//! @param file name of the image file
380
//! @param data handle to the data read
381
//! @param w width of the image
382
//! @param h height of the image
383
////////////////////////////////////////////////////////////////////////////
384
DLL_MAPPING
385
CUTBoolean CUTIL_API
386
cutSavePPMub(
const
char
* file,
unsigned
char
*data,
387
unsigned
int
w,
unsigned
int
h);
388
389
////////////////////////////////////////////////////////////////////////////
390
//! Save PPM image file (with unsigned char as data element type, padded to
391
//! 4 bytes)
392
//! @param file name of the image file
393
//! @param data handle to the data read
394
//! @param w width of the image
395
//! @param h height of the image
396
////////////////////////////////////////////////////////////////////////////
397
DLL_MAPPING
398
CUTBoolean CUTIL_API
399
cutSavePPM4ub(
const
char
* file,
unsigned
char
*data,
400
unsigned
int
w,
unsigned
int
h);
401
402
////////////////////////////////////////////////////////////////////////////
403
//! Save PGM image file (with unsigned int as data element type)
404
//! @param file name of the image file
405
//! @param data handle to the data read
406
//! @param w width of the image
407
//! @param h height of the image
408
////////////////////////////////////////////////////////////////////////////
409
DLL_MAPPING
410
CUTBoolean CUTIL_API
411
cutSavePGMi(
const
char
* file,
unsigned
int
* data,
412
unsigned
int
w,
unsigned
int
h);
413
414
////////////////////////////////////////////////////////////////////////////
415
//! Save PGM image file (with unsigned short as data element type)
416
//! @param file name of the image file
417
//! @param data handle to the data read
418
//! @param w width of the image
419
//! @param h height of the image
420
////////////////////////////////////////////////////////////////////////////
421
DLL_MAPPING
422
CUTBoolean CUTIL_API
423
cutSavePGMs(
const
char
* file,
unsigned
short
* data,
424
unsigned
int
w,
unsigned
int
h);
425
426
////////////////////////////////////////////////////////////////////////////
427
//! Save PGM image file (with float as data element type)
428
//! @param file name of the image file
429
//! @param data handle to the data read
430
//! @param w width of the image
431
//! @param h height of the image
432
////////////////////////////////////////////////////////////////////////////
433
DLL_MAPPING
434
CUTBoolean CUTIL_API
435
cutSavePGMf(
const
char
* file,
float
* data,
436
unsigned
int
w,
unsigned
int
h);
437
438
////////////////////////////////////////////////////////////////////////////
439
// Command line arguments: General notes
440
// * All command line arguments begin with '--' followed by the token;
441
// token and value are separated by '='; example --samples=50
442
// * Arrays have the form --model=[one.obj,two.obj,three.obj]
443
// (without whitespaces)
444
////////////////////////////////////////////////////////////////////////////
445
446
////////////////////////////////////////////////////////////////////////////
447
//! Check if command line argument \a flag-name is given
448
//! @return CUTTrue if command line argument \a flag_name has been given,
449
//! otherwise 0
450
//! @param argc argc as passed to main()
451
//! @param argv argv as passed to main()
452
//! @param flag_name name of command line flag
453
////////////////////////////////////////////////////////////////////////////
454
DLL_MAPPING
455
CUTBoolean CUTIL_API
456
cutCheckCmdLineFlag(
const
int
argc,
const
char
** argv,
457
const
char
* flag_name);
458
459
////////////////////////////////////////////////////////////////////////////
460
//! Get the value of a command line argument of type int
461
//! @return CUTTrue if command line argument \a arg_name has been given and
462
//! is of the requested type, otherwise CUTFalse
463
//! @param argc argc as passed to main()
464
//! @param argv argv as passed to main()
465
//! @param arg_name name of the command line argument
466
//! @param val value of the command line argument
467
////////////////////////////////////////////////////////////////////////////
468
DLL_MAPPING
469
CUTBoolean CUTIL_API
470
cutGetCmdLineArgumenti(
const
int
argc,
const
char
** argv,
471
const
char
* arg_name,
int
* val);
472
473
////////////////////////////////////////////////////////////////////////////
474
//! Get the value of a command line argument of type float
475
//! @return CUTTrue if command line argument \a arg_name has been given and
476
//! is of the requested type, otherwise CUTFalse
477
//! @param argc argc as passed to main()
478
//! @param argv argv as passed to main()
479
//! @param arg_name name of the command line argument
480
//! @param val value of the command line argument
481
////////////////////////////////////////////////////////////////////////////
482
DLL_MAPPING
483
CUTBoolean CUTIL_API
484
cutGetCmdLineArgumentf(
const
int
argc,
const
char
** argv,
485
const
char
* arg_name,
float
* val);
486
487
////////////////////////////////////////////////////////////////////////////
488
//! Get the value of a command line argument of type string
489
//! @return CUTTrue if command line argument \a arg_name has been given and
490
//! is of the requested type, otherwise CUTFalse
491
//! @param argc argc as passed to main()
492
//! @param argv argv as passed to main()
493
//! @param arg_name name of the command line argument
494
//! @param val value of the command line argument
495
////////////////////////////////////////////////////////////////////////////
496
DLL_MAPPING
497
CUTBoolean CUTIL_API
498
cutGetCmdLineArgumentstr(
const
int
argc,
const
char
** argv,
499
const
char
* arg_name,
char
** val);
500
501
////////////////////////////////////////////////////////////////////////////
502
//! Get the value of a command line argument list those element are strings
503
//! @return CUTTrue if command line argument \a arg_name has been given and
504
//! is of the requested type, otherwise CUTFalse
505
//! @param argc argc as passed to main()
506
//! @param argv argv as passed to main()
507
//! @param arg_name name of the command line argument
508
//! @param val command line argument list
509
//! @param len length of the list / number of elements
510
////////////////////////////////////////////////////////////////////////////
511
DLL_MAPPING
512
CUTBoolean CUTIL_API
513
cutGetCmdLineArgumentListstr(
const
int
argc,
const
char
** argv,
514
const
char
* arg_name,
char
** val,
515
unsigned
int
* len);
516
517
////////////////////////////////////////////////////////////////////////////
518
//! Extended assert
519
//! @return CUTTrue if the condition \a val holds, otherwise CUTFalse
520
//! @param val condition to test
521
//! @param file __FILE__ macro
522
//! @param line __LINE__ macro
523
//! @note This function should be used via the CONDITION(val) macro
524
////////////////////////////////////////////////////////////////////////////
525
DLL_MAPPING
526
CUTBoolean CUTIL_API
527
cutCheckCondition(
int
val,
const
char
* file,
const
int
line);
528
529
////////////////////////////////////////////////////////////////////////////
530
//! Compare two float arrays
531
//! @return CUTTrue if \a reference and \a data are identical,
532
//! otherwise CUTFalse
533
//! @param reference handle to the reference data / gold image
534
//! @param data handle to the computed data
535
//! @param len number of elements in reference and data
536
////////////////////////////////////////////////////////////////////////////
537
DLL_MAPPING
538
CUTBoolean CUTIL_API
539
cutComparef(
const
float
* reference,
const
float
* data,
540
const
unsigned
int
len);
541
542
////////////////////////////////////////////////////////////////////////////
543
//! Compare two integer arrays
544
//! @return CUTTrue if \a reference and \a data are identical,
545
//! otherwise CUTFalse
546
//! @param reference handle to the reference data / gold image
547
//! @param data handle to the computed data
548
//! @param len number of elements in reference and data
549
////////////////////////////////////////////////////////////////////////////
550
DLL_MAPPING
551
CUTBoolean CUTIL_API
552
cutComparei(
const
int
* reference,
const
int
* data,
553
const
unsigned
int
len );
554
555
////////////////////////////////////////////////////////////////////////////////
556
//! Compare two unsigned integer arrays, with epsilon and threshold
557
//! @return CUTTrue if \a reference and \a data are identical,
558
//! otherwise CUTFalse
559
//! @param reference handle to the reference data / gold image
560
//! @param data handle to the computed data
561
//! @param len number of elements in reference and data
562
//! @param threshold tolerance % # of comparison errors (0.15f = 15%)
563
////////////////////////////////////////////////////////////////////////////////
564
DLL_MAPPING
565
CUTBoolean CUTIL_API
566
cutCompareuit(
const
unsigned
int
* reference,
const
unsigned
int
* data,
567
const
unsigned
int
len,
const
float
epsilon,
const
float
threshold );
568
569
////////////////////////////////////////////////////////////////////////////
570
//! Compare two unsigned char arrays
571
//! @return CUTTrue if \a reference and \a data are identical,
572
//! otherwise CUTFalse
573
//! @param reference handle to the reference data / gold image
574
//! @param data handle to the computed data
575
//! @param len number of elements in reference and data
576
////////////////////////////////////////////////////////////////////////////
577
DLL_MAPPING
578
CUTBoolean CUTIL_API
579
cutCompareub(
const
unsigned
char
* reference,
const
unsigned
char
* data,
580
const
unsigned
int
len );
581
582
////////////////////////////////////////////////////////////////////////////////
583
//! Compare two integers with a tolernance for # of byte errors
584
//! @return CUTTrue if \a reference and \a data are identical,
585
//! otherwise CUTFalse
586
//! @param reference handle to the reference data / gold image
587
//! @param data handle to the computed data
588
//! @param len number of elements in reference and data
589
//! @param epsilon epsilon to use for the comparison
590
//! @param threshold tolerance % # of comparison errors (0.15f = 15%)
591
////////////////////////////////////////////////////////////////////////////////
592
DLL_MAPPING
593
CUTBoolean CUTIL_API
594
cutCompareubt(
const
unsigned
char
* reference,
const
unsigned
char
* data,
595
const
unsigned
int
len,
const
float
epsilon,
const
float
threshold );
596
597
////////////////////////////////////////////////////////////////////////////////
598
//! Compare two integer arrays witha n epsilon tolerance for equality
599
//! @return CUTTrue if \a reference and \a data are identical,
600
//! otherwise CUTFalse
601
//! @param reference handle to the reference data / gold image
602
//! @param data handle to the computed data
603
//! @param len number of elements in reference and data
604
//! @param epsilon epsilon to use for the comparison
605
////////////////////////////////////////////////////////////////////////////////
606
DLL_MAPPING
607
CUTBoolean CUTIL_API
608
cutCompareube(
const
unsigned
char
* reference,
const
unsigned
char
* data,
609
const
unsigned
int
len,
const
float
epsilon );
610
611
////////////////////////////////////////////////////////////////////////////
612
//! Compare two float arrays with an epsilon tolerance for equality
613
//! @return CUTTrue if \a reference and \a data are identical,
614
//! otherwise CUTFalse
615
//! @param reference handle to the reference data / gold image
616
//! @param data handle to the computed data
617
//! @param len number of elements in reference and data
618
//! @param epsilon epsilon to use for the comparison
619
////////////////////////////////////////////////////////////////////////////
620
DLL_MAPPING
621
CUTBoolean CUTIL_API
622
cutComparefe(
const
float
* reference,
const
float
* data,
623
const
unsigned
int
len,
const
float
epsilon );
624
625
////////////////////////////////////////////////////////////////////////////////
626
//! Compare two float arrays with an epsilon tolerance for equality and a
627
//! threshold for # pixel errors
628
//! @return CUTTrue if \a reference and \a data are identical,
629
//! otherwise CUTFalse
630
//! @param reference handle to the reference data / gold image
631
//! @param data handle to the computed data
632
//! @param len number of elements in reference and data
633
//! @param epsilon epsilon to use for the comparison
634
////////////////////////////////////////////////////////////////////////////////
635
DLL_MAPPING
636
CUTBoolean CUTIL_API
637
cutComparefet(
const
float
* reference,
const
float
* data,
638
const
unsigned
int
len,
const
float
epsilon,
const
float
threshold );
639
640
////////////////////////////////////////////////////////////////////////////
641
//! Compare two float arrays using L2-norm with an epsilon tolerance for
642
//! equality
643
//! @return CUTTrue if \a reference and \a data are identical,
644
//! otherwise CUTFalse
645
//! @param reference handle to the reference data / gold image
646
//! @param data handle to the computed data
647
//! @param len number of elements in reference and data
648
//! @param epsilon epsilon to use for the comparison
649
////////////////////////////////////////////////////////////////////////////
650
DLL_MAPPING
651
CUTBoolean CUTIL_API
652
cutCompareL2fe(
const
float
* reference,
const
float
* data,
653
const
unsigned
int
len,
const
float
epsilon );
654
655
////////////////////////////////////////////////////////////////////////////////
656
//! Compare two PPM image files with an epsilon tolerance for equality
657
//! @return CUTTrue if \a reference and \a data are identical,
658
//! otherwise CUTFalse
659
//! @param src_file filename for the image to be compared
660
//! @param data filename for the reference data / gold image
661
//! @param epsilon epsilon to use for the comparison
662
//! @param threshold threshold of pixels that can still mismatch to pass (i.e. 0.15f = 15% must pass)
663
//! $param verboseErrors output details of image mismatch to std::err
664
////////////////////////////////////////////////////////////////////////////////
665
DLL_MAPPING
666
CUTBoolean CUTIL_API
667
cutComparePPM(
const
char
*src_file,
const
char
*ref_file,
const
float
epsilon,
const
float
threshold,
bool
verboseErrors =
false
);
668
669
670
////////////////////////////////////////////////////////////////////////////
671
//! Timer functionality
672
673
////////////////////////////////////////////////////////////////////////////
674
//! Create a new timer
675
//! @return CUTTrue if a time has been created, otherwise false
676
//! @param name of the new timer, 0 if the creation failed
677
////////////////////////////////////////////////////////////////////////////
678
DLL_MAPPING
679
CUTBoolean CUTIL_API
680
cutCreateTimer(
unsigned
int
* name);
681
682
////////////////////////////////////////////////////////////////////////////
683
//! Delete a timer
684
//! @return CUTTrue if a time has been deleted, otherwise false
685
//! @param name of the timer to delete
686
////////////////////////////////////////////////////////////////////////////
687
DLL_MAPPING
688
CUTBoolean CUTIL_API
689
cutDeleteTimer(
unsigned
int
name);
690
691
////////////////////////////////////////////////////////////////////////////
692
//! Start the time with name \a name
693
//! @param name name of the timer to start
694
////////////////////////////////////////////////////////////////////////////
695
DLL_MAPPING
696
CUTBoolean CUTIL_API
697
cutStartTimer(
const
unsigned
int
name);
698
699
////////////////////////////////////////////////////////////////////////////
700
//! Stop the time with name \a name. Does not reset.
701
//! @param name name of the timer to stop
702
////////////////////////////////////////////////////////////////////////////
703
DLL_MAPPING
704
CUTBoolean CUTIL_API
705
cutStopTimer(
const
unsigned
int
name);
706
707
////////////////////////////////////////////////////////////////////////////
708
//! Resets the timer's counter.
709
//! @param name name of the timer to reset.
710
////////////////////////////////////////////////////////////////////////////
711
DLL_MAPPING
712
CUTBoolean CUTIL_API
713
cutResetTimer(
const
unsigned
int
name);
714
715
////////////////////////////////////////////////////////////////////////////
716
//! Returns total execution time in milliseconds for the timer over all
717
//! runs since the last reset or timer creation.
718
//! @param name name of the timer to return the time of
719
////////////////////////////////////////////////////////////////////////////
720
DLL_MAPPING
721
float
CUTIL_API
722
cutGetTimerValue(
const
unsigned
int
name);
723
724
////////////////////////////////////////////////////////////////////////////
725
//! Return the average time in milliseconds for timer execution as the
726
//! total time for the timer dividied by the number of completed (stopped)
727
//! runs the timer has made.
728
//! Excludes the current running time if the timer is currently running.
729
//! @param name name of the timer to return the time of
730
////////////////////////////////////////////////////////////////////////////
731
DLL_MAPPING
732
float
CUTIL_API
733
cutGetAverageTimerValue(
const
unsigned
int
name);
734
735
////////////////////////////////////////////////////////////////////////////
736
//! Macros
737
738
// This is for the CUTIL bank checker
739
#ifdef _DEBUG
740
#if __DEVICE_EMULATION__
741
// Interface for bank conflict checker
742
#define CUT_BANK_CHECKER( array, index) \
743
(cutCheckBankAccess( threadIdx.x, threadIdx.y, threadIdx.z, blockDim.x, \
744
blockDim.y, blockDim.z, \
745
__FILE__, __LINE__, #array, index ), \
746
array[index])
747
#else
748
#define CUT_BANK_CHECKER( array, index) array[index]
749
#endif
750
#else
751
#define CUT_BANK_CHECKER( array, index) array[index]
752
#endif
753
754
# define CU_SAFE_CALL_NO_SYNC( call ) { \
755
CUresult err = call; \
756
if( CUDA_SUCCESS != err) { \
757
fprintf(stderr, "Cuda driver error %x in file '%s' in line %i.\n", \
758
err, __FILE__, __LINE__ ); \
759
exit(EXIT_FAILURE); \
760
} }
761
762
# define CU_SAFE_CALL( call ) CU_SAFE_CALL_NO_SYNC(call);
763
764
# define CU_SAFE_CTX_SYNC( ) { \
765
CUresult err = cuCtxSynchronize(); \
766
if( CUDA_SUCCESS != err) { \
767
fprintf(stderr, "Cuda driver error %x in file '%s' in line %i.\n", \
768
err, __FILE__, __LINE__ ); \
769
exit(EXIT_FAILURE); \
770
} }
771
772
# define CUDA_SAFE_CALL_NO_SYNC( call) { \
773
cudaError err = call; \
774
if( cudaSuccess != err) { \
775
fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \
776
__FILE__, __LINE__, cudaGetErrorString( err) ); \
777
exit(EXIT_FAILURE); \
778
} }
779
780
# define CUDA_SAFE_CALL( call) CUDA_SAFE_CALL_NO_SYNC(call); \
781
782
# define CUDA_SAFE_THREAD_SYNC( ) { \
783
cudaError err = cudaDeviceSynchronize(); \
784
if ( cudaSuccess != err) { \
785
fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", \
786
__FILE__, __LINE__, cudaGetErrorString( err) ); \
787
} }
788
789
# define CUFFT_SAFE_CALL( call) { \
790
cufftResult err = call; \
791
if( CUFFT_SUCCESS != err) { \
792
fprintf(stderr, "CUFFT error in file '%s' in line %i.\n", \
793
__FILE__, __LINE__); \
794
exit(EXIT_FAILURE); \
795
} }
796
797
# define CUT_SAFE_CALL( call) \
798
if( CUTTrue != call) { \
799
fprintf(stderr, "Cut error in file '%s' in line %i.\n", \
800
__FILE__, __LINE__); \
801
exit(EXIT_FAILURE); \
802
}
803
804
//! Check for CUDA error
805
#ifdef _DEBUG
806
# define CUT_CHECK_ERROR(errorMessage) { \
807
cudaError_t err = cudaGetLastError(); \
808
if( cudaSuccess != err) { \
809
fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
810
errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
811
exit(EXIT_FAILURE); \
812
} \
813
err = cudaDeviceSynchronize(); \
814
if( cudaSuccess != err) { \
815
fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
816
errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
817
exit(EXIT_FAILURE); \
818
} \
819
}
820
#else
821
# define CUT_CHECK_ERROR(errorMessage) { \
822
cudaError_t err = cudaGetLastError(); \
823
if( cudaSuccess != err) { \
824
fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
825
errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
826
exit(EXIT_FAILURE); \
827
} \
828
}
829
#endif
830
831
//! Check for malloc error
832
# define CUT_SAFE_MALLOC( mallocCall ) { \
833
if( !(mallocCall)) { \
834
fprintf(stderr, "Host malloc failure in file '%s' in line %i\n", \
835
__FILE__, __LINE__); \
836
exit(EXIT_FAILURE); \
837
} } while(0);
838
839
//! Check if condition is true (flexible assert)
840
# define CUT_CONDITION( val) \
841
if( CUTFalse == cutCheckCondition( val, __FILE__, __LINE__)) { \
842
exit(EXIT_FAILURE); \
843
}
844
845
#if __DEVICE_EMULATION__
846
847
# define CUT_DEVICE_INIT(ARGC, ARGV)
848
849
#else
850
851
# define CUT_DEVICE_INIT(ARGC, ARGV) { \
852
int deviceCount; \
853
CUDA_SAFE_CALL_NO_SYNC(cudaGetDeviceCount(&deviceCount)); \
854
if (deviceCount == 0) { \
855
fprintf(stderr, "cutil error: no devices supporting CUDA.\n"); \
856
exit(EXIT_FAILURE); \
857
} \
858
int dev = 0; \
859
cutGetCmdLineArgumenti(ARGC, (const char **) ARGV, "device", &dev); \
860
if (dev < 0) dev = 0; \
861
if (dev > deviceCount-1) dev = deviceCount - 1; \
862
cudaDeviceProp deviceProp; \
863
CUDA_SAFE_CALL_NO_SYNC(cudaGetDeviceProperties(&deviceProp, dev)); \
864
if (deviceProp.major < 1) { \
865
fprintf(stderr, "cutil error: device does not support CUDA.\n"); \
866
exit(EXIT_FAILURE); \
867
} \
868
if (cutCheckCmdLineFlag(ARGC, (const char **) ARGV, "quiet") == CUTFalse) \
869
fprintf(stderr, "Using device %d: %s\n", dev, deviceProp.name); \
870
CUDA_SAFE_CALL(cudaSetDevice(dev)); \
871
}
872
873
874
//! Check for CUDA context lost
875
# define CUDA_CHECK_CTX_LOST(errorMessage) { \
876
cudaError_t err = cudaGetLastError(); \
877
if( cudaSuccess != err) { \
878
fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
879
errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
880
exit(EXIT_FAILURE); \
881
} \
882
err = cudaDeviceSynchronize(); \
883
if( cudaSuccess != err) { \
884
fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
885
errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
886
exit(EXIT_FAILURE); \
887
} }
888
889
//! Check for CUDA context lost
890
# define CU_CHECK_CTX_LOST(errorMessage) { \
891
cudaError_t err = cudaGetLastError(); \
892
if( CUDA_ERROR_INVALID_CONTEXT != err) { \
893
fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
894
errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
895
exit(EXIT_FAILURE); \
896
} \
897
err = cudaDeviceSynchronize(); \
898
if( cudaSuccess != err) { \
899
fprintf(stderr, "Cuda error: %s in file '%s' in line %i : %s.\n", \
900
errorMessage, __FILE__, __LINE__, cudaGetErrorString( err) );\
901
exit(EXIT_FAILURE); \
902
} }
903
904
905
#endif
906
907
# define CUT_DEVICE_INIT_DRV(cuDevice, ARGC, ARGV) { \
908
cuDevice = 0; \
909
int deviceCount = 0; \
910
CUresult err = cuInit(0); \
911
if (CUDA_SUCCESS == err) \
912
CU_SAFE_CALL_NO_SYNC(cuDeviceGetCount(&deviceCount)); \
913
if (deviceCount == 0) { \
914
fprintf(stderr, "cutil error: no devices supporting CUDA\n"); \
915
exit(EXIT_FAILURE); \
916
} \
917
int dev = 0; \
918
cutGetCmdLineArgumenti(ARGC, (const char **) ARGV, "device", &dev); \
919
if (dev < 0) dev = 0; \
920
if (dev > deviceCount-1) dev = deviceCount - 1; \
921
CU_SAFE_CALL_NO_SYNC(cuDeviceGet(&cuDevice, dev)); \
922
char name[100]; \
923
cuDeviceGetName(name, 100, cuDevice); \
924
if (cutCheckCmdLineFlag(ARGC, (const char **) ARGV, "quiet") == CUTFalse) \
925
fprintf(stderr, "Using device %d: %s\n", dev, name); \
926
}
927
928
#define CUT_EXIT(argc, argv) \
929
if (!cutCheckCmdLineFlag(argc, (const char**)argv, "noprompt")) { \
930
printf("\nPress ENTER to exit...\n"); \
931
fflush( stdout); \
932
fflush( stderr); \
933
getchar(); \
934
} \
935
exit(EXIT_SUCCESS);
936
937
938
#ifdef __cplusplus
939
}
940
#endif // #ifdef _DEBUG (else branch)