Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/MojoLlama/blob/main/src/mojollama/kernels/mojo_api_v2.mojo # MojoLlama Archived Mojo/MAX quantizer and serving research repository (read-only history) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `MojoLlama / src / mojollama / kernels / mojo_api_v2.mojo` 41 lines ยท 1027 bytes Raw Blame History 1 # Mojo API exploration 2 from std.prelude import * 3 4 fn main(): 5 # Type conversions 6 var ui16: UInt16 = 65000 7 print("UInt16: ", ui16) 8 9 # Convert UInt16 to UInt32 10 var ui32: UInt32 = ui16 # implicit? 11 # Explicit 12 var ui32b: UInt32 = UInt32(ui16) 13 print("UInt32: ", ui32b) 14 15 # SIMD 16 var v = SIMD[DType.uint8, 32](0) 17 print("SIMD len: ", v.size) 18 19 # Pointer 20 var arr = InlineArray[UInt8, 10]() 21 for i in range(10): 22 arr[i] = UInt8(i * 2) 23 print("InlineArray[0]: ", arr[0]) 24 print("InlineArray[9]: ", arr[9]) 25 26 # Try DTypePointer 27 var dp = DTypePointer[DType.uint8].alloc(10) 28 for i in range(10): 29 dp.store(i, UInt8(i * 3)) 30 for i in range(10): 31 print("dp[", i, "] = ", dp.load(i), end=" ") 32 print() 33 dp.free() 34 35 # Benchmark timing 36 var t0 = time.perf_counter() 37 var s: Float64 = 0.0 38 for i in range(`10000000`): 39 s += 0.`00000001` 40 var t1 = time.perf_counter() 41 print("Time: ", (t1 - t0) * 1000, "ms")