-
Notifications
You must be signed in to change notification settings - Fork 287
Expand file tree
/
Copy pathkernels.py
More file actions
159 lines (146 loc) · 2.83 KB
/
kernels.py
File metadata and controls
159 lines (146 loc) · 2.83 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
# SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
kernel_string = """\
#define ITEM_PARAM(x, T) T x
#define REP1(x, T) , ITEM_PARAM(x, T)
#define REP2(x, T) REP1(x##0, T) REP1(x##1, T)
#define REP4(x, T) REP2(x##0, T) REP2(x##1, T)
#define REP8(x, T) REP4(x##0, T) REP4(x##1, T)
#define REP16(x, T) REP8(x##0, T) REP8(x##1, T)
#define REP32(x, T) REP16(x##0, T) REP16(x##1, T)
#define REP64(x, T) REP32(x##0, T) REP32(x##1, T)
#define REP128(x, T) REP64(x##0, T) REP64(x##1, T)
#define REP256(x, T) REP128(x##0, T) REP128(x##1, T)
template<size_t maxBytes>
struct KernelFunctionParam
{
unsigned char p[maxBytes];
};
extern "C" __global__ void small_kernel(float *f)
{
*f = 0.0f;
}
extern "C" __global__ void empty_kernel()
{
return;
}
extern "C" __global__
void small_kernel_512_args(
ITEM_PARAM(F, int*)
REP1(A, int*)
REP2(A, int*)
REP4(A, int*)
REP8(A, int*)
REP16(A, int*)
REP32(A, int*)
REP64(A, int*)
REP128(A, int*)
REP256(A, int*))
{
*F = 0;
}
extern "C" __global__
void small_kernel_512_bools(
ITEM_PARAM(F, bool)
REP1(A, bool)
REP2(A, bool)
REP4(A, bool)
REP8(A, bool)
REP16(A, bool)
REP32(A, bool)
REP64(A, bool)
REP128(A, bool)
REP256(A, bool))
{
return;
}
extern "C" __global__
void small_kernel_512_ints(
ITEM_PARAM(F, int)
REP1(A, int)
REP2(A, int)
REP4(A, int)
REP8(A, int)
REP16(A, int)
REP32(A, int)
REP64(A, int)
REP128(A, int)
REP256(A, int))
{
return;
}
extern "C" __global__
void small_kernel_512_doubles(
ITEM_PARAM(F, double)
REP1(A, double)
REP2(A, double)
REP4(A, double)
REP8(A, double)
REP16(A, double)
REP32(A, double)
REP64(A, double)
REP128(A, double)
REP256(A, double))
{
return;
}
extern "C" __global__
void small_kernel_512_chars(
ITEM_PARAM(F, char)
REP1(A, char)
REP2(A, char)
REP4(A, char)
REP8(A, char)
REP16(A, char)
REP32(A, char)
REP64(A, char)
REP128(A, char)
REP256(A, char))
{
return;
}
extern "C" __global__
void small_kernel_512_longlongs(
ITEM_PARAM(F, long long)
REP1(A, long long)
REP2(A, long long)
REP4(A, long long)
REP8(A, long long)
REP16(A, long long)
REP32(A, long long)
REP64(A, long long)
REP128(A, long long)
REP256(A, long long))
{
return;
}
extern "C" __global__
void small_kernel_256_args(
ITEM_PARAM(F, int*)
REP1(A, int*)
REP2(A, int*)
REP4(A, int*)
REP8(A, int*)
REP16(A, int*)
REP32(A, int*)
REP64(A, int*)
REP128(A, int*))
{
*F = 0;
}
extern "C" __global__
void small_kernel_16_args(
ITEM_PARAM(F, int*)
REP1(A, int*)
REP2(A, int*)
REP4(A, int*)
REP8(A, int*))
{
*F = 0;
}
extern "C" __global__ void small_kernel_2048B(KernelFunctionParam<2048> param)
{
// Do not touch param to prevent compiler from copying
// the whole structure from const bank to lmem.
}
"""