A high-performance general-purpose compute library

- Main Page
- Tutorials
- Release Notes
- Examples

Macros
macros.h File Reference
`#include <stdio.h>`

Go to the source code of this file.

## Macros
#define | AF_MSG(fmt, ...)
| Print a line on screen using printf syntax.
#define | AF_MEM_INFO(msg)
| AF_MEM_INFO macro can be used to print the current stats of ArrayFire's memory manager.

## Macro Definition Documentation

## ◆ AF_MEM_INFO

#define AF_MEM_INFO | ( |  | msg | ) |

Value:
do { \
size_t abytes = 0, abuffs = 0, lbytes = 0, lbuffs = 0; \
af_err err = af_device_mem_info(&abytes, &abuffs, &lbytes, &lbuffs); \
if(err == AF_SUCCESS) { \
printf("AF Memory at %s:%d: " msg "\n", __FILE__, __LINE__); \
printf("Allocated [ Bytes | Buffers ] = [ %ld | %ld ]\n", abytes, abuffs); \
printf("In Use [ Bytes | Buffers ] = [ %ld | %ld ]\n", lbytes, lbuffs); \
} else { \
fprintf(stderr, "AF Memory at %s:%d: " msg "\nAF Error %d\n", \
__FILE__, __LINE__, err); \
} \
} while(0)
af_err
af_err
Definition defines.h:71
AF_SUCCESS
@ AF_SUCCESS
The function returned successfully.
Definition defines.h:75
af_device_mem_info
AFAPI af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers, size_t *lock_bytes, size_t *lock_buffers)
Get memory information from the memory manager.

AF_MEM_INFO macro can be used to print the current stats of ArrayFire's memory manager.

AF_MEM_INFO print 4 values:

Name | Description
--- | ---
Allocated Bytes | Total number of bytes allocated by the memory manager
Allocated Buffers | Total number of buffers allocated
Locked (In Use) Bytes | Number of bytes that are in use by active arrays
Locked (In Use) Buffers | Number of buffers that are in use by active arrays

The `Allocated Bytes` is always a multiple of the memory step size. The default step size is 1024 bytes. This means when a buffer is to be allocated, the size is always rounded up to a multiple of the step size. You can use af::getMemStepSize() to check the current step size and af::setMemStepSize() to set a custom resolution size.

The `Allocated Buffers` is the number of buffers that use up the allocated bytes. This includes buffers currently in scope, as well as buffers marked as free, ie, from arrays gone out of scope. The free buffers are available for use by new arrays that might be created.

The `Locked Bytes` is the number of bytes in use that cannot be reallocated at the moment. The difference of Allocated Bytes and Locked Bytes is the total bytes available for reallocation.

The `Locked Buffers` is the number of buffer in use that cannot be reallocated at the moment. The difference of Allocated Buffers and Locked Buffers is the number of buffers available for reallocation.

The AF_MEM_INFO macro can accept a string an argument that is printed to screen

Parameters

  [in] | msg | (Optional) A message that is printed to screen

AF_MEM_INFO("At start");
AF_MEM_INFO
#define AF_MEM_INFO(msg)
AF_MEM_INFO macro can be used to print the current stats of ArrayFire's memory manager.
Definition macros.h:73

Output:

    AF Memory at /workspace/myfile.cpp:41: At Start
    Allocated [ Bytes | Buffers ] = [ 4096 | 4 ]
    In Use    [ Bytes | Buffers ] = [ 2048 | 2 ]

Definition at line 73 of file macros.h.

73#define AF_MEM_INFO(msg) do { \
74 size_t abytes = 0, abuffs = 0, lbytes = 0, lbuffs = 0; \
75 af_err err = af_device_mem_info(&abytes, &abuffs, &lbytes, &lbuffs); \
76 if(err == AF_SUCCESS) { \
77 printf("AF Memory at %s:%d: " msg "\n", __FILE__, __LINE__); \
78 printf("Allocated [ Bytes | Buffers ] = [ %ld | %ld ]\n", abytes, abuffs); \
79 printf("In Use [ Bytes | Buffers ] = [ %ld | %ld ]\n", lbytes, lbuffs); \
80 } else { \
81 fprintf(stderr, "AF Memory at %s:%d: " msg "\nAF Error %d\n", \
82 __FILE__, __LINE__, err); \
83 } \
84} while(0)

## ◆ AF_MSG

#define AF_MSG | ( |  | fmt,
|  |  | ... )

Value:
do { \
printf("%s:%d: " fmt "\n", \
__FILE__, __LINE__, ##__VA_ARGS__); \
} while (0);

Print a line on screen using printf syntax.

Usage: Uses same syntax and semantics as printf. Output: <filename>:<line number>: <message>

Definition at line 19 of file macros.h.

19#define AF_MSG(fmt,...) do { \
20 printf("%s:%d: " fmt "\n", \
21 __FILE__, __LINE__, ##__VA_ARGS__); \
22 } while (0);