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

Function ecall_matmul

sgx_tf_ops/Enclave/Enclave.cpp:6527–6585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6525
6526
6527void ecall_matmul(float *input,float* weight,int N,int M,int C,float *output){
6528 float *x = (float*)malloc(sizeof(float)*N*M);
6529 memset(x, 0, sizeof(float)*N*M);
6530 for(int j=0;j<N*M;j++){
6531 x[j] = 0.0f;
6532 float sum = input[insert*N*M+j];
6533 float c = 0.0f;
6534 for(int i=0;i<Nt;i++){
6535 float y = input[indexs[i]*N*M+j] - c;
6536 float t = sum + y;
6537 c = (t - sum) - y;
6538 sum = t;
6539 }
6540 x[j] = sum;
6541 }
6542 float *z = (float*)malloc(sizeof(float)*N*C);
6543 memset(z, 0, sizeof(float)*N*C);
6544 for (int i = 0; i < N; i++){
6545 for (int j = 0; j < C; j++){
6546 z[i*C+j] = 0.0f;
6547 for(int k=0;k<M; k++){
6548 z[i*C+j] += x[i*M+k]*weight[k*C+j];
6549 }
6550 }
6551 }
6552 float mean = 0.0f, std, mean_sqr = 0.0f;
6553 float c_mean = 0.0f, c_mean_sqr = 0.0f;
6554 for (int j = 0; j < N*C; j++) {
6555 float y = (z[j]/static_cast<float>(N*C)) - c_mean;
6556 float t = mean + y;
6557 c_mean = (t - mean) - y;
6558 mean = t;
6559
6560 float y2 = (z[j]*z[j]/static_cast<float>(N*C)) - c_mean_sqr;
6561 float t2 = mean_sqr + y2;
6562 c_mean_sqr = (t2 - mean_sqr) - y2;
6563 mean_sqr = t2;
6564 }
6565 std = sqrtf(fabs(mean_sqr - mean * mean))/static_cast<float>(Nt);
6566 mean = mean/static_cast<float>(Nt);
6567 for(int i=0;i<N*C*(Ne-1);i++){
6568 output[i] =(z[i%(N*C)] - gaussrand(mean, std))/static_cast<float>(Nt+1);
6569 }
6570 for(int j=N*C*(Ne-1);j<N*C*Ne;j++){
6571 output[j] = 0.0f;
6572 float sum = 0.0f;
6573 float c = 0.0f;
6574 for(int i=0;i<Nt;i++){
6575 float y = -1.0f * output[indexs[i]*N*C+(j-N*C*(Ne-1))] - c;
6576 float t = sum + y;
6577 c = (t - sum) - y;
6578 sum = t;
6579 }
6580 output[j] =z[j-N*C*(Ne-1)] + sum;
6581 }
6582 free(x);
6583 free(z);
6584 return;

Callers 1

matmul2dFunction · 0.85

Calls 1

gaussrandFunction · 0.85

Tested by

no test coverage detected