oarust 0.8.6

GPU-first semantic computing engine written in Rust
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
//! ML-owned Matrix pooling operations.

use crate::{
	DType, Error, Matrix, OpAttribute, Result,
	runtime::{BufferBinding, ComputeDispatch, KernelId, PushConstant, SemanticDispatch},
};

use crate::ml::autograd;

use super::super::validation::{shader_u32, validate_f32_same_engine};

// ── geometry helpers ─────────────────────────────────────────────────────────

#[derive(Clone, Copy)]
struct Pool2dGeometry {
	batch: u32,
	channels: u32,
	input_height: u32,
	input_width: u32,
	output_height: u32,
	output_width: u32,
	kernel_size: u32,
	stride: u32,
	padding: u32,
}

impl Pool2dGeometry {
	fn resolve(
		input: &Matrix,
		kernel_size: usize,
		stride: usize,
		padding: usize,
		operation: &'static str,
	) -> Result<Self> {
		let [batch, channels, input_height, input_width] = input.shape() else {
			return Err(Error::invalid_argument(format!(
				"{operation} requires NCHW rank-four input; found {:?}",
				input.shape()
			)));
		};
		if *batch == 0
			|| *channels == 0
			|| *input_height == 0
			|| *input_width == 0
			|| kernel_size == 0
			|| stride == 0
		{
			return Err(Error::invalid_argument(format!(
				"{operation} requires nonzero NCHW extents, kernel size, and stride"
			)));
		}
		shader_u32(input.num_elements(), "input element count", operation)?;
		let doubled_padding = padding.checked_mul(2).ok_or_else(|| {
			Error::invalid_argument(format!("{operation} doubled padding overflows usize"))
		})?;
		let padded_height = input_height.checked_add(doubled_padding).ok_or_else(|| {
			Error::invalid_argument(format!("{operation} padded height overflows usize"))
		})?;
		let padded_width = input_width.checked_add(doubled_padding).ok_or_else(|| {
			Error::invalid_argument(format!("{operation} padded width overflows usize"))
		})?;
		if padded_height < kernel_size || padded_width < kernel_size {
			return Err(Error::invalid_argument(format!(
				"{operation} kernel does not fit the padded input"
			)));
		}
		let output_height = (padded_height - kernel_size) / stride + 1;
		let output_width = (padded_width - kernel_size) / stride + 1;
		let last_y = output_height
			.saturating_sub(1)
			.checked_mul(stride)
			.ok_or_else(|| Error::invalid_argument(format!("{operation} Y origin overflows usize")))?;
		let last_x = output_width
			.saturating_sub(1)
			.checked_mul(stride)
			.ok_or_else(|| Error::invalid_argument(format!("{operation} X origin overflows usize")))?;
		let last_y_end = last_y.checked_add(kernel_size).ok_or_else(|| {
			Error::invalid_argument(format!("{operation} final Y window overflows usize"))
		})?;
		let last_x_end = last_x.checked_add(kernel_size).ok_or_else(|| {
			Error::invalid_argument(format!("{operation} final X window overflows usize"))
		})?;
		for (label, value) in [
			("input height", *input_height),
			("input width", *input_width),
			("kernel size", kernel_size),
			("padding", padding),
			("last Y origin", last_y),
			("last X origin", last_x),
			("final Y window end", last_y_end),
			("final X window end", last_x_end),
		] {
			if value > i32::MAX as usize {
				return Err(Error::invalid_argument(format!(
					"{operation} {label} exceeds the signed shader coordinate ABI"
				)));
			}
		}
		let batch = shader_u32(*batch, "batch size", operation)?;
		let channels = shader_u32(*channels, "channel count", operation)?;
		batch.checked_mul(channels).ok_or_else(|| {
			Error::invalid_argument(format!("{operation} batch-channel count exceeds u32"))
		})?;
		Ok(Self {
			batch,
			channels,
			input_height: shader_u32(*input_height, "input height", operation)?,
			input_width: shader_u32(*input_width, "input width", operation)?,
			output_height: shader_u32(output_height, "output height", operation)?,
			output_width: shader_u32(output_width, "output width", operation)?,
			kernel_size: shader_u32(kernel_size, "kernel size", operation)?,
			stride: shader_u32(stride, "stride", operation)?,
			padding: shader_u32(padding, "padding", operation)?,
		})
	}

	fn push_constants(self) -> [PushConstant; 9] {
		[
			PushConstant::U32(self.batch),
			PushConstant::U32(self.channels),
			PushConstant::U32(self.input_height),
			PushConstant::U32(self.input_width),
			PushConstant::U32(self.output_height),
			PushConstant::U32(self.output_width),
			PushConstant::U32(self.kernel_size),
			PushConstant::U32(self.stride),
			PushConstant::U32(self.padding),
		]
	}

	fn attributes(self) -> [OpAttribute; 3] {
		[
			OpAttribute::UnsignedInteger {
				name: "kernel_size".into(),
				value: u64::from(self.kernel_size),
			},
			OpAttribute::UnsignedInteger {
				name: "stride".into(),
				value: u64::from(self.stride),
			},
			OpAttribute::UnsignedInteger {
				name: "padding".into(),
				value: u64::from(self.padding),
			},
		]
	}
}

#[derive(Clone, Copy)]
struct AdaptivePool2dGeometry {
	batch: u32,
	channels: u32,
	input_height: u32,
	input_width: u32,
	output_height: u32,
	output_width: u32,
}

impl AdaptivePool2dGeometry {
	fn resolve(
		input: &Matrix,
		output_height: usize,
		output_width: usize,
		operation: &'static str,
	) -> Result<Self> {
		let [batch, channels, input_height, input_width] = input.shape() else {
			return Err(Error::invalid_argument(format!(
				"{operation} requires NCHW rank-four input; found {:?}",
				input.shape()
			)));
		};
		if [
			*batch,
			*channels,
			*input_height,
			*input_width,
			output_height,
			output_width,
		]
		.contains(&0)
		{
			return Err(Error::invalid_argument(format!(
				"{operation} requires nonzero input and output extents"
			)));
		}
		shader_u32(input.num_elements(), "input element count", operation)?;
		let output_count = batch
			.checked_mul(*channels)
			.and_then(|value| value.checked_mul(output_height))
			.and_then(|value| value.checked_mul(output_width))
			.ok_or_else(|| Error::invalid_argument(format!("{operation} output size overflows usize")))?;
		shader_u32(output_count, "output element count", operation)?;
		for (label, output_extent, input_extent) in [
			("height", output_height, *input_height),
			("width", output_width, *input_width),
		] {
			output_extent
				.checked_mul(input_extent)
				.and_then(|value| value.checked_add(output_extent - 1))
				.and_then(|value| u32::try_from(value).ok())
				.ok_or_else(|| {
					Error::invalid_argument(format!(
						"{operation} adaptive {label} geometry exceeds the u32 shader ABI"
					))
				})?;
		}
		let batch = shader_u32(*batch, "batch size", operation)?;
		let channels = shader_u32(*channels, "channel count", operation)?;
		batch.checked_mul(channels).ok_or_else(|| {
			Error::invalid_argument(format!("{operation} batch-channel count exceeds u32"))
		})?;
		Ok(Self {
			batch,
			channels,
			input_height: shader_u32(*input_height, "input height", operation)?,
			input_width: shader_u32(*input_width, "input width", operation)?,
			output_height: shader_u32(output_height, "output height", operation)?,
			output_width: shader_u32(output_width, "output width", operation)?,
		})
	}

	fn push_constants(self) -> [PushConstant; 6] {
		[
			PushConstant::U32(self.batch),
			PushConstant::U32(self.channels),
			PushConstant::U32(self.input_height),
			PushConstant::U32(self.input_width),
			PushConstant::U32(self.output_height),
			PushConstant::U32(self.output_width),
		]
	}

	fn attributes(self) -> [OpAttribute; 2] {
		[
			OpAttribute::UnsignedInteger {
				name: "output_height".into(),
				value: u64::from(self.output_height),
			},
			OpAttribute::UnsignedInteger {
				name: "output_width".into(),
				value: u64::from(self.output_width),
			},
		]
	}
}

// ── public operations ─────────────────────────────────────────────────────────

/// Pooled values and their exact U32 input argmax indices.
#[must_use]
pub struct MaxPool2dResult {
	/// Maximum value selected from each pooling window.
	pub output: Matrix,
	/// Flat input index selected for each output element.
	pub indices: Matrix,
}

/// Apply two-dimensional average pooling to an NCHW Matrix.
///
/// Padding positions do not contribute to either the sum or divisor. The
/// output spatial extent is `floor((input + 2 * padding - kernel_size) /
/// stride) + 1`, matching the OA C++ operation.
///
/// # Errors
///
/// Returns an error unless `input` is a nonempty rank-four F32 Matrix,
/// `kernel_size` and `stride` are nonzero, the kernel fits the padded input,
/// every shader extent is representable, or runtime recording fails.
pub fn avg_pool_2d(
	input: &Matrix,
	kernel_size: usize,
	stride: usize,
	padding: usize,
) -> Result<Matrix> {
	let output = avg_pool_2d_dispatch(input, kernel_size, stride, padding)?;
	autograd::record_avg_pool_2d(input, kernel_size, stride, padding, &output)?;
	Ok(output)
}

pub(in crate::ml) fn avg_pool_2d_backward(
	input: &Matrix,
	output_gradient: &Matrix,
	kernel_size: usize,
	stride: usize,
	padding: usize,
) -> Result<Matrix> {
	let contract = crate::core::operation::ml::AVG_POOL_2D_BACKWARD;
	let operation = contract.name();
	validate_f32_same_engine(operation, &[input, output_gradient])?;
	let geometry = Pool2dGeometry::resolve(input, kernel_size, stride, padding, operation)?;
	let expected_shape = [
		geometry.batch as usize,
		geometry.channels as usize,
		geometry.output_height as usize,
		geometry.output_width as usize,
	];
	if output_gradient.shape() != expected_shape {
		return Err(Error::invalid_argument(format!(
			"{operation} output gradient must have shape {expected_shape:?}; found {:?}",
			output_gradient.shape()
		)));
	}
	let input_gradient = Matrix::allocate(
		input.engine_handle(),
		input.shape().to_vec(),
		input.num_elements(),
		DType::F32,
	)?;
	let buffers = [
		BufferBinding::read(output_gradient.storage()),
		BufferBinding::write(input_gradient.storage()),
	];
	let push_constants = geometry.push_constants();
	let attributes = geometry.attributes();
	let inputs = [input, output_gradient];
	let outputs = [&input_gradient];
	input.engine_handle().record_semantic(
		ComputeDispatch {
			kernel: KernelId::MlAvgPool2dBackwardF32,
			buffers: &buffers,
			push_constants: &push_constants,
			workgroups: [
				geometry.input_height.div_ceil(16),
				geometry.input_width.div_ceil(16),
				geometry.batch * geometry.channels,
			],
		},
		SemanticDispatch {
			contract,
			inputs: &inputs,
			outputs: &outputs,
			attributes: &attributes,
		},
	)?;
	Ok(input_gradient)
}

/// Apply two-dimensional max pooling to an NCHW Matrix.
///
/// Equal maxima select the first valid input in row-major window order. The
/// returned U32 argmax indices are explicit because they are part of the donor
/// operation contract and make the deterministic adjoint reusable.
///
/// # Errors
///
/// Returns an error under the same geometry and runtime conditions as
/// [`avg_pool_2d`].
pub fn max_pool_2d(
	input: &Matrix,
	kernel_size: usize,
	stride: usize,
	padding: usize,
) -> Result<MaxPool2dResult> {
	let (output, indices) = max_pool_2d_dispatch(input, kernel_size, stride, padding)?;
	autograd::record_max_pool_2d(
		input,
		indices.clone(),
		kernel_size,
		stride,
		padding,
		&output,
	)?;
	Ok(MaxPool2dResult { output, indices })
}

pub(in crate::ml) fn max_pool_2d_backward(
	input: &Matrix,
	indices: &Matrix,
	output_gradient: &Matrix,
	kernel_size: usize,
	stride: usize,
	padding: usize,
) -> Result<Matrix> {
	let contract = crate::core::operation::ml::MAX_POOL_2D_BACKWARD;
	let operation = contract.name();
	validate_f32_same_engine(operation, &[input, output_gradient])?;
	if indices.dtype() != DType::U32 {
		return Err(Error::invalid_argument(format!(
			"{operation} indices must use U32; found {}",
			indices.dtype().token()
		)));
	}
	if !input.engine_handle().same_as(indices.engine_handle()) {
		return Err(Error::invalid_argument(format!(
			"{operation} inputs must belong to the same engine"
		)));
	}
	let geometry = Pool2dGeometry::resolve(input, kernel_size, stride, padding, operation)?;
	let expected_shape = [
		geometry.batch as usize,
		geometry.channels as usize,
		geometry.output_height as usize,
		geometry.output_width as usize,
	];
	if indices.shape() != expected_shape || output_gradient.shape() != expected_shape {
		return Err(Error::invalid_argument(format!(
			"{operation} indices and output gradient must have shape {expected_shape:?}; found {:?} and {:?}",
			indices.shape(),
			output_gradient.shape()
		)));
	}
	let input_gradient = Matrix::allocate(
		input.engine_handle(),
		input.shape().to_vec(),
		input.num_elements(),
		DType::F32,
	)?;
	let buffers = [
		BufferBinding::read(indices.storage()),
		BufferBinding::read(output_gradient.storage()),
		BufferBinding::write(input_gradient.storage()),
	];
	let push_constants = geometry.push_constants();
	let attributes = geometry.attributes();
	let inputs = [input, indices, output_gradient];
	let outputs = [&input_gradient];
	input.engine_handle().record_semantic(
		ComputeDispatch {
			kernel: KernelId::MlMaxPool2dBackwardF32,
			buffers: &buffers,
			push_constants: &push_constants,
			workgroups: [
				geometry.input_height.div_ceil(16),
				geometry.input_width.div_ceil(16),
				geometry.batch * geometry.channels,
			],
		},
		SemanticDispatch {
			contract,
			inputs: &inputs,
			outputs: &outputs,
			attributes: &attributes,
		},
	)?;
	Ok(input_gradient)
}

/// Adaptively average-pool an NCHW Matrix to an exact spatial extent.
///
/// Each output bin independently uses floor/ceiling boundaries along height
/// and width. This supports rectangular and non-divisible geometry without
/// approximating the operation as a square fixed-window pool.
///
/// # Errors
///
/// Returns an error unless the input is nonempty rank-four F32, both output
/// extents are nonzero, all geometry fits the shader ABI, or recording fails.
pub fn adaptive_avg_pool_2d(
	input: &Matrix,
	output_height: usize,
	output_width: usize,
) -> Result<Matrix> {
	let output = adaptive_avg_pool_2d_dispatch(input, output_height, output_width)?;
	autograd::record_adaptive_avg_pool_2d(input, output_height, output_width, &output)?;
	Ok(output)
}

pub(in crate::ml) fn adaptive_avg_pool_2d_backward(
	input: &Matrix,
	output_gradient: &Matrix,
	output_height: usize,
	output_width: usize,
) -> Result<Matrix> {
	let contract = crate::core::operation::ml::ADAPTIVE_AVG_POOL_2D_BACKWARD;
	let operation = contract.name();
	validate_f32_same_engine(operation, &[input, output_gradient])?;
	let geometry = AdaptivePool2dGeometry::resolve(input, output_height, output_width, operation)?;
	let expected_shape = [
		geometry.batch as usize,
		geometry.channels as usize,
		output_height,
		output_width,
	];
	if output_gradient.shape() != expected_shape {
		return Err(Error::invalid_argument(format!(
			"{operation} output gradient must have shape {expected_shape:?}; found {:?}",
			output_gradient.shape()
		)));
	}
	let input_gradient = Matrix::allocate(
		input.engine_handle(),
		input.shape().to_vec(),
		input.num_elements(),
		DType::F32,
	)?;
	let buffers = [
		BufferBinding::read(output_gradient.storage()),
		BufferBinding::write(input_gradient.storage()),
	];
	let push_constants = geometry.push_constants();
	let attributes = geometry.attributes();
	input.engine_handle().record_semantic(
		ComputeDispatch {
			kernel: KernelId::MlAdaptiveAvgPool2dBackwardF32,
			buffers: &buffers,
			push_constants: &push_constants,
			workgroups: [
				geometry.input_height.div_ceil(16),
				geometry.input_width.div_ceil(16),
				geometry.batch * geometry.channels,
			],
		},
		SemanticDispatch {
			contract,
			inputs: &[input, output_gradient],
			outputs: &[&input_gradient],
			attributes: &attributes,
		},
	)?;
	Ok(input_gradient)
}

// ── private dispatch helpers ──────────────────────────────────────────────────

fn avg_pool_2d_dispatch(
	input: &Matrix,
	kernel_size: usize,
	stride: usize,
	padding: usize,
) -> Result<Matrix> {
	let contract = crate::core::operation::ml::AVG_POOL_2D;
	let operation = contract.name();
	validate_f32_same_engine(operation, &[input])?;
	let geometry = Pool2dGeometry::resolve(input, kernel_size, stride, padding, operation)?;
	let output_shape = [
		geometry.batch as usize,
		geometry.channels as usize,
		geometry.output_height as usize,
		geometry.output_width as usize,
	];
	let output_count = output_shape
		.iter()
		.try_fold(1_usize, |product, extent| product.checked_mul(*extent))
		.ok_or_else(|| Error::invalid_argument(format!("{operation} output size overflows usize")))?;
	shader_u32(output_count, "output element count", operation)?;
	let output = Matrix::allocate(
		input.engine_handle(),
		output_shape.to_vec(),
		output_count,
		DType::F32,
	)?;
	let buffers = [
		BufferBinding::read(input.storage()),
		BufferBinding::write(output.storage()),
	];
	let push_constants = geometry.push_constants();
	let attributes = geometry.attributes();
	let inputs = [input];
	let outputs = [&output];
	input.engine_handle().record_semantic(
		ComputeDispatch {
			kernel: KernelId::MlAvgPool2dF32,
			buffers: &buffers,
			push_constants: &push_constants,
			workgroups: [
				geometry.output_height.div_ceil(16),
				geometry.output_width.div_ceil(16),
				geometry.batch * geometry.channels,
			],
		},
		SemanticDispatch {
			contract,
			inputs: &inputs,
			outputs: &outputs,
			attributes: &attributes,
		},
	)?;
	Ok(output)
}

fn max_pool_2d_dispatch(
	input: &Matrix,
	kernel_size: usize,
	stride: usize,
	padding: usize,
) -> Result<(Matrix, Matrix)> {
	let contract = crate::core::operation::ml::MAX_POOL_2D;
	let operation = contract.name();
	validate_f32_same_engine(operation, &[input])?;
	let geometry = Pool2dGeometry::resolve(input, kernel_size, stride, padding, operation)?;
	let output_shape = [
		geometry.batch as usize,
		geometry.channels as usize,
		geometry.output_height as usize,
		geometry.output_width as usize,
	];
	let output_count = output_shape
		.iter()
		.try_fold(1_usize, |product, extent| product.checked_mul(*extent))
		.ok_or_else(|| Error::invalid_argument(format!("{operation} output size overflows usize")))?;
	shader_u32(output_count, "output element count", operation)?;
	let output = Matrix::allocate(
		input.engine_handle(),
		output_shape.to_vec(),
		output_count,
		DType::F32,
	)?;
	let indices = Matrix::allocate(
		input.engine_handle(),
		output_shape.to_vec(),
		output_count,
		DType::U32,
	)?;
	let buffers = [
		BufferBinding::read(input.storage()),
		BufferBinding::write(output.storage()),
		BufferBinding::write(indices.storage()),
	];
	let push_constants = geometry.push_constants();
	let attributes = geometry.attributes();
	let inputs = [input];
	let outputs = [&output, &indices];
	input.engine_handle().record_semantic(
		ComputeDispatch {
			kernel: KernelId::MlMaxPool2dF32,
			buffers: &buffers,
			push_constants: &push_constants,
			workgroups: [
				geometry.output_height.div_ceil(16),
				geometry.output_width.div_ceil(16),
				geometry.batch * geometry.channels,
			],
		},
		SemanticDispatch {
			contract,
			inputs: &inputs,
			outputs: &outputs,
			attributes: &attributes,
		},
	)?;
	Ok((output, indices))
}

fn adaptive_avg_pool_2d_dispatch(
	input: &Matrix,
	output_height: usize,
	output_width: usize,
) -> Result<Matrix> {
	let contract = crate::core::operation::ml::ADAPTIVE_AVG_POOL_2D;
	let operation = contract.name();
	validate_f32_same_engine(operation, &[input])?;
	let geometry = AdaptivePool2dGeometry::resolve(input, output_height, output_width, operation)?;
	let output_shape = [
		geometry.batch as usize,
		geometry.channels as usize,
		output_height,
		output_width,
	];
	let output_count = output_shape.iter().product();
	let output = Matrix::allocate(
		input.engine_handle(),
		output_shape.to_vec(),
		output_count,
		DType::F32,
	)?;
	let buffers = [
		BufferBinding::read(input.storage()),
		BufferBinding::write(output.storage()),
	];
	let push_constants = geometry.push_constants();
	let attributes = geometry.attributes();
	input.engine_handle().record_semantic(
		ComputeDispatch {
			kernel: KernelId::MlAdaptiveAvgPool2dF32,
			buffers: &buffers,
			push_constants: &push_constants,
			workgroups: [
				geometry.output_height.div_ceil(16),
				geometry.output_width.div_ceil(16),
				geometry.batch * geometry.channels,
			],
		},
		SemanticDispatch {
			contract,
			inputs: &[input],
			outputs: &[&output],
			attributes: &attributes,
		},
	)?;
	Ok(output)
}