-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcuda_intercept.cpp
More file actions
1860 lines (1436 loc) · 66.9 KB
/
cuda_intercept.cpp
File metadata and controls
1860 lines (1436 loc) · 66.9 KB
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
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************
MIT License
Copyright (c) 2020 Christos Konstantinos Matzoros
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
***********************/
//Headers
#include <stdio.h>
#include <list>
#include <map>
#include <cassert>
#include <vector_types.h>
#include <dlfcn.h> //for dynamic linking
#include <cuda.h>
#include <driver_types.h>
using namespace std;
typedef struct {
dim3 gridDim;
dim3 blockDim;
list <void*> arguments;
int counter;
} kernel_info_t;
static list<kernel_info_t> kernels_list;
kernel_info_t &kernelInfo() {
static kernel_info_t kernelInfo;
return kernelInfo;
}
/////////////////////////
// PRINT FUNCTIONS //
/////////////////////////
void print_grid_dimensions(dim3 gridDim){
if (gridDim.y == 1 && gridDim.z == 1) { //1D grid (x)
printf("gridDim=%d ", gridDim.x);
} else if (gridDim.z == 1) { //2D grid (x,y)
printf("gridDim=[%d,%d] ", gridDim.x, gridDim.y);
} else { //3D grid (x,y,z)
printf("gridDim=[%d,%d,%d] ", gridDim.x, gridDim.y, gridDim.z);
}
}
void print_block_dimensions(dim3 blockDim){
if (blockDim.y == 1 && blockDim.z == 1) { //1D block (x)
printf("blockDim=%d ", blockDim.x);
} else if (blockDim.z == 1) { //2D block (x,y)
printf("blockDim=[%d,%d] ", blockDim.x, blockDim.y);
} else { //3D block (x,y,z)
printf("blockDim=[%d,%d,%d] ", blockDim.x, blockDim.y, blockDim.z);
}
}
void print_dimensions(dim3 gridDim, dim3 blockDim){
print_grid_dimensions(gridDim);
print_block_dimensions(blockDim);
}
void print_args(list <void*> arg){
for (std::list<void *>::iterator it = arg.begin(), end = arg.end(); it != end; ++it) {
unsigned i = std::distance(arg.begin(), it);
printf("%d:%d \n", i, *(static_cast<int *>(*it)));
}
}
void print_kernel_invocation(const char *entry) {
printf("New kernel invocation\n");
print_dimensions(kernelInfo().gridDim,kernelInfo().blockDim);
//print_args(kernelInfo().arguments);
printf("\n");
}
////////////////////////////
// CALLS INTERCEPTION //
////////////////////////////
//*******************************************//
// CUDA Runtime API Error Handling //
//*******************************************//
/// cudaGetErrorName ///
typedef const char* (*cudaGetErrorName_t)(cudaError_t error);
static cudaGetErrorName_t native_cudaGetErrorName = NULL;
extern "C" const char* cudaGetErrorName(cudaError_t error) {
printf("\n>> cudaGetErrorName interception\n");
if (native_cudaGetErrorName == NULL) {
native_cudaGetErrorName = (cudaGetErrorName_t)dlsym(RTLD_NEXT,"cudaGetErrorName");
}
assert(native_cudaGetErrorName != NULL);
return native_cudaGetErrorName(error);
}
/// cudaGetErrorString ///
typedef const char* (*cudaGetErrorString_t)(cudaError_t error);
static cudaGetErrorString_t native_cudaGetErrorString = NULL;
extern "C" const char* cudaGetErrorString(cudaError_t error) {
printf("\n>> cudaGetErrorString interception\n");
if (native_cudaGetErrorString == NULL) {
native_cudaGetErrorString = (cudaGetErrorString_t)dlsym(RTLD_NEXT,"cudaGetErrorString");
}
assert(native_cudaGetErrorString != NULL);
return native_cudaGetErrorString(error);
}
/// cudaGetLastError ///
typedef cudaError_t (*cudaGetLastError_t)(void);
static cudaGetLastError_t native_cudaGetLastError = NULL;
extern "C" cudaError_t cudaGetLastError(void) {
printf("\n>> cudaGetLastError interception\n");
if (native_cudaGetLastError == NULL) {
native_cudaGetLastError = (cudaGetLastError_t)dlsym(RTLD_NEXT,"cudaGetLastError");
}
assert(native_cudaGetLastError != NULL);
return native_cudaGetLastError();
}
/// cudaGetLastError ///
typedef cudaError_t (*cudaPeekAtLastError_t)(void);
static cudaPeekAtLastError_t native_cudaPeekAtLastError = NULL;
extern "C" cudaError_t cudaPeekAtLastError(void) {
printf("\n>> cudaPeekAtLastError interception\n");
if (native_cudaPeekAtLastError== NULL) {
native_cudaPeekAtLastError = (cudaPeekAtLastError_t)dlsym(RTLD_NEXT,"cudaPeekAtLastError");
}
assert(native_cudaPeekAtLastError != NULL);
return native_cudaPeekAtLastError();
}
//**********************************************//
// CUDA Runtime API Device Management //
//**********************************************//
/// cudaChooseDevice ///
typedef cudaError_t (*cudaChooseDevice_t)(int * device, const struct cudaDeviceProp * prop);
static cudaChooseDevice_t native_cudaChooseDevice = NULL;
extern "C" cudaError_t cudaChooseDevice(int * device, const struct cudaDeviceProp * prop) {
printf("\n>>cudaChooseDevice interception \n");
if (native_cudaChooseDevice == NULL) {
native_cudaChooseDevice = (cudaChooseDevice_t)dlsym(RTLD_NEXT,"cudaChooseDevice");
}
assert(native_cudaChooseDevice != NULL);
return native_cudaChooseDevice(device,prop);
}
/// cudaDeviceGetAttribute ///
typedef cudaError_t (*cudaDeviceGetAttribute_t)(int* value, cudaDeviceAttr attr, int device);
static cudaDeviceGetAttribute_t native_cudaDeviceGetAttribute = NULL;
extern "C" cudaError_t cudaDeviceGetAttribute(int* value, cudaDeviceAttr attr, int device) {
printf("\n>>cudaDeviceGetAttribute interception \n");
if (native_cudaDeviceGetAttribute == NULL) {
native_cudaDeviceGetAttribute = (cudaDeviceGetAttribute_t)dlsym(RTLD_NEXT,"cudaDeviceGetAttribute");
}
assert(native_cudaDeviceGetAttribute != NULL);
return native_cudaDeviceGetAttribute(value,attr,device);
}
/// cudaDeviceGetByPCIBusId ///
typedef cudaError_t (*cudaDeviceGetByPCIBusId_t)(int* device, const char* pciBusId);
static cudaDeviceGetByPCIBusId_t native_cudaDeviceGetByPCIBusId = NULL;
extern "C" cudaError_t cudaDeviceGetByPCIBusId (int* device, const char* pciBusId) {
printf("\n>>cudaDeviceGetByPCIBusId interception\n");
if (native_cudaDeviceGetByPCIBusId == NULL) {
native_cudaDeviceGetByPCIBusId = (cudaDeviceGetByPCIBusId_t)dlsym(RTLD_NEXT,"cudaDeviceGetByPCIBusId ");
}
assert(native_cudaDeviceGetByPCIBusId != NULL);
return native_cudaDeviceGetByPCIBusId (device,pciBusId);
}
/// cudaDeviceGetCacheConfig ///
typedef cudaError_t (*cudaDeviceGetCacheConfig_t)(cudaFuncCache ** pCacheConfig);
static cudaDeviceGetCacheConfig_t native_cudaDeviceGetCacheConfig = NULL;
extern "C" cudaError_t cudaDeviceGetCacheConfig (cudaFuncCache ** pCacheConfig) {
printf("\n>>cudaDeviceGetCacheConfig interception\n");
if (native_cudaDeviceGetCacheConfig == NULL) {
native_cudaDeviceGetCacheConfig = (cudaDeviceGetCacheConfig_t)dlsym(RTLD_NEXT,"cudaDeviceGetCacheConfig");
}
assert(native_cudaDeviceGetCacheConfig != NULL);
return native_cudaDeviceGetCacheConfig(pCacheConfig);
}
/// cudaDeviceGetLimit ///
typedef cudaError_t (*cudaDeviceGetLimit_t)(size_t* pValue, cudaLimit limit);
static cudaDeviceGetLimit_t native_cudaDeviceGetLimit = NULL;
extern "C" cudaError_t cudaDeviceGetLimit (size_t* pValue, cudaLimit limit) {
printf("\n>>cudaDeviceGetLimit interception\n");
if (native_cudaDeviceGetLimit == NULL) {
native_cudaDeviceGetLimit = (cudaDeviceGetLimit_t)dlsym(RTLD_NEXT,"cudaDeviceGetLimit");
}
assert(native_cudaDeviceGetLimit != NULL);
return native_cudaDeviceGetLimit(pValue,limit);
}
/// cudaDeviceGetNvSciSyncAttributes ///
typedef cudaError_t (*cudaDeviceGetNvSciSyncAttributes_t)( void* nvSciSyncAttrList, int device, int flags);
static cudaDeviceGetNvSciSyncAttributes_t native_cudaDeviceGetNvSciSyncAttributes = NULL;
extern "C" cudaError_t cudaDeviceGetNvSciSyncAttributes ( void* nvSciSyncAttrList, int device, int flags) {
printf("\n>>cudaDeviceGetNvSciSyncAttributes interception\n");
if (native_cudaDeviceGetNvSciSyncAttributes== NULL) {
native_cudaDeviceGetNvSciSyncAttributes= (cudaDeviceGetNvSciSyncAttributes_t)dlsym(RTLD_NEXT,"cudaDeviceGetNvSciSyncAttributes");
}
assert(native_cudaDeviceGetNvSciSyncAttributes != NULL);
return native_cudaDeviceGetNvSciSyncAttributes(nvSciSyncAttrList,device,flags);
}
/// cudaDeviceGetP2PAttribute ///
typedef cudaError_t (*cudaDeviceGetP2PAttribute_t)(int* value, cudaDeviceP2PAttr attr, int srcDevice, int dstDevice);
static cudaDeviceGetP2PAttribute_t native_cudaDeviceGetP2PAttribute= NULL;
extern "C" cudaError_t cudaDeviceGetP2PAttribute (int* value, cudaDeviceP2PAttr attr, int srcDevice, int dstDevice) {
printf("\n>>cudaDeviceGetP2PAttribute interception\n");
if (native_cudaDeviceGetP2PAttribute == NULL) {
native_cudaDeviceGetP2PAttribute = (cudaDeviceGetP2PAttribute_t)dlsym(RTLD_NEXT,"cudaDeviceGetP2PAttribute");
}
assert(native_cudaDeviceGetP2PAttribute != NULL);
return native_cudaDeviceGetP2PAttribute(value,attr,srcDevice,dstDevice);
}
/// cudaDeviceGetPCIBusId ///
typedef cudaError_t (*cudaDeviceGetPCIBusId_t)(char* pciBusId, int len, int device);
static cudaDeviceGetPCIBusId_t native_cudaDeviceGetPCIBusId = NULL;
extern "C" cudaError_t cudaDeviceGetPCIBusId (char* pciBusId, int len, int device) {
printf("\n>>cudaDeviceGetPCIBusId interception\n");
if (native_cudaDeviceGetPCIBusId == NULL) {
native_cudaDeviceGetPCIBusId = (cudaDeviceGetPCIBusId_t)dlsym(RTLD_NEXT,"cudaDeviceGetPCIBusId");
}
assert(native_cudaDeviceGetPCIBusId != NULL);
return native_cudaDeviceGetPCIBusId(pciBusId,len,device);
}
/// cudaDeviceGetSharedMemConfig ///
typedef cudaError_t (*cudaDeviceGetSharedMemConfig_t)( cudaSharedMemConfig ** pConfig );
static cudaDeviceGetSharedMemConfig_t native_cudaDeviceGetSharedMemConfig = NULL;
extern "C" cudaError_t cudaDeviceGetSharedMemConfig (cudaSharedMemConfig ** pConfig ) {
printf("\n>>cudaDeviceGetSharedMemConfig interception\n");
if (native_cudaDeviceGetSharedMemConfig == NULL) {
native_cudaDeviceGetSharedMemConfig = (cudaDeviceGetSharedMemConfig_t)dlsym(RTLD_NEXT,"cudaDeviceGetSharedMemConfig");
}
assert(native_cudaDeviceGetSharedMemConfig != NULL);
return native_cudaDeviceGetSharedMemConfig(pConfig);
}
/// cudaDeviceGetStreamPriorityRange ///
typedef cudaError_t (*cudaDeviceGetStreamPriorityRange_t)( int* leastPriority, int* greatestPriority);
static cudaDeviceGetStreamPriorityRange_t native_cudaDeviceGetStreamPriorityRange = NULL;
extern "C" cudaError_t cudaDeviceGetStreamPriorityRange ( int* leastPriority, int* greatestPriority) {
printf("\n>>cudaDeviceGetStreamPriorityRange interception\n");
if (native_cudaDeviceGetStreamPriorityRange == NULL) {
native_cudaDeviceGetStreamPriorityRange = (cudaDeviceGetStreamPriorityRange_t)dlsym(RTLD_NEXT,"cudaDeviceGetStreamPriorityRange");
}
assert(native_cudaDeviceGetStreamPriorityRange != NULL);
return native_cudaDeviceGetStreamPriorityRange(leastPriority,greatestPriority);
}
/// cudaMalloc3D ///
typedef cudaError_t (*cudaDeviceSetCacheConfig_t)(cudaFuncCache cacheConfig);
static cudaDeviceSetCacheConfig_t native_cudaDeviceSetCacheConfig = NULL;
extern "C" cudaError_t cudaDeviceSetCacheConfig (cudaFuncCache cacheConfig) {
printf("\n>>cudaDeviceSetCacheConfig interception\n");
if (native_cudaDeviceSetCacheConfig == NULL) {
native_cudaDeviceSetCacheConfig = (cudaDeviceSetCacheConfig_t)dlsym(RTLD_NEXT,"cudaDeviceSetCacheConfig");
}
assert(native_cudaDeviceSetCacheConfig != NULL);
return native_cudaDeviceSetCacheConfig(cacheConfig);
}
/// cudaDeviceSetLimit ///
typedef cudaError_t (*cudaDeviceSetLimit_t)(cudaLimit limit, size_t value);
static cudaDeviceSetLimit_t native_cudaDeviceSetLimit = NULL;
extern "C" cudaError_t cudaDeviceSetLimit (cudaLimit limit, size_t value) {
printf("\n>>cudaDeviceSetLimit interception\n");
if (native_cudaDeviceSetLimit == NULL) {
native_cudaDeviceSetLimit = (cudaDeviceSetLimit_t)dlsym(RTLD_NEXT,"cudaDeviceSetLimit");
}
assert(native_cudaDeviceSetLimit != NULL);
return native_cudaDeviceSetLimit(limit,value);
}
/// cudaDeviceSetSharedMemConfig ///
typedef cudaError_t (*cudaDeviceSetSharedMemConfig_t)(cudaSharedMemConfig config);
static cudaDeviceSetSharedMemConfig_t native_cudaDeviceSetSharedMemConfig = NULL;
extern "C" cudaError_t cudaDeviceSetSharedMemConfig(cudaSharedMemConfig config) {
printf("\n>>cudaDeviceSetSharedMemConfig interception\n");
if (native_cudaDeviceSetSharedMemConfig == NULL) {
native_cudaDeviceSetSharedMemConfig = (cudaDeviceSetSharedMemConfig_t)dlsym(RTLD_NEXT,"cudaDeviceSetSharedMemConfig");
}
assert(native_cudaDeviceSetSharedMemConfig != NULL);
return native_cudaDeviceSetSharedMemConfig(config);
}
/// cudaDeviceSynchronize ///
typedef cudaError_t (*cudaDeviceSynchronize_t)(void);
static cudaDeviceSynchronize_t native_cudaDeviceSynchronize = NULL;
extern "C" cudaError_t cudaDeviceSynchronize (void) {
printf("\n>>cudaDeviceSynchronize interception\n");
if (native_cudaDeviceSynchronize == NULL) {
native_cudaDeviceSynchronize = (cudaDeviceSynchronize_t)dlsym(RTLD_NEXT,"cudaDeviceSynchronize");
}
assert(native_cudaDeviceSynchronize != NULL);
return native_cudaDeviceSynchronize();
}
/// cudaGetDevice ///
typedef cudaError_t (*cudaGetDevice_t)(int *device);
static cudaGetDevice_t native_cudaGetDevice = NULL;
extern "C" cudaError_t cudaGetDevice(int *device){
printf("\n>>cudaGetDevice \n");
//call of the real function
if (native_cudaGetDevice == NULL) {
native_cudaGetDevice = (cudaGetDevice_t)dlsym(RTLD_NEXT,"cudaGetDevice");
}
assert(native_cudaGetDevice != NULL);
return native_cudaGetDevice(device);
}
/// cudaGetDeviceCount ///
typedef cudaError_t (*cudaGetDeviceCount_t)(int * count);
static cudaGetDeviceCount_t native_cudaGetDeviceCount = NULL;
extern "C" cudaError_t cudaGetDeviceCount(int * count){
printf("\n>>cudaGetDeviceCount interception \n");
if (native_cudaGetDeviceCount == NULL) {
native_cudaGetDeviceCount = (cudaGetDeviceCount_t)dlsym(RTLD_NEXT,"cudaGetDeviceCount");
}
assert(native_cudaGetDeviceCount != NULL);
return native_cudaGetDeviceCount(count);
}
/// cudaGetDeviceFlags ///
typedef cudaError_t (*cudaGetDeviceFlags_t)(unsigned int* flags);
static cudaGetDeviceFlags_t native_cudaGetDeviceFlags = NULL;
extern "C" cudaError_t cudaGetDeviceFlags (unsigned int* flags) {
printf("\n>>cudaGetDeviceFlags interception\n");
if (native_cudaGetDeviceFlags == NULL) {
native_cudaGetDeviceFlags = (cudaGetDeviceFlags_t)dlsym(RTLD_NEXT,"cudaGetDeviceFlags");
}
assert(native_cudaGetDeviceFlags != NULL);
return native_cudaGetDeviceFlags(flags);
}
/// cudaGetDeviceProperties ///
typedef cudaError_t (*cudaGetDeviceProperties_t)(struct cudaDeviceProp * prop, int device);
static cudaGetDeviceProperties_t native_cudaGetDeviceProperties = NULL;
extern "C" cudaError_t cudaGetDeviceProperties(struct cudaDeviceProp * prop, int device){
printf("\n>>cudaGetDeviceProperties interception \n");
if (native_cudaGetDeviceProperties == NULL) {
native_cudaGetDeviceProperties = (cudaGetDeviceProperties_t)dlsym(RTLD_NEXT,"cudaGetDeviceProperties");
}
assert(native_cudaGetDeviceProperties != NULL);
return native_cudaGetDeviceProperties(prop,device);
}
/// cudaIpcCloseMemHandle ///
typedef cudaError_t (*cudaIpcCloseMemHandle_t)(void* devPtr);
static cudaIpcCloseMemHandle_t native_cudaIpcCloseMemHandle = NULL;
extern "C" cudaError_t cudaIpcCloseMemHandle (void* devPtr) {
printf("\n>>cudaIpcCloseMemHandle interception\n");
if (native_cudaIpcCloseMemHandle == NULL) {
native_cudaIpcCloseMemHandle= (cudaIpcCloseMemHandle_t)dlsym(RTLD_NEXT,"cudaIpcCloseMemHandle");
}
assert(native_cudaIpcCloseMemHandle != NULL);
return native_cudaIpcCloseMemHandle(devPtr);
}
/// cudaIpcGetEventHandle ///
typedef cudaError_t (*cudaIpcGetEventHandle_t)(cudaIpcEventHandle_t* handle, cudaEvent_t event);
static cudaIpcGetEventHandle_t native_cudaIpcGetEventHandle = NULL;
extern "C" cudaError_t cudaIpcGetEventHandle (cudaIpcEventHandle_t* handle, cudaEvent_t event) {
printf("\n>>cudaIpcGetEventHandle interception\n");
if (native_cudaIpcGetEventHandle == NULL) {
native_cudaIpcGetEventHandle = (cudaIpcGetEventHandle_t)dlsym(RTLD_NEXT,"cudaIpcGetEventHandle");
}
assert(native_cudaIpcGetEventHandle != NULL);
return native_cudaIpcGetEventHandle(handle,event);
}
/// cudaIpcGetMemHandle ///
typedef cudaError_t (*cudaIpcGetMemHandle_t)(cudaIpcMemHandle_t* handle, void* devPtr);
static cudaIpcGetMemHandle_t native_cudaIpcGetMemHandle= NULL;
extern "C" cudaError_t cudaIpcGetMemHandle (cudaIpcMemHandle_t* handle, void* devPtr) {
printf("\n>>cudaIpcGetMemHandle interception\n");
if (native_cudaIpcGetMemHandle == NULL) {
native_cudaIpcGetMemHandle = (cudaIpcGetMemHandle_t)dlsym(RTLD_NEXT,"cudaIpcGetMemHandle");
}
assert(native_cudaIpcGetMemHandle!= NULL);
return native_cudaIpcGetMemHandle(handle,devPtr);
}
/// cudaIpcOpenEventHandle ///
typedef cudaError_t (*cudaIpcOpenEventHandle_t)(cudaEvent_t* event, cudaIpcEventHandle_t handle);
static cudaIpcOpenEventHandle_t native_cudaIpcOpenEventHandle = NULL;
extern "C" cudaError_t cudaIpcOpenEventHandle (cudaEvent_t* event, cudaIpcEventHandle_t handle) {
printf("\n>>cudaIpcOpenEventHandle interception\n");
if (native_cudaIpcOpenEventHandle== NULL) {
native_cudaIpcOpenEventHandle = (cudaIpcOpenEventHandle_t)dlsym(RTLD_NEXT,"cudaIpcOpenEventHandle");
}
assert(native_cudaIpcOpenEventHandle != NULL);
return native_cudaIpcOpenEventHandle(event,handle);
}
/// cudaIpcOpenMemHandle ///
typedef cudaError_t (*cudaIpcOpenMemHandle_t)(void** devPtr, cudaIpcMemHandle_t handle, unsigned int flags);
static cudaIpcOpenMemHandle_t native_cudaIpcOpenMemHandle = NULL;
extern "C" cudaError_t cudaIpcOpenMemHandle (void** devPtr, cudaIpcMemHandle_t handle, unsigned int flags) {
printf("\n>>cudaIpcOpenMemHandle interception\n");
if (native_cudaIpcOpenMemHandle == NULL) {
native_cudaIpcOpenMemHandle = (cudaIpcOpenMemHandle_t)dlsym(RTLD_NEXT,"cudaIpcOpenMemHandle");
}
assert(native_cudaIpcOpenMemHandle != NULL);
return native_cudaIpcOpenMemHandle(devPtr,handle,flags);
}
/// cudaSetDevice ///
typedef cudaError_t (*cudaSetDevice_t)(int device);
static cudaSetDevice_t native_cudaSetDevice = NULL;
extern "C" cudaError_t cudaSetDevice(int device){
printf("\n>>cudaSetDevice interception \n");
if (native_cudaSetDevice == NULL) {
native_cudaSetDevice = (cudaSetDevice_t)dlsym(RTLD_NEXT,"cudaSetDevice");
}
assert(native_cudaSetDevice != NULL);
return native_cudaSetDevice(device);
}
/// cudaSetDeviceFlags ///
typedef cudaError_t (*cudaSetDeviceFlags_t)(int flags);
static cudaSetDeviceFlags_t native_cudaSetDeviceFlags = NULL;
extern "C" cudaError_t cudaSetDeviceFlags(int flags){
printf("\n>>cudaSetDeviceFlags interception \n");
if (native_cudaSetDeviceFlags == NULL) {
native_cudaSetDeviceFlags = (cudaSetDeviceFlags_t)dlsym(RTLD_NEXT,"cudaSetDeviceFlags");
}
assert(native_cudaSetDeviceFlags != NULL);
return native_cudaSetDeviceFlags(flags);
}
/// cudaSetValidDevices ///
typedef cudaError_t (*cudaSetValidDevices_t)(int * device_arr, int len);
static cudaSetValidDevices_t native_cudaSetValidDevices = NULL;
extern "C" cudaError_t cudaSetValidDevices(int * device_arr, int len){
printf("\n>>cudaSetValidDevices interception \n");
if (native_cudaSetValidDevices == NULL) {
native_cudaSetValidDevices = (cudaSetValidDevices_t)dlsym(RTLD_NEXT,"cudaSetValidDevices");
}
assert(native_cudaSetValidDevices != NULL);
return native_cudaSetValidDevices(device_arr,len);
}
//**********************************************//
// CUDA Runtime API Stream Management //
//**********************************************//
/// cudaStreamAttachMemAsync ///
typedef cudaError_t (*cudaStreamAttachMemAsync_t)(cudaStream_t stream, void* devPtr, size_t length, unsigned int flags);
static cudaStreamAttachMemAsync_t native_cudaStreamAttachMemAsync = NULL;
extern "C" cudaError_t cudaStreamAttachMemAsync(cudaStream_t stream, void* devPtr, size_t length, unsigned int flags){
printf("\n>>cudaStreamAttachMemAsync interception \n");
if (native_cudaStreamAttachMemAsync == NULL) {
native_cudaStreamAttachMemAsync = (cudaStreamAttachMemAsync_t)dlsym(RTLD_NEXT,"cudaStreamAttachMemAsync");
}
assert(native_cudaStreamAttachMemAsync != NULL);
return native_cudaStreamAttachMemAsync(stream,devPtr,length,flags);
}
/// cudaStreamCreate ///
typedef cudaError_t (*cudaStreamCreate_t)(cudaStream_t * pStream);
static cudaStreamCreate_t native_cudaStreamCreate = NULL;
extern "C" cudaError_t cudaStreamCreate(cudaStream_t * pStream){
printf("\n>>cudaStreamCreate interception \n");
if (native_cudaStreamCreate == NULL) {
native_cudaStreamCreate = (cudaStreamCreate_t)dlsym(RTLD_NEXT,"cudaStreamCreate");
}
assert(native_cudaStreamCreate != NULL);
return native_cudaStreamCreate(pStream);
}
/// cudaStreamCreateWithFlags ///
typedef cudaError_t (*cudaStreamCreateWithFlags_t)(cudaStream_t* pStream, unsigned int flags);
static cudaStreamCreateWithFlags_t native_cudaStreamCreateWithFlags = NULL;
extern "C" cudaError_t cudaStreamCreateWithFlags(cudaStream_t* pStream, unsigned int flags){
printf("\n>>cudaStreamCreateWithFlags interception \n");
if (native_cudaStreamCreateWithFlags == NULL) {
native_cudaStreamCreateWithFlags = (cudaStreamCreateWithFlags_t)dlsym(RTLD_NEXT,"cudaStreamCreateWithFlags");
}
assert(native_cudaStreamCreateWithFlags != NULL);
return native_cudaStreamCreateWithFlags(pStream,flags);
}
/// cudaStreamCreateWithPriority ///
typedef cudaError_t (*cudaStreamCreateWithPriority_t)(cudaStream_t* pStream, unsigned int flags, int priority);
static cudaStreamCreateWithPriority_t native_cudaStreamCreateWithPriority = NULL;
extern "C" cudaError_t cudaStreamCreateWithPriority(cudaStream_t* pStream, unsigned int flags, int priority){
printf("\n>>cudaStreamCreateWithPriority interception \n");
if (native_cudaStreamCreateWithPriority == NULL) {
native_cudaStreamCreateWithPriority = (cudaStreamCreateWithPriority_t)dlsym(RTLD_NEXT,"cudaStreamCreateWithPriority");
}
assert(native_cudaStreamCreateWithPriority != NULL);
return native_cudaStreamCreateWithPriority(pStream,flags,priority);
}
/// cudaStreamDestroy ///
typedef cudaError_t (*cudaStreamDestroy_t)(cudaStream_t stream);
static cudaStreamDestroy_t native_cudaStreamDestroy = NULL;
extern "C" cudaError_t cudaStreamDestroy(cudaStream_t stream){
printf("\n>>cudaStreamDestroy interception \n");
if (native_cudaStreamDestroy == NULL) {
native_cudaStreamDestroy = (cudaStreamDestroy_t)dlsym(RTLD_NEXT,"cudaStreamDestroy");
}
assert(native_cudaStreamDestroy != NULL);
return native_cudaStreamDestroy(stream);
}
/// cudaStreamGetFlags ///
typedef cudaError_t (*cudaStreamGetFlags_t)(cudaStream_t hStream, unsigned int* flags);
static cudaStreamGetFlags_t native_cudaStreamGetFlags= NULL;
extern "C" cudaError_t cudaStreamGetFlags(cudaStream_t hStream, unsigned int* flags){
printf("\n>>cudaStreamGetFlags interception \n");
if (native_cudaStreamGetFlags == NULL) {
native_cudaStreamGetFlags = (cudaStreamGetFlags_t)dlsym(RTLD_NEXT,"cudaStreamGetFlags");
}
assert(native_cudaStreamGetFlags != NULL);
return native_cudaStreamGetFlags(hStream,flags);
}
/// cudaStreamGetPriority ///
typedef cudaError_t (*cudaStreamGetPriority_t)(cudaStream_t hStream, int* priority);
static cudaStreamGetPriority_t native_cudaStreamGetPriority = NULL;
extern "C" cudaError_t cudaStreamGetPriority(cudaStream_t hStream, int* priority){
printf("\n>>cudaStreamGetPriority interception \n");
if (native_cudaStreamGetPriority == NULL) {
native_cudaStreamGetPriority = (cudaStreamGetPriority_t)dlsym(RTLD_NEXT,"cudaStreamGetPriority");
}
assert(native_cudaStreamGetPriority != NULL);
return native_cudaStreamGetPriority(hStream,priority);
}
/// cudaStreamQuery ///
typedef cudaError_t (*cudaStreamQuery_t)(cudaStream_t stream);
static cudaStreamQuery_t native_cudaStreamQuery = NULL;
extern "C" cudaError_t cudaStreamQuery(cudaStream_t stream){
printf("\n>>cudaStreamQuery interception \n");
if (native_cudaStreamQuery == NULL) {
native_cudaStreamQuery = (cudaStreamQuery_t)dlsym(RTLD_NEXT,"cudaStreamQuery");
}
assert(native_cudaStreamQuery != NULL);
return native_cudaStreamQuery(stream);
}
/// cudaStreamSynchronize ///
typedef cudaError_t (*cudaStreamSynchronize_t)(cudaStream_t stream);
static cudaStreamSynchronize_t native_cudaStreamSynchronize = NULL;
extern "C" cudaError_t cudaStreamSynchronize(cudaStream_t stream){
printf("\n>>cudaStreamSynchronize interception \n");
if (native_cudaStreamSynchronize== NULL) {
native_cudaStreamSynchronize = (cudaStreamSynchronize_t)dlsym(RTLD_NEXT,"cudaStreamSynchronize");
}
assert(native_cudaStreamSynchronize != NULL);
return native_cudaStreamSynchronize(stream);
}
/// cudaStreamWaitEvent ///
typedef cudaError_t (*cudaStreamWaitEvent_t)(cudaStream_t stream, cudaEvent_t event, unsigned int flags);
static cudaStreamWaitEvent_t native_cudaStreamWaitEvent = NULL;
extern "C" cudaError_t cudaStreamWaitEvent(cudaStream_t stream, cudaEvent_t event, unsigned int flags){
printf("\n>>cudaStreamWaitEvent interception \n");
if (native_cudaStreamWaitEvent == NULL) {
native_cudaStreamWaitEvent = (cudaStreamWaitEvent_t)dlsym(RTLD_NEXT,"cudaStreamWaitEvent");
}
assert(native_cudaStreamWaitEvent != NULL);
return native_cudaStreamWaitEvent(stream,event,flags);
}
//*********************************************//
// CUDA Runtime API Event Management //
//*********************************************//
/// cudaDriverGetVersion ///
typedef cudaError_t (*cudaEventCreate_t)(cudaEvent_t * event);
static cudaEventCreate_t native_cudaEventCreate = NULL;
extern "C" cudaError_t cudaEventCreate (cudaEvent_t * event) {
printf("\n>>cudaEventCreate interception\n");
if (native_cudaEventCreate == NULL) {
native_cudaEventCreate = (cudaEventCreate_t)dlsym(RTLD_NEXT,"cudaEventCreate");
}
assert(native_cudaEventCreate != NULL);
return native_cudaEventCreate(event);
}
/// cudaEventCreateWithFlags ///
typedef cudaError_t (*cudaEventCreateWithFlags_t)(cudaEvent_t * event, int flags);
static cudaEventCreateWithFlags_t native_cudaEventCreateWithFlags = NULL;
extern "C" cudaError_t cudaEventCreateWithFlags(cudaEvent_t * event, int flags) {
printf("\n>>cudaEventCreateWithFlags interception\n");
if (native_cudaEventCreateWithFlags == NULL) {
native_cudaEventCreateWithFlags = (cudaEventCreateWithFlags_t)dlsym(RTLD_NEXT,"cudaEventCreateWithFlags");
}
assert(native_cudaEventCreateWithFlags != NULL);
return native_cudaEventCreateWithFlags(event,flags);
}
/// cudaEventDestroy ///
typedef cudaError_t (*cudaEventDestroy_t)(cudaEvent_t event);
static cudaEventDestroy_t native_cudaEventDestroy = NULL;
extern "C" cudaError_t cudaEventDestroy (cudaEvent_t event) {
printf("\n>>cudaEventDestroy interception\n");
if (native_cudaEventDestroy == NULL) {
native_cudaEventDestroy = (cudaEventDestroy_t)dlsym(RTLD_NEXT,"cudaEventDestroy");
}
assert(native_cudaEventDestroy != NULL);
return native_cudaEventDestroy(event);
}
/// cudaEventElapsedTime ///
typedef cudaError_t (*cudaEventElapsedTime_t)(float * ms, cudaEvent_t start, cudaEvent_t end);
static cudaEventElapsedTime_t native_cudaEventElapsedTime = NULL;
extern "C" cudaError_t cudaEventElapsedTime (float * ms, cudaEvent_t start,cudaEvent_t end) {
printf("\n>>cudaEventElapsedTime interception\n");
if (native_cudaEventElapsedTime == NULL) {
native_cudaEventElapsedTime = (cudaEventElapsedTime_t)dlsym(RTLD_NEXT,"cudaEventElapsedTime");
}
assert(native_cudaEventElapsedTime != NULL);
return native_cudaEventElapsedTime(ms,start,end);
}
/// cudaEventQuery ///
typedef cudaError_t (*cudaEventQuery_t)(cudaEvent_t event);
static cudaEventQuery_t native_cudaEventQuery = NULL;
extern "C" cudaError_t cudaEventQuery (cudaEvent_t event) {
printf("\n>>cudaEventQuery interception\n");
if (native_cudaEventQuery == NULL) {
native_cudaEventQuery = (cudaEventQuery_t)dlsym(RTLD_NEXT,"cudaEventQuery");
}
assert(native_cudaEventQuery != NULL);
return native_cudaEventQuery(event);
}
/// cudaEventRecord ///
typedef cudaError_t (*cudaEventRecord_t)(cudaEvent_t event, cudaStream_t stream);
static cudaEventRecord_t native_cudaEventRecord = NULL;
extern "C" cudaError_t cudaEventRecord(cudaEvent_t event, cudaStream_t stream) {
printf("\n>>cudaEventRecord interception\n");
if (native_cudaEventRecord == NULL) {
native_cudaEventRecord = (cudaEventRecord_t)dlsym(RTLD_NEXT,"cudaEventRecord");
}
assert(native_cudaEventRecord != NULL);
return native_cudaEventRecord(event,stream);
}
/// cudaEventSynchronize ///
typedef cudaError_t (*cudaEventSynchronize_t)(cudaEvent_t event);
static cudaEventSynchronize_t native_cudaEventSynchronize = NULL;
extern "C" cudaError_t cudaEventSynchronize (cudaEvent_t event) {
printf("\n>>cudaEventSynchronize interception\n");
if (native_cudaEventSynchronize == NULL) {
native_cudaEventSynchronize = (cudaEventSynchronize_t)dlsym(RTLD_NEXT,"cudaEventSynchronize");
}
assert(native_cudaEventSynchronize != NULL);
return native_cudaEventSynchronize(event);
}
//**********************************************//
// CUDA Runtime API Execution Control //
//**********************************************//
// cudaConfigureCall ///
typedef cudaError_t (*cudaConfigureCall_t)(dim3,dim3,size_t,cudaStream_t);
static cudaConfigureCall_t native_CudaConfigureCall = NULL;
extern "C" cudaError_t cudaConfigureCall(dim3 gridDim, dim3 blockDim, size_t sharedMem=0, cudaStream_t stream=0) {
assert(kernelInfo().counter == 0);
kernelInfo().gridDim = gridDim;
kernelInfo().blockDim = blockDim;
//kernelInfo().counter++; //increase a counter to indicate an expected cudaLaunch to be completed
printf("\n>>cudaConfigureCall interception\n");
//call of the real function
if (native_CudaConfigureCall == NULL)
native_CudaConfigureCall = (cudaConfigureCall_t)dlsym(RTLD_NEXT,"cudaConfigureCall");
assert(native_CudaConfigureCall != NULL);
return native_CudaConfigureCall(gridDim,blockDim,sharedMem,stream);
}
/// cudaFuncGetAttributes ///
typedef cudaError_t (*cudaFuncGetAttributes_t)(struct cudaFuncAttributes * attr, const char * func);
static cudaFuncGetAttributes_t native_cudaFuncGetAttributes = NULL;
extern "C" cudaError_t cudaFuncGetAttributes (struct cudaFuncAttributes * attr, const char * func) {
printf("\n>>cudaFuncGetAttributes interception\n");
if (native_cudaFuncGetAttributes == NULL) {
native_cudaFuncGetAttributes = (cudaFuncGetAttributes_t)dlsym(RTLD_NEXT,"cudaFuncGetAttributes");
}
assert(native_cudaFuncGetAttributes != NULL);
return native_cudaFuncGetAttributes(attr,func);
}
/// cudaFuncSetAttribute ///
typedef cudaError_t (*cudaFuncSetAttribute_t)(const void* func, cudaFuncAttribute attr, int value);
static cudaFuncSetAttribute_t native_cudaFuncSetAttribute = NULL;
extern "C" cudaError_t cudaFuncSetAttribute (const void* func, cudaFuncAttribute attr, int value) {
printf("\n>>cudaFuncSetAttribute interception\n");
if (native_cudaFuncSetAttribute == NULL) {
native_cudaFuncSetAttribute = (cudaFuncSetAttribute_t)dlsym(RTLD_NEXT,"cudaFuncSetAttribute");
}
assert(native_cudaFuncSetAttribute != NULL);
return native_cudaFuncSetAttribute(func,attr,value);
}
/// cudaLaunch ///
typedef cudaError_t (*cudaLaunch_t)(const char* entry);
static cudaLaunch_t native_cudaLaunch = NULL;
extern "C" cudaError_t cudaLaunch( const char* entry){
//print_kernel_invocation(entry);
//kernelInfo().counter--;
printf("\n>>cudaLaunch interception\n");
//call of the real function
if (native_cudaLaunch == NULL) {
native_cudaLaunch = (cudaLaunch_t)dlsym(RTLD_NEXT,"cudaLaunch");
}
assert(native_cudaLaunch != NULL);
return native_cudaLaunch(entry);
}
/// cudaFuncSetCacheConfig ///
typedef cudaError_t (*cudaFuncSetCacheConfig_t)(const void* func, cudaFuncCache cacheConfig);
static cudaFuncSetCacheConfig_t native_cudaFuncSetCacheConfig = NULL;
extern "C" cudaError_t cudaFuncSetCacheConfig (const void* func, cudaFuncCache cacheConfig) {
printf("\n>>cudaFuncSetCacheConfig interception\n");
if (native_cudaFuncSetCacheConfig == NULL) {
native_cudaFuncSetCacheConfig = (cudaFuncSetCacheConfig_t)dlsym(RTLD_NEXT,"cudaFuncSetCacheConfig");
}
assert(native_cudaFuncSetCacheConfig != NULL);
return native_cudaFuncSetCacheConfig(func,cacheConfig);
}
/// cudaFuncSetSharedMemConfig ///
typedef cudaError_t (*cudaFuncSetSharedMemConfig_t)(const void* func, cudaSharedMemConfig config);
static cudaFuncSetSharedMemConfig_t native_cudaFuncSetSharedMemConfig = NULL;
extern "C" cudaError_t cudaFuncSetSharedMemConfig (const void* func, cudaSharedMemConfig config) {
printf("\n>>cudaFuncSetSharedMemConfig interception\n");
if (native_cudaFuncSetSharedMemConfig == NULL) {
native_cudaFuncSetSharedMemConfig = (cudaFuncSetSharedMemConfig_t)dlsym(RTLD_NEXT,"cudaFuncSetSharedMemConfig");
}
assert(native_cudaFuncSetSharedMemConfig != NULL);
return native_cudaFuncSetSharedMemConfig(func,config);
}
/// cudaGetParameterBuffer ///
typedef cudaError_t (*cudaGetParameterBuffer_t)(size_t alignment, size_t size);
static cudaGetParameterBuffer_t native_cudaGetParameterBuffer = NULL;
extern "C" cudaError_t cudaGetParameterBuffer (size_t alignment, size_t size) {
printf("\n>>cudaGetParameterBuffer interception\n");
if (native_cudaGetParameterBuffer == NULL) {
native_cudaGetParameterBuffer = (cudaGetParameterBuffer_t)dlsym(RTLD_NEXT,"cudaGetParameterBuffer");
}
assert(native_cudaGetParameterBuffer != NULL);
return native_cudaGetParameterBuffer(alignment,size);
}
/// cudaGetParameterBufferV2 ///
typedef cudaError_t (*cudaGetParameterBufferV2_t)(void* func, dim3 gridDimension, dim3 blockDimension, unsigned int sharedMemSize);
static cudaGetParameterBufferV2_t native_cudaGetParameterBufferV2 = NULL;
extern "C" cudaError_t cudaGetParameterBufferV2 (void* func, dim3 gridDimension, dim3 blockDimension, unsigned int sharedMemSize) {
printf("\n>>cudaGetParameterBufferV2 interception\n");
if (native_cudaGetParameterBufferV2 == NULL) {
native_cudaGetParameterBufferV2 = (cudaGetParameterBufferV2_t)dlsym(RTLD_NEXT,"cudaGetParameterBufferV2");
}
assert(native_cudaGetParameterBufferV2 != NULL);
return native_cudaGetParameterBufferV2(func,gridDimension,blockDimension,sharedMemSize);
}
/// cudaLaunchCooperativeKernel ///
typedef cudaError_t (*cudaLaunchCooperativeKernel_t)(const void* func, dim3 gridDim, dim3 blockDim, void** args, size_t sharedMem, cudaStream_t stream);
static cudaLaunchCooperativeKernel_t native_cudaLaunchCooperativeKernel = NULL;
extern "C" cudaError_t cudaLaunchCooperativeKernel(const void* func, dim3 gridDim, dim3 blockDim, void** args, size_t sharedMem, cudaStream_t stream) {
printf("\n>>cudaLaunchCooperativeKernel interception\n");
if (native_cudaLaunchCooperativeKernel == NULL) {
native_cudaLaunchCooperativeKernel = (cudaLaunchCooperativeKernel_t)dlsym(RTLD_NEXT,"cudaLaunchCooperativeKernel");
}
assert(native_cudaLaunchCooperativeKernel != NULL);
return native_cudaLaunchCooperativeKernel(func,gridDim,blockDim,args,sharedMem,stream);
}
/// cudaLaunchCooperativeKernelMultiDevice ///
typedef cudaError_t (*cudaLaunchCooperativeKernelMultiDevice_t)(cudaLaunchParams* launchParamsList, unsigned int numDevices, unsigned int flags);
static cudaLaunchCooperativeKernelMultiDevice_t native_cudaLaunchCooperativeKernelMultiDevice = NULL;
extern "C" cudaError_t cudaLaunchCooperativeKernelMultiDevice (cudaLaunchParams* launchParamsList, unsigned int numDevices, unsigned int flags) {
printf("\n>>cudaLaunchCooperativeKernelMultiDevice interception\n");
if (native_cudaLaunchCooperativeKernelMultiDevice == NULL) {
native_cudaLaunchCooperativeKernelMultiDevice = (cudaLaunchCooperativeKernelMultiDevice_t)dlsym(RTLD_NEXT,"cudaLaunchCooperativeKernelMultiDevice");
}
assert(native_cudaLaunchCooperativeKernelMultiDevice != NULL);
return native_cudaLaunchCooperativeKernelMultiDevice(launchParamsList,numDevices,flags);
}
/// cudaLaunchKernel ///
typedef cudaError_t (*cudaLaunchKernel_t)(const void* func, dim3 gridDim, dim3 blockDim, void** args, size_t sharedMem, cudaStream_t stream);
static cudaLaunchKernel_t native_cudaLaunchKernel = NULL;
extern "C" cudaError_t cudaLaunchKernel (const void* func, dim3 gridDim, dim3 blockDim, void** args, size_t sharedMem, cudaStream_t stream) {
printf("\n>>cudaLaunchKernel interception\n");
if (native_cudaLaunchKernel == NULL) {
native_cudaLaunchKernel = (cudaLaunchKernel_t)dlsym(RTLD_NEXT,"cudaLaunchKernel");
}
assert(native_cudaLaunchKernel != NULL);
return native_cudaLaunchKernel(func,gridDim,blockDim,args,sharedMem,stream);
}
/// cudaSetDoubleForDevice ///
typedef cudaError_t (*cudaSetDoubleForDevice_t)(double *d);
static cudaSetDoubleForDevice_t native_cudaSetDoubleForDevice = NULL;
extern "C" cudaError_t cudaSetDoubleForDevice (double *d) {
printf("\n>>cudaSetDoubleForDevice interception\n");
if (native_cudaSetDoubleForDevice == NULL) {
native_cudaSetDoubleForDevice = (cudaSetDoubleForDevice_t)dlsym(RTLD_NEXT,"cudaSetDoubleForDevice");
}
assert(native_cudaSetDoubleForDevice != NULL);
return native_cudaSetDoubleForDevice(d);
}
/// cudaSetDoubleForHost ///
typedef cudaError_t (*cudaSetDoubleForHost_t)(double *d);
static cudaSetDoubleForHost_t native_cudaSetDoubleForHost = NULL;
extern "C" cudaError_t cudaSetDoubleForHost (double *d) {
printf("\n>>cudaSetDoubleForHost interception\n");
if (native_cudaSetDoubleForHost == NULL) {
native_cudaSetDoubleForHost = (cudaSetDoubleForHost_t)dlsym(RTLD_NEXT,"cudaSetDoubleForHost");
}
assert(native_cudaSetDoubleForHost != NULL);
return native_cudaSetDoubleForHost(d);
}
/* cudaSetupArgument ///
typedef cudaError_t (*cudaSetupArgument_t)(const void *, size_t, size_t);
static cudaSetupArgument_t native_CudaSetupArgument = NULL;
extern "C" cudaError_t cudaSetupArgument(const void *arg, size_t size, size_t offset) {
kernelInfo().arguments.push_back(const_cast<void *>(arg));
//call of the real function
if (native_CudaSetupArgument == NULL) {
native_CudaSetupArgument = (cudaSetupArgument_t)dlsym(RTLD_NEXT,"cudaSetupArgument");
}
assert(native_CudaSetupArgument != NULL);
return native_CudaSetupArgument(arg, size, offset);
}
*/
//**********************************************//
// CUDA Runtime API Memory Management //
//**********************************************//
/// cudaFree ///