Skip to content

Commit 2fa0366

Browse files
olwangclaude
andcommitted
rsscript: declare Tensor sin/trunc/floordiv/floormod + metal_* in tensor.rssi
The ml/tensor-alu and ml/metal-ffi slices registered these intrinsics + added the Rust kernels, but the embedded .rssi interface declarations were left uncommitted, so rss code calling them failed typecheck (RS0206 does not resolve). Declares all six native methods. (.rssi is include_str!-embedded, so callers also need a rebuilt rss binary.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent bc5dbda commit 2fa0366

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

packages/ml/interface/tensor.rssi

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@ pub native fn Tensor.matmul(
3737
) -> Result<fresh Tensor, TensorError>
3838
effects(native)
3939

40+
// Whether a Metal GPU is available for the native compute path (false off macOS or
41+
// when no device is present).
42+
pub native fn Tensor.metal_available() -> Bool
43+
effects(native)
44+
45+
// The Metal device name (e.g. "Apple M2 Max"), or an empty string when no GPU is
46+
// available.
47+
pub native fn Tensor.metal_device_name() -> fresh String
48+
effects(native)
49+
50+
// GPU matrix multiply: same contract as `matmul`, dispatched to Metal. NOT bit-
51+
// identical to the CPU kernel (GPU reductions reorder), so it matches to f32
52+
// tolerance. Errors on non-rank-2 operands, an inner-dim mismatch, or no GPU.
53+
pub native fn Tensor.matmul_metal(
54+
a: read Tensor,
55+
b: read Tensor,
56+
) -> Result<fresh Tensor, TensorError>
57+
effects(native)
58+
4059
// Elementwise binary ops over two same-shape tensors. No broadcasting — the
4160
// shapes must match exactly (broadcasting is deferred to a later slice). Errors
4261
// on a shape mismatch.
@@ -257,6 +276,15 @@ pub native fn Tensor.log2(t: read Tensor) -> fresh Tensor
257276
pub native fn Tensor.rsqrt(t: read Tensor) -> fresh Tensor
258277
effects(native)
259278

279+
// Elementwise sine (radians). Output dtype F32.
280+
pub native fn Tensor.sin(t: read Tensor) -> fresh Tensor
281+
effects(native)
282+
283+
// Elementwise truncation toward zero (drops the fractional part, keeps the sign);
284+
// a float-result op that preserves dtype, unlike cast_i32 which retags to I32.
285+
pub native fn Tensor.trunc(t: read Tensor) -> fresh Tensor
286+
effects(native)
287+
260288
// Elementwise power a^b with broadcasting. Output dtype F32. Error if not
261289
// broadcast-compatible.
262290
pub native fn Tensor.pow(a: read Tensor, b: read Tensor) -> Result<fresh Tensor, TensorError>
@@ -283,6 +311,17 @@ pub native fn Tensor.idiv(a: read Tensor, b: read Tensor) -> Result<fresh Tensor
283311
pub native fn Tensor.modulo(a: read Tensor, b: read Tensor) -> Result<fresh Tensor, TensorError>
284312
effects(native)
285313

314+
// Floor division (Python //): rounds toward negative infinity, so the quotient
315+
// sign follows the divisor (distinct from idiv's truncate-toward-zero). Div-by-zero
316+
// -> 0. Broadcasts; output dtype I32.
317+
pub native fn Tensor.floordiv(a: read Tensor, b: read Tensor) -> Result<fresh Tensor, TensorError>
318+
effects(native)
319+
320+
// Floor modulo (Python %): the remainder sign follows the DIVISOR (distinct from
321+
// modulo, whose sign follows the dividend). Mod-by-zero -> 0. Broadcasts; dtype I32.
322+
pub native fn Tensor.floormod(a: read Tensor, b: read Tensor) -> Result<fresh Tensor, TensorError>
323+
effects(native)
324+
286325
// Left / right shift on i64 values, shift count masked to 0..63.
287326
pub native fn Tensor.shl(a: read Tensor, b: read Tensor) -> Result<fresh Tensor, TensorError>
288327
effects(native)

0 commit comments

Comments
 (0)