Initial commit

This commit is contained in:
2026-07-01 16:28:57 +02:00
commit 677150ec41
9 changed files with 1363 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
.zig-cache/
zig-out/
zig-pkg/
*.o
*.a
*.so
*.dylib
*.dll
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 kbz_8
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+65
View File
@@ -0,0 +1,65 @@
# miclib Zig wrapper
Zig 0.16 wrapper for Intel/CIRCL `miclib.h` / `libmicmgmt`.
This repo does **not** vendor MPSS, `miclib.h`, `scif.h`, `libmicmgmt`, or `libscif`.
Install/build miclib separately, then point Zig at the include/library directories.
## Build
```sh
zig build \
-Dmiclib_include=/usr/local/include \
-Dmiclib_libdir=/usr/local/lib
```
The default miclib system library name is `micmgmt`, which links `-lmicmgmt`.
Override it if your install uses another name:
```sh
zig build -Dmiclib_name=micmgmt
```
`miclib.h` includes `scif.h`, so `-Dmiclib_include` must reference a directory where both headers are visible.
The build script links `micmgmt`, `scif`, libc, and libc++ because the upstream implementation is C++ with a C ABI.
## Use as a dependency
```sh
zig fetch --save git+https://git.kbz8.me/kbz_8/miclib-zig.git
```
Then in your `build.zig`:
```zig
const miclib_dep = b.dependency("miclib", .{
.target = target,
.optimize = optimize,
.miclib_include = "/usr/local/include",
.miclib_libdir = "/usr/local/lib",
});
exe.root_module.addImport("miclib", miclib_dep.module("miclib"));
```
Then in Zig:
```zig
const mic = @import("miclib");
var list = try mic.DeviceList.init();
defer list.deinit();
const count = try list.count();
for (0..count) |index| {
const device_num = try list.deviceAtIndex(index);
var device = try mic.Device.open(device_num);
defer device.deinit();
var memory = try device.memoryInfo();
defer memory.deinit();
const mem_mib = try memory.size();
_ = mem_mib;
}
```
+84
View File
@@ -0,0 +1,84 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const miclib_include = b.option(
[]const u8,
"miclib_include",
"Directory containing miclib.h and scif.h. Example: -Dmiclib_include=/usr/local/include",
);
const miclib_libdir = b.option(
[]const u8,
"miclib_libdir",
"Directory containing libmicmgmt.so/libscif.so. Example: -Dmiclib_libdir=/usr/local/lib",
);
const miclib_name = b.option(
[]const u8,
"miclib_name",
"System library name for miclib without lib/extension. Default: micmgmt",
) orelse "micmgmt";
const module = b.addModule("miclib", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
configureMiclibModule(module, miclib_include, miclib_libdir, miclib_name);
const test_module = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
configureMiclibModule(test_module, miclib_include, miclib_libdir, miclib_name);
const c_includes = b.addTranslateC(.{
.root_source_file = b.path("src/c_includes.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
module.addImport("miclib_c", c_includes.createModule());
const lib_tests = b.addTest(.{ .root_module = test_module });
const run_tests = b.addRunArtifact(lib_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_tests.step);
const enumerate_module = b.createModule(.{
.root_source_file = b.path("examples/enumerate.zig"),
.target = target,
.optimize = optimize,
.imports = &.{.{ .name = "miclib", .module = module }},
});
const enumerate = b.addExecutable(.{
.name = "miclib-enumerate",
.root_module = enumerate_module,
});
b.installArtifact(enumerate);
const run_enumerate = b.addRunArtifact(enumerate);
const run_step = b.step("example", "Run examples/enumerate.zig");
run_step.dependOn(&run_enumerate.step);
}
fn configureMiclibModule(module: *std.Build.Module, miclib_include: ?[]const u8, miclib_libdir: ?[]const u8, miclib_name: []const u8) void {
if (miclib_include) |path|
module.addIncludePath(.{ .cwd_relative = path });
if (miclib_libdir) |path|
module.addLibraryPath(.{ .cwd_relative = path });
module.link_libcpp = true;
module.linkSystemLibrary(miclib_name, .{});
module.linkSystemLibrary("scif", .{});
}
+16
View File
@@ -0,0 +1,16 @@
.{
.name = .miclib,
.version = "1.0.0",
.fingerprint = 0xee5712284bf0b001,
.minimum_zig_version = "0.16.0",
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
"src",
"examples",
"README.md",
"LICENSE",
"third_party",
},
}
+116
View File
@@ -0,0 +1,116 @@
const std = @import("std");
const mic = @import("miclib");
pub fn main() !void {
var devices = mic.DeviceList.init() catch |err| {
std.debug.print("mic_get_devices failed: {s}\n", .{@errorName(err)});
printLastMicError();
return err;
};
defer devices.deinit();
const count = try devices.count();
std.debug.print("found {} MIC device(s)\n", .{count});
for (0..count) |index| {
const device_num = try devices.deviceAtIndex(index);
var device = mic.Device.open(device_num) catch |err| {
std.debug.print("mic{}: open failed: {s}\n", .{ device_num, @errorName(err) });
printLastMicError();
continue;
};
defer device.deinit();
try printDevice(device_num, device);
}
}
fn printDevice(device_num: u32, device: mic.Device) !void {
var buffer: [mic.default_string_buffer_len]u8 = undefined;
const device_type = device.deviceType() catch 0;
std.debug.print("\nmic{}: {s}\n", .{ device_num, device.name() });
std.debug.print(" type: {}{s}\n", .{ device_type, if (device_type == mic.knc_id) " (KNC)" else "" });
if (device.serialNumber(buffer[0..])) |serial| {
std.debug.print(" serial: {s}\n", .{serial});
} else |err| printSkipped("serial", err);
if (device.siliconSku(buffer[0..])) |sku| {
std.debug.print(" sku: {s}\n", .{sku});
} else |err| printSkipped("sku", err);
if (device.pciConfig()) |pci_value| {
var pci = pci_value;
defer pci.deinit();
std.debug.print(" pci: {x:0>4}:{x:0>2}:{x:0>2}, vendor={x:0>4}, device={x:0>4}\n", .{
pci.domainId() catch 0,
pci.busNumber() catch 0,
pci.deviceNumber() catch 0,
pci.vendorId() catch 0,
pci.deviceId() catch 0,
});
if (pci.linkSpeed(buffer[0..])) |speed| {
std.debug.print(" pci-link: {s} x{}\n", .{ speed, pci.linkWidth() catch 0 });
} else |err| printSkipped("pci-link", err);
} else |err| printSkipped("pci", err);
if (device.coresInfo()) |cores_value| {
var cores = cores_value;
defer cores.deinit();
std.debug.print(" cores: {}, freq={} MHz, voltage={} mV\n", .{
cores.count() catch 0,
cores.frequency() catch 0,
cores.voltage() catch 0,
});
} else |err| printSkipped("cores", err);
if (device.memoryInfo()) |memory_value| {
var memory = memory_value;
defer memory.deinit();
const memory_type = memory.memoryType(buffer[0..]) catch "unknown";
std.debug.print(" memory: {} MiB, type={s}, freq={} MHz, ecc={}\n", .{
memory.size() catch 0,
memory_type,
memory.frequency() catch 0,
memory.eccMode() catch 0,
});
} else |err| printSkipped("memory", err);
if (device.thermalInfo()) |thermal_value| {
var thermal = thermal_value;
defer thermal.deinit();
std.debug.print(" thermals: die={} C, fan={} RPM, pwm={}\n", .{
thermal.dieTemp() catch 0,
thermal.fanRpm() catch 0,
thermal.fanPwm() catch 0,
});
} else |err| printSkipped("thermals", err);
if (device.versionInfo()) |version_value| {
var version = version_value;
defer version.deinit();
if (version.uosVersion(buffer[0..])) |uos| {
std.debug.print(" uos: {s}\n", .{uos});
} else |err| printSkipped("uos", err);
if (version.flashVersion(buffer[0..])) |flash| {
std.debug.print(" flash: {s}\n", .{flash});
} else |err| printSkipped("flash", err);
} else |err| printSkipped("version", err);
}
fn printSkipped(name: []const u8, err: anyerror) void {
std.debug.print(" {s}: unavailable ({s})\n", .{ name, @errorName(err) });
}
fn printLastMicError() void {
const last = mic.lastErrorString();
if (last.len != 0) std.debug.print("miclib: {s}\n", .{last});
}
+1
View File
@@ -0,0 +1 @@
#include <miclib.h>
+1045
View File
File diff suppressed because it is too large Load Diff
+7
View File
@@ -0,0 +1,7 @@
# Third-party notices
This package is a Zig wrapper only. It does not vendor or redistribute Intel/CIRCL `miclib.h`, `scif.h`, `libmicmgmt`, `libscif`, MPSS, or any Xeon Phi firmware/tooling.
The upstream `CIRCL/miclib` repository describes itself as `miclib v3.6.1 (Intel Xeon Phi Coprocessor) for Ubuntu LTS 14.04 Trusty (extracted from mpss-micmgmt)`.
The upstream `miclib.h` header is licensed under LGPL-2.1 text in its header comments and carries Intel notices. Link and distribute the native library according to the license terms that apply to your installed MPSS/miclib build.