2023-05-15 09:36:41 +00:00
|
|
|
const builtin = @import("builtin");
|
2024-01-16 14:13:45 +00:00
|
|
|
|
|
|
|
|
const asynk = @import("async");
|
2023-05-15 09:36:41 +00:00
|
|
|
const c = @import("c");
|
2024-01-16 14:13:45 +00:00
|
|
|
const pjrt = @import("pjrt");
|
2023-05-15 09:36:41 +00:00
|
|
|
|
|
|
|
|
pub fn isEnabled() bool {
|
|
|
|
|
return @hasDecl(c, "ZML_RUNTIME_CPU");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn load() !*const pjrt.Api {
|
|
|
|
|
if (comptime !isEnabled()) {
|
|
|
|
|
return error.Unavailable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ext = switch (builtin.os.tag) {
|
|
|
|
|
.windows => ".dll",
|
|
|
|
|
.macos, .ios, .watchos => ".dylib",
|
|
|
|
|
else => ".so",
|
|
|
|
|
};
|
2024-01-16 14:13:45 +00:00
|
|
|
return try asynk.callBlocking(pjrt.Api.loadFrom, .{"libpjrt_cpu" ++ ext});
|
2023-05-15 09:36:41 +00:00
|
|
|
}
|