-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Managed to get built spirv working as long as we go through the
non-passthrough route. Can't get sum_to working until wgpu supports atomic operations. Which is super unfortunate. Maybe I'll work on that soon...
- Loading branch information
Showing
34 changed files
with
487 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#version 460 core | ||
|
||
#extension GL_ARB_compute_shader: enable | ||
#extension GL_ARB_shader_storage_buffer_object: enable | ||
|
||
layout(local_size_x = 128) in; | ||
|
||
layout(std430, binding = 1) buffer inpBlock { | ||
TYPENAME inp[]; | ||
}; | ||
|
||
layout(std430, binding = 2) buffer outpBlock { | ||
TYPENAME outp[]; | ||
}; | ||
|
||
layout(std430, binding = 3) buffer input_gradBlock { | ||
TYPENAME input_grad[]; | ||
}; | ||
|
||
layout(std430, binding = 4) buffer output_gradBlock { | ||
TYPENAME output_grad[]; | ||
}; | ||
|
||
void main() { | ||
TYPENAME dx = sign(inp[gl_GlobalInvocationID.x]); | ||
|
||
input_grad[gl_GlobalInvocationID.x] = dx * output_grad[gl_GlobalInvocationID.x]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#version 460 core | ||
|
||
#extension GL_ARB_compute_shader: enable | ||
#extension GL_ARB_shader_storage_buffer_object: enable | ||
|
||
layout(local_size_x = 128) in; | ||
|
||
layout(std430, binding = 1) buffer inpBlock { | ||
TYPENAME inp[]; | ||
}; | ||
|
||
layout(std430, binding = 2) buffer outpBlock{ | ||
TYPENAME outp[]; | ||
}; | ||
|
||
void main() { | ||
if (inp.length() == 0) { | ||
outp[gl_GlobalInvocationID.x] = abs(outp[gl_GlobalInvocationID.x]); | ||
} else { | ||
outp[gl_GlobalInvocationID.x] = abs(inp[gl_GlobalInvocationID.x]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,25 @@ | ||
use super::AbsKernelOp; | ||
use crate::tensor_ops::webgpu_kernels::webgpu_unary; | ||
|
||
const WGSL: &str = include_str!("abs.wgsl"); | ||
const GLSL_FWD: &str = include_str!("abs.fwd.glsl"); | ||
const GLSL_BWD: &str = include_str!("abs.bwd.glsl"); | ||
const SPV_FWD: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/abs.fwd.float.spv")); | ||
const SPV_BWD: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/abs.bwd.float.spv")); | ||
|
||
webgpu_unary!(AbsKernelOp, f32, WGSL, "abs_fwd_f32", "abs_bwd_f32"); | ||
webgpu_unary!(AbsKernelOp, f32, SPV_FWD, SPV_BWD); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::{tensor::*, tensor_ops::*, tests::*}; | ||
|
||
#[test] | ||
fn test_webgpu_abs() { | ||
let dev: Webgpu = Default::default(); | ||
let x = dev.tensor([-2.0, -1.0, 0.0, 1.0, 2.0]); | ||
let r = x.leaky_trace().abs(); | ||
assert_close_to_literal!(r, [2.0, 1.0, 0.0, 1.0, 2.0]); | ||
// TODO: Add mean back in | ||
// let g = r.mean().backward(); | ||
// assert_close_to_literal!(g.get(&x), [-0.2, -0.2, 0.0, 0.2, 0.2]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
use crate::prelude::webgpu_kernels::webgpu_unary; | ||
|
||
const WGSL: &str = "TODO"; | ||
const WGSL: &[u8] = b"TODO"; | ||
|
||
webgpu_unary!( | ||
super::AccurateGeLUKernelOp, | ||
f32, | ||
WGSL, | ||
"gelu_fwd_f32", | ||
"gelu_bwd_f32" | ||
); | ||
webgpu_unary!(super::AccurateGeLUKernelOp, f32, WGSL, WGSL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
use crate::prelude::webgpu_kernels::webgpu_unary; | ||
|
||
const WGSL: &str = "TODO"; | ||
const WGSL: &[u8] = b"TODO"; | ||
|
||
webgpu_unary!( | ||
super::ClampKernelOp<f32>, | ||
f32, | ||
WGSL, | ||
"clamp_fwd_f32", | ||
"clamp_bwd_f32" | ||
); | ||
webgpu_unary!(super::ClampKernelOp<f32>, f32, WGSL, WGSL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use crate::prelude::webgpu_kernels::webgpu_unary; | ||
|
||
const WGSL: &str = "TODO"; | ||
const WGSL: &[u8] = b"TODO"; | ||
|
||
webgpu_unary!(super::CosKernelOp, f32, WGSL, "cos_fwd_f32", "cos_bwd_f32"); | ||
webgpu_unary!(super::CosKernelOp, f32, WGSL, WGSL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use crate::prelude::webgpu_kernels::webgpu_unary; | ||
|
||
const WGSL: &str = "TODO"; | ||
const WGSL: &[u8] = b"TODO"; | ||
|
||
webgpu_unary!(super::ExpKernelOp, f32, WGSL, "exp_fwd_f32", "exp_bwd_f32"); | ||
webgpu_unary!(super::ExpKernelOp, f32, WGSL, WGSL); |
Oops, something went wrong.