Class MetalHandlerTranslationService
- Namespace
- DotCompute.Backends.Metal.Compilation
- Assembly
- DotCompute.Backends.Metal.dll
Service for discovering and translating C# message handlers to MSL device functions for Ring Kernels.
public sealed class MetalHandlerTranslationService
- Inheritance
-
MetalHandlerTranslationService
- Inherited Members
Remarks
This service implements the C# to MSL translation pipeline for Ring Kernel message handlers:
- Discovers handler classes by naming convention (e.g., VectorAddHandler for VectorAddRequest)
- Validates handler method signatures (ProcessMessage with correct parameters)
- Uses CSharpToMSLTranslator to convert C# method body to MSL
- Wraps translated code in Metal function with proper signature
Handler Convention:
- Handler class name: {MessageType}Handler (e.g., VectorAddHandler)
- Handler method: static bool ProcessMessage(Span<byte> inputBuffer, int inputSize, Span<byte> outputBuffer, int outputSize)
- Returns: true on success, false on failure
MSL Output:
bool process_vector_add_message(
device uchar* input_buffer,
int input_size,
device uchar* output_buffer,
int output_size)
{
// Translated C# code...
}
Constructors
MetalHandlerTranslationService(ILogger<MetalHandlerTranslationService>, ILogger)
Initializes a new instance of the MetalHandlerTranslationService class.
public MetalHandlerTranslationService(ILogger<MetalHandlerTranslationService> logger, ILogger translatorLogger)
Parameters
loggerILogger<MetalHandlerTranslationService>Logger for diagnostic messages.
translatorLoggerILoggerLogger for the translator.
Methods
TranslateHandler(string, IEnumerable<Assembly>?)
Discovers and translates a message handler for the specified message type using runtime reflection.
[RequiresUnreferencedCode("Handler discovery uses runtime reflection which is not compatible with trimming.")]
public string? TranslateHandler(string messageTypeName, IEnumerable<Assembly>? assemblies = null)
Parameters
messageTypeNamestringSimple name of the message type (e.g., "VectorAddRequest").
assembliesIEnumerable<Assembly>Assemblies to search for handler classes.
Returns
- string
Translated MSL function code, or null if no handler found.
TranslateHandlers(IEnumerable<string>, IEnumerable<Assembly>?)
Generates MSL handler stubs for multiple message types.
[RequiresUnreferencedCode("Handler discovery uses runtime reflection which is not compatible with trimming.")]
public string TranslateHandlers(IEnumerable<string> messageTypeNames, IEnumerable<Assembly>? assemblies = null)
Parameters
messageTypeNamesIEnumerable<string>Collection of message type names.
assembliesIEnumerable<Assembly>Assemblies to search for handler classes.
Returns
- string
Combined MSL code with all translated handlers.