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

Class EnCryptGradOp

en_ops/encrypt.cc:137–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135REGISTER_KERNEL_BUILDER(Name("EnCrypt").Device(DEVICE_CPU), EnCryptOp);
136
137class EnCryptGradOp : public OpKernel
138{
139public:
140 explicit EnCryptGradOp(OpKernelConstruction *context) : OpKernel(context)
141 {
142 OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_));
143 OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_));
144 OP_REQUIRES_OK(context, context->GetAttr("times", &times_));
145 lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY);
146 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
147 }
148 void Compute(OpKernelContext *context) override
149 {
150
151 // get the input tensor
152 const Tensor &input = context->input(0);
153 auto input_flat = input.flat<float>();
154 // check shapes of input
155 const TensorShape &input_shape = input.shape();
156 TensorShape output_shape;
157 if (input_shape.dims() == 2)
158 {
159 output_shape.AddDim(input_shape.dim_size(0) / times_);
160 output_shape.AddDim(input_shape.dim_size(1));
161 }
162 else if (input_shape.dims() == 3)
163 {
164 output_shape.AddDim(input_shape.dim_size(0) / times_);
165 output_shape.AddDim(input_shape.dim_size(1));
166 output_shape.AddDim(input_shape.dim_size(2));
167 }
168 else
169 {
170 output_shape.AddDim(input_shape.dim_size(0) / times_);
171 output_shape.AddDim(input_shape.dim_size(1));
172 output_shape.AddDim(input_shape.dim_size(2));
173 output_shape.AddDim(input_shape.dim_size(3));
174 }
175 // create output tensor
176 Tensor *output = NULL;
177 OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output));
178 auto output_flat = output->flat<float>();
179 int N = input_flat.size() / times_;
180
181 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
182 typedef void (*function)(unsigned long int eid, float *x, int N, float *y);
183 dlerror();
184 function decrypt_kernel = (function)dlsym(lib, "decrypt");
185 const char *dlsym_error = dlerror();
186 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of decrypt failed: ", dlsym_error));
187 decrypt_kernel(eid_, (float *)input_flat.data(), N, (float *)output_flat.data());
188 };
189
190private:
191 void *lib;
192 int64 eid_low_;
193 int64 eid_high_;
194 int64 times_;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected