| 87 | REGISTER_KERNEL_BUILDER(Name("ELogLoss").Device(DEVICE_CPU), ELogLossOp); |
| 88 | |
| 89 | class ELogLossGradOp : public OpKernel |
| 90 | { |
| 91 | public: |
| 92 | explicit ELogLossGradOp(OpKernelConstruction *context) : OpKernel(context) |
| 93 | { |
| 94 | OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_)); |
| 95 | OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_)); |
| 96 | OP_REQUIRES_OK(context, context->GetAttr("times", ×_)); |
| 97 | lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY); |
| 98 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 99 | } |
| 100 | void Compute(OpKernelContext *context) override |
| 101 | { |
| 102 | |
| 103 | const Tensor &grad = context->input(0); |
| 104 | const Tensor &input = context->input(1); |
| 105 | const Tensor &real = context->input(2); |
| 106 | const Tensor &weights = context->input(3); |
| 107 | auto input_flat = input.flat<float>(); |
| 108 | auto real_flat = real.flat<float>(); |
| 109 | auto grad_flat = grad.flat<float>(); |
| 110 | auto weights_flat = weights.flat<float>(); |
| 111 | |
| 112 | const TensorShape &input_shape = input.shape(); |
| 113 | const TensorShape &real_shape = real.shape(); |
| 114 | const TensorShape &weights_shape = weights.shape(); |
| 115 | // create output tensor |
| 116 | Tensor *output = NULL; |
| 117 | OP_REQUIRES_OK(context, context->allocate_output(0, input_shape, &output)); |
| 118 | auto output_flat = output->flat<float>(); |
| 119 | |
| 120 | Tensor *grad_w = NULL; |
| 121 | OP_REQUIRES_OK(context, context->allocate_output(1, weights_shape, &grad_w)); |
| 122 | auto grad_w_flat = grad_w->flat<float>(); |
| 123 | |
| 124 | Tensor *grad_r = NULL; |
| 125 | OP_REQUIRES_OK(context, context->allocate_output(2, real_shape, &grad_r)); |
| 126 | auto grad_r_flat = grad_r->flat<float>(); |
| 127 | |
| 128 | const int N = input_flat.size() / times_; |
| 129 | const int M = input_shape.dim_size(0) / times_; |
| 130 | const int C = input_shape.dim_size(1); |
| 131 | |
| 132 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 133 | typedef void (*function)(unsigned long int eid, float *input, float grad, int N, int M, int C, float *label, float *weight, float *grad_x, float *grad_w, float *grad_l); |
| 134 | dlerror(); |
| 135 | function logloss_grad_kernel = (function)dlsym(lib, "logloss_grad"); |
| 136 | const char *dlsym_error = dlerror(); |
| 137 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of logloss_grad failed: ", dlsym_error)); |
| 138 | logloss_grad_kernel(eid_, (float *)input_flat.data(), grad_flat(0), N, M, C, (float *)real_flat.data(), (float *)weights_flat.data(), (float *)output_flat.data(), (float *)grad_w_flat.data(), (float *)grad_r_flat.data()); |
| 139 | }; |
| 140 | |
| 141 | private: |
| 142 | void *lib; |
| 143 | int64 eid_low_; |
| 144 | int64 eid_high_; |
| 145 | int64 times_; |
| 146 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected