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

Class EReduceMeanZeroGradOp

en_ops/e_reduce_mean_zero.cc:83–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81REGISTER_KERNEL_BUILDER(Name("EReduceMeanZero").Device(DEVICE_CPU), EReduceMeanZeroOp);
82
83class EReduceMeanZeroGradOp : public OpKernel
84{
85public:
86 explicit EReduceMeanZeroGradOp(OpKernelConstruction *context) : OpKernel(context)
87 {
88 OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_));
89 OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_));
90 OP_REQUIRES_OK(context, context->GetAttr("times", &times_));
91 lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY);
92 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
93 }
94 void Compute(OpKernelContext *context) override
95 {
96
97 const Tensor &grad = context->input(0);
98 const Tensor &input = context->input(1);
99
100 auto grad_flat = grad.flat<float>();
101 auto input_flat = input.flat<float>();
102
103 const TensorShape &input_shape = input.shape();
104
105 Tensor *output = NULL;
106 OP_REQUIRES_OK(context, context->allocate_output(0, input_shape, &output));
107 auto output_flat = output->flat<float>();
108
109 int N = input_flat.size() / times_;
110 int M = input_shape.dim_size(0) / times_;
111 int L = input_shape.dim_size(1);
112
113 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
114 typedef void (*function)(unsigned long int eid, float *input, float *grad, int N, int M, int L, float *output);
115 dlerror();
116 function reducemean_0_grad_kernel = (function)dlsym(lib, "reducemean_0_grad");
117 const char *dlsym_error = dlerror();
118 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of reducemean_0_grad failed: ", dlsym_error));
119 reducemean_0_grad_kernel(eid_, (float *)input_flat.data(), (float *)grad_flat.data(), N, M, L, (float *)output_flat.data());
120 };
121
122private:
123 void *lib;
124 int64 eid_low_;
125 int64 eid_high_;
126 int64 times_;
127};
128REGISTER_KERNEL_BUILDER(Name("EReduceMeanZeroGrad").Device(DEVICE_CPU), EReduceMeanZeroGradOp);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected