| 35 | .Output("output2: float"); |
| 36 | |
| 37 | class EMaximumOp : public OpKernel |
| 38 | { |
| 39 | public: |
| 40 | explicit EMaximumOp(OpKernelConstruction *context) : OpKernel(context) |
| 41 | { |
| 42 | OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_)); |
| 43 | OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_)); |
| 44 | OP_REQUIRES_OK(context, context->GetAttr("times", ×_)); |
| 45 | lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY); |
| 46 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 47 | } |
| 48 | void Compute(OpKernelContext *context) override |
| 49 | { |
| 50 | const Tensor &input1 = context->input(0); |
| 51 | auto input1_flat = input1.flat<float>(); |
| 52 | |
| 53 | const Tensor &input2 = context->input(1); |
| 54 | auto input2_flat = input2.flat<float>(); |
| 55 | |
| 56 | const TensorShape &input_shape = input1.shape(); |
| 57 | |
| 58 | Tensor *output = NULL; |
| 59 | OP_REQUIRES_OK(context, context->allocate_output(0, input_shape, &output)); |
| 60 | auto output_flat = output->flat<float>(); |
| 61 | int N = input1_flat.size() / times_; |
| 62 | |
| 63 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 64 | typedef void (*function)(unsigned long int eid, float *input1, float *input2, int N, float *output); |
| 65 | dlerror(); |
| 66 | function maximum_kernel = (function)dlsym(lib, "maximum"); |
| 67 | const char *dlsym_error = dlerror(); |
| 68 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of maximum failed: ", dlsym_error)); |
| 69 | maximum_kernel(eid_, (float *)input1_flat.data(), (float *)input2_flat.data(), N, (float *)output_flat.data()); |
| 70 | }; |
| 71 | |
| 72 | private: |
| 73 | void *lib; |
| 74 | int64 eid_low_; |
| 75 | int64 eid_high_; |
| 76 | int64 times_; |
| 77 | }; |
| 78 | REGISTER_KERNEL_BUILDER(Name("EMaximum").Device(DEVICE_CPU), EMaximumOp); |
| 79 | |
| 80 | class EMaximumGradOp : public OpKernel |
nothing calls this directly
no outgoing calls
no test coverage detected