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

Class EReduceMaxZeroGradOp

en_ops/e_reduce_max_zero_.cc:88–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected