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

Function ecall_batchnorm_grad

sgx_tf_ops/Enclave/Enclave.cpp:3863–4052  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3861
3862
3863void ecall_batchnorm_grad(float* input,float* grad,float* scale,float* offset,float* mean_x,float* variance, int N,int M,int H,int W, float* grad_in,float* grad_sc,float* grad_off,float* grad_mean,float* grad_var,float epsilon){
3864 float *x = (float*)malloc(sizeof(float)*N);
3865 memset(x, 0, sizeof(float)*N);
3866 for(int j=0;j<N;j++){
3867 x[j] = 0.0f;
3868 float sum = input[insert*N+j];
3869 float c = 0.0f;
3870 for(int i=0;i<Nt;i++){
3871 float y = input[indexs[i]*N+j] - c;
3872 float t = sum + y;
3873 c = (t - sum) - y;
3874 sum = t;
3875 }
3876 x[j] = sum;
3877 if(fabs(x[j])<1e-7f){
3878 x[j]= 0.0f;
3879 }
3880 }
3881
3882 float *g = (float*)malloc(sizeof(float)*N);
3883 memset(g, 0, sizeof(float)*N);
3884 for(int j=0;j<N;j++){
3885 g[j] = 0.0f;
3886 float sum = grad[insert*N+j];
3887 float c = 0.0f;
3888 for(int i=0;i<Nt;i++){
3889 float y = grad[indexs[i]*N+j] - c;
3890 float t = sum + y;
3891 c = (t - sum) - y;
3892 sum = t;
3893 }
3894 g[j] = sum;
3895 }
3896 float *mu = (float*)malloc(sizeof(float)*M*H);
3897 memset(mu, 0, sizeof(float)*M*H);
3898 for(int j=0;j<M*H;j++){
3899 mu[j] = 0.0f;
3900 float sum = mean_x[insert*M*H+j];
3901 float c = 0.0f;
3902 for(int i=0;i<Nt;i++){
3903 float y = mean_x[indexs[i]*M*H+j] - c;
3904 float t = sum + y;
3905 c = (t - sum) - y;
3906 sum = t;
3907 }
3908 mu[j] = sum;
3909 }
3910 float *sig = (float*)malloc(sizeof(float)*M*H);
3911 memset(sig, 0, sizeof(float)*M*H);
3912 for(int j=0;j<M*H;j++){
3913 sig[j] = 0.0f;
3914 float sum = variance[insert*M*H+j];
3915 float c = 0.0f;
3916 for(int i=0;i<Nt;i++){
3917 float y = variance[indexs[i]*M*H+j] - c;
3918 float t = sum + y;
3919 c = (t - sum) - y;
3920 sum = t;

Callers 1

batchnorm_gradFunction · 0.85

Calls 1

gaussrandFunction · 0.85

Tested by

no test coverage detected