switching to Pytorch's cpuinfo

This commit is contained in:
2025-12-08 11:20:15 +01:00
parent 6d56998779
commit c67cb86dff
4 changed files with 17 additions and 16 deletions

View File

@@ -183,7 +183,6 @@ vkUpdateDescriptorSets | ⚙️ WIP
vkWaitForFences | ✅ Implemented vkWaitForFences | ✅ Implemented
</details> </details>
\
[Here](https://vulkan-driver-cts-report.kbz8.me/) shalt thou find a most meticulous account of the Vulkan 1.0 conformance trials, set forth for thy scrutiny. [Here](https://vulkan-driver-cts-report.kbz8.me/) shalt thou find a most meticulous account of the Vulkan 1.0 conformance trials, set forth for thy scrutiny.
## License ## License

View File

@@ -7,7 +7,7 @@ const ImplementationDesc = struct {
name: []const u8, name: []const u8,
root_source_file: []const u8, root_source_file: []const u8,
vulkan_version: std.SemanticVersion, vulkan_version: std.SemanticVersion,
custom: ?*const fn (*std.Build, *std.Build.Module) anyerror!void = null, custom: ?*const fn (*std.Build, *std.Build.Step.Compile) anyerror!void = null,
}; };
const implementations = [_]ImplementationDesc{ const implementations = [_]ImplementationDesc{
@@ -59,10 +59,6 @@ pub fn build(b: *std.Build) !void {
lib_mod.addSystemIncludePath(vulkan_headers.path("include")); lib_mod.addSystemIncludePath(vulkan_headers.path("include"));
if (impl.custom) |custom| {
custom(b, lib_mod) catch continue;
}
const lib = b.addLibrary(.{ const lib = b.addLibrary(.{
.name = b.fmt("vulkan_{s}", .{impl.name}), .name = b.fmt("vulkan_{s}", .{impl.name}),
.root_module = lib_mod, .root_module = lib_mod,
@@ -70,6 +66,10 @@ pub fn build(b: *std.Build) !void {
.use_llvm = true, // Fixes some random bugs happenning with custom backend. Investigations needed .use_llvm = true, // Fixes some random bugs happenning with custom backend. Investigations needed
}); });
if (impl.custom) |custom| {
custom(b, lib) catch continue;
}
const icd_file = b.addWriteFile( const icd_file = b.addWriteFile(
b.getInstallPath(.lib, b.fmt("vk_stroll_{s}.json", .{impl.name})), b.getInstallPath(.lib, b.fmt("vk_stroll_{s}.json", .{impl.name})),
b.fmt( b.fmt(
@@ -122,9 +122,10 @@ pub fn build(b: *std.Build) !void {
docs_step.dependOn(&install_docs.step); docs_step.dependOn(&install_docs.step);
} }
fn customSoft(b: *std.Build, mod: *std.Build.Module) !void { fn customSoft(b: *std.Build, lib: *std.Build.Step.Compile) !void {
const cpuinfo = b.lazyDependency("cpuinfo", .{}) orelse return error.UnresolvedDependency; const cpuinfo = b.lazyDependency("cpuinfo", .{}) orelse return error.UnresolvedDependency;
mod.addImport("cpuinfo", cpuinfo.module("cpuinfo")); lib.addSystemIncludePath(cpuinfo.path("include"));
lib.linkLibrary(cpuinfo.artifact("cpuinfo"));
} }
fn addCTest(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, vulkan_headers: *std.Build.Dependency, impl: *const ImplementationDesc, impl_lib: *std.Build.Step.Compile) !*std.Build.Step.Compile { fn addCTest(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, vulkan_headers: *std.Build.Dependency, impl: *const ImplementationDesc, impl_lib: *std.Build.Step.Compile) !*std.Build.Step.Compile {

View File

@@ -30,8 +30,8 @@
.hash = "N-V-__8AAAQc6QJfozxsyRgirFFsKICXgADgmdztIaZkDBmF", .hash = "N-V-__8AAAQc6QJfozxsyRgirFFsKICXgADgmdztIaZkDBmF",
}, },
.cpuinfo = .{ .cpuinfo = .{
.url = "git+https://github.com/Kbz-8/cpuinfo-zig#77f82a1248194e7fb706967343c66021f8522766", .url = "git+https://github.com/Kbz-8/cpuinfo#4883954cfcec3f6c9ca9c4aaddfc26107e08726f",
.hash = "cpuinfo-0.1.0-V7dMLcghAADJuG7dkd3MnwDPZ232pBK_8uGjxY43eP5u", .hash = "cpuinfo-0.0.1-RLgIQTLRMgF4dLo8AJ-HvnpFsJe6jmXCJjMWWjil6RF1",
.lazy = true, .lazy = true,
}, },
.volk = .{ .volk = .{

View File

@@ -2,7 +2,7 @@ const std = @import("std");
const vk = @import("vulkan"); const vk = @import("vulkan");
const base = @import("base"); const base = @import("base");
const root = @import("lib.zig"); const root = @import("lib.zig");
const cpuinfo = @import("cpuinfo"); const cpuinfo = @cImport(@cInclude("cpuinfo.h"));
const SoftDevice = @import("SoftDevice.zig"); const SoftDevice = @import("SoftDevice.zig");
@@ -193,12 +193,13 @@ pub fn create(allocator: std.mem.Allocator, instance: *const base.Instance) VkEr
interface.queue_family_props.appendSlice(allocator, queue_family_props[0..]) catch return VkError.OutOfHostMemory; interface.queue_family_props.appendSlice(allocator, queue_family_props[0..]) catch return VkError.OutOfHostMemory;
if (device_name[0] == 0) { if (device_name[0] == 0) {
// TODO: use Pytorch's cpuinfo someday
const name = blk: { const name = blk: {
const info = cpuinfo.get(command_allocator) catch break :blk command_allocator.dupe(u8, "Unkown") catch return VkError.OutOfHostMemory; if (cpuinfo.cpuinfo_initialize()) {
defer info.deinit(command_allocator); const package = cpuinfo.cpuinfo_get_package(0).*;
const non_sentinel_name = package.name[0..(std.mem.len(@as([*:0]const u8, @ptrCast(&package.name))))];
break :blk command_allocator.dupe(u8, info.name) catch return VkError.OutOfHostMemory; break :blk std.fmt.allocPrint(command_allocator, "{s} {d} cores", .{ non_sentinel_name, package.processor_count }) catch return VkError.OutOfHostMemory;
}
break :blk command_allocator.dupe(u8, "Unkown") catch return VkError.OutOfHostMemory;
}; };
defer command_allocator.free(name); defer command_allocator.free(name);