MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / alloc_fn

Function alloc_fn

test/memory.cpp:766–798  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

764}
765
766af_err alloc_fn(af_memory_manager manager, void **ptr,
767 /* bool */ int userLock, const unsigned ndims, dim_t *dims,
768 const unsigned element_size) {
769 size_t size = element_size;
770 for (unsigned i = 0; i < ndims; ++i) { size *= dims[i]; }
771
772 if (size > 0) {
773 float pressure;
774 get_memory_pressure_fn(manager, &pressure);
775 float threshold;
776 af_memory_manager_get_memory_pressure_threshold(manager, &threshold);
777 if (pressure >= threshold) { signal_memory_cleanup_fn(manager); }
778
779 if (af_err err = af_memory_manager_native_alloc(manager, ptr, size)) {
780 return err;
781 }
782
783 auto *payload = getMemoryManagerPayload<E2ETestPayload>(manager);
784 payload->table[*ptr] = size;
785 payload->totalBytes += size;
786 payload->totalBuffers++;
787
788 // Simple implementation: treat user and AF allocations the same
789 payload->locked.insert(*ptr);
790 payload->lockedBytes += size;
791
792 payload->lastNdims = ndims;
793 payload->lastDims = dim4(ndims, dims);
794 payload->lastElementSize = element_size;
795 }
796
797 return AF_SUCCESS;
798}
799
800void add_memory_management_fn(af_memory_manager manager, int id) {}
801

Callers

nothing calls this directly

Tested by

no test coverage detected