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

Class ESoftplusGradOp

en_ops/e_softplus.cc:74–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected