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

Class EAbsGradOp

en_ops/e_abs.cc:76–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74REGISTER_KERNEL_BUILDER(Name("EAbs").Device(DEVICE_CPU), EAbsOp);
75
76class EAbsGradOp : public OpKernel
77{
78public:
79 explicit EAbsGradOp(OpKernelConstruction *context) : OpKernel(context)
80 {
81 OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_));
82 OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_));
83 OP_REQUIRES_OK(context, context->GetAttr("times", &times_));
84 lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY);
85 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
86 }
87 void Compute(OpKernelContext *context) override
88 {
89
90 const Tensor &grad = context->input(0);
91 const Tensor &input = context->input(1);
92
93 auto grad_flat = grad.flat<float>();
94 auto input_flat = input.flat<float>();
95
96 const TensorShape &input_shape = input.shape();
97
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 abs_grad_kernel = (function)dlsym(lib, "abs_grad");
108 const char *dlsym_error = dlerror();
109 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of abs_grad failed: ", dlsym_error));
110 abs_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("EAbsGrad").Device(DEVICE_CPU), EAbsGradOp);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected