forked from dumerrill/merge-spmv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
859 lines (696 loc) · 21.6 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
/******************************************************************************
* Copyright (c) 2011-2015, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the NVIDIA CORPORATION nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIAeBILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
#pragma once
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#undef min // Windows is terrible for polluting macro namespace
#undef max // Windows is terrible for polluting macro namespace
#undef small // Windows is terrible for polluting macro namespace
#else
#include <sys/resource.h>
#include <time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <sstream>
#include <iostream>
#include <limits>
#ifdef CUB_MKL
#include "omp.h"
#endif
/******************************************************************************
* Assertion macros
******************************************************************************/
/**
* Assert equals
*/
#define AssertEquals(a, b) if ((a) != (b)) { std::cerr << "\n(" << __FILE__ << ": " << __LINE__ << ")\n"; exit(1);}
//---------------------------------------------------------------------
// Random number generation
//---------------------------------------------------------------------
static unsigned long long g_num_rand_samples = 0;
namespace mersenne {
/* Period parameters */
const unsigned int N = 624;
const unsigned int M = 397;
const unsigned int MATRIX_A = 0x9908b0df; /* constant vector a */
const unsigned int UPPER_MASK = 0x80000000; /* most significant w-r bits */
const unsigned int LOWER_MASK = 0x7fffffff; /* least significant r bits */
static unsigned int mt[N]; /* the array for the state vector */
static int mti = N + 1; /* mti==N+1 means mt[N] is not initialized */
/* initializes mt[N] with a seed */
void init_genrand(unsigned int s)
{
mt[0] = s & 0xffffffff;
for (mti = 1; mti < N; mti++)
{
mt[mti] = (1812433253 * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for mtiplier. */
/* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */
mt[mti] &= 0xffffffff;
/* for >32 bit machines */
}
}
/* initialize by an array with array-length */
/* init_key is the array for initializing keys */
/* key_length is its length */
/* slight change for C++, 2004/2/26 */
void init_by_array(unsigned int init_key[], int key_length)
{
int i, j, k;
init_genrand(19650218);
i = 1;
j = 0;
k = (N > key_length ? N : key_length);
for (; k; k--)
{
mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525))
+ init_key[j] + j; /* non linear */
mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
i++;
j++;
if (i >= N)
{
mt[0] = mt[N - 1];
i = 1;
}
if (j >= key_length) j = 0;
}
for (k = N - 1; k; k--)
{
mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941)) - i; /* non linear */
mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
i++;
if (i >= N)
{
mt[0] = mt[N - 1];
i = 1;
}
}
mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */
}
/* generates a random number on [0,0xffffffff]-interval */
unsigned int genrand_int32(void)
{
unsigned int y;
static unsigned int mag01[2] = { 0x0, MATRIX_A };
/* mag01[x] = x * MATRIX_A for x=0,1 */
if (mti >= N)
{ /* generate N words at one time */
int kk;
if (mti == N + 1) /* if init_genrand() has not been called, */
init_genrand(5489); /* a defat initial seed is used */
for (kk = 0; kk < N - M; kk++)
{
y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1];
}
for (; kk < N - 1; kk++)
{
y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1];
}
y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1];
mti = 0;
}
y = mt[mti++];
/* Tempering */
y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680;
y ^= (y << 15) & 0xefc60000;
y ^= (y >> 18);
return y;
}
} // namespace mersenne
/**
* Generates random keys.
*
* We always take the second-order byte from rand() because the higher-order
* bits returned by rand() are commonly considered more uniformly distributed
* than the lower-order bits.
*
* We can decrease the entropy level of keys by adopting the technique
* of Thearling and Smith in which keys are computed from the bitwise AND of
* multiple random samples:
*
* entropy_reduction | Effectively-unique bits per key
* -----------------------------------------------------
* -1 | 0
* 0 | 32
* 1 | 25.95 (81%)
* 2 | 17.41 (54%)
* 3 | 10.78 (34%)
* 4 | 6.42 (20%)
* ... | ...
*
*/
template <typename K>
void RandomBits(
K &key,
int entropy_reduction = 0,
int begin_bit = 0,
int end_bit = sizeof(K) * 8)
{
const int NUM_BYTES = sizeof(K);
const int WORD_BYTES = sizeof(unsigned int);
const int NUM_WORDS = (NUM_BYTES + WORD_BYTES - 1) / WORD_BYTES;
unsigned int word_buff[NUM_WORDS];
if (entropy_reduction == -1)
{
memset((void *) &key, 0, sizeof(key));
return;
}
if (end_bit < 0)
end_bit = sizeof(K) * 8;
// Generate random word_buff
for (int j = 0; j < NUM_WORDS; j++)
{
int current_bit = j * WORD_BYTES * 8;
unsigned int word = 0xffffffff;
word &= 0xffffffff << std::max(0, begin_bit - current_bit);
word &= 0xffffffff >> std::max(0, (current_bit + (WORD_BYTES * 8)) - end_bit);
for (int i = 0; i <= entropy_reduction; i++)
{
// Grab some of the higher bits from rand (better entropy, supposedly)
word &= mersenne::genrand_int32();
g_num_rand_samples++;
}
word_buff[j] = word;
}
memcpy(&key, word_buff, sizeof(K));
}
/// Randomly select number between [0:max)
template <typename T>
T RandomValue(T max)
{
unsigned int bits;
unsigned int max_int = (unsigned int) -1;
do {
RandomBits(bits);
} while (bits == max_int);
return (T) ((double(bits) / double(max_int)) * double(max));
}
//---------------------------------------------------------------------
// Command-line
//---------------------------------------------------------------------
/**
* Utility for parsing command line arguments
*/
struct CommandLineArgs
{
std::vector<std::string> keys;
std::vector<std::string> values;
std::vector<std::string> args;
#ifdef __NVCC__
cudaDeviceProp deviceProp;
#endif // __NVCC__
float device_giga_bandwidth;
size_t device_free_physmem;
size_t device_total_physmem;
/**
* Constructor
*/
CommandLineArgs(int argc, char **argv) :
keys(10),
values(10)
{
using namespace std;
// Initialize mersenne generator
unsigned int mersenne_init[4]= {0x123, 0x234, 0x345, 0x456};
mersenne::init_by_array(mersenne_init, 4);
for (int i = 1; i < argc; i++)
{
string arg = argv[i];
if ((arg[0] != '-') || (arg[1] != '-'))
{
args.push_back(arg);
continue;
}
string::size_type pos;
string key, val;
if ((pos = arg.find('=')) == string::npos) {
key = string(arg, 2, arg.length() - 2);
val = "";
} else {
key = string(arg, 2, pos - 2);
val = string(arg, pos + 1, arg.length() - 1);
}
keys.push_back(key);
values.push_back(val);
}
}
/**
* Checks whether a flag "--<flag>" is present in the commandline
*/
bool CheckCmdLineFlag(const char* arg_name)
{
using namespace std;
for (int i = 0; i < int(keys.size()); ++i)
{
if (keys[i] == string(arg_name))
return true;
}
return false;
}
/**
* Returns number of naked (non-flag and non-key-value) commandline parameters
*/
template <typename T>
int NumNakedArgs()
{
return args.size();
}
/**
* Returns the commandline parameter for a given index (not including flags)
*/
template <typename T>
void GetCmdLineArgument(int index, T &val)
{
using namespace std;
if (index < args.size()) {
istringstream str_stream(args[index]);
str_stream >> val;
}
}
/**
* Returns the value specified for a given commandline parameter --<flag>=<value>
*/
template <typename T>
void GetCmdLineArgument(const char *arg_name, T &val)
{
using namespace std;
for (int i = 0; i < int(keys.size()); ++i)
{
if (keys[i] == string(arg_name))
{
istringstream str_stream(values[i]);
str_stream >> val;
}
}
}
/**
* Returns the values specified for a given commandline parameter --<flag>=<value>,<value>*
*/
template <typename T>
void GetCmdLineArguments(const char *arg_name, std::vector<T> &vals)
{
using namespace std;
if (CheckCmdLineFlag(arg_name))
{
// Clear any default values
vals.clear();
// Recover from multi-value string
for (int i = 0; i < keys.size(); ++i)
{
if (keys[i] == string(arg_name))
{
string val_string(values[i]);
istringstream str_stream(val_string);
string::size_type old_pos = 0;
string::size_type new_pos = 0;
// Iterate comma-separated values
T val;
while ((new_pos = val_string.find(',', old_pos)) != string::npos)
{
if (new_pos != old_pos)
{
str_stream.width(new_pos - old_pos);
str_stream >> val;
vals.push_back(val);
}
// skip over comma
str_stream.ignore(1);
old_pos = new_pos + 1;
}
// Read last value
str_stream >> val;
vals.push_back(val);
}
}
}
}
/**
* The number of pairs parsed
*/
int ParsedArgc()
{
return (int) keys.size();
}
#ifdef __NVCC__
/**
* Initialize device
*/
cudaError_t DeviceInit(int dev = -1)
{
cudaError_t error = cudaSuccess;
do
{
int deviceCount;
error = CubDebug(cudaGetDeviceCount(&deviceCount));
if (error) break;
if (deviceCount == 0) {
fprintf(stderr, "No devices supporting CUDA.\n");
exit(1);
}
if (dev < 0)
{
GetCmdLineArgument("device", dev);
}
if ((dev > deviceCount - 1) || (dev < 0))
{
dev = 0;
}
error = CubDebug(cudaSetDevice(dev));
if (error) break;
CubDebugExit(cudaMemGetInfo(&device_free_physmem, &device_total_physmem));
int ptx_version;
error = CubDebug(cub::PtxVersion(ptx_version));
if (error) break;
error = CubDebug(cudaGetDeviceProperties(&deviceProp, dev));
if (error) break;
if (deviceProp.major < 1) {
fprintf(stderr, "Device does not support CUDA.\n");
exit(1);
}
device_giga_bandwidth = float(deviceProp.memoryBusWidth) * deviceProp.memoryClockRate * 2 / 8 / 1000 / 1000;
if (!CheckCmdLineFlag("quiet"))
{
printf(
"Using device %d: %s (PTX version %d, SM%d, %d SMs, "
"%lld free / %lld total MB physmem, "
"%.3f GB/s @ %d kHz mem clock, ECC %s)\n",
dev,
deviceProp.name,
ptx_version,
deviceProp.major * 100 + deviceProp.minor * 10,
deviceProp.multiProcessorCount,
(unsigned long long) device_free_physmem / 1024 / 1024,
(unsigned long long) device_total_physmem / 1024 / 1024,
device_giga_bandwidth,
deviceProp.memoryClockRate,
(deviceProp.ECCEnabled) ? "on" : "off");
fflush(stdout);
}
} while (0);
return error;
}
#endif // __NVCC__
};
//---------------------------------------------------------------------
// Performance evaluation
//---------------------------------------------------------------------
#ifdef CUB_MKL
/**
* CPU timer (use omp wall timer because rusage accumulates time from all threads)
*/
struct CpuTimer
{
double start;
double stop;
void Start()
{
start = omp_get_wtime();
}
void Stop()
{
stop = omp_get_wtime();
}
float ElapsedMillis()
{
return (stop - start) * 1000;
}
};
#else
struct CpuTimer
{
#if defined(_WIN32) || defined(_WIN64)
LARGE_INTEGER ll_freq;
LARGE_INTEGER ll_start;
LARGE_INTEGER ll_stop;
CpuTimer()
{
QueryPerformanceFrequency(&ll_freq);
}
void Start()
{
QueryPerformanceCounter(&ll_start);
}
void Stop()
{
QueryPerformanceCounter(&ll_stop);
}
float ElapsedMillis()
{
double start = double(ll_start.QuadPart) / double(ll_freq.QuadPart);
double stop = double(ll_stop.QuadPart) / double(ll_freq.QuadPart);
return float((stop - start) * 1000);
}
#else // _WINXXX
rusage start;
rusage stop;
void Start()
{
getrusage(RUSAGE_SELF, &start);
}
void Stop()
{
getrusage(RUSAGE_SELF, &stop);
}
float ElapsedMillis()
{
float sec = stop.ru_utime.tv_sec - start.ru_utime.tv_sec;
float usec = stop.ru_utime.tv_usec - start.ru_utime.tv_usec;
return (sec * 1000) + (usec / 1000);
}
#endif // _WINXXX
};
#endif // CUB_MKL
#ifdef __NVCC__
/**
* GPU timer
*/
struct GpuTimer
{
cudaEvent_t start;
cudaEvent_t stop;
GpuTimer()
{
cudaEventCreate(&start);
cudaEventCreate(&stop);
}
~GpuTimer()
{
cudaEventDestroy(start);
cudaEventDestroy(stop);
}
void Start()
{
cudaEventRecord(start, 0);
}
void Stop()
{
cudaEventRecord(stop, 0);
}
float ElapsedMillis()
{
float elapsed;
cudaEventSynchronize(stop);
cudaEventElapsedTime(&elapsed, start, stop);
return elapsed;
}
};
#endif // __NVCC__
//---------------------------------------------------------------------
// Verification
//---------------------------------------------------------------------
/**
* Compares the equivalence of two arrays
*/
template <typename S, typename T, typename OffsetT>
int CompareResults(T* computed, S* reference, OffsetT len, bool verbose = true)
{
for (OffsetT i = 0; i < len; i++)
{
if (computed[i] != reference[i])
{
if (verbose) std::cout << "INCORRECT: [" << i << "]: "
<< computed[i] << " != "
<< reference[i];
return 1;
}
}
return 0;
}
/**
* Compares the equivalence of two arrays
*/
template <typename OffsetT>
int CompareResults(float* computed, float* reference, OffsetT len, bool verbose = true)
{
float meps = std::numeric_limits<float>::epsilon();
for (OffsetT i = 0; i < len; i++)
{
float a = computed[i];
float b = reference[i];
int int_diff = std::abs(*(int*)&a - *(int*)&b);
float sqrt_diff = sqrt(float(int_diff));
if (sqrt_diff > len)
{
if (verbose) std::cout << "INCORRECT (sqrt_diff: " << sqrt_diff << "): [" << i << "]: "
<< computed[i] << " != "
<< reference[i];
return 1;
}
}
return 0;
}
/**
* Compares the equivalence of two arrays
*/
template <typename OffsetT>
int CompareResults(double* computed, double* reference, OffsetT len, bool verbose = true)
{
double meps = std::numeric_limits<double>::epsilon();
float fmeps = std::numeric_limits<float>::epsilon();
for (OffsetT i = 0; i < len; i++)
{
float a = computed[i];
float b = reference[i];
int int_diff = std::abs(*(int*)&a - *(int*)&b);
float sqrt_diff = sqrt(float(int_diff));
if (sqrt_diff > len)
{
if (verbose) std::cout << "INCORRECT (sqrt_diff: " << sqrt_diff << "): [" << i << "]: "
<< computed[i] << " != "
<< reference[i];
return 1;
}
}
return 0;
}
#ifdef __NVCC__
/**
* Print the contents of a device array
*/
template <typename T>
void DisplayDeviceResults(
T *d_data,
size_t num_items)
{
// Allocate array on host
T *h_data = (T*) malloc(num_items * sizeof(T));
// Copy data back
cudaMemcpy(h_data, d_data, sizeof(T) * num_items, cudaMemcpyDeviceToHost);
DisplayResults(h_data, num_items);
// Cleanup
if (h_data) free(h_data);
}
/**
* Verify the contents of a device array match those
* of a host array
*/
template <typename S, typename T>
int CompareDeviceResults(
S *h_reference,
T *d_data,
size_t num_items,
bool verbose = true,
bool display_data = false)
{
// Allocate array on host
T *h_data = (T*) malloc(num_items * sizeof(T));
// Copy data back
cudaMemcpy(h_data, d_data, sizeof(T) * num_items, cudaMemcpyDeviceToHost);
// Display data
if (display_data)
{
printf("Reference:\n");
for (int i = 0; i < int(num_items); i++)
{
std::cout << h_reference[i] << ", ";
}
printf("\n\nComputed:\n");
for (int i = 0; i < int(num_items); i++)
{
std::cout << h_data[i] << ", ";
}
printf("\n\n");
}
// Check
int retval = CompareResults(h_data, h_reference, num_items, verbose);
// Cleanup
if (h_data) free(h_data);
return retval;
}
/**
* Verify the contents of a device array match those
* of a device array
*/
template <typename T>
int CompareDeviceDeviceResults(
T *d_reference,
T *d_data,
size_t num_items,
bool verbose = true,
bool display_data = false)
{
// Allocate array on host
T *h_reference = (T*) malloc(num_items * sizeof(T));
T *h_data = (T*) malloc(num_items * sizeof(T));
// Copy data back
cudaMemcpy(h_reference, d_reference, sizeof(T) * num_items, cudaMemcpyDeviceToHost);
cudaMemcpy(h_data, d_data, sizeof(T) * num_items, cudaMemcpyDeviceToHost);
// Display data
if (display_data) {
printf("Reference:\n");
for (int i = 0; i < num_items; i++)
{
std::cout << CoutCast(h_reference[i]) << ", ";
}
printf("\n\nComputed:\n");
for (int i = 0; i < num_items; i++)
{
std::cout << CoutCast(h_data[i]) << ", ";
}
printf("\n\n");
}
// Check
int retval = CompareResults(h_data, h_reference, num_items, verbose);
// Cleanup
if (h_reference) free(h_reference);
if (h_data) free(h_data);
return retval;
}
#endif // __NVCC__