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