Skip to content

Commit d8b1780

Browse files
committed
Use objc2::available macro instead
1 parent 1fc2392 commit d8b1780

File tree

2 files changed

+4
-79
lines changed

2 files changed

+4
-79
lines changed

candle-metal-kernels/src/kernel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use crate::source::{
22
AFFINE, BINARY, CAST, CONV, FILL, INDEXING, MLX_GEMM, MLX_SORT, QUANTIZED, RANDOM, REDUCE,
33
SDPA, SORT, TERNARY, UNARY,
44
};
5-
use crate::utils::{get_env_bool, os_version_at_least};
5+
use crate::utils::get_env_bool;
66
use crate::{
7-
available, ComputePipeline, ConstantValues, Device, Function, Library, MTLCompileOptions,
7+
ComputePipeline, ConstantValues, Device, Function, Library, MTLCompileOptions,
88
MTLMathFloatingPointFunctions, MTLMathMode, MetalKernelError, Source,
99
};
10+
use objc2::available;
1011
use objc2::rc::Retained;
1112
use std::collections::HashMap;
1213
use std::sync::RwLock;

candle-metal-kernels/src/utils.rs

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::metal::{Buffer, CommandBuffer, ComputeCommandEncoder, ComputePipeline};
2-
use objc2_foundation::{NSOperatingSystemVersion, NSProcessInfo};
3-
use objc2_metal::MTLSize;
2+
use crate::MTLSize;
43
use std::ffi::OsStr;
54
use std::ops::Deref;
65
use std::sync::{RwLockReadGuard, RwLockWriteGuard};
@@ -239,81 +238,6 @@ impl<'a, T> From<RwLockWriteGuard<'a, T>> for RwLockGuard<'a, T> {
239238
}
240239
}
241240

242-
pub(crate) struct OSVersion {
243-
pub major: isize,
244-
pub minor: isize,
245-
pub patch: isize,
246-
}
247-
248-
impl From<isize> for OSVersion {
249-
fn from(major: isize) -> OSVersion {
250-
OSVersion {
251-
major,
252-
minor: 0,
253-
patch: 0,
254-
}
255-
}
256-
}
257-
258-
impl From<(isize, isize)> for OSVersion {
259-
fn from((major, minor): (isize, isize)) -> OSVersion {
260-
OSVersion {
261-
major,
262-
minor,
263-
patch: 0,
264-
}
265-
}
266-
}
267-
268-
impl From<(isize, isize, isize)> for OSVersion {
269-
fn from((major, minor, patch): (isize, isize, isize)) -> OSVersion {
270-
OSVersion {
271-
major,
272-
minor,
273-
patch,
274-
}
275-
}
276-
}
277-
278-
impl From<OSVersion> for NSOperatingSystemVersion {
279-
fn from(v: OSVersion) -> NSOperatingSystemVersion {
280-
NSOperatingSystemVersion {
281-
majorVersion: v.major,
282-
minorVersion: v.minor,
283-
patchVersion: v.patch,
284-
}
285-
}
286-
}
287-
288-
// Checks if OS version is at least the provided (major, minor, patch) version
289-
pub(crate) fn os_version_at_least<V: Into<OSVersion>>(v: V) -> bool {
290-
let v: OSVersion = v.into();
291-
let info = NSProcessInfo::new();
292-
info.isOperatingSystemAtLeastVersion(v.into())
293-
}
294-
295-
// Poor man's Swift @available attribute
296-
#[macro_export]
297-
macro_rules! available {
298-
(ios=$t:expr) => {
299-
if cfg!(target_os = "ios") {
300-
os_version_at_least($t)
301-
} else {
302-
true
303-
}
304-
};
305-
(macos=$t:expr) => {
306-
if cfg!(target_os = "macos") {
307-
os_version_at_least($t)
308-
} else {
309-
true
310-
}
311-
};
312-
($i:ident=$e:expr, $($is:ident=$es:expr)*) => {{
313-
(available!($i=$e)) && (available!($($is=$es),+))
314-
}};
315-
}
316-
317241
fn is_truthy(s: String) -> bool {
318242
match s.as_str() {
319243
"true" | "t" | "yes" | "y" | "1" => true,

0 commit comments

Comments
 (0)