diff options
author | Laurent Mazare <laurent.mazare@gmail.com> | 2024-07-24 08:27:30 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-24 09:27:30 +0200 |
commit | a925ae6bc659d1b40570b5068b6913d38e75b12e (patch) | |
tree | a282e4da64f2b4514cb4528fd2b046cef362737e /candle-metal-kernels/src/utils.rs | |
parent | 6056fd5c90801971733bf8126a02b31fcb76980a (diff) | |
download | candle-a925ae6bc659d1b40570b5068b6913d38e75b12e.tar.gz candle-a925ae6bc659d1b40570b5068b6913d38e75b12e.tar.bz2 candle-a925ae6bc659d1b40570b5068b6913d38e75b12e.zip |
Use a trait for the encoder provider (so that encoder can ultimately be reused). (#2352)
Diffstat (limited to 'candle-metal-kernels/src/utils.rs')
-rw-r--r-- | candle-metal-kernels/src/utils.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/candle-metal-kernels/src/utils.rs b/candle-metal-kernels/src/utils.rs index 194cddf4..4ef2162c 100644 --- a/candle-metal-kernels/src/utils.rs +++ b/candle-metal-kernels/src/utils.rs @@ -160,3 +160,26 @@ macro_rules! set_params { )* ); } + +pub trait EncoderProvider { + fn encoder(&self) -> &ComputeCommandEncoderRef; + fn maybe_end_encoding(&self, enc: &ComputeCommandEncoderRef); +} + +impl EncoderProvider for &metal::CommandBuffer { + fn encoder(&self) -> &ComputeCommandEncoderRef { + self.new_compute_command_encoder() + } + fn maybe_end_encoding(&self, enc: &ComputeCommandEncoderRef) { + enc.end_encoding() + } +} + +impl EncoderProvider for &metal::CommandBufferRef { + fn encoder(&self) -> &ComputeCommandEncoderRef { + self.new_compute_command_encoder() + } + fn maybe_end_encoding(&self, enc: &ComputeCommandEncoderRef) { + enc.end_encoding() + } +} |