const std = @import("std"); const cpu = @import("platforms/cpu"); const cuda = @import("platforms/cuda"); const furiosa = @import("platforms/furiosa"); const metal = @import("platforms/metal"); const neuron = @import("platforms/neuron"); const oneapi = @import("platforms/oneapi"); const pjrt = @import("pjrt"); const platforms_options = @import("platforms/options"); const rocm = @import("platforms/rocm"); const tpu = @import("platforms/tpu"); const platforms = @This(); pub const Platform = enum { cpu, cuda, rocm, tpu, neuron, oneapi, metal, furiosa, pub fn selectFirstAcceleratorEnabled() error{Unavailable}!Platform { inline for (@typeInfo(Platform).@"enum".field_names) |field| { const target: Platform = @field(Platform, field); if (comptime (target != .cpu and target.isEnabled())) return target; } if (!comptime Platform.cpu.isEnabled()) @compileError("No platform was enabled, use --@zml//platforms:cuda=true to eg enable Cuda"); return .cpu; } pub fn isEnabled(target: Platform) bool { return switch (target) { inline else => |tag| @field(platforms_options, @tagName(tag) ++ "_enabled"), }; } pub fn load(target: Platform, allocator: std.mem.Allocator, io: std.Io) !*const pjrt.Api { return switch (target) { inline else => |tag| @field(platforms, @tagName(tag)).load(allocator, io), }; } }; pub const load = Platform.load; pub const isEnabled = Platform.isEnabled;