MCPcopy Create free account
hub / github.com/conflow-dev/ConFlow / ecall_reducemax_one

Function ecall_reducemax_one

sgx_tf_ops/Enclave/Enclave.cpp:2571–2634  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2569}
2570
2571void ecall_reducemax_one(float *input,int N,int M,int C,int L,float *output){
2572 float *x = (float*)malloc(sizeof(float)*N);
2573 memset(x, 0, sizeof(float)*N);
2574 for(int j=0;j<N;j++){
2575 x[j] = 0.0f;
2576 float sum = input[insert*N+j];
2577 float c = 0.0f;
2578 for(int i=0;i<Nt;i++){
2579 float y = input[indexs[i]*N+j] - c;
2580 float t = sum + y;
2581 c = (t - sum) - y;
2582 sum = t;
2583 }
2584 x[j] = sum;
2585
2586 }
2587 float *x1 = (float*)malloc(sizeof(float)*M*L);
2588 memset(x1, 0, sizeof(float)*M*L);
2589
2590 for (int i = 0; i < M; i++) {
2591 for (int j = 0; j < L; j++) {
2592 float max_val = x[i*C*L+j];
2593 for (int k = 1; k < C; k++) {
2594 max_val = fmaxf(max_val, x[i*C*L+j+k*L]);
2595 }
2596 x1[i*L+j] = max_val;
2597 }
2598 }
2599
2600 float mean = 0.0f, std, mean_sqr = 0.0f;
2601 float c_mean = 0.0f, c_mean_sqr = 0.0f;
2602
2603 for (int j = 0; j < M*L; j++) {
2604 float y = (x1[j]/static_cast<float>(M*L)) - c_mean;
2605 float t = mean + y;
2606 c_mean = (t - mean) - y;
2607 mean = t;
2608
2609 float y2 = (x1[j]*x1[j]/static_cast<float>(M*L)) - c_mean_sqr;
2610 float t2 = mean_sqr + y2;
2611 c_mean_sqr = (t2 - mean_sqr) - y2;
2612 mean_sqr = t2;
2613 }
2614 std = sqrtf(mean_sqr - mean * mean)/static_cast<float>(Nt);
2615 mean = mean/static_cast<float>(Nt);
2616 for(int i=0;i<M*L*(Ne-1);i++){
2617 output[i] =(x1[i%(M*L)] - gaussrand(mean, std))/static_cast<float>(Nt+1);
2618 }
2619 for(int j=M*L*(Ne-1);j<M*L*Ne;j++){
2620 output[j] = 0.0f;
2621 float sum = 0.0f;
2622 float c = 0.0f;
2623 for(int i=0;i<Nt;i++){
2624 float y = -1.0f * output[indexs[i]*M*L+(j-M*L*(Ne-1))] - c;
2625 float t = sum + y;
2626 c = (t - sum) - y;
2627 sum = t;
2628 }

Callers 1

reducemax_oneFunction · 0.85

Calls 1

gaussrandFunction · 0.85

Tested by

no test coverage detected