[backend]更新脚本和库以支持性能测试用例
This commit is contained in:
113
testdata/performance/h-11-03.sy
vendored
Normal file
113
testdata/performance/h-11-03.sy
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
int n = 100;
|
||||
int ks = 15;
|
||||
int ps = 4;
|
||||
float input[2000][2000];
|
||||
float kernel[15][15];
|
||||
float conv_output[2000][2000];
|
||||
float pooling_output[493][493];
|
||||
|
||||
float max(float a, float b) {
|
||||
if (a > b) {
|
||||
return a;
|
||||
} else {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
float exp(float x) {
|
||||
return 1 + x + (x*x)/2 + (x*x*x)/6 + (x*x*x*x)/24;
|
||||
}
|
||||
|
||||
float sigmoid(float x) {
|
||||
return 1 / (1 + exp(-x));
|
||||
}
|
||||
|
||||
void kernel_conv_pooling(float A[][2000], float B[][2000], float C[][493], float kernel[][15], int n, int ks, int ps) {
|
||||
int i, j, k, l;
|
||||
float v;
|
||||
i = 0;
|
||||
while (i < n - ks + 1) {
|
||||
j = 0;
|
||||
while (j < n - ks + 1) {
|
||||
v = 0;
|
||||
k = 0;
|
||||
while (k < ks) {
|
||||
l = 0;
|
||||
while (l < ks) {
|
||||
v =v+ A[i + k][j + l] * kernel[k][l];
|
||||
l =l+ 1;
|
||||
}
|
||||
k =k+ 1;
|
||||
}
|
||||
B[i][j] = v;
|
||||
j =j+ 1;
|
||||
}
|
||||
i =i+ 1;
|
||||
}
|
||||
n = n - ks + 1;
|
||||
i = 0;
|
||||
while (i < n - ks + 1) {
|
||||
j = 0;
|
||||
while (j < n - ks + 1) {
|
||||
v = 0;
|
||||
k = 0;
|
||||
while (k < ks) {
|
||||
l = 0;
|
||||
while (l < ks) {
|
||||
v =v+ B[i + k][j + l] * kernel[k][l];
|
||||
l =l+ 1;
|
||||
}
|
||||
k =k+ 1;
|
||||
}
|
||||
A[i][j] = v;
|
||||
j =j+ 1;
|
||||
}
|
||||
i =i+ 1;
|
||||
}
|
||||
|
||||
n = (n - ks + 1) / ps;
|
||||
i = 0;
|
||||
while (i < n) {
|
||||
j = 0;
|
||||
while (j < n) {
|
||||
v = A[i * ps][j * ps];
|
||||
k = 0;
|
||||
while (k < ps) {
|
||||
l = 0;
|
||||
while (l < ps) {
|
||||
v = max(v, A[i * ps + k][j * ps + l]);
|
||||
l =l+ 1;
|
||||
}
|
||||
k =k+ 1;
|
||||
}
|
||||
C[i][j] = v;
|
||||
j =j+ 1;
|
||||
}
|
||||
i =i+ 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n) {
|
||||
v = 0;
|
||||
j = 0;
|
||||
while (j < n) {
|
||||
C[i][j] = C[i][j] * sigmoid(C[i][j]);
|
||||
j =j+ 1;
|
||||
}
|
||||
i =i+ 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int os = (n - 2 * ks + 2) / ps;
|
||||
getfarray(input);
|
||||
getfarray(kernel);
|
||||
|
||||
starttime();
|
||||
kernel_conv_pooling(input, conv_output, pooling_output, kernel, n, ks, ps);
|
||||
stoptime();
|
||||
|
||||
putfarray(os*os, pooling_output);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user