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

Function ecall_square_grad

sgx_tf_ops/Enclave/Enclave.cpp:1507–1577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1505 }
1506
1507void ecall_square_grad(float *input,float *grad,int N,float *output){
1508 float *x = (float*)malloc(sizeof(float)*N);
1509 memset(x, 0, sizeof(float)*N);
1510 for(int j=0;j<N;j++){
1511 x[j] = 0.0f;
1512 float sum = input[insert*N+j];
1513 float c = 0.0f;
1514 for(int i=0;i<Nt;i++){
1515 float y = input[indexs[i]*N+j] - c;
1516 float t = sum + y;
1517 c = (t - sum) - y;
1518 sum = t;
1519 }
1520 x[j] = sum;
1521
1522 }
1523
1524 float *g = (float*)malloc(sizeof(float)*N);
1525 memset(g, 0, sizeof(float)*N);
1526 for(int j=0;j<N;j++){
1527 g[j] = 0.0f;
1528 float sum = grad[insert*N+j];
1529 float c = 0.0f;
1530 for(int i=0;i<Nt;i++){
1531 float y = grad[indexs[i]*N+j] - c;
1532 float t = sum + y;
1533 c = (t - sum) - y;
1534 sum = t;
1535 }
1536 g[j] = sum;
1537 }
1538
1539 for (int j = 0; j < N; j++) {
1540 float tmp = 2.0f*x[j];
1541 g[j] = g[j]*tmp;
1542 }
1543
1544 float mean = 0.0f, std, mean_sqr = 0.0f;
1545 float c_mean = 0.0f, c_mean_sqr = 0.0f;
1546 for (int j = 0; j < N; j++) {
1547 float y = (g[j] /static_cast<float>(N)) - c_mean;
1548 float t = mean + y;
1549 c_mean = (t - mean) - y;
1550 mean = t;
1551
1552 float y2 = (g[j]*g[j]/static_cast<float>(N)) - c_mean_sqr;
1553 float t2 = mean_sqr + y2;
1554 c_mean_sqr = (t2 - mean_sqr) - y2;
1555 mean_sqr = t2;
1556 }
1557 std = sqrtf(mean_sqr - mean * mean)/static_cast<float>(Nt);
1558 mean = mean/static_cast<float>(Nt);
1559 for(int i=0;i<N*(Ne-1);i++){
1560 output[i] =(g[i%N] - gaussrand(mean, std))/static_cast<float>(Nt+1);
1561 }
1562 for(int j=N*(Ne-1);j<N*Ne;j++){
1563 output[j] = 0.0f;
1564 float sum = 0.0f;

Callers 1

square_gradFunction · 0.85

Calls 1

gaussrandFunction · 0.85

Tested by

no test coverage detected