Skip to content

Commit

Permalink
Fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertdelajonquieresonos committed Oct 18, 2024
1 parent 808d1fd commit 8ef7a78
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions metal/src/kernels/array/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl MultiBroadcast {
input_offset: usize,
output_shape: &[usize],
) -> Result<MetalTensor> {
let output = unsafe { MetalTensor::uninitialized_dt(input.datum_type(), &output_shape)? };
let output = unsafe { MetalTensor::uninitialized_dt(input.datum_type(), output_shape)? };
self.dispatch_eval(context, input, input_offset, &output)?;
context.wait_until_completed()?;
Ok(output)
Expand Down Expand Up @@ -96,7 +96,7 @@ impl MultiBroadcast {
metal::MTLResourceUsage::Read,
);
encoder.set_slice(1, &input_broadcast_strides);
encoder.set_metal_tensor(2, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(2, output, metal::MTLResourceUsage::Write);
encoder.set_slice(3, output.shape());
encoder.set_slice(4, output.strides());

Expand Down
2 changes: 1 addition & 1 deletion metal/src/kernels/array/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Cast {
let encoder = command_buffer.new_compute_command_encoder();
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_metal_tensor(0, input, metal::MTLResourceUsage::Read);
encoder.set_metal_tensor(1, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(1, output, metal::MTLResourceUsage::Write);

let grid_size = MTLSize { width: output.len() as NSUInteger, height: 1, depth: 1 };
let group_size = MTLSize { width: 1, height: 1, depth: 1 };
Expand Down
4 changes: 2 additions & 2 deletions metal/src/kernels/array/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ impl Concat {
encoder.set_slice(1, i_strides);
encoder.set_metal_tensor_with_offset(
2,
&output,
output,
offset as _,
metal::MTLResourceUsage::Write,
);
encoder.set_slice(3, i_shape);
encoder.set_slice(4, &output_strides);
encoder.set_slice(4, output_strides);
let grid_size = utils::build_metal_size_for_shape(i_shape);
let group_size = utils::build_metal_size_with_ones();
encoder.dispatch_thread_groups(grid_size, group_size);
Expand Down
2 changes: 1 addition & 1 deletion metal/src/kernels/array/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Memcpy {
input_offset as _,
metal::MTLResourceUsage::Read,
);
encoder.set_metal_tensor(1, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(1, output, metal::MTLResourceUsage::Write);

let grid_size = MTLSize { width: output.len() as NSUInteger, height: 1, depth: 1 };
let group_size = MTLSize { width: 1, height: 1, depth: 1 };
Expand Down
2 changes: 1 addition & 1 deletion metal/src/kernels/array/permute_axes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl PermuteAxes {
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_metal_tensor(0, input, metal::MTLResourceUsage::Read);
encoder.set_slice(1, &new_strides);
encoder.set_metal_tensor(2, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(2, output, metal::MTLResourceUsage::Write);
encoder.set_slice(3, output.shape());
encoder.set_slice(4, output.strides());

Expand Down
4 changes: 2 additions & 2 deletions metal/src/kernels/bin_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl BinOps {
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_metal_tensor(0, lhs, metal::MTLResourceUsage::Read);
encoder.set_metal_tensor(1, rhs, metal::MTLResourceUsage::Read);
encoder.set_metal_tensor(2, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(2, output, metal::MTLResourceUsage::Write);

let grid_size = MTLSize { width: output.len() as NSUInteger, height: 1, depth: 1 };
let group_size = MTLSize { width: 1, height: 1, depth: 1 };
Expand Down Expand Up @@ -228,7 +228,7 @@ impl BinOps {
encoder.set_slice(1, &lhs_strides);
encoder.set_metal_tensor(2, rhs, metal::MTLResourceUsage::Read);
encoder.set_slice(3, &rhs_strides);
encoder.set_metal_tensor(4, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(4, output, metal::MTLResourceUsage::Write);
encoder.set_slice(5, output_shape);

let grid_size = MTLSize {
Expand Down
2 changes: 1 addition & 1 deletion metal/src/kernels/element_wise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl ElementWiseOps {
let encoder = command_buffer.new_compute_command_encoder();
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_metal_tensor(0, input, metal::MTLResourceUsage::Read);
encoder.set_metal_tensor(1, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(1, output, metal::MTLResourceUsage::Write);

let grid_size = MTLSize { width: output.len() as NSUInteger, height: 1, depth: 1 };
let group_size = MTLSize { width: 1, height: 1, depth: 1 };
Expand Down
8 changes: 3 additions & 5 deletions metal/src/kernels/nn/new_gelu.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::encoder::EncoderExt;
use crate::{LibraryName, MetalContext, MetalTensor};
use anyhow::Result;
use metal::MTLSize;
Expand Down Expand Up @@ -56,13 +57,10 @@ impl NewGelu {
let command_buffer = context.command_buffer();
let encoder = command_buffer.new_compute_command_encoder();
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_buffer(0, Some(input.metal()), input.metal_offset());
encoder.set_buffer(1, Some(output.metal()), output.metal_offset());

encoder.set_metal_tensor(0, input, metal::MTLResourceUsage::Read);
encoder.set_metal_tensor(1, output, metal::MTLResourceUsage::Write);
let grid_size = MTLSize { width: output.len() as _, height: 1, depth: 1 };
let group_size = MTLSize { width: 1, height: 1, depth: 1 };
encoder.use_resource(input.metal(), metal::MTLResourceUsage::Read);
encoder.use_resource(output.metal(), metal::MTLResourceUsage::Write);
encoder.dispatch_thread_groups(grid_size, group_size);
encoder.end_encoding();
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions metal/src/kernels/nn/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Reducer {

let input_shape_nd3 = Self::reshape_to_rank_3(input.shape(), axis);
let input_strides_nd3 = Tensor::natural_strides(&input_shape_nd3);
let output_shape_nd3 = Self::reshape_to_rank_3(&output.shape(), axis);
let output_shape_nd3 = Self::reshape_to_rank_3(output.shape(), axis);
let output_strides_nd3 = Tensor::natural_strides(&output_shape_nd3);

let pipeline = context
Expand All @@ -83,7 +83,7 @@ impl Reducer {
let encoder = command_buffer.new_compute_command_encoder();
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_metal_tensor(0, input, metal::MTLResourceUsage::Read);
encoder.set_metal_tensor(1, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(1, output, metal::MTLResourceUsage::Write);
encoder.set_slice(2, &input_shape_nd3);
encoder.set_slice(3, &input_strides_nd3);
encoder.set_slice(4, &output_strides_nd3);
Expand Down
2 changes: 1 addition & 1 deletion metal/src/kernels/nn/rms_norm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl RmsNorm {
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_metal_tensor(0, input, metal::MTLResourceUsage::Read);
encoder.set_tensor(1, eps);
encoder.set_metal_tensor(2, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(2, output, metal::MTLResourceUsage::Write);
encoder.set_slice(3, &shape_nd3);
encoder.set_slice(4, &strides_nd3);

Expand Down
2 changes: 1 addition & 1 deletion metal/src/kernels/nn/silu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Silu {
let encoder = command_buffer.new_compute_command_encoder();
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_metal_tensor(0, input, metal::MTLResourceUsage::Read);
encoder.set_metal_tensor(1, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(1, output, metal::MTLResourceUsage::Write);

let grid_size = MTLSize { width: output.len() as _, height: 1, depth: 1 };
let group_size = MTLSize { width: 1, height: 1, depth: 1 };
Expand Down
2 changes: 1 addition & 1 deletion metal/src/kernels/nn/softmax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Softmax {
let encoder = command_buffer.new_compute_command_encoder();
encoder.set_compute_pipeline_state(&pipeline);
encoder.set_metal_tensor(0, input, metal::MTLResourceUsage::Read);
encoder.set_metal_tensor(1, &output, metal::MTLResourceUsage::Write);
encoder.set_metal_tensor(1, output, metal::MTLResourceUsage::Write);
encoder.set_slice(2, &shape_nd3);
encoder.set_slice(3, &strides_nd3);

Expand Down

0 comments on commit 8ef7a78

Please sign in to comment.