-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixMult.cl
More file actions
133 lines (103 loc) · 2.93 KB
/
MatrixMult.cl
File metadata and controls
133 lines (103 loc) · 2.93 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
__kernel void MatrixMult(__global const float* a, __global const float* b, __global float* c, int Aw, int Ah, int Bw, int Bh)
{
// Получаем индекс в массиве
int iGID = get_global_id(0);
int y = iGID / Bw;
int x = iGID - y * Bw;
// Проверяем, не вылезли ли за пределы массива
if (iGID >= Bw * Ah)
{
return;
}
float sum = 0;
for (int i = 0; i < Aw; i++)
{
sum += a[i + Aw * y] * b[i * Bw + x];
}
c[iGID] = sum;
}
__kernel void MatrixInsert(__global const float* a, __global const float* b, __global float* c, int Aw, int Ah, int Bw, int Bh, int start_w, int start_h)
{
// Получаем индекс в массиве
int iGID = get_global_id(0);
int y = iGID / Aw;
int x = iGID - y * Aw;
// Проверяем, не вылезли ли за пределы массива
if (iGID >= Aw * Ah)
{
return;
}
if (x >= start_w && x < start_w + Bw && y >= start_h && y < start_h + Bh)
c[iGID] = b[(y - start_h) * Bw + (x - start_w)];
else
c[iGID] = a[y * Aw + x];
}
__kernel void MatrixTranspose(__global const float* a, __global float* c, int Aw, int Ah)
{
// Получаем индекс в массиве
int iGID = get_global_id(0);
int y = iGID / Aw;
int x = iGID - y * Aw;
// Проверяем, не вылезли ли за пределы массива
if (iGID >= Aw * Ah)
{
return;
}
c[x * Ah + y] = a[iGID];
}
__kernel void MatrixElMult(__global const float* a, __global const float* b, __global float* c, int Aw, int Ah, int Bw, int Bh)
{
int iGID = get_global_id(0);
if (iGID >= Aw * Ah)
{
return;
}
c[iGID] = a[iGID] * b[iGID];
}
__kernel void MatrixSum(__global const float* a, __global const float* b, __global float* c, int Aw, int Ah, int Bw, int Bh)
{
int iGID = get_global_id(0);
if (iGID >= Aw * Ah)
{
return;
}
c[iGID] = a[iGID] + b[iGID];
}
__kernel void MatrixNumMult(__global const float* a, __global float* c, int Aw, int Ah, float num)
{
int iGID = get_global_id(0);
if (iGID >= Aw * Ah)
{
return;
}
c[iGID] = a[iGID] * num;
}
__kernel void MatrixNumSum(__global const float* a, __global float* c, int Aw, int Ah, int num)
{
int iGID = get_global_id(0);
if (iGID >= Aw * Ah)
{
return;
}
c[iGID] = a[iGID] + num;
}
__kernel void MatrixInvert(__global const float* a, __global float* c, int Aw, int Ah, int num)
{
int iGID = get_global_id(0);
if (iGID >= Aw * Ah)
{
return;
}
c[iGID] = 1 / a[iGID];
}
__kernel void MatrixAbs(__global const float* a, __global float* c, int Aw, int Ah)
{
int iGID = get_global_id(0);
if (iGID >= Aw * Ah)
{
return;
}
if (a[iGID] < 0)
c[iGID] = -a[iGID];
else c[iGID] = a[iGID];
}