1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
/// Macro to print the current stats of ArrayFire's memory manager. /// /// `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 [get_mem_step_size](./fn.get_mem_step_size.html) to check the /// current step size and [set_mem_step_size](./fn.set_mem_step_size.html) 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. /// /// # Parameters /// /// - `msg` is the message that is printed to screen before printing stats /// /// # Examples /// /// ```rust /// # #[macro_use(mem_info)] extern crate arrayfire; /// # fn main() { /// use arrayfire::{Dim4, device_mem_info, print, randu}; /// /// let dims = Dim4::new(&[5, 5, 1, 1]); /// let a = randu::<f32>(dims); /// print(&a); /// mem_info!("Hello!"); /// # } /// ``` /// /// Sample Output: /// /// ```text /// AF Memory: Here /// Allocated [ Bytes | Buffers ] = [ 4096 | 4 ] /// In Use [ Bytes | Buffers ] = [ 2048 | 2 ] /// ``` #[macro_export] macro_rules! mem_info { [$msg: expr] => { { let (abytes, abuffs, lbytes, lbuffs) = device_mem_info(); println!("AF Memory: {:?}", $msg); println!("Allocated [Bytes | Buffers] = [ {} | {} ]", abytes, abuffs); println!("In Use [Bytes | Buffers] = [ {} | {} ]", lbytes, lbuffs); } }; } /// Join multiple Arrays along a given dimension /// /// All the Arrays provided to this macro should be of type `&Array` /// /// # Examples /// /// ```rust /// # #[macro_use] extern crate arrayfire; /// /// # fn main() { /// use arrayfire::{Dim4, join_many, print, randu}; /// /// let a = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])); /// let b = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])); /// let c = &randu::<f32>(Dim4::new(&[5, 3, 1, 1])); /// let d = join_many![2; a, b, c]; /// print(&d); /// # } /// ``` /// /// # Panics /// /// This macro just calls [join_many](./fn.join_many.html) function after collecting all /// the input arrays into a vector. // Using macro to implement join many wrapper #[macro_export] macro_rules! join_many { [$dim: expr; $($x:ident),+] => { { let mut temp_vec = Vec::new(); $( temp_vec.push($x); )* join_many($dim, temp_vec) } }; } /// Print given message before printing out the Array to standard output /// /// # Examples /// /// ```rust /// # #[macro_use] extern crate arrayfire; /// /// # fn main() { /// use arrayfire::{Dim4, print_gen, randu}; /// let dims = Dim4::new(&[3, 1, 1, 1]); /// let a = randu::<f32>(dims); /// af_print!("Create a 5-by-3 matrix of random floats on the GPU", a); /// # } /// ``` /// #[macro_export] macro_rules! af_print { [$msg: expr, $x: ident] => { { print_gen(String::from($msg), &$x, Some(4)); } }; } /// Evaluate arbitrary number of arrays #[macro_export] macro_rules! eval { [$($x:ident),+] => { { let mut temp_vec = Vec::new(); $( temp_vec.push($x); )* eval_multiple(temp_vec) } }; }