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/openclaw-rs/blob/main/mojo/openclaw_simd.mojo # openclaw-rs High-performance sovereign agent runtime in native Rust and Mojo for NVIDIA DGX Spark 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 `openclaw-rs / mojo / openclaw_simd.mojo` 55 lines ยท 2298 bytes Raw Blame History 1 # OpenClaw Mojo 1.1 SIMD Vector Acceleration Kernel 2 # High performance token tensor manipulation and vector similarity for Grace Blackwell GB10 3 4 from std.math import sqrt 5 6 @export("openclaw_simd_version") 7 def openclaw_simd_version() abi("C") -> Int32: 8 return 101 9 10 @export("openclaw_cosine_similarity_4d") 11 def openclaw_cosine_similarity_4d( 12 a0: Float32, a1: Float32, a2: Float32, a3: Float32, 13 b0: Float32, b1: Float32, b2: Float32, b3: Float32 14 ) abi("C") -> Float32: 15 var va = SIMD[DType.float32, 4](a0, a1, a2, a3) 16 var vb = SIMD[DType.float32, 4](b0, b1, b2, b3) 17 var dot = Float32((va * vb).reduce_add()) 18 var norm_a = Float32((va * va).reduce_add()) 19 var norm_b = Float32((vb * vb).reduce_add()) 20 if norm_a <= 0.0 or norm_b <= 0.0: 21 return 0.0 22 return dot / (sqrt(norm_a) * sqrt(norm_b)) 23 24 @export("openclaw_simd_accumulate") 25 def openclaw_simd_accumulate(base_val: Float32, scale: Float32, steps: Int32) abi("C") -> Float32: 26 var acc = SIMD[DType.float32, 4](base_val, base_val * 1.5, base_val * 2.0, base_val * 2.5) 27 var step_vec = SIMD[DType.float32, 4](scale, scale * 1.1, scale * 1.2, scale * 1.3) 28 for _ in range(Int(steps)): 29 acc = acc * step_vec + SIMD[DType.float32, 4](0.01, 0.02, 0.03, 0.04) 30 return Float32(acc.reduce_add()) 31 32 @export("openclaw_token_entropy_simd") 33 def openclaw_token_entropy_simd(p0: Float32, p1: Float32, p2: Float32, p3: Float32) abi("C") -> Float32: 34 var probs = SIMD[DType.float32, 4](p0, p1, p2, p3) 35 var log_probs = SIMD[DType.float32, 4](0.0, 0.0, 0.0, 0.0) 36 for i in range(4): 37 if probs[i] > 0.00001: 38 log_probs[i] = probs[i] * (probs[i] - 1.0) 39 return Float32(log_probs.reduce_add()) 40 41 @export("openclaw_token_projection_simd") 42 def openclaw_token_projection_simd( 43 t0: Float32, t1: Float32, t2: Float32, t3: Float32, 44 w0: Float32, w1: Float32, w2: Float32, w3: Float32, 45 bias: Float32 46 ) abi("C") -> Float32: 47 var vt = SIMD[DType.float32, 4](t0, t1, t2, t3) 48 var vw = SIMD[DType.float32, 4](w0, w1, w2, w3) 49 return Float32((vt * vw).reduce_add()) + bias 50 51 @export("openclaw_temperature_scale_simd") 52 def openclaw_temperature_scale_simd(logit: Float32, temp: Float32) abi("C") -> Float32: 53 if temp <= 0.0001: 54 return logit 55 return logit / temp