Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions mlx/backend/metal/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,9 @@ void depthwise_conv_2D_gpu(

MTL::Size group_dims = MTL::Size(tc, tw, th);
MTL::Size grid_dims = MTL::Size(
conv_params.C / tc, conv_params.oS[1] / tw, (conv_params.oS[0] / th) * N);
conv_params.C / tc,
(conv_params.oS[1] + tw - 1) / tw,
((conv_params.oS[0] + th - 1) / th) * N);

compute_encoder.dispatch_threadgroups(grid_dims, group_dims);
}
Expand All @@ -986,7 +988,6 @@ void dispatch_conv_2D_gpu(
if (C_per_group == 1 && O_per_group == 1 && is_kdil_one &&
conv_params.wS[0] <= 7 && conv_params.wS[1] <= 7 &&
conv_params.str[0] <= 2 && conv_params.str[1] <= 2 &&
conv_params.oS[0] % 8 == 0 && conv_params.oS[1] % 8 == 0 &&
conv_params.wt_strides[1] == conv_params.wS[1] &&
conv_params.C % 16 == 0 && conv_params.C == conv_params.O) {
return depthwise_conv_2D_gpu(s, d, in, wt, out, conv_params);
Expand Down
1 change: 1 addition & 0 deletions mlx/backend/metal/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ build_kernel(random)
build_kernel(rms_norm)
build_kernel(rope)
build_kernel(scaled_dot_product_attention sdpa_vector.h)
build_kernel(fused_qsdpa fused_qsdpa.h)
if(MLX_METAL_VERSION GREATER_EQUAL 320)
build_kernel(fence)
endif()
Expand Down
6 changes: 5 additions & 1 deletion mlx/backend/metal/kernels/conv.metal
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ template <typename T>

threadgroup T ins[TGH * TGW * TGC];

const int n_tgblocks_h = params.oS[0] / th;
const int n_tgblocks_h = (params.oS[0] + th - 1) / th;
const int n = tid.z / n_tgblocks_h;
const int tghid = tid.z % n_tgblocks_h;
const int oh = tghid * th + lid.z;
Expand Down Expand Up @@ -277,6 +277,10 @@ template <typename T>
}
threadgroup_barrier(mem_flags::mem_none);

if (oh >= params.oS[0] || ow >= params.oS[1]) {
return;
}

out += n * params.out_strides[0] + oh * params.out_strides[1] +
ow * params.out_strides[2];
out[c] = static_cast<T>(o);
Expand Down
Loading
Loading