Skip to content

Commit

Permalink
Spirv shader, update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurBrussee committed Nov 22, 2024
1 parent ec06010 commit c5f4ad4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
31 changes: 14 additions & 17 deletions crates/cubecl-wgpu/src/compiler/spirv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,23 +102,20 @@ impl WgpuCompiler for SpirvCompiler<GLCompute> {
})
.unwrap_or_else(|| {
let source = &kernel.source;
let module = match mode {
ExecutionMode::Checked => {
server
.device
.create_shader_module(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(source)),
})
}
ExecutionMode::Unchecked => unsafe {
server
.device
.create_shader_module_unchecked(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(source)),
})
},
// Cube always in principle uses unchecked modules. Certain operations like
// indexing are instead checked by cube. The WebGPU specification only makes
// incredibly loose gaurantees that Cube can't rely on. Additionally, kernels
// can opt in/out per operation whether checks should be performed which can be faster.
//
// SAFETY: Cube gaurantees OOB safety when launching in checked mode. Launching in unchecked mode
// is only availble through the use of unsafe code.
let module = unsafe {
server
.device
.create_shader_module_unchecked(wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(source)),
})
};
(module, None)
});
Expand Down
6 changes: 3 additions & 3 deletions crates/cubecl-wgpu/src/compiler/wgsl/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,9 +1066,9 @@ fn index(
if let Some(ind) = index {
if let Some(len) = len {
// Note: This is technically not 100% allowed. According to the WebGPU specification,
// indexing OOB is a "dynamic error" which allows "many possible outcomes". In practice,
// both wgpu and Dawn handle this by either returning 0s or clamping the index
// to valid bounds. In practice this means it's harmless to use in a select.
// any OOB access is a "dynamic error" which allows "many possible outcomes". In practice,
// both wgpu and Dawn handle this by either returning dummy data or clamping the index
// to valid bounds. This means it's harmless to use in a select.
let out_item = out.item();
value = format!("select({out_item}(0), {value}, {ind} < {len})");
};
Expand Down

0 comments on commit c5f4ad4

Please sign in to comment.