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

Class EReluGradOp

en_ops/e_relu.cc:75–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected