This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utcc-hints.h
154 lines (132 loc) · 3.13 KB
/
utcc-hints.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
#include <assert.h>
void claimNonNegativeInt (int *in) {}
void claimNonNegativeUint (unsigned int *in) {}
void claimNonNegativeFP32 (float *in) {}
void claimNonNegativeFP64 (double *in) {}
struct NonNegativeXYZCoordinates {
unsigned int x;
unsigned int y;
unsigned int z;
};
struct float2 {
float x;
float y;
};
struct float4 {
float w;
float x;
float y;
float z;
};
struct uchar4 {
unsigned char w;
unsigned char x;
unsigned char y;
unsigned char z;
};
struct uint3 {
unsigned int x;
unsigned int y;
unsigned int z;
};
struct uint4 {
unsigned int w;
unsigned int x;
unsigned int y;
unsigned int z;
};
typedef struct NonNegativeXYZCoordinates NonNegativeXYZCoordinates;
typedef struct float2 float2;
typedef struct float4 float4;
typedef struct uchar4 uchar4;
typedef struct uint3 uint3;
typedef struct uint4 uint4;
typedef struct uint3 dim3;
// Since utcc is a static analysis, the actual values are not important
const struct NonNegativeXYZCoordinates gridDim = {0, 0, 0};
const struct NonNegativeXYZCoordinates blockDim = {0, 0, 0};
const struct NonNegativeXYZCoordinates blockIdx = {0, 0, 0};
const struct NonNegativeXYZCoordinates threadIdx = {0, 0, 0};
// some fake cuda math functions...
// since utcc is a static analysis... the following functions don't have the actual code.
// but it doesn't matter... for now
double ceil (double in) { return in; }
double floor (double in) { return in; }
double fabs (double in) { return in; }
double sqrt (double in) { return in; }
double exp (double in) { return in; }
// double length (double in) { return in; }
double min (double a, double b) { return (a >= b ? b : a); }
double max (double a, double b) { return (a >= b ? a : b); }
// some helper functions for float4
inline
float2 float2float2Add (float2 a2, float2 b2) {
float2 ret;
ret.x = a2.x + b2.x;
ret.y = a2.y + b2.y;
return ret;
}
inline
float2 float2float2Sub (float2 a2, float2 b2) {
float2 ret;
ret.x = a2.x - b2.x;
ret.y = a2.y - b2.y;
return ret;
}
inline
float2 float2scalarMul (float2 a2, float fp) {
float2 ret;
ret.x = a2.x * fp;
ret.y = a2.y * fp;
return ret;
}
// some helper functions for float4
inline
float4 float4float4Add (float4 a4, float4 b4) {
float4 ret4;
ret4.w = a4.w + b4.w;
ret4.x = a4.x + b4.x;
ret4.y = a4.y + b4.y;
ret4.z = a4.z + b4.z;
return ret4;
}
inline
float4 float4uchar4Add (float4 a4, uchar4 b4) {
float4 f4;
f4.w = b4.w;
f4.x = b4.x;
f4.y = b4.y;
f4.z = b4.z;
return float4float4Add(a4, f4);
}
inline
float4 float4float4Sub (float4 a4, float4 b4) {
float4 ret4;
ret4.w = a4.w - b4.w;
ret4.x = a4.x - b4.x;
ret4.y = a4.y - b4.y;
ret4.z = a4.z - b4.z;
return ret4;
}
inline
float4 float4scalarMul (float4 f4, float s) {
float4 ret4;
ret4.w = f4.w * s;
ret4.x = f4.x * s;
ret4.y = f4.y * s;
ret4.z = f4.z * s;
return ret4;
}
inline
float4 float4scalarDiv (float4 f4, float s) {
float4 ret4;
ret4.w = f4.w / s;
ret4.x = f4.x / s;
ret4.y = f4.y / s;
ret4.z = f4.z / s;
return ret4;
}
void
utcc_assert(int cond) {
assert(cond);
}