Skip to content

Commit a94b4e3

Browse files
committed
cli: add info command
1 parent 0f86583 commit a94b4e3

5 files changed

Lines changed: 19 additions & 12 deletions

File tree

build.zig.zon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.{
22
.name = .nvuv,
3-
.version = "0.1.1",
3+
.version = "0.1.2",
44
.fingerprint = 0x41ef1274ed5bfde3,
55
.minimum_zig_version = "0.16.0-dev.3013+abd131e33",
66
.dependencies = .{

src/cli.zig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ pub const Command = enum {
1919
reset,
2020
cfg,
2121
applycfg,
22+
info,
2223
};
2324

24-
// for internal use, mapped from SubCommands
25+
// for internal use, mapped from Commands
2526
pub const Op = enum {
2627
query,
2728
set,
2829
reset,
2930
showcfg,
3031
applycfg,
32+
info,
3133
noop,
3234
};
3335

@@ -37,6 +39,7 @@ pub const Parsed = union(Op) {
3739
reset: ResetHandler,
3840
showcfg: ConfigOption,
3941
applycfg: ConfigOption,
42+
info,
4043
noop,
4144
};
4245

@@ -48,7 +51,6 @@ pub const CliQueryProperty = enum {
4851
gpu, // all info about a GPU
4952
gn,
5053
gpun, // GPUs number
51-
driver, // NVIDIA driver version
5254
ps, // supported P-states list
5355
pstates,
5456
psc, // GPU/MEM clocks and offsets
@@ -64,7 +66,6 @@ pub const CliQueryProperty = enum {
6466
return switch (self) {
6567
.gpu => .gpu,
6668
.gn, .gpun => .gpu_num,
67-
.driver => .driver,
6869
.ps, .pstates => .pstates,
6970
.psc, .pstateclk => .pstate_clock,
7071
.w, .pl => .power_limit,
@@ -119,6 +120,7 @@ const main_help =
119120
\\ reset Reset gpu settings to default (root required)
120121
\\ cfg Print config file
121122
\\ applycfg Apply settings from config file (root required)
123+
\\ info Print driver, NVML version and detected GPUs
122124
\\
123125
\\Options:
124126
\\ -h, --help Print help
@@ -188,6 +190,7 @@ pub fn cli(args: std.process.Args, io: std.Io, gpa: std.mem.Allocator) !Parsed {
188190
.reset => try reset(io, gpa, &iter),
189191
.cfg => try config_commands(.showcfg, io, gpa, &iter, showcfg_help),
190192
.applycfg => try config_commands(.applycfg, io, gpa, &iter, applycfg_help),
193+
.info => .info,
191194
};
192195
}
193196

@@ -201,7 +204,6 @@ fn get(io: std.Io, gpa: std.mem.Allocator, iter: *std.process.Args.Iterator) !Pa
201204
\\ <QUERY> Possible values:
202205
\\ gpu Print gpu info
203206
\\ gn, gpun Print the number of gpus present on the system
204-
\\ driver Print NVIDIA driver version
205207
\\ ps, pstates Print supported P-states list
206208
\\ psc, pstateclk Print all P-states clocks and offsets
207209
\\ w, pl Print power limit

src/main.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ pub fn main(init: std.process.Init) !void {
3333
var nvml = try Nvml.init(gpa);
3434
defer nvml.deinit();
3535

36-
if (nvml.gpu_count == 0) {
36+
if (nvml.gpu_count == 0 and parsed != .info) {
3737
std.log.warn("no GPU found", .{});
3838
return;
3939
}
4040
const userconf = if (config) |conf| conf.get() else null;
41-
try nvml.exec(parsed, userconf);
41+
try nvml.dispatch(parsed, userconf);
4242
}

src/nvml.zig

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,24 @@ pub const Nvml = struct {
6262
};
6363
}
6464

65-
pub fn exec(self: *const Nvml, parsed: Parsed, config: ?UserConfig) !void {
65+
pub fn dispatch(self: *const Nvml, parsed: Parsed, config: ?UserConfig) !void {
6666
switch (parsed) {
6767
.query => |handler| {
68-
try handler.run(self.gpus, self.driver_version);
68+
try handler.run(self.gpus);
6969
},
7070
.set => |handler| {
7171
try handler.run(self.gpus);
7272
},
7373
.reset => |handler| {
7474
try handler.run(self.gpus);
7575
},
76+
.info => {
77+
std.debug.print("NVIDIA driver: {s}\n", .{self.driver_version});
78+
std.debug.print("NVML version: {s}\n", .{self.nvml_version});
79+
for (self.gpus) |gpu| {
80+
std.debug.print("GPU{d}: {s}\n", .{ gpu.index, gpu.name });
81+
}
82+
},
7683
.applycfg => {
7784
const conf = config orelse {
7885
std.log.warn("no config to apply", .{});

src/query.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const Gpu = @import("gpu.zig").Gpu;
77
pub const Query = enum {
88
gpu, // all info about a GPU
99
gpu_num, // GPUs number
10-
driver, // NVIDIA driver version
1110
pstates, // supported P-states list
1211
pstate_clock, // GPU/MEM clocks and offsets
1312
power_limit,
@@ -22,7 +21,7 @@ pub const QueryHandler = struct {
2221
gpu: ?u16,
2322
pstate: ?u16,
2423

25-
pub fn run(self: QueryHandler, gpus: []const Gpu, driver: []const u8) !void {
24+
pub fn run(self: QueryHandler, gpus: []const Gpu) !void {
2625
if (gpus.len == 0) unreachable;
2726

2827
const index = self.gpu orelse 0;
@@ -35,7 +34,6 @@ pub const QueryHandler = struct {
3534
switch (self.query) {
3635
.gpu => gpus[index].print(),
3736
.gpu_num => std.debug.print("GPU count: {d}\n", .{gpus.len}),
38-
.driver => std.debug.print("NVIDIA driver: {s}\n", .{driver}),
3937
.pstates => gpus[index].printSupportedPStates(),
4038
.pstate_clock => try gpus[index].printPStateClocks(self.pstate),
4139
.power_limit => gpu.printPowerLimit(),

0 commit comments

Comments
 (0)