| 229 | } |
| 230 | |
| 231 | void ecall_relu(float *input,int N,float *output){ |
| 232 | float *x = (float*)malloc(sizeof(float)*N); |
| 233 | memset(x, 0, sizeof(float)*N); |
| 234 | for(int j=0;j<N;j++){ |
| 235 | x[j] = 0.0f; |
| 236 | float sum = input[insert*N+j]; |
| 237 | float c = 0.0f; |
| 238 | for(int i=0;i<Nt;i++){ |
| 239 | float y = input[indexs[i]*N+j] - c; |
| 240 | float t = sum + y; |
| 241 | c = (t - sum) - y; |
| 242 | sum = t; |
| 243 | } |
| 244 | x[j] = sum; |
| 245 | } |
| 246 | |
| 247 | for (int j = 0; j < N; j++) { |
| 248 | x[j]= x[j] >= 1e-7f ? x[j] : 0.0f; |
| 249 | } |
| 250 | |
| 251 | float mean = 0.0f, std, mean_sqr = 0.0f; |
| 252 | float c_mean = 0.0f, c_mean_sqr = 0.0f; |
| 253 | |
| 254 | for (int j = 0; j < N; j++) { |
| 255 | float y = (x[j]/static_cast<float>(N)) - c_mean; |
| 256 | float t = mean + y; |
| 257 | c_mean = (t - mean) - y; |
| 258 | mean = t; |
| 259 | |
| 260 | float y2 = (x[j]*x[j]/static_cast<float>(N)) - c_mean_sqr; |
| 261 | float t2 = mean_sqr + y2; |
| 262 | c_mean_sqr = (t2 - mean_sqr) - y2; |
| 263 | mean_sqr = t2; |
| 264 | } |
| 265 | std = sqrtf(mean_sqr - mean * mean)/static_cast<float>(Nt); |
| 266 | mean = mean/static_cast<float>(Nt); |
| 267 | for(int i=0;i<N*(Ne-1);i++){ |
| 268 | output[i] =(x[i%N] - gaussrand(mean, std))/static_cast<float>(Nt+1); |
| 269 | } |
| 270 | for(int j=N*(Ne-1);j<N*Ne;j++){ |
| 271 | output[j] = 0.0f; |
| 272 | float sum = 0.0f; |
| 273 | float c = 0.0f; |
| 274 | for(int i=0;i<Nt;i++){ |
| 275 | float y = -1.0f * output[indexs[i]*N+(j-N*(Ne-1))] - c; |
| 276 | float t = sum + y; |
| 277 | c = (t - sum) - y; |
| 278 | sum = t; |
| 279 | } |
| 280 | output[j] =x[j-N*(Ne-1)] + sum; |
| 281 | if(output[j]<1e-6 && output[j]>-1e-6){ |
| 282 | output[j]= 0.0f; |
| 283 | } |
| 284 | } |
| 285 | free(x); |
| 286 | return; |
| 287 | } |
| 288 | |