| 342 | } |
| 343 | |
| 344 | void ecall_logloss(float *input,int N,int M,int C,float *label,float *weight,float *output){ |
| 345 | float *x = (float*)malloc(sizeof(float)*N); |
| 346 | memset(x, 0, sizeof(float)*N); |
| 347 | for(int j=0;j<N;j++){ |
| 348 | x[j] = 0.0f; |
| 349 | float sum = input[insert*N+j]; |
| 350 | float c = 0.0f; |
| 351 | for(int i=0;i<Nt;i++){ |
| 352 | float y = input[indexs[i]*N+j] - c; |
| 353 | float t = sum + y; |
| 354 | c = (t - sum) - y; |
| 355 | sum = t; |
| 356 | } |
| 357 | x[j] = sum; |
| 358 | } |
| 359 | output[0] = 0.0f; |
| 360 | float epsilon = 1e-7f; |
| 361 | for (int i = 0; i < M; i++ ){ |
| 362 | for (int j = 0; j< C;j++){ |
| 363 | output[0] = output[0] - ((label[i*C+j] * logf(x[i*C+j] + epsilon) ) + (1 - label[i*C+j]) * logf(1 - x[i*C+j] + epsilon))* weight[i]; |
| 364 | } |
| 365 | } |
| 366 | free(x); |
| 367 | return; |
| 368 | } |
| 369 | |
| 370 | void ecall_relu_grad(float *input,float *grad,int N,float *output){ |
| 371 | float *x = (float*)malloc(sizeof(float)*N); |