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

Method Compute

en_ops/e_dot.cc:128–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
127 }
128 void Compute(OpKernelContext *context) override
129 {
130
131 const Tensor &grad = context->input(0);
132 const Tensor &input1 = context->input(1);
133 auto input1_flat = input1.flat<float>();
134
135 const Tensor &input2 = context->input(2);
136 auto input2_flat = input2.flat<float>();
137
138 auto grad_flat = grad.flat<float>();
139
140 const TensorShape &input1_shape = input1.shape();
141 const TensorShape &input2_shape = input2.shape();
142
143 int shape1[input1_shape.dims()];
144 for (int i = 0; i < input1_shape.dims(); i++)
145 {
146 shape1[i] = input1_shape.dim_size(i);
147 }
148
149 int shape2[input2_shape.dims()];
150 for (int i = 0; i < input2_shape.dims(); i++)
151 {
152 shape2[i] = input2_shape.dim_size(i);
153 }
154
155 Tensor *output1 = NULL;
156 OP_REQUIRES_OK(context, context->allocate_output(0, input1_shape, &output1));
157 auto output1_flat = output1->flat<float>();
158
159 Tensor *output2 = NULL;
160 OP_REQUIRES_OK(context, context->allocate_output(1, input2_shape, &output2));
161 auto output2_flat = output2->flat<float>();
162
163 int N1 = input1_flat.size() / times_;
164 int N2 = input2_flat.size() / times_;
165 int ndims = input1_shape.dims();
166
167 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
168 typedef void (*function)(unsigned long int eid, float *input1, float *input2, float *grad, int N1, int N2, int *shape1, int *shape2, int ndims, float *output1, float *output2);
169 dlerror();
170 function dot_grad_kernel = (function)dlsym(lib, "dot_grad");
171 const char *dlsym_error = dlerror();
172 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of dot_grad failed: ", dlsym_error));
173 dot_grad_kernel(eid_, (float *)input1_flat.data(), (float *)input2_flat.data(), (float *)grad_flat.data(), N1, N2, (int *)shape1, (int *)shape2, ndims, (float *)output1_flat.data(), (float *)output2_flat.data());
174 };
175
176private:
177 void *lib;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected