| 78 | REGISTER_KERNEL_BUILDER(Name("EMinimum").Device(DEVICE_CPU), EMinimumOp); |
| 79 | |
| 80 | class EMinimumGradOp : public OpKernel |
| 81 | { |
| 82 | public: |
| 83 | explicit EMinimumGradOp(OpKernelConstruction *context) : OpKernel(context) |
| 84 | { |
| 85 | OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_)); |
| 86 | OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_)); |
| 87 | OP_REQUIRES_OK(context, context->GetAttr("times", ×_)); |
| 88 | lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY); |
| 89 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 90 | } |
| 91 | void Compute(OpKernelContext *context) override |
| 92 | { |
| 93 | |
| 94 | const Tensor &grad = context->input(0); |
| 95 | const Tensor &input1 = context->input(1); |
| 96 | auto input1_flat = input1.flat<float>(); |
| 97 | |
| 98 | const Tensor &input2 = context->input(2); |
| 99 | auto input2_flat = input2.flat<float>(); |
| 100 | |
| 101 | auto grad_flat = grad.flat<float>(); |
| 102 | |
| 103 | const TensorShape &input_shape = input1.shape(); |
| 104 | |
| 105 | Tensor *output1 = NULL; |
| 106 | OP_REQUIRES_OK(context, context->allocate_output(0, input_shape, &output1)); |
| 107 | auto output1_flat = output1->flat<float>(); |
| 108 | |
| 109 | Tensor *output2 = NULL; |
| 110 | OP_REQUIRES_OK(context, context->allocate_output(1, input_shape, &output2)); |
| 111 | auto output2_flat = output2->flat<float>(); |
| 112 | |
| 113 | const int N = input1_flat.size() / times_; |
| 114 | |
| 115 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 116 | typedef void (*function)(unsigned long int eid, float *input1, float *input2, float *grad, int N, float *output1, float *output2); |
| 117 | dlerror(); |
| 118 | function minimum_grad_kernel = (function)dlsym(lib, "minimum_grad"); |
| 119 | const char *dlsym_error = dlerror(); |
| 120 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of minimum_grad failed: ", dlsym_error)); |
| 121 | minimum_grad_kernel(eid_, (float *)input1_flat.data(), (float *)input2_flat.data(), (float *)grad_flat.data(), N, (float *)output1_flat.data(), (float *)output2_flat.data()); |
| 122 | }; |
| 123 | |
| 124 | private: |
| 125 | void *lib; |
| 126 | int64 eid_low_; |
| 127 | int64 eid_high_; |
| 128 | int64 times_; |
| 129 | }; |
| 130 | REGISTER_KERNEL_BUILDER(Name("EMinimumGrad").Device(DEVICE_CPU), EMinimumGradOp); |
nothing calls this directly
no outgoing calls
no test coverage detected