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

Class ESampleOp

en_ops/e_sample.cc:37–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 return Status::OK(); });
36
37class ESampleOp : public OpKernel
38{
39public:
40 explicit ESampleOp(OpKernelConstruction *context) : OpKernel(context)
41 {
42 OP_REQUIRES_OK(context, context->GetAttr("nums", &nums_));
43 OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_));
44 OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_));
45 OP_REQUIRES_OK(context, context->GetAttr("times", &times_));
46 lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY);
47 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
48 }
49 void Compute(OpKernelContext *context) override
50 {
51 const Tensor &input1 = context->input(0);
52 auto input1_flat = input1.flat<float>();
53
54 const Tensor &input2 = context->input(1);
55 auto input2_flat = input2.flat<float>();
56
57 const TensorShape &input_shape = input1.shape();
58
59 TensorShape output_shape;
60 output_shape.AddDim(nums_);
61 output_shape.AddDim(input_shape.dim_size(0));
62 output_shape.AddDim(input_shape.dim_size(1));
63
64 Tensor *output = NULL;
65 OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output));
66 auto output_flat = output->flat<float>();
67 int N = input1_flat.size() / times_;
68
69 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
70 typedef void (*function)(unsigned long int eid, float *input1, float *input2, int N, int nums, float *output);
71 dlerror();
72 function sample_kernel = (function)dlsym(lib, "sample");
73 const char *dlsym_error = dlerror();
74 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of sample failed: ", dlsym_error));
75 sample_kernel(eid_, (float *)input1_flat.data(), (float *)input2_flat.data(), N, nums_, (float *)output_flat.data());
76 };
77
78private:
79 void *lib;
80 int64 nums_;
81 int64 eid_low_;
82 int64 eid_high_;
83 int64 times_;
84};
85REGISTER_KERNEL_BUILDER(Name("ESample").Device(DEVICE_CPU), ESampleOp);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected