| 50 | .Output("output2: float"); |
| 51 | |
| 52 | class EDotOp : public OpKernel |
| 53 | { |
| 54 | public: |
| 55 | explicit EDotOp(OpKernelConstruction *context) : OpKernel(context) |
| 56 | { |
| 57 | OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_)); |
| 58 | OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_)); |
| 59 | OP_REQUIRES_OK(context, context->GetAttr("times", ×_)); |
| 60 | lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY); |
| 61 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 62 | } |
| 63 | void Compute(OpKernelContext *context) override |
| 64 | { |
| 65 | const Tensor &input1 = context->input(0); |
| 66 | auto input1_flat = input1.flat<float>(); |
| 67 | |
| 68 | const Tensor &input2 = context->input(1); |
| 69 | auto input2_flat = input2.flat<float>(); |
| 70 | |
| 71 | const TensorShape &input1_shape = input1.shape(); |
| 72 | const TensorShape &input2_shape = input2.shape(); |
| 73 | |
| 74 | int shape1[input1_shape.dims()]; |
| 75 | for (int i = 0; i < input1_shape.dims(); i++) |
| 76 | { |
| 77 | shape1[i] = input1_shape.dim_size(i); |
| 78 | } |
| 79 | |
| 80 | int shape2[input2_shape.dims()]; |
| 81 | for (int i = 0; i < input2_shape.dims(); i++) |
| 82 | { |
| 83 | shape2[i] = input2_shape.dim_size(i); |
| 84 | } |
| 85 | |
| 86 | TensorShape output_shape; |
| 87 | for (int i = 0; i < input1_shape.dims(); i++) |
| 88 | { |
| 89 | int dim_tmp = shape1[i] >= shape2[i] ? shape1[i] : shape2[i]; |
| 90 | output_shape.AddDim(dim_tmp); |
| 91 | } |
| 92 | |
| 93 | Tensor *output = NULL; |
| 94 | OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); |
| 95 | auto output_flat = output->flat<float>(); |
| 96 | int N1 = input1_flat.size() / times_; |
| 97 | int N2 = input2_flat.size() / times_; |
| 98 | int ndims = input1_shape.dims(); |
| 99 | |
| 100 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 101 | typedef void (*function)(unsigned long int eid, float *input1, float *input2, int N1, int N2, int *shape1, int *shape2, int ndims, float *output); |
| 102 | dlerror(); |
| 103 | function dot_kernel = (function)dlsym(lib, "dot"); |
| 104 | const char *dlsym_error = dlerror(); |
| 105 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of dot failed: ", dlsym_error)); |
| 106 | dot_kernel(eid_, (float *)input1_flat.data(), (float *)input2_flat.data(), N1, N2, (int *)shape1, (int *)shape2, ndims, (float *)output_flat.data()); |
| 107 | }; |
| 108 | |
| 109 | private: |
nothing calls this directly
no outgoing calls
no test coverage detected