cubecl_spirv/
sync.rs

1use cubecl_core::ir::Synchronization;
2use rspirv::spirv::{MemorySemantics, Scope};
3
4use crate::{SpirvCompiler, SpirvTarget};
5
6impl<T: SpirvTarget> SpirvCompiler<T> {
7    pub fn compile_sync(&mut self, sync: Synchronization) {
8        match sync {
9            Synchronization::SyncCube => {
10                // Adopting wgpu semantics
11                let scope = self.const_u32(Scope::Workgroup as u32);
12                let semantics =
13                    MemorySemantics::ACQUIRE_RELEASE | MemorySemantics::WORKGROUP_MEMORY;
14                let semantics = self.const_u32(semantics.bits());
15                self.control_barrier(scope, scope, semantics).unwrap();
16            }
17            Synchronization::SyncPlane => {
18                // Adopting wgpu semantics
19                let scope = self.const_u32(Scope::Subgroup as u32);
20                let semantics = MemorySemantics::RELAXED;
21                let semantics = self.const_u32(semantics.bits());
22                self.control_barrier(scope, scope, semantics).unwrap();
23            }
24            Synchronization::SyncStorage => {
25                // Adopting wgpu semantics
26                let scope_exec = self.const_u32(Scope::Workgroup as u32);
27                let scope_mem = self.const_u32(Scope::Device as u32);
28                let semantics = MemorySemantics::ACQUIRE_RELEASE | MemorySemantics::UNIFORM_MEMORY;
29                let semantics = self.const_u32(semantics.bits());
30                self.control_barrier(scope_exec, scope_mem, semantics)
31                    .unwrap();
32            }
33            Synchronization::SyncAsyncProxyShared => {
34                panic!("TMA proxy sync not supported in SPIR-V")
35            }
36        }
37    }
38}