The allocation that holds GPU address `p` (or CPU address `p` of a host allocation), with the offset into it.
| 137 | |
| 138 | /// The allocation that holds GPU address `p` (or CPU address `p` of a host allocation), with the offset into it. |
| 139 | const Alloc* find(const void* p, size_t* off) { |
| 140 | Runtime& r = rt(); |
| 141 | std::lock_guard<std::mutex> lk(r.mu); |
| 142 | const uint64_t a = (uint64_t) (uintptr_t) p; |
| 143 | auto it = r.by_gpu.upper_bound(a); |
| 144 | if (it != r.by_gpu.begin()) { |
| 145 | --it; |
| 146 | if (a < it->first + it->second.bytes) { *off = a - it->first; return &it->second; } |
| 147 | } |
| 148 | auto ic = r.by_cpu.upper_bound((uintptr_t) p); |
| 149 | if (ic != r.by_cpu.begin()) { |
| 150 | --ic; |
| 151 | const Alloc& al = r.by_gpu[ic->second]; |
| 152 | if ((uintptr_t) p < ic->first + al.bytes) { *off = (uintptr_t) p - ic->first; return &al; } |
| 153 | } |
| 154 | return nullptr; |
| 155 | } |
| 156 | |
| 157 | MTL::CommandBuffer* open_cb(StreamImpl* s) { |
| 158 | if (!s->cb) { |