| 66 | } |
| 67 | |
| 68 | void Compute(OpKernelContext* context) override { |
| 69 | core::RefCountPtr<Var> variable; |
| 70 | OP_REQUIRES_OK(context, LookupResource(context, HandleFromInput(context, 0), |
| 71 | &variable)); |
| 72 | mutex_lock l(*variable->mu()); |
| 73 | Tensor before_increment = *variable->tensor(); |
| 74 | OP_REQUIRES( |
| 75 | context, TensorShapeUtils::IsScalar(before_increment.shape()), |
| 76 | errors::InvalidArgument("input is not a scalar: ", |
| 77 | before_increment.shape().DebugString())); |
| 78 | if (before_increment.scalar<T>()() >= limit_) { |
| 79 | context->SetStatus(errors::OutOfRange("Reached limit of ", limit_)); |
| 80 | return; |
| 81 | } |
| 82 | // Allocate new buffer |
| 83 | AllocatorAttributes attr; |
| 84 | attr.set_gpu_compatible(true); |
| 85 | attr.set_nic_compatible(true); |
| 86 | PersistentTensor unused; |
| 87 | Tensor* tmp; |
| 88 | OP_REQUIRES_OK(context, context->allocate_persistent( |
| 89 | dtype_, TensorShape({}), &unused, &tmp, attr)); |
| 90 | *variable->tensor() = *tmp; |
| 91 | tmp->scalar<T>()() = before_increment.scalar<T>()() + 1; |
| 92 | context->set_output(0, before_increment); |
| 93 | } |
| 94 | |
| 95 | private: |
| 96 | T limit_; |
nothing calls this directly
no test coverage detected