MCPcopy Create free account
hub / github.com/conflow-dev/ConFlow / ESortDeGradOp

Class ESortDeGradOp

en_ops/e_sort_de.cc:77–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75REGISTER_KERNEL_BUILDER(Name("ESortDe").Device(DEVICE_CPU), ESortDeOp);
76
77class ESortDeGradOp : public OpKernel
78{
79public:
80 explicit ESortDeGradOp(OpKernelConstruction *context) : OpKernel(context)
81 {
82 OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_));
83 OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_));
84 OP_REQUIRES_OK(context, context->GetAttr("times", &times_));
85 lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY);
86 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
87 }
88 void Compute(OpKernelContext *context) override
89 {
90
91 const Tensor &grad = context->input(0);
92 const Tensor &input = context->input(1);
93
94 auto grad_flat = grad.flat<float>();
95 auto input_flat = input.flat<float>();
96
97 const TensorShape &input_shape = input.shape();
98
99 Tensor *output = NULL;
100 OP_REQUIRES_OK(context, context->allocate_output(0, input_shape, &output));
101 auto output_flat = output->flat<float>();
102
103 const int N = input_flat.size() / times_;
104 int M = input_shape.dim_size(0) / times_;
105 int C = input_shape.dim_size(1);
106 int L = input_shape.dim_size(2);
107
108 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
109 typedef void (*function)(unsigned long int eid, float *input, float *grad, int N, int M, int C, int L, float *output);
110 dlerror();
111 function sort_de_grad_kernel = (function)dlsym(lib, "sort_de_grad");
112 const char *dlsym_error = dlerror();
113 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of sort_de_grad failed: ", dlsym_error));
114 sort_de_grad_kernel(eid_, (float *)input_flat.data(), (float *)grad_flat.data(), N, M, C, L, (float *)output_flat.data());
115 };
116
117private:
118 void *lib;
119 int64 eid_low_;
120 int64 eid_high_;
121 int64 times_;
122};
123REGISTER_KERNEL_BUILDER(Name("ESortDeGrad").Device(DEVICE_CPU), ESortDeGradOp);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected