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

Class DeCryptGradOp

en_ops/decrypt.cc:139–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected