-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinjectionKernel.cpp
More file actions
104 lines (82 loc) · 2.36 KB
/
injectionKernel.cpp
File metadata and controls
104 lines (82 loc) · 2.36 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
#define _GNU_SOURCE
#include <dlfcn.h>
#include <stdio.h>
/* ===== DRIVER API TYPES ===== */
typedef int CUresult;
typedef void* CUfunction;
typedef void* CUstream;
/* ===== RUNTIME API TYPES ===== */
typedef int cudaError_t;
typedef void* cudaStream_t;
/* ===============================
INTERCEPT cudaLaunchKernel
=============================== */
struct dim3 {
unsigned int x;
unsigned int y;
unsigned int z;
};
extern "C"
cudaError_t cudaLaunchKernel(
const void* func,
dim3 gridDim,
dim3 blockDim,
void** args,
size_t sharedMem,
cudaStream_t stream)
{
typedef cudaError_t (*real_t)(
const void*, dim3, dim3, void**, size_t, cudaStream_t);
static real_t real_func = nullptr;
if (!real_func)
real_func = (real_t)dlsym(RTLD_NEXT, "cudaLaunchKernel");
printf("🔥 RUNTIME kernel launch intercepted\n");
return real_func(func, gridDim, blockDim, args, sharedMem, stream);
}
/* ===============================
INTERCEPT cuLaunchKernel
=============================== */
extern "C"
CUresult cuLaunchKernel(
CUfunction f,
unsigned int gridDimX,
unsigned int gridDimY,
unsigned int gridDimZ,
unsigned int blockDimX,
unsigned int blockDimY,
unsigned int blockDimZ,
unsigned int sharedMemBytes,
CUstream hStream,
void **kernelParams,
void **extra)
{
typedef CUresult (*real_t)(
CUfunction,
unsigned int, unsigned int, unsigned int,
unsigned int, unsigned int, unsigned int,
unsigned int, CUstream, void**, void**);
static real_t real_func = nullptr;
if (!real_func)
real_func = (real_t)dlsym(RTLD_NEXT, "cuLaunchKernel");
printf("🔥 DRIVER kernel launch intercepted\n");
return real_func(f,
gridDimX, gridDimY, gridDimZ,
blockDimX, blockDimY, blockDimZ,
sharedMemBytes, hStream,
kernelParams, extra);
}
extern "C"
cudaError_t cudaLaunchKernel_ptsz(
const void* func,
dim3 gridDim,
dim3 blockDim,
void** args,
size_t sharedMem,
cudaStream_t stream)
{
static auto real_func =
(decltype(&cudaLaunchKernel_ptsz))
dlsym(RTLD_NEXT, "cudaLaunchKernel_ptsz");
printf("🔥 cudaLaunchKernel_ptsz intercepted\n");
return real_func(func, gridDim, blockDim, args, sharedMem, stream);
}