-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmylib.h
More file actions
31 lines (25 loc) · 766 Bytes
/
mylib.h
File metadata and controls
31 lines (25 loc) · 766 Bytes
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
// Automatically uses CUDA's built-in variables
__device__
int getIndex1D() {
return threadIdx.x + blockIdx.x * blockDim.x;
}
__device__
int getIndex2D() {
int x = threadIdx.x + blockIdx.x * blockDim.x;
int y = threadIdx.y + blockIdx.y * blockDim.y;
int width = blockDim.x * gridDim.x;
return x + y * width;
}
__device__
int getIndex3D() {
int x = threadIdx.x + blockIdx.x * blockDim.x;
int y = threadIdx.y + blockIdx.y * blockDim.y;
int z = threadIdx.z + blockIdx.z * blockDim.z;
int width = blockDim.x * gridDim.x;
int height = blockDim.y * gridDim.y;
return x + y * width + z * width * height;
}
void fill(int *mat, int rows, int cols) {
for (int i = 0; i < rows * cols; ++i)
mat[i] = rand() % 100;
}