| 38 | using namespace tensorflow; |
| 39 | |
| 40 | class EClipOp : public OpKernel |
| 41 | { |
| 42 | public: |
| 43 | explicit EClipOp(OpKernelConstruction *context) : OpKernel(context) |
| 44 | { |
| 45 | OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_)); |
| 46 | OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_)); |
| 47 | OP_REQUIRES_OK(context, context->GetAttr("times", ×_)); |
| 48 | lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY); |
| 49 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 50 | } |
| 51 | void Compute(OpKernelContext *context) override |
| 52 | { |
| 53 | const Tensor &input = context->input(0); |
| 54 | auto input_flat = input.flat<float>(); |
| 55 | |
| 56 | const Tensor &down = context->input(1); |
| 57 | auto down_flat = down.flat<float>(); |
| 58 | |
| 59 | const Tensor &up = context->input(2); |
| 60 | auto up_flat = up.flat<float>(); |
| 61 | |
| 62 | const TensorShape &input_shape = input.shape(); |
| 63 | |
| 64 | Tensor *output = NULL; |
| 65 | OP_REQUIRES_OK(context, context->allocate_output(0, input_shape, &output)); |
| 66 | auto output_flat = output->flat<float>(); |
| 67 | int N = input_flat.size() / times_; |
| 68 | int n1 = 1; |
| 69 | int n2 = 1; |
| 70 | if (down_flat.size() > 1) |
| 71 | { |
| 72 | n1 = down_flat.size() / times_; |
| 73 | } |
| 74 | if (up_flat.size() > 1) |
| 75 | { |
| 76 | n2 = up_flat.size() / times_; |
| 77 | } |
| 78 | |
| 79 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 80 | typedef void (*function)(unsigned long int eid, float *input, float *down, float *up, int n1, int n2, int N, float *output); |
| 81 | dlerror(); |
| 82 | function clip_kernel = (function)dlsym(lib, "clip"); |
| 83 | const char *dlsym_error = dlerror(); |
| 84 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of clip failed: ", dlsym_error)); |
| 85 | clip_kernel(eid_, (float *)input_flat.data(), (float *)down_flat.data(), (float *)up_flat.data(), n1, n2, N, (float *)output_flat.data()); |
| 86 | }; |
| 87 | |
| 88 | private: |
| 89 | void *lib; |
| 90 | int64 eid_low_; |
| 91 | int64 eid_high_; |
| 92 | int64 times_; |
| 93 | }; |
| 94 | REGISTER_KERNEL_BUILDER(Name("EClip").Device(DEVICE_CPU), EClipOp); |
| 95 | |
| 96 | class EClipGradOp : public OpKernel |
nothing calls this directly
no outgoing calls
no test coverage detected