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

Class EWhereEqualGradOp

en_ops/e_where_equal.cc:100–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98REGISTER_KERNEL_BUILDER(Name("EWhereEqual").Device(DEVICE_CPU), EWhereEqualOp);
99
100class EWhereEqualGradOp : public OpKernel
101{
102public:
103 explicit EWhereEqualGradOp(OpKernelConstruction *context) : OpKernel(context)
104 {
105 OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_));
106 OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_));
107 OP_REQUIRES_OK(context, context->GetAttr("times", &times_));
108 lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY);
109 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
110 }
111 void Compute(OpKernelContext *context) override
112 {
113
114 const Tensor &grad = context->input(0);
115 auto grad_flat = grad.flat<float>();
116
117 const Tensor &input1 = context->input(1);
118 auto input1_flat = input1.flat<float>();
119
120 const Tensor &input2 = context->input(2);
121 auto input2_flat = input2.flat<float>();
122
123 const Tensor &cond1 = context->input(3);
124 auto cond1_flat = cond1.flat<float>();
125
126 const Tensor &cond2 = context->input(4);
127 auto cond2_flat = cond2.flat<float>();
128
129 const TensorShape &input1_shape = input1.shape();
130 const TensorShape &input2_shape = input2.shape();
131
132 Tensor *output1 = NULL;
133 OP_REQUIRES_OK(context, context->allocate_output(0, input1_shape, &output1));
134 auto output1_flat = output1->flat<float>();
135
136 Tensor *output2 = NULL;
137 OP_REQUIRES_OK(context, context->allocate_output(1, input2_shape, &output2));
138 auto output2_flat = output2->flat<float>();
139 int N = input1_flat.size() / times_;
140
141 int n1 = 1;
142 int n2 = 1;
143 if (cond1_flat.size() > 1)
144 {
145 n1 = cond1_flat.size() / times_;
146 }
147 if (cond2_flat.size() > 1)
148 {
149 n2 = cond2_flat.size() / times_;
150 }
151
152 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
153 typedef void (*function)(unsigned long int eid, float *grad, float *input1, float *input2, float *cond1, float *cond2, int N, int n1, int n2, float *output1, float *output2);
154 dlerror();
155 function where_equal_grad_kernel = (function)dlsym(lib, "where_equal_grad");
156 const char *dlsym_error = dlerror();
157 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of where_equal_grad failed: ", dlsym_error));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected