| 392 | } |
| 393 | |
| 394 | TFE_TensorHandle* ConvertToEagerTensor(TFE_Context* ctx, PyObject* value, |
| 395 | DataType dtype, |
| 396 | const char* device_name) { |
| 397 | // Reduce the overhead of allocation/transfer-to-device for scalars by |
| 398 | // caching the corresponding handles. Note that currently only Python |
| 399 | // scalars are cached. |
| 400 | // TODO(slebedev): also cache singleton NumPy arrays and scalars? |
| 401 | if (PyArray_IsPythonNumber(value)) { |
| 402 | auto* cache = TFE_TensorHandleCache::Get(); |
| 403 | TFE_TensorHandle* handle = cache->Lookup(value, dtype, device_name); |
| 404 | if (handle != nullptr) return handle; |
| 405 | handle = ConvertToEagerTensorUncached(ctx, value, dtype, device_name); |
| 406 | if (handle == nullptr) return nullptr; |
| 407 | cache->Insert(value, dtype, device_name, handle); |
| 408 | return handle; |
| 409 | } else { |
| 410 | return ConvertToEagerTensorUncached(ctx, value, dtype, device_name); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | } // namespace tensorflow |
| 415 |
no test coverage detected