cubecl-core 0.12.0-pre.1

CubeCL core create
Documentation
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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
use crate::{prelude::*, runtime_tests::stream_errors};
use alloc::{string::ToString, vec, vec::Vec};
use core::time::Duration;
use cubecl_common::device::{Device, DeviceId};
use cubecl_runtime::{
    client::{Client, ClientGroup, ClientGroupError, MemberBuffers},
    runtime::Runtime,
    server::{Handle, ReduceOperation},
};
use std::sync::{
    Mutex, MutexGuard, PoisonError,
    mpsc::{self, RecvTimeoutError},
};

/// Tests in one process share each device's communicators, which pair collectives in the order
/// each device queues them, so the tests queue theirs one at a time.
static COLLECTIVES: Mutex<()> = Mutex::new(());

/// Devices whose communicators were queued in different orders hang rather than fail.
const TIME_LIMIT: Duration = Duration::from_secs(60);

const F32: cubecl_ir::ElemType = cubecl_ir::ElemType::Float(cubecl_ir::FloatKind::F32);
const I32: cubecl_ir::ElemType = cubecl_ir::ElemType::Int(cubecl_ir::IntKind::I32);

/// Elements of each member's contribution, and of each chunk.
const LEN: usize = 6;

/// No collective here writes it, since no contribution is negative.
const UNWRITTEN: f32 = -1.0;

pub fn test_a_group_all_reduce_sums_and_averages<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(all_reduce::<R>);
}

pub fn test_all_gather_concatenates_in_member_order<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(all_gather::<R>);
}

pub fn test_reduce_scatter_gives_each_member_its_chunk<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(reduce_scatter::<R>);
}

pub fn test_broadcast_copies_the_root_to_every_member<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(broadcast::<R>);
}

pub fn test_all_to_all_exchanges_chunks_by_rank<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(all_to_all::<R>);
}

pub fn test_a_group_without_the_first_device_gathers<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(later_devices::<R>);
}

pub fn test_a_group_takes_a_source_from_another_stream<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(source_from_another_stream::<R>);
}

pub fn test_a_transfer_moves_bytes_of_any_type<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(transfer_of_any_type::<R>);
}

pub fn test_a_collective_refuses_a_repeated_device<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(repeated_device::<R>);
}

pub fn test_a_refused_collective_queues_no_part<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(refused_on_the_caller::<R>);
}

pub fn test_a_failed_part_breaks_its_group<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(broken_group::<R>);
}

pub fn test_a_group_of_one_device_runs_its_collectives<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(one_member::<R>);
}

pub fn test_a_group_moves_bytes_no_element_type_divides<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(odd_bytes::<R>);
}

pub fn test_an_all_to_all_reads_and_writes_at_offsets<R: Runtime>() {
    let _collectives = queue_alone();
    finish_within_limit(offset_buffers::<R>);
}

/// Holds every device's collectives for the caller until the guard drops.
pub fn queue_alone() -> MutexGuard<'static, ()> {
    COLLECTIVES.lock().unwrap_or_else(PoisonError::into_inner)
}

/// Runs `test`, aborting the process if it hangs.
pub fn finish_within_limit(test: fn()) {
    let (finished, done) = mpsc::channel();
    let test = std::thread::spawn(move || {
        test();
        let _ = finished.send(());
    });
    if let Err(RecvTimeoutError::Timeout) = done.recv_timeout(TIME_LIMIT) {
        // A panic would leave the devices waiting on each other for every later test.
        std::eprintln!(
            "still running after {TIME_LIMIT:?}, most likely on devices waiting for each other"
        );
        std::process::abort();
    }
    if let Err(panic) = test.join() {
        std::panic::resume_unwind(panic);
    }
}

fn all_reduce<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    let members = group.clients().len();
    let contributions = || -> Vec<MemberBuffers> {
        group
            .clients()
            .iter()
            .enumerate()
            .map(|(member, client)| MemberBuffers {
                src: from_values(client, &values(member, LEN)),
                dst: unwritten(client, LEN),
            })
            .collect()
    };
    let summed: Vec<f32> = (0..LEN)
        .map(|i| (0..members).map(|member| values(member, LEN)[i]).sum())
        .collect();

    let buffers = contributions();
    let sums = destinations(&buffers);
    group.all_reduce(buffers, F32, ReduceOperation::Sum);
    assert_every_member_holds(&group, sums, |_| summed.clone());

    let buffers = contributions();
    let means = destinations(&buffers);
    group.all_reduce(buffers, F32, ReduceOperation::Mean);
    for (member, (client, destination)) in group.clients().iter().zip(means).enumerate() {
        let actual = client.read_one(destination).unwrap();
        for (actual, sum) in f32::from_bytes(&actual).iter().zip(&summed) {
            let mean = sum / members as f32;
            assert!((actual - mean).abs() <= mean * 1e-6, "member {member}");
        }
    }

    let in_place: Vec<Handle> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| {
            let values: Vec<i32> = values(member, LEN).iter().map(|it| *it as i32).collect();
            client.create_from_slice(i32::as_bytes(&values))
        })
        .collect();
    let buffers = in_place
        .iter()
        .map(|handle| MemberBuffers {
            src: handle.clone(),
            dst: handle.clone(),
        })
        .collect();
    group.all_reduce(buffers, I32, ReduceOperation::Sum);
    for (member, (client, handle)) in group.clients().iter().zip(in_place).enumerate() {
        let actual = client.read_one(handle).unwrap();
        let expected: Vec<i32> = summed.iter().map(|it| *it as i32).collect();
        assert_eq!(i32::from_bytes(&actual), expected, "member {member}");
    }
}

fn all_gather<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    gather_every_member(&group);
}

fn reduce_scatter<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    let members = group.clients().len();
    let buffers: Vec<_> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| MemberBuffers {
            src: from_values(client, &values(member, members * LEN)),
            dst: unwritten(client, LEN),
        })
        .collect();
    let destinations = destinations(&buffers);

    group.reduce_scatter(buffers, F32, ReduceOperation::Sum);

    let reduced: Vec<f32> = (0..members * LEN)
        .map(|i| {
            (0..members)
                .map(|member| values(member, members * LEN)[i])
                .sum()
        })
        .collect();
    assert_every_member_holds(&group, destinations, |member| {
        reduced[member * LEN..(member + 1) * LEN].to_vec()
    });
}

fn broadcast<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    // The last member, so a root taken for rank 0 shows.
    let root = group.clients().len() - 1;
    let destinations: Vec<_> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| match member == root {
            true => from_values(client, &values(root, LEN)),
            false => unwritten(client, LEN),
        })
        .collect();

    group.broadcast(destinations[root].clone(), destinations.clone());
    assert_every_member_holds(&group, destinations, |_| values(root, LEN));

    let src = from_values(&group.clients()[0], &values(0, LEN));
    let destinations: Vec<_> = group
        .clients()
        .iter()
        .map(|client| unwritten(client, LEN))
        .collect();
    group.broadcast(src, destinations.clone());
    assert_every_member_holds(&group, destinations, |_| values(0, LEN));
}

fn all_to_all<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    let members = group.clients().len();
    let chunk = |from: usize, to: usize| -> Vec<f32> {
        (0..LEN)
            .map(|i| (100 * from + 10 * to + i) as f32)
            .collect()
    };
    let buffers: Vec<_> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| {
            let src: Vec<f32> = (0..members).flat_map(|to| chunk(member, to)).collect();
            MemberBuffers {
                src: from_values(client, &src),
                dst: unwritten(client, members * LEN),
            }
        })
        .collect();
    let destinations = destinations(&buffers);

    group.all_to_all(buffers);

    assert_every_member_holds(&group, destinations, |member| {
        (0..members).flat_map(|from| chunk(from, member)).collect()
    });
}

fn source_from_another_stream<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    let members = group.clients().len();
    let client = group.clients()[0].clone();
    let elsewhere = std::thread::spawn(move || from_values(&client, &values(0, LEN)))
        .join()
        .unwrap();
    let mut buffers: Vec<_> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| MemberBuffers {
            src: from_values(client, &values(member, LEN)),
            dst: unwritten(client, members * LEN),
        })
        .collect();
    buffers[0].src = elsewhere;
    let destinations = destinations(&buffers);

    group.all_gather(buffers);

    let expected: Vec<f32> = (0..members)
        .flat_map(|member| values(member, LEN))
        .collect();
    assert_every_member_holds(&group, destinations, |_| expected.clone());
}

fn later_devices<R: Runtime>() {
    let device_ids = R::enumerate_devices(0);
    if device_ids.len() < 2 {
        return;
    }
    let Some(group) = group_of::<R>(&device_ids[1..]) else {
        return;
    };
    gather_every_member(&group);
}

fn transfer_of_any_type<R: Runtime>() {
    let device_ids = R::enumerate_devices(0);
    if device_ids.len() < 2 {
        return;
    }
    let mut source = R::client(&R::Device::from_id(device_ids[0]));
    let destination = R::client(&R::Device::from_id(device_ids[1]));
    if !source.has_device_transport() {
        log::warn!("skipping transfers: {} has no transport", source.name());
        return;
    }
    // Three `i16`s, a type NCCL has no name for.
    let bytes = [1u8, 2, 3, 4, 5, 6];
    let src = source.create_from_slice(&bytes);

    let moved = source.to_client(src, &destination);

    assert_eq!(destination.read_one(moved).unwrap().to_vec(), bytes);
}

fn repeated_device<R: Runtime>() {
    let Some(device) = R::enumerate_devices(0).first().copied() else {
        return;
    };
    let client = R::client(&R::Device::from_id(device));
    if !client.has_device_transport() {
        return;
    }

    let refused = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
        client.ensure_init_collective(vec![device, device]);
    }));

    assert_panicked_with(refused, "appears twice");
}

fn refused_on_the_caller<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    let wrong_size = group
        .clients()
        .iter()
        .map(|client| MemberBuffers {
            src: unwritten(client, LEN),
            dst: unwritten(client, LEN),
        })
        .collect();

    let refused = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
        group.all_gather(wrong_size)
    }));

    assert_panicked_with(refused, "holds");
    // No member queued a part, so the devices still run the next collective.
    gather_every_member(&group);
}

fn broken_group<R: Runtime>() {
    // Alone in its group, so no peer is left waiting, on a device no other test groups alone.
    let device_ids = R::enumerate_devices(0);
    let [_, .., last] = device_ids.as_slice() else {
        return;
    };
    let Some(alone) = group_of::<R>(&[*last]) else {
        return;
    };
    let client = &alone.clients()[0];
    let gather = || MemberBuffers {
        src: from_values(client, &values(0, LEN)),
        dst: unwritten(client, LEN),
    };
    let tainted = gather();
    let reason = "the source's writer never ran";
    unsafe {
        stream_errors::rejected::launch_unchecked(
            client,
            CubeCount::new_single(),
            CubeDim::new_1d(1),
            BufferArg::from_raw_parts(tainted.src.clone(), 1),
            reason.to_string(),
        )
    };
    let failed = tainted.dst.clone();
    alone.all_gather(vec![tainted]);
    let clean = gather();
    let refused = clean.dst.clone();
    alone.all_gather(vec![clean]);

    for (part, dst) in [("failed", failed), ("next", refused)] {
        let error = client.read_one(dst).expect_err(part).to_string();
        assert!(error.contains(reason), "{part}: {error}");
    }
    // Only the group whose part failed is broken.
    if let Some(group) = group::<R>() {
        gather_every_member(&group);
    }
}

fn one_member<R: Runtime>() {
    let Some(device) = R::enumerate_devices(0).first().copied() else {
        return;
    };
    let Some(group) = group_of::<R>(&[device]) else {
        return;
    };
    let client = &group.clients()[0];
    gather_every_member(&group);

    let dst = unwritten(client, LEN);
    let buffers = vec![MemberBuffers {
        src: from_values(client, &values(0, LEN)),
        dst: dst.clone(),
    }];
    group.all_reduce(buffers, F32, ReduceOperation::Sum);
    assert_every_member_holds(&group, vec![dst], |_| values(0, LEN));
}

fn odd_bytes<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    let members = group.clients().len();
    let bytes = |member: usize, len: usize| -> Vec<u8> {
        (0..len).map(|i| (16 * member + i) as u8).collect()
    };
    let read = |member: usize, handle: Handle| group.clients()[member].read_one(handle).unwrap();

    // Three bytes per member, which no element type wider than a byte divides.
    let buffers: Vec<_> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| MemberBuffers {
            src: client.create_from_slice(&bytes(member, 3)),
            dst: client.empty(3 * members),
        })
        .collect();
    let gathered = destinations(&buffers);
    group.all_gather(buffers);
    let expected: Vec<u8> = (0..members).flat_map(|member| bytes(member, 3)).collect();
    for (member, dst) in gathered.into_iter().enumerate() {
        assert_eq!(read(member, dst).to_vec(), expected, "member {member}");
    }

    let src = group.clients()[0].create_from_slice(&bytes(0, 5));
    let broadcast: Vec<_> = group
        .clients()
        .iter()
        .map(|client| client.empty(5))
        .collect();
    group.broadcast(src, broadcast.clone());
    for (member, dst) in broadcast.into_iter().enumerate() {
        assert_eq!(read(member, dst).to_vec(), bytes(0, 5), "member {member}");
    }

    let buffers: Vec<_> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| MemberBuffers {
            src: client.create_from_slice(&bytes(member, members)),
            dst: client.empty(members),
        })
        .collect();
    let exchanged = destinations(&buffers);
    group.all_to_all(buffers);
    for (member, dst) in exchanged.into_iter().enumerate() {
        let expected: Vec<u8> = (0..members)
            .map(|from| bytes(from, members)[member])
            .collect();
        assert_eq!(read(member, dst).to_vec(), expected, "member {member}");
    }
}

fn offset_buffers<R: Runtime>() {
    let Some(group) = group::<R>() else {
        return;
    };
    let members = group.clients().len();
    let skipped = (LEN * size_of::<f32>()) as u64;
    let chunk = |from: usize, to: usize| -> Vec<f32> {
        (0..LEN)
            .map(|i| (100 * from + 10 * to + i) as f32)
            .collect()
    };
    let wholes: Vec<_> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| {
            let src: Vec<f32> = core::iter::repeat_n(UNWRITTEN, LEN)
                .chain((0..members).flat_map(|to| chunk(member, to)))
                .collect();
            MemberBuffers {
                src: from_values(client, &src),
                dst: unwritten(client, (members + 1) * LEN),
            }
        })
        .collect();
    let buffers = wholes
        .iter()
        .map(|whole| MemberBuffers {
            src: whole.src.clone().offset_start(skipped),
            dst: whole.dst.clone().offset_start(skipped),
        })
        .collect();

    group.all_to_all(buffers);

    // The bytes before each offset stay as they were.
    assert_every_member_holds(&group, destinations(&wholes), |member| {
        core::iter::repeat_n(UNWRITTEN, LEN)
            .chain((0..members).flat_map(|from| chunk(from, member)))
            .collect()
    });
}

/// Gathers `values(member, LEN)` from every member, checking each holds them all in order.
fn gather_every_member(group: &ClientGroup) {
    let members = group.clients().len();
    let buffers: Vec<_> = group
        .clients()
        .iter()
        .enumerate()
        .map(|(member, client)| MemberBuffers {
            src: from_values(client, &values(member, LEN)),
            dst: unwritten(client, members * LEN),
        })
        .collect();
    let destinations = destinations(&buffers);

    group.all_gather(buffers);

    let expected: Vec<f32> = (0..members)
        .flat_map(|member| values(member, LEN))
        .collect();
    assert_every_member_holds(group, destinations, |_| expected.clone());
}

fn assert_panicked_with(outcome: std::thread::Result<()>, reason: &str) {
    let panic = outcome.expect_err("the collective was accepted");
    let message = panic
        .downcast_ref::<std::string::String>()
        .map(std::string::String::as_str)
        .unwrap_or_default();
    assert!(message.contains(reason), "{message}");
}

/// A group of every device, or `None` when there are fewer than two or no transport.
fn group<R: Runtime>() -> Option<ClientGroup> {
    let device_ids = R::enumerate_devices(0);
    if device_ids.len() < 2 {
        return None;
    }
    group_of::<R>(&device_ids)
}

/// A group of `device_ids`, or `None` when their runtime has no transport.
fn group_of<R: Runtime>(device_ids: &[DeviceId]) -> Option<ClientGroup> {
    let clients = device_ids
        .iter()
        .map(|id| R::client(&R::Device::from_id(*id)))
        .collect();
    match ClientGroup::new(clients) {
        Ok(group) => Some(group),
        Err(ClientGroupError::NoDeviceTransport { runtime }) => {
            log::warn!("skipping collectives: {runtime} has no transport between its devices");
            None
        }
        Err(error) => panic!("{error}"),
    }
}

/// `len` values that tell `member`'s contribution apart from every other.
fn values(member: usize, len: usize) -> Vec<f32> {
    (0..len).map(|i| (100 * member + i) as f32).collect()
}

fn from_values(client: &Client, values: &[f32]) -> Handle {
    client.create_from_slice(f32::as_bytes(values))
}

/// A destination of `len` values, so one read before its result lands shows.
fn unwritten(client: &Client, len: usize) -> Handle {
    from_values(client, &vec![UNWRITTEN; len])
}

fn destinations(buffers: &[MemberBuffers]) -> Vec<Handle> {
    buffers.iter().map(|buffers| buffers.dst.clone()).collect()
}

fn assert_every_member_holds(
    group: &ClientGroup,
    destinations: Vec<Handle>,
    expected: impl Fn(usize) -> Vec<f32>,
) {
    for (member, (client, destination)) in group.clients().iter().zip(destinations).enumerate() {
        let actual = client.read_one(destination).unwrap();
        assert_eq!(
            f32::from_bytes(&actual),
            expected(member),
            "member {member}"
        );
    }
}

#[allow(missing_docs)]
#[macro_export]
macro_rules! testgen_collectives {
    () => {
        use super::*;

        #[$crate::runtime_tests::test_log::test]
        fn test_a_group_all_reduce_sums_and_averages() {
            cubecl_core::runtime_tests::collectives::test_a_group_all_reduce_sums_and_averages::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_all_gather_concatenates_in_member_order() {
            cubecl_core::runtime_tests::collectives::test_all_gather_concatenates_in_member_order::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_reduce_scatter_gives_each_member_its_chunk() {
            cubecl_core::runtime_tests::collectives::test_reduce_scatter_gives_each_member_its_chunk::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_broadcast_copies_the_root_to_every_member() {
            cubecl_core::runtime_tests::collectives::test_broadcast_copies_the_root_to_every_member::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_a_group_takes_a_source_from_another_stream() {
            cubecl_core::runtime_tests::collectives::test_a_group_takes_a_source_from_another_stream::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_all_to_all_exchanges_chunks_by_rank() {
            cubecl_core::runtime_tests::collectives::test_all_to_all_exchanges_chunks_by_rank::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_a_group_without_the_first_device_gathers() {
            cubecl_core::runtime_tests::collectives::test_a_group_without_the_first_device_gathers::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_a_transfer_moves_bytes_of_any_type() {
            cubecl_core::runtime_tests::collectives::test_a_transfer_moves_bytes_of_any_type::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_a_refused_collective_queues_no_part() {
            cubecl_core::runtime_tests::collectives::test_a_refused_collective_queues_no_part::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_a_failed_part_breaks_its_group() {
            cubecl_core::runtime_tests::collectives::test_a_failed_part_breaks_its_group::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_a_group_of_one_device_runs_its_collectives() {
            cubecl_core::runtime_tests::collectives::test_a_group_of_one_device_runs_its_collectives::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_a_group_moves_bytes_no_element_type_divides() {
            cubecl_core::runtime_tests::collectives::test_a_group_moves_bytes_no_element_type_divides::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_an_all_to_all_reads_and_writes_at_offsets() {
            cubecl_core::runtime_tests::collectives::test_an_all_to_all_reads_and_writes_at_offsets::<
                TestRuntime,
            >();
        }

        #[$crate::runtime_tests::test_log::test]
        fn test_a_collective_refuses_a_repeated_device() {
            cubecl_core::runtime_tests::collectives::test_a_collective_refuses_a_repeated_device::<
                TestRuntime,
            >();
        }
    };
}