MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / aligned_malloc

Function aligned_malloc

tensorflow/compiler/xla/cpu_function_runtime.cc:25–42  ·  view source on GitHub ↗

Inline memory allocation routines here, because depending on '//base' brings in libraries which use c++ streams, which adds considerable code size on android.

Source from the content-addressed store, hash-verified

23// in libraries which use c++ streams, which adds considerable code size on
24// android.
25void* aligned_malloc(size_t size, int minimum_alignment) {
26#if defined(__ANDROID__) || defined(OS_ANDROID) || defined(OS_CYGWIN)
27 return memalign(minimum_alignment, size);
28#elif defined(_WIN32)
29 return _aligned_malloc(size, minimum_alignment);
30#else // !__ANDROID__ && !OS_ANDROID && !OS_CYGWIN
31 void* ptr = nullptr;
32 // posix_memalign requires that the requested alignment be at least
33 // sizeof(void*). In this case, fall back on malloc which should return memory
34 // aligned to at least the size of a pointer.
35 const int required_alignment = sizeof(void*);
36 if (minimum_alignment < required_alignment) return malloc(size);
37 if (posix_memalign(&ptr, minimum_alignment, size) != 0)
38 return nullptr;
39 else
40 return ptr;
41#endif
42}
43
44void aligned_free(void* aligned_memory) {
45#if defined(_WIN32)

Callers 2

TESTFunction · 0.85
MallocContiguousBuffersFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68