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