| 146 | OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!")); |
| 147 | } |
| 148 | void Compute(OpKernelContext *context) override |
| 149 | { |
| 150 | |
| 151 | // get the input tensor |
| 152 | const Tensor &input = context->input(0); |
| 153 | auto input_flat = input.flat<float>(); |
| 154 | // check shapes of input |
| 155 | const TensorShape &input_shape = input.shape(); |
| 156 | TensorShape output_shape; |
| 157 | if (input_shape.dims() == 2) |
| 158 | { |
| 159 | output_shape.AddDim(input_shape.dim_size(0) / times_); |
| 160 | output_shape.AddDim(input_shape.dim_size(1)); |
| 161 | } |
| 162 | else if (input_shape.dims() == 3) |
| 163 | { |
| 164 | output_shape.AddDim(input_shape.dim_size(0) / times_); |
| 165 | output_shape.AddDim(input_shape.dim_size(1)); |
| 166 | output_shape.AddDim(input_shape.dim_size(2)); |
| 167 | } |
| 168 | else |
| 169 | { |
| 170 | output_shape.AddDim(input_shape.dim_size(0) / times_); |
| 171 | output_shape.AddDim(input_shape.dim_size(1)); |
| 172 | output_shape.AddDim(input_shape.dim_size(2)); |
| 173 | output_shape.AddDim(input_shape.dim_size(3)); |
| 174 | } |
| 175 | // create output tensor |
| 176 | Tensor *output = NULL; |
| 177 | OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output)); |
| 178 | auto output_flat = output->flat<float>(); |
| 179 | int N = input_flat.size() / times_; |
| 180 | |
| 181 | unsigned long int eid_ = (eid_high_ << 32) + eid_low_; |
| 182 | typedef void (*function)(unsigned long int eid, float *x, int N, float *y); |
| 183 | dlerror(); |
| 184 | function decrypt_kernel = (function)dlsym(lib, "decrypt"); |
| 185 | const char *dlsym_error = dlerror(); |
| 186 | OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of decrypt failed: ", dlsym_error)); |
| 187 | decrypt_kernel(eid_, (float *)input_flat.data(), N, (float *)output_flat.data()); |
| 188 | }; |
| 189 | |
| 190 | private: |
| 191 | void *lib; |
nothing calls this directly
no outgoing calls
no test coverage detected