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

Method Compute

en_ops/e_logloss.cc:100–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
99 }
100 void Compute(OpKernelContext *context) override
101 {
102
103 const Tensor &grad = context->input(0);
104 const Tensor &input = context->input(1);
105 const Tensor &real = context->input(2);
106 const Tensor &weights = context->input(3);
107 auto input_flat = input.flat<float>();
108 auto real_flat = real.flat<float>();
109 auto grad_flat = grad.flat<float>();
110 auto weights_flat = weights.flat<float>();
111
112 const TensorShape &input_shape = input.shape();
113 const TensorShape &real_shape = real.shape();
114 const TensorShape &weights_shape = weights.shape();
115 // create output tensor
116 Tensor *output = NULL;
117 OP_REQUIRES_OK(context, context->allocate_output(0, input_shape, &output));
118 auto output_flat = output->flat<float>();
119
120 Tensor *grad_w = NULL;
121 OP_REQUIRES_OK(context, context->allocate_output(1, weights_shape, &grad_w));
122 auto grad_w_flat = grad_w->flat<float>();
123
124 Tensor *grad_r = NULL;
125 OP_REQUIRES_OK(context, context->allocate_output(2, real_shape, &grad_r));
126 auto grad_r_flat = grad_r->flat<float>();
127
128 const int N = input_flat.size() / times_;
129 const int M = input_shape.dim_size(0) / times_;
130 const int C = input_shape.dim_size(1);
131
132 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
133 typedef void (*function)(unsigned long int eid, float *input, float grad, int N, int M, int C, float *label, float *weight, float *grad_x, float *grad_w, float *grad_l);
134 dlerror();
135 function logloss_grad_kernel = (function)dlsym(lib, "logloss_grad");
136 const char *dlsym_error = dlerror();
137 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of logloss_grad failed: ", dlsym_error));
138 logloss_grad_kernel(eid_, (float *)input_flat.data(), grad_flat(0), N, M, C, (float *)real_flat.data(), (float *)weights_flat.data(), (float *)output_flat.data(), (float *)grad_w_flat.data(), (float *)grad_r_flat.data());
139 };
140
141private:
142 void *lib;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected