| 
									
										
										
										
											2024-03-28 09:40:31 -07:00
										 |  |  | // Copyright © 2024 Apple Inc.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <cassert>
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "mlx/mlx.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-12 00:08:29 +09:00
										 |  |  | namespace mx = mlx::core; | 
					
						
							| 
									
										
										
										
											2024-03-28 09:40:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | int main() { | 
					
						
							| 
									
										
										
										
											2024-04-07 21:47:43 -07:00
										 |  |  |   // To use Metal debugging and profiling:
 | 
					
						
							|  |  |  |   // 1. Build with the MLX_METAL_DEBUG CMake option (i.e. -DMLX_METAL_DEBUG=ON).
 | 
					
						
							|  |  |  |   // 2. Run with MTL_CAPTURE_ENABLED=1.
 | 
					
						
							| 
									
										
										
										
											2024-12-12 00:08:29 +09:00
										 |  |  |   mx::metal::start_capture("mlx_trace.gputrace"); | 
					
						
							| 
									
										
										
										
											2024-03-28 09:40:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Start at index two because the default GPU and CPU streams have indices
 | 
					
						
							|  |  |  |   // zero and one, respectively. This naming matches the label assigned to each
 | 
					
						
							|  |  |  |   // stream's command queue.
 | 
					
						
							| 
									
										
										
										
											2024-12-12 00:08:29 +09:00
										 |  |  |   auto s2 = new_stream(mx::Device::gpu); | 
					
						
							|  |  |  |   auto s3 = new_stream(mx::Device::gpu); | 
					
						
							| 
									
										
										
										
											2024-03-28 09:40:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-12 00:08:29 +09:00
										 |  |  |   auto a = mx::arange(1.f, 10.f, 1.f, mx::float32, s2); | 
					
						
							|  |  |  |   auto b = mx::arange(1.f, 10.f, 1.f, mx::float32, s3); | 
					
						
							|  |  |  |   auto x = mx::add(a, a, s2); | 
					
						
							|  |  |  |   auto y = mx::add(b, b, s3); | 
					
						
							| 
									
										
										
										
											2024-03-28 09:40:31 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // The multiply will happen on the default stream.
 | 
					
						
							| 
									
										
										
										
											2024-12-12 00:08:29 +09:00
										 |  |  |   std::cout << mx::multiply(x, y) << std::endl; | 
					
						
							| 
									
										
										
										
											2024-03-28 09:40:31 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-12 00:08:29 +09:00
										 |  |  |   mx::metal::stop_capture(); | 
					
						
							| 
									
										
										
										
											2024-03-28 09:40:31 -07:00
										 |  |  | } |