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

Function ecall_matadd

sgx_tf_ops/Enclave/Enclave.cpp:4850–4901  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4848
4849
4850void ecall_matadd(float* input1,float* input2,int N,int C,float* output){
4851 float *x = (float*)malloc(sizeof(float)*N);
4852 memset(x, 0, sizeof(float)*N);
4853 for(int j=0;j<N;j++){
4854 x[j] = 0.0f;
4855 float sum = input1[insert*N+j];
4856 float c = 0.0f;
4857 for(int i=0;i<Nt;i++){
4858 float y = input1[indexs[i]*N+j] - c;
4859 float t = sum + y;
4860 c = (t - sum) - y;
4861 sum = t;
4862 }
4863 x[j] = sum;
4864 }
4865 for (int j = 0; j < N; j++) {
4866 x[j]= x[j] + input2[j%C];
4867}
4868float mean = 0.0f, std, mean_sqr = 0.0f;
4869 float c_mean = 0.0f, c_mean_sqr = 0.0f;
4870
4871 for (int j = 0; j < N; j++) {
4872 float y = (x[j] /static_cast<float>(N)) - c_mean;
4873 float t = mean + y;
4874 c_mean = (t - mean) - y;
4875 mean = t;
4876
4877 float y2 = (x[j]*x[j]/static_cast<float>(N)) - c_mean_sqr;
4878 float t2 = mean_sqr + y2;
4879 c_mean_sqr = (t2 - mean_sqr) - y2;
4880 mean_sqr = t2;
4881 }
4882 std = sqrtf(fabs(mean_sqr - mean * mean))/static_cast<float>(Nt);
4883 mean = mean/static_cast<float>(Nt);
4884 for(int i=0;i<N*(Ne-1);i++){
4885 output[i] =(x[i%N] - gaussrand(mean, std))/static_cast<float>(Nt+1);
4886 }
4887 for(int j=N*(Ne-1);j<N*Ne;j++){
4888 output[j] = 0.0f;
4889 float sum = 0.0f;
4890 float c = 0.0f;
4891 for(int i=0;i<Nt;i++){
4892 float y = -1.0f * output[indexs[i]*N+(j-N*(Ne-1))] - c;
4893 float t = sum + y;
4894 c = (t - sum) - y;
4895 sum = t;
4896 }
4897 output[j] =x[j-N*(Ne-1)] + sum;
4898 }
4899 free(x);
4900 return;
4901}
4902
4903void ecall_matadd_grad(float* input1,float* input2,float* grad,int N,int C,float* output1,float* output2){
4904 float *g = (float*)malloc(sizeof(float)*N);

Callers 1

mataddFunction · 0.85

Calls 1

gaussrandFunction · 0.85

Tested by

no test coverage detected