| 294 | } |
| 295 | |
| 296 | Error free_alloc(void* p) { |
| 297 | if (!p) return kSuccess; |
| 298 | Runtime& r = rt(); |
| 299 | size_t off = 0; |
| 300 | const Alloc* a = find(p, &off); |
| 301 | if (!a || off != 0) return fail(kErrorInvalidValue); |
| 302 | device_synchronize(); // as cudaFree: the GPU is done with it |
| 303 | std::lock_guard<std::mutex> lk(r.mu); |
| 304 | MTL::Buffer* b = a->buf; |
| 305 | const uint64_t g = a->gpu; |
| 306 | r.by_cpu.erase((uintptr_t) a->cpu); |
| 307 | r.by_gpu.erase(g); |
| 308 | r.rs->removeAllocation(b); |
| 309 | r.rs->commit(); |
| 310 | b->release(); |
| 311 | return kSuccess; |
| 312 | } |
| 313 | |
| 314 | } // namespace |
| 315 | |