| 83 | REGISTER_KERNEL_BUILDER(Name("EEmbTransfer").Device(DEVICE_CPU), EEmbTransferOp); |
| 84 | |
| 85 | class EEmbTransferGradOp : public OpKernel |
| 86 | { |
| 87 | public: |
| 88 | explicit EEmbTransferGradOp(OpKernelConstruction *context) : OpKernel(context) |
| 89 | { |
| 90 | OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_)); |
| 91 | OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_)); |
| 92 | lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY); |
| 93 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 94 | } |
| 95 | void Compute(OpKernelContext *context) override |
| 96 | { |
| 97 | |
| 98 | const Tensor &grad = context->input(0); |
| 99 | auto grad_flat = grad.flat<float>(); |
| 100 | const TensorShape &input_shape = grad.shape(); |
| 101 | |
| 102 | TensorShape output_shape; |
| 103 | output_shape.AddDim(input_shape.dim_size(0) / 10); |
| 104 | output_shape.AddDim(input_shape.dim_size(1) + 1); |
| 105 | Tensor *output = NULL; |
| 106 | OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); |
| 107 | auto output_flat = output->flat<float>(); |
| 108 | |
| 109 | int M = input_shape.dim_size(0) / 10; |
| 110 | int C = input_shape.dim_size(1); |
| 111 | |
| 112 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 113 | typedef void (*function)(unsigned long int eid, float *grad, float *output, int M, int C); |
| 114 | dlerror(); |
| 115 | function emb_transfer_grad_kernel = (function)dlsym(lib, "emb_transfer_grad"); |
| 116 | const char *dlsym_error = dlerror(); |
| 117 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of relu_grad failed: ", dlsym_error)); |
| 118 | emb_transfer_grad_kernel(eid_, (float *)grad_flat.data(), (float *)output_flat.data(), M, C); |
| 119 | }; |
| 120 | |
| 121 | private: |
| 122 | void *lib; |
| 123 | int64 eid_low_; |
| 124 | int64 eid_high_; |
| 125 | }; |
| 126 | REGISTER_KERNEL_BUILDER(Name("EEmbTransferGrad").Device(DEVICE_CPU), EEmbTransferGradOp); |
nothing calls this directly
no outgoing calls
no test coverage detected