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

Class ESigmoidGradOp

en_ops/e_sigmoid.cc:73–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected