39 void *
safe_malloc_(
const char *func,
const char *file,
int line,
size_t size);
42 void device_free_(
const char *func,
const char *file,
int line,
void *ptr);
44 void host_free_(
const char *func,
const char *file,
int line,
void *ptr);
47 inline constexpr
const char*
str_end(
const char *str) {
return *str ?
str_end(str + 1) : str; }
48 inline constexpr
bool str_slant(
const char *str) {
return *str ==
'/' ? true : (*str ?
str_slant(str + 1) :
false); }
49 inline constexpr
const char*
r_slant(
const char* str) {
return *str ==
'/' ? (str + 1) :
r_slant(str - 1); }
57 inline bool is_aligned(
const void *ptr,
size_t alignment)
59 return (reinterpret_cast<std::uintptr_t>(ptr) & (alignment - 1)) == 0;
64 #define device_malloc(size) quda::device_malloc_(__func__, quda::file_name(__FILE__), __LINE__, size) 65 #define device_pinned_malloc(size) quda::device_pinned_malloc_(__func__, quda::file_name(__FILE__), __LINE__, size) 66 #define safe_malloc(size) quda::safe_malloc_(__func__, quda::file_name(__FILE__), __LINE__, size) 67 #define pinned_malloc(size) quda::pinned_malloc_(__func__, quda::file_name(__FILE__), __LINE__, size) 68 #define mapped_malloc(size) quda::mapped_malloc_(__func__, quda::file_name(__FILE__), __LINE__, size) 69 #define device_free(ptr) quda::device_free_(__func__, quda::file_name(__FILE__), __LINE__, ptr) 70 #define device_pinned_free(ptr) quda::device_pinned_free_(__func__, quda::file_name(__FILE__), __LINE__, ptr) 71 #define host_free(ptr) quda::host_free_(__func__, quda::file_name(__FILE__), __LINE__, ptr) 95 void device_free_(
const char *func,
const char *file,
int line,
void *ptr);
103 void *
pinned_malloc_(
const char *func,
const char *file,
int line,
size_t size);
109 void pinned_free_(
const char *func,
const char *file,
int line,
void *ptr);
125 #define pool_device_malloc(size) quda::pool::device_malloc_(__func__, __FILE__, __LINE__, size) 126 #define pool_device_free(ptr) quda::pool::device_free_(__func__, __FILE__, __LINE__, ptr) 127 #define pool_pinned_malloc(size) quda::pool::pinned_malloc_(__func__, __FILE__, __LINE__, size) 128 #define pool_pinned_free(ptr) quda::pool::pinned_free_(__func__, __FILE__, __LINE__, ptr) 131 #endif // _MALLOC_QUDA_H long device_allocated_peak()
void * safe_malloc_(const char *func, const char *file, int line, size_t size)
void * device_malloc_(const char *func, const char *file, int line, size_t size)
constexpr const char * r_slant(const char *str)
void * device_pinned_malloc_(const char *func, const char *file, int line, size_t size)
void device_free_(const char *func, const char *file, int line, void *ptr)
Virtual free of pinned-memory allocation.
void * pinned_malloc_(const char *func, const char *file, int line, size_t size)
Allocate pinned-memory. If a free pre-existing allocation exists reuse this.
void device_free_(const char *func, const char *file, int line, void *ptr)
constexpr const char * str_end(const char *str)
bool is_aligned(const void *ptr, size_t alignment)
void flush_pinned()
Free all outstanding pinned-memory allocations.
void device_pinned_free_(const char *func, const char *file, int line, void *ptr)
void init()
Initialize the memory pool allocator.
void host_free_(const char *func, const char *file, int line, void *ptr)
void flush_device()
Free all outstanding device-memory allocations.
long host_allocated_peak()
long mapped_allocated_peak()
void * mapped_malloc_(const char *func, const char *file, int line, size_t size)
QudaFieldLocation get_pointer_location(const void *ptr)
constexpr bool str_slant(const char *str)
enum QudaFieldLocation_s QudaFieldLocation
long pinned_allocated_peak()
void * device_malloc_(const char *func, const char *file, int line, size_t size)
Allocate device-memory. If free pre-existing allocation exists reuse this.
constexpr const char * file_name(const char *str)
void pinned_free_(const char *func, const char *file, int line, void *ptr)
Virtual free of pinned-memory allocation.
void * pinned_malloc_(const char *func, const char *file, int line, size_t size)