MCPcopy Create free account
hub / github.com/Niko1221/Strata / new_alloc

Function new_alloc

engine/metal/src/gpu/runtime.cpp:278–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276}
277
278Error new_alloc(void** p, size_t bytes, bool host) {
279 Runtime& r = rt();
280 const size_t n = bytes ? bytes : 1;
281 MTL::Buffer* b = r.dev->newBuffer(n, MTL::ResourceStorageModeShared | MTL::ResourceHazardTrackingModeUntracked);
282 if (!b) return fail(kErrorMemoryAllocation);
283 Alloc a{b, b->gpuAddress(), (uint8_t*) b->contents(), n, host};
284 alloc_log(host ? "host alloc" : "device alloc", n);
285 {
286 std::lock_guard<std::mutex> lk(r.mu);
287 r.by_gpu[a.gpu] = a;
288 r.by_cpu[(uintptr_t) a.cpu] = a.gpu;
289 r.rs->addAllocation(b);
290 r.rs->commit();
291 }
292 *p = host ? (void*) a.cpu : (void*) (uintptr_t) a.gpu;
293 return kSuccess;
294}
295
296Error free_alloc(void* p) {
297 if (!p) return kSuccess;

Callers 2

malloc_device_rawFunction · 0.85
host_alloc_rawFunction · 0.85

Calls 4

alloc_logFunction · 0.85
contentsMethod · 0.80
failFunction · 0.70
commitMethod · 0.45

Tested by

no test coverage detected