Wraps a tensor that is held by an Op across calls to Compute(). For memory safety when using asynchronous devices like GPUs, the system must be notified when a Tensor is used inside an Op execution. The wrapper ensures that all uses of the Tensor are tracked, because in order to retrieve the Tensor the caller must use AccessTensor which notifies the context.
| 265 | // order to retrieve the Tensor the caller must use AccessTensor which |
| 266 | // notifies the context. |
| 267 | class PersistentTensor { |
| 268 | public: |
| 269 | PersistentTensor() {} |
| 270 | explicit PersistentTensor(const Tensor& tensor) : tensor_(tensor) {} |
| 271 | |
| 272 | // Caller does not own the returned Tensor*. |
| 273 | Tensor* AccessTensor(OpKernelConstruction* context); |
| 274 | // Caller does not own the returned Tensor*. |
| 275 | Tensor* AccessTensor(OpKernelContext* context); |
| 276 | |
| 277 | // The check for initialization does not need to access the |
| 278 | // underlying tensor buffer. |
| 279 | bool IsInitialized() const { return tensor_.IsInitialized(); } |
| 280 | |
| 281 | int64 NumElements() const { return tensor_.NumElements(); } |
| 282 | |
| 283 | int64 AllocatedBytes() const { return tensor_.AllocatedBytes(); } |
| 284 | |
| 285 | private: |
| 286 | Tensor tensor_; |
| 287 | }; |
| 288 | |
| 289 | class OpKernelConstruction { |
| 290 | public: |
no outgoing calls
no test coverage detected