summaryrefslogtreecommitdiff
path: root/candle-metal-kernels/src/utils.rs
diff options
context:
space:
mode:
authorLaurent Mazare <laurent.mazare@gmail.com>2024-07-24 08:27:30 +0100
committerGitHub <noreply@github.com>2024-07-24 09:27:30 +0200
commita925ae6bc659d1b40570b5068b6913d38e75b12e (patch)
treea282e4da64f2b4514cb4528fd2b046cef362737e /candle-metal-kernels/src/utils.rs
parent6056fd5c90801971733bf8126a02b31fcb76980a (diff)
downloadcandle-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.rs23
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()
+ }
+}