| 116 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 117 | } |
| 118 | void Compute(OpKernelContext *context) override |
| 119 | { |
| 120 | |
| 121 | const Tensor &grad = context->input(0); |
| 122 | const Tensor &input = context->input(1); |
| 123 | const Tensor &scale = context->input(2); |
| 124 | const Tensor &offset = context->input(3); |
| 125 | const Tensor &mean = context->input(4); |
| 126 | const Tensor &variance = context->input(5); |
| 127 | |
| 128 | Tensor *grad_input = NULL; |
| 129 | Tensor *grad_scale = NULL; |
| 130 | Tensor *grad_offset = NULL; |
| 131 | Tensor *grad_mean = NULL; |
| 132 | Tensor *grad_var = NULL; |
| 133 | OP_REQUIRES_OK(context, context->allocate_output(0, input.shape(), &grad_input)); |
| 134 | OP_REQUIRES_OK(context, context->allocate_output(1, scale.shape(), &grad_scale)); |
| 135 | OP_REQUIRES_OK(context, context->allocate_output(2, offset.shape(), &grad_offset)); |
| 136 | OP_REQUIRES_OK(context, context->allocate_output(3, mean.shape(), &grad_mean)); |
| 137 | OP_REQUIRES_OK(context, context->allocate_output(4, variance.shape(), &grad_var)); |
| 138 | |
| 139 | auto grad_flat = grad.flat<float>(); |
| 140 | auto input_flat = input.flat<float>(); |
| 141 | auto scale_flat = scale.flat<float>(); |
| 142 | auto offset_flat = offset.flat<float>(); |
| 143 | auto mean_flat = mean.flat<float>(); |
| 144 | auto variance_flat = variance.flat<float>(); |
| 145 | |
| 146 | auto grad_input_flat = grad_input->flat<float>(); |
| 147 | auto grad_scale_flat = grad_scale->flat<float>(); |
| 148 | auto grad_offset_flat = grad_offset->flat<float>(); |
| 149 | auto grad_mean_flat = grad_mean->flat<float>(); |
| 150 | auto grad_var_flat = grad_var->flat<float>(); |
| 151 | |
| 152 | const TensorShape &input_shape = input.shape(); |
| 153 | int M = input_shape.dim_size(0) / times_; |
| 154 | int H = input_shape.dim_size(1); |
| 155 | int W = input_shape.dim_size(2); |
| 156 | const int N = input_flat.size() / times_; |
| 157 | |
| 158 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 159 | typedef void (*function)(unsigned long int eid, float *input, float *grad, float *scale, float *offset, float *mean_x, float *variance, int N, int M, int H, int W, float *grad_in, float *grad_sc, float *grad_off, float *grad_mean, float *grad_var, float epsilon); |
| 160 | dlerror(); |
| 161 | function batchnorm_grad_kernel = (function)dlsym(lib, "batchnorm_grad"); |
| 162 | const char *dlsym_error = dlerror(); |
| 163 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of batchnorm_grad failed: ", dlsym_error)); |
| 164 | batchnorm_grad_kernel(eid_, (float *)input_flat.data(), (float *)grad_flat.data(), (float *)scale_flat.data(), (float *)offset_flat.data(), (float *)mean_flat.data(), (float *)variance_flat.data(), N, M, H, W, (float *)grad_input_flat.data(), (float *)grad_scale_flat.data(), (float *)grad_offset_flat.data(), (float *)grad_mean_flat.data(), (float *)grad_var_flat.data(), epsilon_); |
| 165 | }; |
| 166 | |
| 167 | private: |
| 168 | void *lib; |
nothing calls this directly
no outgoing calls
no test coverage detected