A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

memory.h
Go to the documentation of this file.
1/*******************************************************
2 * Copyright (c) 2019, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10#pragma once
11
12#include <af/defines.h>
13#include <af/event.h>
14
15#include <stddef.h>
16
17#if AF_API_VERSION >= 37
18
22 typedef void* af_memory_manager;
23
24#ifdef __cplusplus
25 extern "C" {
26#endif // __cplusplus
27
36 typedef af_err (*af_memory_manager_initialize_fn)(af_memory_manager handle);
37
46 typedef af_err (*af_memory_manager_shutdown_fn)(af_memory_manager handle);
47
66 typedef af_err (*af_memory_manager_alloc_fn)(af_memory_manager handle,
67 void** ptr,
68 /* bool */ int user_lock,
69 const unsigned ndims, dim_t* dims,
70 const unsigned element_size);
71
82 typedef af_err (*af_memory_manager_allocated_fn)(af_memory_manager handle,
83 size_t* size, void* ptr);
84
95 typedef af_err (*af_memory_manager_unlock_fn)(af_memory_manager handle,
96 void* ptr, /* bool */ int user_unlock);
97
109 typedef af_err (*af_memory_manager_signal_memory_cleanup_fn)(
110 af_memory_manager handle);
111
127 typedef af_err (*af_memory_manager_print_info_fn)(af_memory_manager handle,
128 char* buffer, int id);
129
139 typedef af_err (*af_memory_manager_user_lock_fn)(af_memory_manager handle,
140 void* ptr);
141
151 typedef af_err (*af_memory_manager_user_unlock_fn)(af_memory_manager handle,
152 void* ptr);
153
164 typedef af_err (*af_memory_manager_is_user_locked_fn)(af_memory_manager handle,
165 int* out, void* ptr);
166
176 typedef af_err (*af_memory_manager_get_memory_pressure_fn)(
177 af_memory_manager handle, float* pressure);
178
203 typedef af_err (*af_memory_manager_jit_tree_exceeds_memory_pressure_fn)(
204 af_memory_manager handle, int* out, size_t size);
205
215 typedef void (*af_memory_manager_add_memory_management_fn)(
216 af_memory_manager handle, int id);
217
227 typedef void (*af_memory_manager_remove_memory_management_fn)(
228 af_memory_manager handle, int id);
229
239 AFAPI af_err af_create_memory_manager(af_memory_manager* out);
240
251 AFAPI af_err af_release_memory_manager(af_memory_manager handle);
252
265 AFAPI af_err af_set_memory_manager(af_memory_manager handle);
266
279 AFAPI af_err af_set_memory_manager_pinned(af_memory_manager handle);
280
295 AFAPI af_err af_unset_memory_manager();
296
311 AFAPI af_err af_unset_memory_manager_pinned();
312
322 AFAPI af_err af_memory_manager_get_payload(af_memory_manager handle,
323 void** payload);
324
338 AFAPI af_err af_memory_manager_set_payload(af_memory_manager handle,
339 void* payload);
340
350 AFAPI af_err af_memory_manager_set_initialize_fn(
351 af_memory_manager handle, af_memory_manager_initialize_fn fn);
352
362 AFAPI af_err af_memory_manager_set_shutdown_fn(
363 af_memory_manager handle, af_memory_manager_shutdown_fn fn);
364
374 AFAPI af_err af_memory_manager_set_alloc_fn(af_memory_manager handle,
375 af_memory_manager_alloc_fn fn);
376
386 AFAPI af_err af_memory_manager_set_allocated_fn(
387 af_memory_manager handle, af_memory_manager_allocated_fn fn);
388
398 AFAPI af_err af_memory_manager_set_unlock_fn(af_memory_manager handle,
399 af_memory_manager_unlock_fn fn);
400
411 AFAPI af_err af_memory_manager_set_signal_memory_cleanup_fn(
412 af_memory_manager handle, af_memory_manager_signal_memory_cleanup_fn fn);
413
423 AFAPI af_err af_memory_manager_set_print_info_fn(
424 af_memory_manager handle, af_memory_manager_print_info_fn fn);
425
435 AFAPI af_err af_memory_manager_set_user_lock_fn(
436 af_memory_manager handle, af_memory_manager_user_lock_fn fn);
437
447 AFAPI af_err af_memory_manager_set_user_unlock_fn(
448 af_memory_manager handle, af_memory_manager_user_unlock_fn fn);
449
459 AFAPI af_err af_memory_manager_set_is_user_locked_fn(
460 af_memory_manager handle, af_memory_manager_is_user_locked_fn fn);
461
472 AFAPI af_err af_memory_manager_set_get_memory_pressure_fn(
473 af_memory_manager handle, af_memory_manager_get_memory_pressure_fn fn);
474
486 AFAPI af_err af_memory_manager_set_jit_tree_exceeds_memory_pressure_fn(
487 af_memory_manager handle,
488 af_memory_manager_jit_tree_exceeds_memory_pressure_fn fn);
489
500 AFAPI af_err af_memory_manager_set_add_memory_management_fn(
501 af_memory_manager handle, af_memory_manager_add_memory_management_fn fn);
502
513 AFAPI af_err af_memory_manager_set_remove_memory_management_fn(
514 af_memory_manager handle, af_memory_manager_remove_memory_management_fn fn);
515
517
527 AFAPI af_err af_memory_manager_get_active_device_id(af_memory_manager handle,
528 int* id);
529
542 AFAPI af_err af_memory_manager_native_alloc(af_memory_manager handle,
543 void** ptr, size_t size);
544
554 AFAPI af_err af_memory_manager_native_free(af_memory_manager handle, void* ptr);
555
564 AFAPI af_err af_memory_manager_get_max_memory_size(af_memory_manager handle,
565 size_t* size, int id);
566
576 AFAPI af_err af_memory_manager_get_memory_pressure_threshold(
577 af_memory_manager handle, float* value);
578
593 AFAPI af_err af_memory_manager_set_memory_pressure_threshold(
594 af_memory_manager handle, float value);
595
596#ifdef __cplusplus
597}
598#endif // __cplusplus
599#endif // AF_API_VERSION >= 37
defines.h
dim_t
long long dim_t
Definition defines.h:56
af_err
af_err
Definition defines.h:71
AFAPI
#define AFAPI
Definition defines.h:38
event.h
af_memory_manager_is_user_locked_fn
af_err(* af_memory_manager_is_user_locked_fn)(af_memory_manager handle, int *out, void *ptr)
Queries if a buffer is user locked.
Definition memory.h:164
af_memory_manager
void * af_memory_manager
Definition memory.h:22
af_memory_manager_unlock_fn
af_err(* af_memory_manager_unlock_fn)(af_memory_manager handle, void *ptr, int user_unlock)
Unlocks memory from use.
Definition memory.h:95
af_memory_manager_print_info_fn
af_err(* af_memory_manager_print_info_fn)(af_memory_manager handle, char *buffer, int id)
Populates a character array with human readable information about the current state of the memory man...
Definition memory.h:127
af_memory_manager_remove_memory_management_fn
void(* af_memory_manager_remove_memory_management_fn)(af_memory_manager handle, int id)
Removes a device from the memory manager (OpenCL only)
Definition memory.h:227
af_memory_manager_get_memory_pressure_fn
af_err(* af_memory_manager_get_memory_pressure_fn)(af_memory_manager handle, float *pressure)
Gets memory pressure for a memory manager.
Definition memory.h:176
af_memory_manager_allocated_fn
af_err(* af_memory_manager_allocated_fn)(af_memory_manager handle, size_t *size, void *ptr)
Checks the amount of allocated memory for a pointer.
Definition memory.h:82
af_memory_manager_add_memory_management_fn
void(* af_memory_manager_add_memory_management_fn)(af_memory_manager handle, int id)
Adds a new device to the memory manager (OpenCL only)
Definition memory.h:215
af_memory_manager_jit_tree_exceeds_memory_pressure_fn
af_err(* af_memory_manager_jit_tree_exceeds_memory_pressure_fn)(af_memory_manager handle, int *out, size_t size)
Called to query if additions to the JIT tree would exert too much memory pressure.
Definition memory.h:203
af_memory_manager_user_lock_fn
af_err(* af_memory_manager_user_lock_fn)(af_memory_manager handle, void *ptr)
Called to lock a buffer as user-owned memory.
Definition memory.h:139
af_memory_manager_shutdown_fn
af_err(* af_memory_manager_shutdown_fn)(af_memory_manager handle)
Called after a memory manager is unset and becomes unused.
Definition memory.h:46
af_memory_manager_signal_memory_cleanup_fn
af_err(* af_memory_manager_signal_memory_cleanup_fn)(af_memory_manager handle)
Called to signal the memory manager should free memory if possible.
Definition memory.h:109
af_memory_manager_initialize_fn
af_err(* af_memory_manager_initialize_fn)(af_memory_manager handle)
Called after a memory manager is set and becomes active.
Definition memory.h:36
af_memory_manager_alloc_fn
af_err(* af_memory_manager_alloc_fn)(af_memory_manager handle, void **ptr, int user_lock, const unsigned ndims, dim_t *dims, const unsigned element_size)
Function pointer that will be called by ArrayFire to allocate memory.
Definition memory.h:66
af_memory_manager_user_unlock_fn
af_err(* af_memory_manager_user_unlock_fn)(af_memory_manager handle, void *ptr)
Called to unlock a buffer from user-owned memory.
Definition memory.h:151
af_memory_manager_set_initialize_fn
AFAPI af_err af_memory_manager_set_initialize_fn(af_memory_manager handle, af_memory_manager_initialize_fn fn)
Sets an af_memory_manager_initialize_fn for a memory manager.
af_memory_manager_set_jit_tree_exceeds_memory_pressure_fn
AFAPI af_err af_memory_manager_set_jit_tree_exceeds_memory_pressure_fn(af_memory_manager handle, af_memory_manager_jit_tree_exceeds_memory_pressure_fn fn)
Sets an af_memory_manager_jit_tree_exceeds_memory_pressure_fn for a memory manager.
af_memory_manager_set_user_lock_fn
AFAPI af_err af_memory_manager_set_user_lock_fn(af_memory_manager handle, af_memory_manager_user_lock_fn fn)
Sets an af_memory_manager_user_lock_fn for a memory manager.
af_create_memory_manager
AFAPI af_err af_create_memory_manager(af_memory_manager *out)
Creates an af_memory_manager handle.
af_memory_manager_get_payload
AFAPI af_err af_memory_manager_get_payload(af_memory_manager handle, void **payload)
Gets the payload ptr from an af_memory_manager.
af_memory_manager_set_signal_memory_cleanup_fn
AFAPI af_err af_memory_manager_set_signal_memory_cleanup_fn(af_memory_manager handle, af_memory_manager_signal_memory_cleanup_fn fn)
Sets an af_memory_manager_signal_memory_cleanup_fn for a memory manager.
af_memory_manager_set_alloc_fn
AFAPI af_err af_memory_manager_set_alloc_fn(af_memory_manager handle, af_memory_manager_alloc_fn fn)
Sets an af_memory_manager_alloc_fn for a memory manager.
af_memory_manager_set_payload
AFAPI af_err af_memory_manager_set_payload(af_memory_manager handle, void *payload)
Sets the payload ptr from an af_memory_manager.
af_memory_manager_set_add_memory_management_fn
AFAPI af_err af_memory_manager_set_add_memory_management_fn(af_memory_manager handle, af_memory_manager_add_memory_management_fn fn)
Sets an af_memory_manager_add_memory_management_fn for a memory manager.
af_memory_manager_set_get_memory_pressure_fn
AFAPI af_err af_memory_manager_set_get_memory_pressure_fn(af_memory_manager handle, af_memory_manager_get_memory_pressure_fn fn)
Sets an af_memory_manager_get_memory_pressure_fn for a memory manager.
af_set_memory_manager
AFAPI af_err af_set_memory_manager(af_memory_manager handle)
Sets an af_memory_manager to be the default memory manager for non-pinned memory allocations in Array...
af_memory_manager_set_user_unlock_fn
AFAPI af_err af_memory_manager_set_user_unlock_fn(af_memory_manager handle, af_memory_manager_user_unlock_fn fn)
Sets an af_memory_manager_user_unlock_fn for a memory manager.
af_memory_manager_set_is_user_locked_fn
AFAPI af_err af_memory_manager_set_is_user_locked_fn(af_memory_manager handle, af_memory_manager_is_user_locked_fn fn)
Sets an af_memory_manager_is_user_locked_fn for a memory manager.
af_memory_manager_set_shutdown_fn
AFAPI af_err af_memory_manager_set_shutdown_fn(af_memory_manager handle, af_memory_manager_shutdown_fn fn)
Sets an af_memory_manager_shutdown_fn for a memory manager.
af_unset_memory_manager_pinned
AFAPI af_err af_unset_memory_manager_pinned()
Reset the pinned memory manager being used in ArrayFire to the default memory manager,...
af_set_memory_manager_pinned
AFAPI af_err af_set_memory_manager_pinned(af_memory_manager handle)
Sets an af_memory_manager to be the default memory manager for pinned memory allocations in ArrayFire...
af_release_memory_manager
AFAPI af_err af_release_memory_manager(af_memory_manager handle)
Destroys an af_memory_manager handle.
af_memory_manager_set_print_info_fn
AFAPI af_err af_memory_manager_set_print_info_fn(af_memory_manager handle, af_memory_manager_print_info_fn fn)
Sets an af_memory_manager_print_info_fn for a memory manager.
af_memory_manager_set_unlock_fn
AFAPI af_err af_memory_manager_set_unlock_fn(af_memory_manager handle, af_memory_manager_unlock_fn fn)
Sets an af_memory_manager_unlock_fn for a memory manager.
af_memory_manager_set_remove_memory_management_fn
AFAPI af_err af_memory_manager_set_remove_memory_management_fn(af_memory_manager handle, af_memory_manager_remove_memory_management_fn fn)
Sets an af_memory_manager_remove_memory_management_fn for a memory manager.
af_unset_memory_manager
AFAPI af_err af_unset_memory_manager()
Reset the memory manager being used in ArrayFire to the default memory manager, shutting down the exi...
af_memory_manager_set_allocated_fn
AFAPI af_err af_memory_manager_set_allocated_fn(af_memory_manager handle, af_memory_manager_allocated_fn fn)
Sets an af_memory_manager_allocated_fn for a memory manager.
af_memory_manager_native_alloc
AFAPI af_err af_memory_manager_native_alloc(af_memory_manager handle, void **ptr, size_t size)
Allocates memory with a native memory function for the active backend.
af_memory_manager_get_max_memory_size
AFAPI af_err af_memory_manager_get_max_memory_size(af_memory_manager handle, size_t *size, int id)
Gets the maximum memory size for a managed device.
af_memory_manager_get_memory_pressure_threshold
AFAPI af_err af_memory_manager_get_memory_pressure_threshold(af_memory_manager handle, float *value)
Gets the memory pressure threshold for a memory manager.
af_memory_manager_get_active_device_id
AFAPI af_err af_memory_manager_get_active_device_id(af_memory_manager handle, int *id)
Gets the id of the currently-active device.
af_memory_manager_native_free
AFAPI af_err af_memory_manager_native_free(af_memory_manager handle, void *ptr)
Frees a pointer with a native memory function for the active backend.
af_memory_manager_set_memory_pressure_threshold
AFAPI af_err af_memory_manager_set_memory_pressure_threshold(af_memory_manager handle, float value)
Sets the memory pressure threshold for a memory manager.