fixing Phi device upload, adding actions for bidirectionnal git mirrors
This commit is contained in:
@@ -32,6 +32,7 @@ pub const FlintQueryPool = @import("FlintQueryPool.zig");
|
||||
pub const FlintRenderPass = @import("FlintRenderPass.zig");
|
||||
pub const FlintSampler = @import("FlintSampler.zig");
|
||||
pub const FlintShaderModule = @import("FlintShaderModule.zig");
|
||||
pub const compiler = @import("compiler/root.zig");
|
||||
|
||||
pub const Instance = FlintInstance;
|
||||
|
||||
@@ -89,6 +90,7 @@ test {
|
||||
std.testing.refAllDecls(FlintRenderPass);
|
||||
std.testing.refAllDecls(FlintSampler);
|
||||
std.testing.refAllDecls(FlintShaderModule);
|
||||
std.testing.refAllDecls(compiler);
|
||||
std.testing.refAllDecls(kmd);
|
||||
std.testing.refAllDecls(base);
|
||||
}
|
||||
|
||||
+39
-9
@@ -81,9 +81,27 @@ pub fn create(instance: *base.Instance, physical_device: *base.PhysicalDevice, a
|
||||
const phi_physical_device: *PhiPhysicalDevice = @alignCast(@fieldParentPtr("interface", physical_device));
|
||||
|
||||
const transport = PhiTransport.init(instance, phi_physical_device.scif_node_id) catch blk: {
|
||||
// If first connect failed try to upload the daemon to the card
|
||||
// If the first connection failed, upload and launch the daemon on the card.
|
||||
try uploadAndLaunchDaemon(instance, allocator, phi_physical_device.mic_device_num);
|
||||
break :blk try PhiTransport.init(instance, phi_physical_device.scif_node_id);
|
||||
|
||||
const max_connect_attempts = 3;
|
||||
for (0..max_connect_attempts) |attempt| {
|
||||
(std.Io.Clock.Duration{
|
||||
.raw = .fromNanoseconds(std.time.ns_per_s),
|
||||
.clock = .awake,
|
||||
}).sleep(instance.io()) catch return VkError.InitializationFailed;
|
||||
|
||||
const retry = PhiTransport.init(instance, phi_physical_device.scif_node_id) catch |err| {
|
||||
if (attempt + 1 == max_connect_attempts) return err;
|
||||
std.log.scoped(.PhiDevice).debug(
|
||||
"Phi daemon is not ready; retrying connection ({d}/{d})",
|
||||
.{ attempt + 1, max_connect_attempts },
|
||||
);
|
||||
continue;
|
||||
};
|
||||
break :blk retry;
|
||||
}
|
||||
unreachable;
|
||||
};
|
||||
|
||||
self.* = .{
|
||||
@@ -226,10 +244,12 @@ pub fn getDeviceGroupSurfacePresentModesKHR(_: *Interface, _: *base.SurfaceKHR)
|
||||
|
||||
fn uploadAndLaunchDaemon(instance: *base.Instance, allocator: std.mem.Allocator, mic_device_num: u32) VkError!void {
|
||||
const io = instance.io();
|
||||
const process_id = std.os.linux.getpid();
|
||||
const thread_id = std.Thread.getCurrentId();
|
||||
|
||||
const local_path = std.fmt.allocPrint(allocator, "/tmp/ape_phi_device_{d}_{d}.mic", .{ std.os.linux.getpid(), mic_device_num }) catch return VkError.OutOfHostMemory;
|
||||
const local_path = std.fmt.allocPrint(allocator, "/tmp/ape_phi_device_{d}_{d}_{d}.mic", .{ process_id, thread_id, mic_device_num }) catch return VkError.OutOfHostMemory;
|
||||
defer allocator.free(local_path);
|
||||
defer std.Io.Dir.deleteFileAbsolute(io, local_path) catch @panic("Caught an error while handling an error");
|
||||
defer std.Io.Dir.deleteFileAbsolute(io, local_path) catch @panic("Caught an error in a deferred cleanup");
|
||||
|
||||
std.Io.Dir.writeFile(.cwd(), io, .{
|
||||
.sub_path = local_path,
|
||||
@@ -242,19 +262,29 @@ fn uploadAndLaunchDaemon(instance: *base.Instance, allocator: std.mem.Allocator,
|
||||
const host = std.fmt.allocPrint(allocator, "{s}{d}", .{ config.phi_daemon_host_prefix, mic_device_num }) catch return VkError.OutOfHostMemory;
|
||||
defer allocator.free(host);
|
||||
|
||||
const remote_target = std.fmt.allocPrint(allocator, "{s}:{s}", .{ host, config.phi_daemon_remote_path }) catch return VkError.OutOfHostMemory;
|
||||
defer allocator.free(remote_target);
|
||||
// Upload beside the daemon and atomically replace it. Copying directly over a
|
||||
// running executable fails with ETXTBSY ("Text file busy") on the card.
|
||||
const remote_upload_path = std.fmt.allocPrint(
|
||||
allocator,
|
||||
"{s}.upload-{d}-{d}-{d}",
|
||||
.{ config.phi_daemon_remote_path, process_id, thread_id, mic_device_num },
|
||||
) catch return VkError.OutOfHostMemory;
|
||||
defer allocator.free(remote_upload_path);
|
||||
|
||||
const remote_upload_target = std.fmt.allocPrint(allocator, "{s}:{s}", .{ host, remote_upload_path }) catch return VkError.OutOfHostMemory;
|
||||
defer allocator.free(remote_upload_target);
|
||||
|
||||
std.log.scoped(.PhiDevice).debug("Uploading Phi daemon to {s}", .{remote_upload_target});
|
||||
try runHostCommand(instance, allocator, &.{
|
||||
"scp",
|
||||
local_path,
|
||||
remote_target,
|
||||
remote_upload_target,
|
||||
});
|
||||
|
||||
const launch_command = std.fmt.allocPrint(
|
||||
allocator,
|
||||
"chmod +x {s} && nohup {s} >/tmp/phi_device.log 2>&1 </dev/null &",
|
||||
.{ config.phi_daemon_remote_path, config.phi_daemon_remote_path },
|
||||
"chmod +x {s} && mv -f {s} {s} && (nohup {s} >/tmp/phi_device.log 2>&1 </dev/null &)",
|
||||
.{ remote_upload_path, remote_upload_path, config.phi_daemon_remote_path, config.phi_daemon_remote_path },
|
||||
) catch return VkError.OutOfHostMemory;
|
||||
defer allocator.free(launch_command);
|
||||
|
||||
|
||||
@@ -45,6 +45,11 @@ pub fn init(instance: *base.Instance, node_id: u16) VkError!Self {
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Self) void {
|
||||
var reply: proto.PhiResult = undefined;
|
||||
self.request(proto.PHI_PACKET_SHUTDOWN, &.{}, std.mem.asBytes(&reply)) catch |err| {
|
||||
std.log.scoped(.PhiTransport).warn("Failed to shut down remote session: {s}", .{@errorName(err)});
|
||||
};
|
||||
|
||||
_ = scif.close(self.epd);
|
||||
scif.unload();
|
||||
std.log.scoped(.PhiTransport).info("Closed connection", .{});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <Daemon.h>
|
||||
#include <CommandBuffer.h>
|
||||
#include <Daemon.h>
|
||||
#include <Logger.h>
|
||||
#include <Memory.h>
|
||||
|
||||
@@ -50,7 +50,7 @@ scif_epd_t StartDaemon()
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(scif_listen(endpoint, 1) < 0)
|
||||
if(scif_listen(endpoint, 16) < 0)
|
||||
{
|
||||
PhiLogError("Could not listen to SCIF port");
|
||||
scif_close(endpoint);
|
||||
|
||||
@@ -25,7 +25,7 @@ int HandleAllocMemory(scif_epd_t endpoint, const PhiMessageHeader* header)
|
||||
if(ReadAll(endpoint, &request, sizeof(request)) < 0)
|
||||
return -1;
|
||||
|
||||
void* memory = malloc((size_t)request.size);
|
||||
const void* memory = malloc((size_t)request.size);
|
||||
|
||||
if(memory == NULL)
|
||||
{
|
||||
|
||||
+29
-3
@@ -1,13 +1,35 @@
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <Daemon.h>
|
||||
#include <Logger.h>
|
||||
|
||||
static void* HandleClient(void* const argument)
|
||||
{
|
||||
scif_epd_t client = (scif_epd_t)(intptr_t)argument;
|
||||
|
||||
(void)HandlePacket(client);
|
||||
scif_close(client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
scif_epd_t endpoint = StartDaemon();
|
||||
pthread_attr_t client_thread_attributes;
|
||||
|
||||
if(endpoint == 0)
|
||||
return 1;
|
||||
|
||||
if(pthread_attr_init(&client_thread_attributes) != 0 ||
|
||||
pthread_attr_setdetachstate(&client_thread_attributes, PTHREAD_CREATE_DETACHED) != 0)
|
||||
{
|
||||
PhiLogError("Could not initialize client thread attributes");
|
||||
ShutdownDaemon(endpoint);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(;;)
|
||||
{
|
||||
struct scif_portID peer;
|
||||
@@ -21,11 +43,15 @@ int main(void)
|
||||
break;
|
||||
}
|
||||
|
||||
(void)HandlePacket(client);
|
||||
|
||||
scif_close(client);
|
||||
pthread_t client_thread;
|
||||
if(pthread_create(&client_thread, &client_thread_attributes, HandleClient, (void*)(intptr_t)client) != 0)
|
||||
{
|
||||
PhiLogError("Could not create SCIF client thread");
|
||||
scif_close(client);
|
||||
}
|
||||
}
|
||||
|
||||
pthread_attr_destroy(&client_thread_attributes);
|
||||
ShutdownDaemon(endpoint);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef APE_PHI_PROTOCOL_H
|
||||
#define APE_PHI_PROTOCOL_H
|
||||
|
||||
#include "Commands.h"
|
||||
#include "Commands.h" // IWYU pragma: keep
|
||||
#include <stdint.h>
|
||||
|
||||
#define PHI_PROTOCOL_MAGIC 0x50484941u
|
||||
|
||||
Reference in New Issue
Block a user