| 60 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 61 | } |
| 62 | void Compute(OpKernelContext *context) override |
| 63 | { |
| 64 | const Tensor &input = context->input(0); |
| 65 | const Tensor &scale = context->input(1); |
| 66 | const Tensor &offset = context->input(2); |
| 67 | const Tensor &mean = context->input(3); |
| 68 | const Tensor &variance = context->input(4); |
| 69 | |
| 70 | const TensorShape &input_shape = input.shape(); |
| 71 | |
| 72 | Tensor *output = NULL; |
| 73 | OP_REQUIRES_OK(context, context->allocate_output(0, input_shape, &output)); |
| 74 | |
| 75 | int M = input_shape.dim_size(0) / times_; |
| 76 | int H = input_shape.dim_size(1); |
| 77 | int W = input_shape.dim_size(2); |
| 78 | |
| 79 | auto input_flat = input.flat<float>(); |
| 80 | auto scale_flat = scale.flat<float>(); |
| 81 | auto offset_flat = offset.flat<float>(); |
| 82 | auto mean_flat = mean.flat<float>(); |
| 83 | auto variance_flat = variance.flat<float>(); |
| 84 | auto output_flat = output->flat<float>(); |
| 85 | |
| 86 | int N = input_flat.size() / times_; |
| 87 | |
| 88 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 89 | typedef void (*function)(unsigned long int eid, float *input, float *scale, float *offset, float *mean_x, float *variance, int N, int M, int H, int W, float *output, float epsilon); |
| 90 | dlerror(); |
| 91 | function batchnorm_kernel = (function)dlsym(lib, "batchnorm"); |
| 92 | const char *dlsym_error = dlerror(); |
| 93 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of batchnorm failed: ", dlsym_error)); |
| 94 | batchnorm_kernel(eid_, (float *)input_flat.data(), (float *)scale_flat.data(), (float *)offset_flat.data(), (float *)mean_flat.data(), (float *)variance_flat.data(), N, M, H, W, (float *)output_flat.data(), epsilon_); |
| 95 | }; |
| 96 | |
| 97 | private: |
| 98 | void *lib; |
nothing calls this directly
no outgoing calls
no test coverage detected