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

Class EReduceMaxZeroOp

en_ops/e_reduce_max_zero_.cc:41–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39 .Output("output: float");
40
41class EReduceMaxZeroOp : public OpKernel
42{
43public:
44 explicit EReduceMaxZeroOp(OpKernelConstruction *context) : OpKernel(context)
45 {
46 OP_REQUIRES_OK(context, context->GetAttr("eid_low", &eid_low_));
47 OP_REQUIRES_OK(context, context->GetAttr("eid_high", &eid_high_));
48 OP_REQUIRES_OK(context, context->GetAttr("times", &times_));
49 lib = dlopen("/home/zhangyan/jhrsgx/privacy_test/privacy_tf/sgx_tf_ops/sgx.so", RTLD_LAZY);
50 OP_REQUIRES(context, lib != NULL, errors::Unknown("Unable to load sgx.so!"));
51 }
52 void Compute(OpKernelContext *context) override
53 {
54 const Tensor &input = context->input(0);
55 auto input_flat = input.flat<float>();
56
57 const TensorShape &input_shape = input.shape();
58
59 TensorShape output_shape;
60 output_shape.AddDim(input_shape.dim_size(1));
61 output_shape.AddDim(input_shape.dim_size(2));
62
63 Tensor *output = NULL;
64 OP_REQUIRES_OK(context, context->allocate_output(0, output_shape, &output));
65 auto output_flat = output->flat<float>();
66 int N = input_flat.size() / times_;
67 int M = input_shape.dim_size(0) / times_;
68 int C = input_shape.dim_size(1);
69 int L = input_shape.dim_size(2);
70
71 unsigned long int eid_ = (eid_high_ << 32) + eid_low_;
72 typedef void (*function)(unsigned long int eid, float *input, int N, int M, int C, int L, float *output);
73 dlerror();
74 function reducemax_zero_kernel = (function)dlsym(lib, "reducemax_zero");
75 const char *dlsym_error = dlerror();
76 OP_REQUIRES(context, !dlsym_error, errors::Unknown("loading of reducemax_zero failed: ", dlsym_error));
77 reducemax_zero_kernel(eid_, (float *)input_flat.data(), N, M, C, L, (float *)output_flat.data());
78 };
79
80private:
81 void *lib;
82 int64 eid_low_;
83 int64 eid_high_;
84 int64 times_;
85};
86REGISTER_KERNEL_BUILDER(Name("EReduceMaxZero").Device(DEVICE_CPU), EReduceMaxZeroOp);
87
88class EReduceMaxZeroGradOp : public OpKernel

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected