[Phi] fixing name consistency

This commit is contained in:
2026-08-18 18:21:52 +02:00
parent 8360d8edfe
commit e98907df8e
18 changed files with 114 additions and 79 deletions
+2
View File
@@ -576,7 +576,9 @@ fn addPhiDaemonCompilerArgs(
"-std=c11", "-std=c11",
"-Wall", "-Wall",
"-Wextra", "-Wextra",
"-Werror",
"-Wno-unused-parameter", "-Wno-unused-parameter",
"-Wno-unused-variable",
"-pthread", "-pthread",
}); });
+1
View File
@@ -1,5 +1,6 @@
-xc -xc
-std=c11 -std=c11
-mavx512f
-Isrc/phi/shared -Isrc/phi/shared
-Isrc/phi/mic -Isrc/phi/mic
-isystem/opt/mpss/3.8.6/sysroots/k1om-mpss-linux/usr/include/ -isystem/opt/mpss/3.8.6/sysroots/k1om-mpss-linux/usr/include/
+10 -1
View File
@@ -367,8 +367,17 @@ pub fn fillBuffer(interface: *Interface, buffer: *base.Buffer, offset: vk.Device
const memory = try remoteMemory(buffer); const memory = try remoteMemory(buffer);
var fill_size = if (size == vk.WHOLE_SIZE)
buffer.size - offset
else
size;
// VK_WHOLE_SIZE fills only complete 4-byte words. Any trailing 1-3 bytes are untouched
if (size == vk.WHOLE_SIZE)
fill_size &= ~@as(vk.DeviceSize, 3);
try self.appendCommand(proto.PhiCmdFillBuffer, proto.PHI_CMD_FILL_BUFFER, .{ try self.appendCommand(proto.PhiCmdFillBuffer, proto.PHI_CMD_FILL_BUFFER, .{
.size = if (size == vk.WHOLE_SIZE) buffer.size - offset else size, .size = fill_size,
.memory = @intCast(memory.remote_handle), .memory = @intCast(memory.remote_handle),
.offset = offset, .offset = offset,
.data = data, .data = data,
+3 -4
View File
@@ -1,15 +1,13 @@
const std = @import("std"); const std = @import("std");
const vk = @import("vulkan"); const vk = @import("vulkan");
const base = @import("base"); const base = @import("base");
const proto = @import("lib").proto;
const VkError = base.VkError; const VkError = base.VkError;
const Self = @This(); const Self = @This();
pub const Interface = base.Image; pub const Interface = base.Image;
pub const F32x4 = @Vector(4, f32);
pub const U32x4 = @Vector(4, u32);
interface: Interface, interface: Interface,
pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const vk.ImageCreateInfo) VkError!*Self { pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const vk.ImageCreateInfo) VkError!*Self {
@@ -39,7 +37,8 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
} }
pub fn getMemoryRequirements(_: *Interface, requirements: *vk.MemoryRequirements) VkError!void { pub fn getMemoryRequirements(_: *Interface, requirements: *vk.MemoryRequirements) VkError!void {
_ = requirements; requirements.alignment = proto.PHI_MEMORY_ALIGNMENT;
requirements.size = std.mem.alignForward(vk.DeviceSize, requirements.size, proto.PHI_MEMORY_ALIGNMENT);
} }
pub fn copyToMemory(interface: *const Interface, memory: []u8, subresource: vk.ImageSubresourceLayers) VkError!void { pub fn copyToMemory(interface: *const Interface, memory: []u8, subresource: vk.ImageSubresourceLayers) VkError!void {
+13 -5
View File
@@ -1,9 +1,10 @@
#include <Buffer.h> #include <Buffer.h>
#include <Logger.h>
#include <Memory.h> #include <Memory.h>
#include <avx/Avx.h> #include <avx/Avx.h>
int PhiIsBufferCommand(const PhiCmdHeader* header) int IsBufferCommand(const PhiCmdHeader* header)
{ {
switch((PhiCmdType)header->type) switch((PhiCmdType)header->type)
{ {
@@ -19,7 +20,7 @@ int PhiIsBufferCommand(const PhiCmdHeader* header)
static PhiStatus CopyBuffer(PhiCommandReader* reader) static PhiStatus CopyBuffer(PhiCommandReader* reader)
{ {
PhiCmdCopyBuffer command; PhiCmdCopyBuffer command;
PhiStatus status = PhiReadCommandData(reader, &command, sizeof(command)); PhiStatus status = ReadCommandData(reader, &command, sizeof(command));
if(status != PHI_STATUS_OK) if(status != PHI_STATUS_OK)
return status; return status;
@@ -41,13 +42,16 @@ static PhiStatus FillBuffer(PhiCommandReader* reader)
{ {
PhiCmdFillBuffer command; PhiCmdFillBuffer command;
PhiStatus status = PhiReadCommandData(reader, &command, sizeof(command)); PhiStatus status = ReadCommandData(reader, &command, sizeof(command));
if(status != PHI_STATUS_OK) if(status != PHI_STATUS_OK)
return status; return status;
if(command.memory == 0) if(command.memory == 0)
{
LogErrorFmt("Invalid memory handle: %p", command.memory);
return PHI_STATUS_INVALID_HANDLE; return PHI_STATUS_INVALID_HANDLE;
}
Memory* memory = (Memory*)command.memory; Memory* memory = (Memory*)command.memory;
@@ -57,8 +61,12 @@ static PhiStatus FillBuffer(PhiCommandReader* reader)
const uint32_t value = command.data; const uint32_t value = command.data;
// Check if dst and size are 4-byte aligned // Check if dst and size are 4-byte aligned
if((((uintptr_t)dst | size) & 3) != 0) uintptr_t alignment = ((uintptr_t)dst | size) & 3;
if(alignment != 0)
{
LogErrorFmt("Invalid memory alignment: %d", alignment);
return PHI_STATUS_INVALID_ARGUMENT; return PHI_STATUS_INVALID_ARGUMENT;
}
// Bring dst to a 64-byte cache-line boundary. // Bring dst to a 64-byte cache-line boundary.
while(size >= 4 && ((uintptr_t)dst & 63) != 0) while(size >= 4 && ((uintptr_t)dst & 63) != 0)
@@ -95,7 +103,7 @@ static PhiStatus FillBuffer(PhiCommandReader* reader)
return PHI_STATUS_OK; return PHI_STATUS_OK;
} }
PhiStatus PhiExecuteBufferCommand(PhiCommandReader* reader, const PhiCmdHeader* header) PhiStatus ExecuteBufferCommand(PhiCommandReader* reader, const PhiCmdHeader* header)
{ {
switch((PhiCmdType)header->type) switch((PhiCmdType)header->type)
{ {
+2 -2
View File
@@ -3,7 +3,7 @@
#include <CommandBuffer.h> #include <CommandBuffer.h>
int PhiIsBufferCommand(const PhiCmdHeader* header); int IsBufferCommand(const PhiCmdHeader* header);
PhiStatus PhiExecuteBufferCommand(PhiCommandReader* reader, const PhiCmdHeader* header); PhiStatus ExecuteBufferCommand(PhiCommandReader* reader, const PhiCmdHeader* header);
#endif #endif
+16 -7
View File
@@ -1,8 +1,9 @@
#include <CommandBuffer.h> #include <CommandBuffer.h>
#include <Logger.h>
#include <Buffer.h> #include <Buffer.h>
PhiStatus PhiReadCommandData(PhiCommandReader* reader, void* data, uint64_t size) PhiStatus ReadCommandData(PhiCommandReader* reader, void* data, uint64_t size)
{ {
if(reader->remaining < size) if(reader->remaining < size)
return PHI_STATUS_BAD_MESSAGE; return PHI_STATUS_BAD_MESSAGE;
@@ -14,7 +15,7 @@ PhiStatus PhiReadCommandData(PhiCommandReader* reader, void* data, uint64_t size
return PHI_STATUS_OK; return PHI_STATUS_OK;
} }
int PhiDrainCommandReader(PhiCommandReader* reader) int DrainCommandReader(PhiCommandReader* reader)
{ {
if(reader->remaining == 0) if(reader->remaining == 0)
return 0; return 0;
@@ -26,7 +27,7 @@ int PhiDrainCommandReader(PhiCommandReader* reader)
static PhiStatus ReadCommandHeader(PhiCommandReader* reader, PhiCmdHeader* command_header) static PhiStatus ReadCommandHeader(PhiCommandReader* reader, PhiCmdHeader* command_header)
{ {
PhiStatus status = PhiReadCommandData(reader, command_header, sizeof(*command_header)); PhiStatus status = ReadCommandData(reader, command_header, sizeof(*command_header));
if(status != PHI_STATUS_OK) if(status != PHI_STATUS_OK)
return status; return status;
@@ -38,12 +39,17 @@ static PhiStatus ReadCommandHeader(PhiCommandReader* reader, PhiCmdHeader* comma
static PhiStatus ExecuteCommand(PhiCommandReader* reader, const PhiCmdHeader* command_header) static PhiStatus ExecuteCommand(PhiCommandReader* reader, const PhiCmdHeader* command_header)
{ {
if(PhiIsBufferCommand(command_header)) if(IsBufferCommand(command_header))
return PhiExecuteBufferCommand(reader, command_header); return ExecuteBufferCommand(reader, command_header);
return PHI_STATUS_BAD_MESSAGE; return PHI_STATUS_BAD_MESSAGE;
} }
static const char* CommandName[] = {
"CopyBuffer",
"FillBuffer",
};
int HandleWorkExecution(PhiEndpoint endpoint, const PhiMessageHeader* header) int HandleWorkExecution(PhiEndpoint endpoint, const PhiMessageHeader* header)
{ {
PhiWorkExecutionRequest request; PhiWorkExecutionRequest request;
@@ -71,7 +77,7 @@ int HandleWorkExecution(PhiEndpoint endpoint, const PhiMessageHeader* header)
if(reader.remaining != request.command_buffer_size) if(reader.remaining != request.command_buffer_size)
{ {
if(PhiDrainCommandReader(&reader) < 0) if(DrainCommandReader(&reader) < 0)
return -1; return -1;
reply.result.status = PHI_STATUS_BAD_MESSAGE; reply.result.status = PHI_STATUS_BAD_MESSAGE;
return SendReply(endpoint, header, &reply, sizeof(reply)); return SendReply(endpoint, header, &reply, sizeof(reply));
@@ -86,10 +92,13 @@ int HandleWorkExecution(PhiEndpoint endpoint, const PhiMessageHeader* header)
reply.result.status = ExecuteCommand(&reader, &cmd_header); reply.result.status = ExecuteCommand(&reader, &cmd_header);
if(reply.result.status != PHI_STATUS_OK) if(reply.result.status != PHI_STATUS_OK)
{
LogErrorFmt("Command %s execution failed: %s", CommandName[cmd_header.type], StatusName[reply.result.status]);
break; break;
}
} }
if(reader.remaining > 0 && PhiDrainCommandReader(&reader) < 0) if(reader.remaining > 0 && DrainCommandReader(&reader) < 0)
return -1; return -1;
return SendReply(endpoint, header, &reply, sizeof(reply)); return SendReply(endpoint, header, &reply, sizeof(reply));
+2 -2
View File
@@ -10,7 +10,7 @@ typedef struct PhiCommandReader
} PhiCommandReader; } PhiCommandReader;
int HandleWorkExecution(PhiEndpoint endpoint, const PhiMessageHeader* header); int HandleWorkExecution(PhiEndpoint endpoint, const PhiMessageHeader* header);
int PhiDrainCommandReader(PhiCommandReader* reader); int DrainCommandReader(PhiCommandReader* reader);
PhiStatus PhiReadCommandData(PhiCommandReader* reader, void* data, uint64_t size); PhiStatus ReadCommandData(PhiCommandReader* reader, void* data, uint64_t size);
#endif #endif
+8 -8
View File
@@ -35,20 +35,20 @@ static int HandleHello(PhiEndpoint endpoint, const PhiMessageHeader* header)
PhiEndpoint StartDaemon(void) PhiEndpoint StartDaemon(void)
{ {
PhiLogInfo("Starting the daemon..."); LogInfo("Starting the daemon...");
PhiEndpoint endpoint = PhiTransportListen(PHI_TRANSPORT_PORT); PhiEndpoint endpoint = TransportListen(PHI_TRANSPORT_PORT);
if(endpoint == PHI_ENDPOINT_INVALID) if(endpoint == PHI_ENDPOINT_INVALID)
PhiLogError("Could not listen on the Phi transport"); LogError("Could not listen on the Phi transport");
PhiLogInfo("Daemon started"); LogInfo("Daemon started");
return endpoint; return endpoint;
} }
void ShutdownDaemon(PhiEndpoint endpoint) void ShutdownDaemon(PhiEndpoint endpoint)
{ {
PhiLogInfo("Shutting down the daemon..."); LogInfo("Shutting down the daemon...");
PhiTransportClose(endpoint); TransportClose(endpoint);
} }
int HandlePacket(PhiEndpoint endpoint) int HandlePacket(PhiEndpoint endpoint)
@@ -116,7 +116,7 @@ int ReadAll(PhiEndpoint endpoint, void* data, size_t size)
while(offset < size) while(offset < size)
{ {
ssize_t got = PhiTransportReceive(endpoint, bytes + offset, size - offset); ssize_t got = TransportReceive(endpoint, bytes + offset, size - offset);
if(got <= 0) if(got <= 0)
return -1; return -1;
offset += (size_t)got; offset += (size_t)got;
@@ -132,7 +132,7 @@ int WriteAll(PhiEndpoint endpoint, const void* data, size_t size)
while(offset < size) while(offset < size)
{ {
ssize_t sent = PhiTransportSend(endpoint, bytes + offset, size - offset); ssize_t sent = TransportSend(endpoint, bytes + offset, size - offset);
if(sent <= 0) if(sent <= 0)
return -1; return -1;
offset += (size_t)sent; offset += (size_t)sent;
+1 -1
View File
@@ -37,7 +37,7 @@ inline static void SetConsoleColor(FILE* file, int code)
fprintf(file, "\033[1;%dm", code); fprintf(file, "\033[1;%dm", code);
} }
void PhiLog(PhiLogLevel level, const char* fmt, const char* file, const char* function, int line, ...) void Log(LogLevel level, const char* fmt, const char* file, const char* function, int line, ...)
{ {
time_t now = time(0); time_t now = time(0);
struct tm tstruct = *localtime(&now); struct tm tstruct = *localtime(&now);
+22 -11
View File
@@ -1,24 +1,35 @@
#ifndef APE_PHI_LOGGER_H #ifndef APE_PHI_LOGGER_H
#define APE_PHI_LOGGER_H #define APE_PHI_LOGGER_H
typedef enum PhiLogLevel typedef enum LogLevel
{ {
PHI_LOG_LEVEL_INFO = 0, PHI_LOG_LEVEL_INFO = 0,
PHI_LOG_LEVEL_WARN = 1, PHI_LOG_LEVEL_WARN = 1,
PHI_LOG_LEVEL_ERR = 2, PHI_LOG_LEVEL_ERR = 2,
PHI_LOG_LEVEL_FATAL = 3, PHI_LOG_LEVEL_FATAL = 3,
} PhiLogLevel; } LogLevel;
void PhiLog(PhiLogLevel level, const char* fmt, const char* file, const char* function, int line, ...); static const char* StatusName[] = {
"OK",
"Bad Message",
"Unsupported version",
"Unsupported packed",
"Out of memory",
"Invalid handle",
"Host memory map failed",
"Invalid argument",
};
#define PhiLogError(msg) PhiLog(PHI_LOG_LEVEL_ERR, msg, __FILE__, __FUNCTION__, __LINE__) void Log(LogLevel level, const char* fmt, const char* file, const char* function, int line, ...);
#define PhiLogWarning(msg) PhiLog(PHI_LOG_LEVEL_WARN, msg, __FILE__, __FUNCTION__, __LINE__)
#define PhiLogInfo(msg) PhiLog(PHI_LOG_LEVEL_INFO, msg, __FILE__, __FUNCTION__, __LINE__)
#define PhiLogFatal(msg) PhiLog(PHI_LOG_LEVEL_FATAL, msg, __FILE__, __FUNCTION__, __LINE__)
#define PhiLogErrorFmt(msg, ...) PhiLog(PHI_LOG_LEVEL_ERR, msg, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) #define LogError(msg) Log(PHI_LOG_LEVEL_ERR, msg, __FILE__, __FUNCTION__, __LINE__)
#define PhiLogWarningFmt(msg, ...) PhiLog(PHI_LOG_LEVEL_WARN, msg, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) #define LogWarning(msg) Log(PHI_LOG_LEVEL_WARN, msg, __FILE__, __FUNCTION__, __LINE__)
#define PhiLogInfoFmt(msg, ...) PhiLog(PHI_LOG_LEVEL_INFO, msg, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) #define LogInfo(msg) Log(PHI_LOG_LEVEL_INFO, msg, __FILE__, __FUNCTION__, __LINE__)
#define PhiLogFatalFmt(msg, ...) PhiLog(PHI_LOG_LEVEL_FATAL, msg, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) #define LogFatal(msg) Log(PHI_LOG_LEVEL_FATAL, msg, __FILE__, __FUNCTION__, __LINE__)
#define LogErrorFmt(msg, ...) Log(PHI_LOG_LEVEL_ERR, msg, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LogWarningFmt(msg, ...) Log(PHI_LOG_LEVEL_WARN, msg, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LogInfoFmt(msg, ...) Log(PHI_LOG_LEVEL_INFO, msg, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
#define LogFatalFmt(msg, ...) Log(PHI_LOG_LEVEL_FATAL, msg, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
#endif #endif
+9 -9
View File
@@ -17,7 +17,7 @@ static Memory* MapHostMemory(PhiEndpoint epd, const PhiMapHostMemoryRequest* req
if(ptr == MAP_FAILED) if(ptr == MAP_FAILED)
{ {
PhiLogErrorFmt("Failed to map host memory: %s", strerror(errno)); LogErrorFmt("Failed to map host memory: %s", strerror(errno));
return NULL; return NULL;
} }
@@ -25,7 +25,7 @@ static Memory* MapHostMemory(PhiEndpoint epd, const PhiMapHostMemoryRequest* req
if(!memory) if(!memory)
{ {
scif_munmap(ptr, request->scif_size); scif_munmap(ptr, request->scif_size);
PhiLogError("Failed to allocate memory"); LogError("Failed to allocate memory");
return NULL; return NULL;
} }
@@ -80,9 +80,9 @@ int HandleNewMemory(PhiEndpoint endpoint, const PhiMessageHeader* header)
return -1; return -1;
memory = AllocMemory(endpoint, &request); memory = AllocMemory(endpoint, &request);
if(memory == NULL) if(memory == NULL)
PhiLogErrorFmt("Failed to allocate %zu bytes", (size_t)request.size); LogErrorFmt("Failed to allocate %zu bytes", (size_t)request.size);
else else
PhiLogInfoFmt("Allocated %llu bytes to handle 0x%X", request.size, (uintptr_t)memory); LogInfoFmt("Allocated %llu bytes to handle 0x%X", request.size, (uintptr_t)memory);
} }
else if(header->type == PHI_PACKET_MAP_HOST_MEMORY) else if(header->type == PHI_PACKET_MAP_HOST_MEMORY)
{ {
@@ -93,7 +93,7 @@ int HandleNewMemory(PhiEndpoint endpoint, const PhiMessageHeader* header)
if(memory == NULL) if(memory == NULL)
reply.result.status = PHI_STATUS_MAP_HOST_MEMORY_FAILED; reply.result.status = PHI_STATUS_MAP_HOST_MEMORY_FAILED;
else else
PhiLogInfoFmt("Mapped host memory to handle 0x%X", (uint64_t)(uintptr_t)memory); LogInfoFmt("Mapped host memory to handle 0x%X", (uint64_t)(uintptr_t)memory);
} }
if(memory != NULL) if(memory != NULL)
@@ -131,7 +131,7 @@ int HandleDestroyMemory(PhiEndpoint endpoint, const PhiMessageHeader* header)
if(request.remote_handle == 0) if(request.remote_handle == 0)
{ {
reply.result.status = PHI_STATUS_INVALID_HANDLE; reply.result.status = PHI_STATUS_INVALID_HANDLE;
PhiLogErrorFmt("Could not free memory: invalid handle 0x%X", request.remote_handle); LogErrorFmt("Could not free memory: invalid handle 0x%X", request.remote_handle);
} }
else else
{ {
@@ -142,9 +142,9 @@ int HandleDestroyMemory(PhiEndpoint endpoint, const PhiMessageHeader* header)
else if(memory->type == PHI_MEMORY_HOST_MAPPED) else if(memory->type == PHI_MEMORY_HOST_MAPPED)
scif_munmap((void*)memory->ptr, memory->size); scif_munmap((void*)memory->ptr, memory->size);
PhiLogInfoFmt("Destroyed %s memory handle 0x%X", LogInfoFmt("Destroyed %s memory handle 0x%X",
memory->type == PHI_MEMORY_LOCAL ? "local" : "host-mapped", memory->type == PHI_MEMORY_LOCAL ? "local" : "host-mapped",
request.remote_handle); request.remote_handle);
} }
return SendReply(endpoint, header, &reply, sizeof(reply)); return SendReply(endpoint, header, &reply, sizeof(reply));
+6 -6
View File
@@ -1,6 +1,6 @@
#include <Transport.h> #include <Transport.h>
PhiEndpoint PhiTransportAccept(PhiEndpoint endpoint) PhiEndpoint TransportAccept(PhiEndpoint endpoint)
{ {
struct scif_portID peer; struct scif_portID peer;
PhiEndpoint client = PHI_ENDPOINT_INVALID; PhiEndpoint client = PHI_ENDPOINT_INVALID;
@@ -9,12 +9,12 @@ PhiEndpoint PhiTransportAccept(PhiEndpoint endpoint)
return client; return client;
} }
int PhiTransportClose(PhiEndpoint endpoint) int TransportClose(PhiEndpoint endpoint)
{ {
return scif_close(endpoint); return scif_close(endpoint);
} }
PhiEndpoint PhiTransportListen(uint16_t port) PhiEndpoint TransportListen(uint16_t port)
{ {
PhiEndpoint endpoint = scif_open(); PhiEndpoint endpoint = scif_open();
if(endpoint == PHI_ENDPOINT_INVALID) if(endpoint == PHI_ENDPOINT_INVALID)
@@ -22,18 +22,18 @@ PhiEndpoint PhiTransportListen(uint16_t port)
if(scif_bind(endpoint, port) < 0 || scif_listen(endpoint, 16) < 0) if(scif_bind(endpoint, port) < 0 || scif_listen(endpoint, 16) < 0)
{ {
PhiTransportClose(endpoint); TransportClose(endpoint);
return PHI_ENDPOINT_INVALID; return PHI_ENDPOINT_INVALID;
} }
return endpoint; return endpoint;
} }
ssize_t PhiTransportReceive(PhiEndpoint endpoint, void* data, size_t size) ssize_t TransportReceive(PhiEndpoint endpoint, void* data, size_t size)
{ {
return scif_recv(endpoint, data, size, SCIF_RECV_BLOCK); return scif_recv(endpoint, data, size, SCIF_RECV_BLOCK);
} }
ssize_t PhiTransportSend(PhiEndpoint endpoint, const void* data, size_t size) ssize_t TransportSend(PhiEndpoint endpoint, const void* data, size_t size)
{ {
return scif_send(endpoint, (void*)data, size, SCIF_SEND_BLOCK); return scif_send(endpoint, (void*)data, size, SCIF_SEND_BLOCK);
} }
+5 -5
View File
@@ -10,11 +10,11 @@ typedef scif_epd_t PhiEndpoint;
#define PHI_ENDPOINT_INVALID ((PhiEndpoint) - 1) #define PHI_ENDPOINT_INVALID ((PhiEndpoint) - 1)
PhiEndpoint PhiTransportAccept(PhiEndpoint endpoint); PhiEndpoint TransportAccept(PhiEndpoint endpoint);
int PhiTransportClose(PhiEndpoint endpoint); int TransportClose(PhiEndpoint endpoint);
PhiEndpoint PhiTransportListen(uint16_t port); PhiEndpoint TransportListen(uint16_t port);
ssize_t PhiTransportReceive(PhiEndpoint endpoint, void* data, size_t size); ssize_t TransportReceive(PhiEndpoint endpoint, void* data, size_t size);
ssize_t PhiTransportSend(PhiEndpoint endpoint, const void* data, size_t size); ssize_t TransportSend(PhiEndpoint endpoint, const void* data, size_t size);
#endif #endif
+5 -10
View File
@@ -5,11 +5,6 @@
#define PHI_CACHE_LINE_SIZE 64 #define PHI_CACHE_LINE_SIZE 64
static inline __m512i Load512KNC(const uint8_t* src)
{
return _mm512_load_epi32((const void*)src);
}
void AvxCopy(uint8_t* dst, const uint8_t* src, size_t size) void AvxCopy(uint8_t* dst, const uint8_t* src, size_t size)
{ {
if(size == 0) if(size == 0)
@@ -74,10 +69,10 @@ void AvxCopy(uint8_t* dst, const uint8_t* src, size_t size)
// KNC's loadunpack pair implements the conceptual unaligned 64-byte load. // KNC's loadunpack pair implements the conceptual unaligned 64-byte load.
while(size >= 256) while(size >= 256)
{ {
const __m512i v0 = Load512KNC(src + 0); const __m512i v0 = _mm512_load_epi32((const void*)(src + 0));
const __m512i v1 = Load512KNC(src + 64); const __m512i v1 = _mm512_load_epi32((const void*)(src + 64));
const __m512i v2 = Load512KNC(src + 128); const __m512i v2 = _mm512_load_epi32((const void*)(src + 128));
const __m512i v3 = Load512KNC(src + 192); const __m512i v3 = _mm512_load_epi32((const void*)(src + 192));
_mm512_store_epi32((void*)(dst + 0), v0); _mm512_store_epi32((void*)(dst + 0), v0);
_mm512_store_epi32((void*)(dst + 64), v1); _mm512_store_epi32((void*)(dst + 64), v1);
@@ -91,7 +86,7 @@ void AvxCopy(uint8_t* dst, const uint8_t* src, size_t size)
while(size >= 64) while(size >= 64)
{ {
const __m512i value = Load512KNC(src); const __m512i value = _mm512_load_epi32((const void*)src);
_mm512_store_epi32((void*)dst, value); _mm512_store_epi32((void*)dst, value);
+1 -1
View File
@@ -4,7 +4,7 @@
#include <immintrin.h> #include <immintrin.h>
#include <stdint.h> #include <stdint.h>
static inline __attribute__((always_inline)) __m512i _mm512_set1_epi32_knc(uint32_t value) inline __attribute__((always_inline)) __m512i _mm512_set1_epi32_knc(uint32_t value)
{ {
__m512i result; __m512i result;
__asm__("vpbroadcastd %1, %0" : "=x"(result) : "m"(value)); __asm__("vpbroadcastd %1, %0" : "=x"(result) : "m"(value));
+7 -7
View File
@@ -10,7 +10,7 @@ static void* HandleClient(void* const argument)
PhiEndpoint client = (PhiEndpoint)(intptr_t)argument; PhiEndpoint client = (PhiEndpoint)(intptr_t)argument;
(void)HandlePacket(client); (void)HandlePacket(client);
PhiTransportClose(client); TransportClose(client);
return NULL; return NULL;
} }
@@ -28,30 +28,30 @@ int main(int argc, char** argv)
if(pthread_attr_init(&client_thread_attributes) != 0 || if(pthread_attr_init(&client_thread_attributes) != 0 ||
pthread_attr_setdetachstate(&client_thread_attributes, PTHREAD_CREATE_DETACHED) != 0) pthread_attr_setdetachstate(&client_thread_attributes, PTHREAD_CREATE_DETACHED) != 0)
{ {
PhiLogError("Could not initialize client thread attributes"); LogError("Could not initialize client thread attributes");
ShutdownDaemon(endpoint); ShutdownDaemon(endpoint);
return 1; return 1;
} }
for(;;) for(;;)
{ {
PhiEndpoint client = PhiTransportAccept(endpoint); PhiEndpoint client = TransportAccept(endpoint);
if(client == PHI_ENDPOINT_INVALID) if(client == PHI_ENDPOINT_INVALID)
{ {
if(errno == EINTR) if(errno == EINTR)
continue; continue;
PhiLogError("Could not accept transport connection"); LogError("Could not accept transport connection");
break; break;
} }
PhiLogInfo("Host connected to the daemon"); LogInfo("Host connected to the daemon");
pthread_t client_thread; pthread_t client_thread;
if(pthread_create(&client_thread, &client_thread_attributes, HandleClient, (void*)(intptr_t)client) != 0) if(pthread_create(&client_thread, &client_thread_attributes, HandleClient, (void*)(intptr_t)client) != 0)
{ {
PhiLogError("Could not create transport client thread"); LogError("Could not create transport client thread");
PhiTransportClose(client); TransportClose(client);
} }
} }
+1
View File
@@ -26,6 +26,7 @@ typedef enum PhiPacketType
PHI_PACKET_MAP_HOST_MEMORY = 8, PHI_PACKET_MAP_HOST_MEMORY = 8,
} PhiPacketType; } PhiPacketType;
// When adding status, update StatusName in Logger.h
typedef enum PhiStatus typedef enum PhiStatus
{ {
PHI_STATUS_OK = 0, PHI_STATUS_OK = 0,