Table of Contents

Class CudaMemoryPackSerializerGenerator

Namespace
DotCompute.Backends.CUDA.Compilation
Assembly
DotCompute.Backends.CUDA.dll

Generates CUDA C++ serializer/deserializer code that matches MemoryPack's exact binary format.

public sealed class CudaMemoryPackSerializerGenerator
Inheritance
CudaMemoryPackSerializerGenerator
Inherited Members

Remarks

MemoryPack binary format: - Header: 1-byte member count (0-249 = count, 255 = null) - Fields: Serialized in declaration order, no padding - Primitive types: Little-endian, direct copy - Guid: 16 bytes using ToByteArray() ordering - Nullable<T>: 1-byte has_value flag + T value (if present) - Collections: 4-byte signed int32 length (-1 = null) + elements - Strings: 4-byte signed int32 byte count (-1 = null) + UTF-8 bytes

Generated code enables GPU-side message processing without host round-trips.

Constructors

CudaMemoryPackSerializerGenerator(ILogger<CudaMemoryPackSerializerGenerator>)

Initializes a new instance of the CudaMemoryPackSerializerGenerator class.

public CudaMemoryPackSerializerGenerator(ILogger<CudaMemoryPackSerializerGenerator> logger)

Parameters

logger ILogger<CudaMemoryPackSerializerGenerator>

Logger for diagnostic output.

Methods

GenerateBatchSerializer(IEnumerable<Type>, string, bool)

Generates CUDA serialization code for multiple MemoryPackable types in a single compilation unit.

[UnconditionalSuppressMessage("AOT", "IL2072", Justification = "Types passed to this method are expected to be MemoryPackable types with PublicProperties preserved")]
public string GenerateBatchSerializer(IEnumerable<Type> messageTypes, string compilationUnitName = "MemoryPackSerializers", bool skipHandlerGeneration = false)

Parameters

messageTypes IEnumerable<Type>

The message types to generate code for.

compilationUnitName string

The name of the compilation unit.

skipHandlerGeneration bool

When true, skips generating message handler (manual handler will be provided).

Returns

string

Generated CUDA C++ code for all types.

Remarks

Callers must ensure that all types in messageTypes have PublicProperties accessible. This is typically satisfied by types marked with [MemoryPackable] attribute.

Code is generated in a specific order to ensure forward declarations are not needed: 1. All struct definitions (so Response struct exists when handler is generated) 2. All deserializers 3. All serializers 4. Message handlers (one per Request/Response pair, not per type)

GenerateSerializer(Type)

Generates complete CUDA C++ serialization code for a MemoryPackable type.

public string GenerateSerializer(Type messageType)

Parameters

messageType Type

The message type to generate code for.

Returns

string

Generated CUDA C++ code including struct, deserializer, and serializer.

Exceptions

ArgumentNullException

Thrown when messageType is null.

InvalidOperationException

Thrown when code generation fails.