|
| 1 | +/// Macro to print the current stats of ArrayFire's memory manager. |
| 2 | +/// |
| 3 | +/// `mem_info!` print 4 values: |
| 4 | +/// |
| 5 | +/// Name | Description |
| 6 | +/// -------------------------|------------------------- |
| 7 | +/// Allocated Bytes | Total number of bytes allocated by the memory manager |
| 8 | +/// Allocated Buffers | Total number of buffers allocated |
| 9 | +/// Locked (In Use) Bytes | Number of bytes that are in use by active arrays |
| 10 | +/// Locked (In Use) Buffers | Number of buffers that are in use by active arrays |
| 11 | +/// |
| 12 | +/// The `Allocated Bytes` is always a multiple of the memory step size. The |
| 13 | +/// default step size is 1024 bytes. This means when a buffer is to be |
| 14 | +/// allocated, the size is always rounded up to a multiple of the step size. |
| 15 | +/// You can use [get_mem_step_size](./fn.get_mem_step_size.html) to check the |
| 16 | +/// current step size and [set_mem_step_size](./fn.set_mem_step_size.html) to |
| 17 | +/// set a custom resolution size. |
| 18 | +/// |
| 19 | +/// The `Allocated Buffers` is the number of buffers that use up the allocated |
| 20 | +/// bytes. This includes buffers currently in scope, as well as buffers marked |
| 21 | +/// as free, ie, from arrays gone out of scope. The free buffers are available |
| 22 | +/// for use by new arrays that might be created. |
| 23 | +/// |
| 24 | +/// The `Locked Bytes` is the number of bytes in use that cannot be |
| 25 | +/// reallocated at the moment. The difference of Allocated Bytes and Locked |
| 26 | +/// Bytes is the total bytes available for reallocation. |
| 27 | +/// |
| 28 | +/// The `Locked Buffers` is the number of buffer in use that cannot be |
| 29 | +/// reallocated at the moment. The difference of Allocated Buffers and Locked |
| 30 | +/// Buffers is the number of buffers available for reallocation. |
| 31 | +/// |
| 32 | +/// # Parameters |
| 33 | +/// |
| 34 | +/// - `msg` is the message that is printed to screen before printing stats |
| 35 | +/// |
| 36 | +/// # Examples |
| 37 | +/// |
| 38 | +/// ``` |
| 39 | +/// mem_info!("Here"); |
| 40 | +/// ``` |
| 41 | +/// |
| 42 | +/// Sample Output: |
| 43 | +/// |
| 44 | +/// ``` |
| 45 | +/// AF Memory: Here |
| 46 | +/// Allocated [ Bytes | Buffers ] = [ 4096 | 4 ] |
| 47 | +/// In Use [ Bytes | Buffers ] = [ 2048 | 2 ] |
| 48 | +/// ``` |
| 49 | +#[macro_export] |
| 50 | +macro_rules! mem_info { |
| 51 | + [$msg: expr] => { |
| 52 | + { |
| 53 | + let (abytes, abuffs, lbytes, lbuffs) = device_mem_info().unwrap(); |
| 54 | + println!("AF Memory: {:?}", $msg); |
| 55 | + println!("Allocated [Bytes | Buffers] = [ {} | {} ]", abytes, abuffs); |
| 56 | + println!("In Use [Bytes | Buffers] = [ {} | {} ]", lbytes, lbuffs); |
| 57 | + } |
| 58 | + }; |
| 59 | +} |
| 60 | + |
| 61 | +/// Join multiple Arrays along a given dimension |
| 62 | +/// |
| 63 | +/// # Examples |
| 64 | +/// |
| 65 | +/// ``` |
| 66 | +/// # #[macro_use] extern crate arrayfire; |
| 67 | +/// # fn main() { |
| 68 | +/// let a = randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap(); |
| 69 | +/// let b = randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap(); |
| 70 | +/// let c = randu::<f32>(Dim4::new(&[5, 3, 1, 1])).unwrap(); |
| 71 | +/// let d = join_many![2, a, b, c]; |
| 72 | +/// # } |
| 73 | +/// ``` |
| 74 | +/// |
| 75 | +/// # Panics |
| 76 | +/// |
| 77 | +/// This macro just calls [join_many](./fn.join_many.html) function after collecting all |
| 78 | +/// the input arrays into a vector. |
| 79 | +// Using macro to implement join many wrapper |
| 80 | +#[macro_export] |
| 81 | +macro_rules! join_many { |
| 82 | + [$dim: expr; $($x:ident),+] => { |
| 83 | + { |
| 84 | + let mut temp_vec = Vec::new(); |
| 85 | + $( |
| 86 | + temp_vec.push($x); |
| 87 | + )* |
| 88 | + join_many($dim, temp_vec) |
| 89 | + } |
| 90 | + }; |
| 91 | +} |
0 commit comments