| 64 | } |
| 65 | |
| 66 | bool ImageCacheBlob::Read(const ImageKey& image_key, |
| 67 | void* destination_buffer, |
| 68 | cudaStream_t stream) const { |
| 69 | DALI_ENFORCE(!image_key.empty()); |
| 70 | DALI_ENFORCE(destination_buffer != nullptr); |
| 71 | std::lock_guard<std::mutex> lock(mutex_); |
| 72 | LOG_LINE << "Read: image_key[" << image_key << "]" << std::endl; |
| 73 | const auto it = cache_.find(image_key); |
| 74 | if (it == cache_.end()) |
| 75 | return false; |
| 76 | const auto& data = it->second; |
| 77 | DALI_ENFORCE(data.data < tail_); |
| 78 | const auto n = data.num_elements(); |
| 79 | DALI_ENFORCE(data.data + n <= tail_); |
| 80 | |
| 81 | SyncToRead(stream); |
| 82 | MemCopy(destination_buffer, data.data, n, stream); |
| 83 | |
| 84 | if (stats_enabled_) stats_[image_key].reads++; |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | ImageCache::DecodedImage ImageCacheBlob::Get(const ImageKey& image_key) const { |
| 89 | DALI_ENFORCE(!image_key.empty()); |