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