aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/kernels/fact_op.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/core/kernels/fact_op.cc')
-rw-r--r--tensorflow/core/kernels/fact_op.cc33
1 files changed, 27 insertions, 6 deletions
diff --git a/tensorflow/core/kernels/fact_op.cc b/tensorflow/core/kernels/fact_op.cc
index 52ad2d0c1f..f1ab4c4a4d 100644
--- a/tensorflow/core/kernels/fact_op.cc
+++ b/tensorflow/core/kernels/fact_op.cc
@@ -73,25 +73,46 @@ static void E(string* s) {
}
}
-template <const char* const FACTS[], uint64 N>
class FactOpKernel : public OpKernel {
public:
explicit FactOpKernel(OpKernelConstruction* context) : OpKernel(context) {}
- void Compute(OpKernelContext* context) override {
+ void Compute(OpKernelContext* context) override = 0;
+
+ protected:
+ void Compute(OpKernelContext* context, const char* const facts[],
+ uint64 count) {
Tensor* output_tensor = NULL;
OP_REQUIRES_OK(
context, context->allocate_output(0, TensorShape({}), &output_tensor));
auto output = output_tensor->template scalar<string>();
- string coded = FACTS[context->env()->NowMicros() % N];
+ string coded = facts[context->env()->NowMicros() % count];
E(&coded);
output() = coded;
}
};
+class FactOpKernel1 : public FactOpKernel {
+ public:
+ FactOpKernel1(OpKernelConstruction* context) : FactOpKernel(context) {}
+
+ void Compute(OpKernelContext* context) override {
+ FactOpKernel::Compute(context, kFacts1, kNum1);
+ }
+};
+
+class FactOpKernel2 : public FactOpKernel {
+ public:
+ FactOpKernel2(OpKernelConstruction* context) : FactOpKernel(context) {}
+
+ void Compute(OpKernelContext* context) override {
+ FactOpKernel::Compute(context, kFacts2, kNum2);
+ }
+};
+
REGISTER_KERNEL_BUILDER(Name("Fact").Device(DEVICE_GPU).HostMemory("fact"),
- FactOpKernel<kFacts1, kNum1>);
+ FactOpKernel1);
static string D(const char* s) {
string ret(s);
@@ -102,10 +123,10 @@ static string D(const char* s) {
REGISTER_KERNEL_BUILDER(Name("Fact")
.Device(DEVICE_CPU)
.Label(D("Yoxmos").c_str()),
- FactOpKernel<kFacts2, kNum2>);
+ FactOpKernel2);
REGISTER_KERNEL_BUILDER(Name("Fact")
.Device(DEVICE_CPU)
.Label(D("yoxmos").c_str()),
- FactOpKernel<kFacts2, kNum2>);
+ FactOpKernel2);
} // namespace tensorflow