Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cuda support for attn softmax #64

Merged
merged 5 commits into from
Jan 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Debug
  • Loading branch information
EricLBuehler committed Jan 11, 2025
commit b4491b8652c35d57d54f8ecddc49de59339ce0be
7 changes: 5 additions & 2 deletions candle-nn/src/ops.rs
Original file line number Diff line number Diff line change
@@ -706,8 +706,9 @@ impl candle::InplaceOp2 for AttnSoftmaxLastDim {
let (nrows_x, ncols_x) = (el / dim_m1, dim_m1);

const WARP_SIZE: usize = 32;
const CUDA_SOFT_MAX_BLOCK_SIZE: usize = 1024;
let mut nth = WARP_SIZE;
while nth < ncols_x && nth < 1024 {
while nth < ncols_x && nth < CUDA_SOFT_MAX_BLOCK_SIZE {
nth *= 2;
}

@@ -716,6 +717,7 @@ impl candle::InplaceOp2 for AttnSoftmaxLastDim {
block_dim: (nrows_x as u32, 1, 1),
shared_mem_bytes: (WARP_SIZE * std::mem::size_of::<f32>()) as u32,
};
dbg!(&cfg);
let func =
dev.get_or_load_func(&kernel_name::<T>("attn_soft_max"), kernels::REDUCE)?;
let params = (&a, &mask, &a, ncols_x as i32, nrows_y as i32, self.scale);
@@ -876,8 +878,9 @@ impl candle::CustomOp2 for AttnSoftmaxLastDim {
let (nrows_x, ncols_x) = (el / dim_m1, dim_m1);

const WARP_SIZE: usize = 32;
const CUDA_SOFT_MAX_BLOCK_SIZE: usize = 1024;
let mut nth = WARP_SIZE;
while nth < ncols_x && nth < 1024 {
while nth < ncols_x && nth < CUDA_SOFT_MAX_BLOCK_SIZE {
nth *= 2;
}

Loading