synor/sdk/csharp
Gulshan Yadav a874faef13 feat: complete Phase 3 SDKs for Swift, C, C++, C#, and Ruby
Implements Database, Hosting, and Bridge SDKs for remaining languages:

Swift SDKs:
- SynorDatabase with KV, Document, Vector, TimeSeries stores
- SynorHosting with domain, DNS, deployment, SSL operations
- SynorBridge with lock-mint and burn-unlock cross-chain flows

C SDKs:
- database.h/c - multi-model database client
- hosting.h/c - hosting and domain management
- bridge.h/c - cross-chain asset transfers

C++ SDKs:
- database.hpp - modern C++17 with std::future async
- hosting.hpp - domain and deployment operations
- bridge.hpp - cross-chain bridge with wait operations

C# SDKs:
- SynorDatabase.cs - async/await with inner store classes
- SynorHosting.cs - domain management and analytics
- SynorBridge.cs - cross-chain with BridgeException handling

Ruby SDKs:
- synor_database - Struct-based types with Faraday HTTP
- synor_hosting - domain, DNS, SSL, analytics
- synor_bridge - lock-mint/burn-unlock with retry logic

Phase 3 complete: Database/Hosting/Bridge now available in all 12 languages.
2026-01-27 02:23:07 +05:30
..
Synor.Sdk feat: complete Phase 3 SDKs for Swift, C, C++, C#, and Ruby 2026-01-27 02:23:07 +05:30
SynorCompute feat(sdk): add consumer SDKs for Java, Kotlin, Swift, C, C++, C#, Ruby, and Rust 2026-01-11 17:46:22 +05:30
SynorCompute.Tests test(sdk): add comprehensive unit tests for all SDKs 2026-01-11 17:56:11 +05:30
.gitignore feat(sdk): add consumer SDKs for Java, Kotlin, Swift, C, C++, C#, Ruby, and Rust 2026-01-11 17:46:22 +05:30
README.md docs(sdk): add comprehensive documentation for all 12 SDKs 2026-01-11 18:05:03 +05:30

Synor Compute SDK for C#/.NET

Access distributed heterogeneous compute at 90% cost reduction.

Installation

NuGet

dotnet add package SynorCompute

Package Manager Console

Install-Package SynorCompute

Quick Start

using SynorCompute;

var client = new SynorClient("your-api-key");

// Matrix multiplication on GPU
var a = Tensor.Random(512, 512);
var b = Tensor.Random(512, 512);

var result = await client.MatMulAsync(a, b, new MatMulOptions
{
    Precision = Precision.FP16,
    Processor = ProcessorType.GPU
});

if (result.IsSuccess)
{
    Console.WriteLine($"Time: {result.ExecutionTimeMs}ms");
    Console.WriteLine($"Cost: ${result.Cost}");
}

Tensor Operations

// Create tensors
var zeros = Tensor.Zeros(3, 3);
var ones = Tensor.Ones(2, 2);
var random = Tensor.Random(10, 10);
var randn = Tensor.Randn(100);
var eye = Tensor.Eye(3);

// From array
float[,] data = { { 1, 2, 3 }, { 4, 5, 6 } };
var tensor = Tensor.FromArray(data);

// From 1D with shape
var data1d = new float[] { 1, 2, 3, 4, 5, 6 };
var tensor1d = new Tensor(data1d, new[] { 2, 3 });

// Operations
var reshaped = tensor.Reshape(3, 2);
var transposed = tensor.Transpose();

// Math
var mean = tensor.Mean();
var sum = tensor.Sum();
var std = tensor.Std();

Async/Await API

// Matrix multiplication
var result = await client.MatMulAsync(a, b, new MatMulOptions
{
    Precision = Precision.FP16,
    Processor = ProcessorType.GPU,
    Strategy = BalancingStrategy.Speed
});

// 2D Convolution
var conv = await client.Conv2DAsync(input, kernel, new Conv2DOptions
{
    Stride = (1, 1),
    Padding = (1, 1)
});

// Attention
var attention = await client.AttentionAsync(query, key, value, new AttentionOptions
{
    NumHeads = 8,
    Flash = true
});

LLM Inference

// Single response
var response = await client.InferenceAsync("llama-3-70b", "Explain quantum computing",
    new InferenceOptions
    {
        MaxTokens = 512,
        Temperature = 0.7f
    });
Console.WriteLine(response.Result);

// Streaming with IAsyncEnumerable
await foreach (var chunk in client.InferenceStreamAsync("llama-3-70b", "Write a poem"))
{
    Console.Write(chunk);
}

Configuration

var config = new SynorConfig
{
    ApiKey = "your-api-key",
    BaseUrl = "https://api.synor.io/compute/v1",
    DefaultProcessor = ProcessorType.GPU,
    DefaultPrecision = Precision.FP16,
    Timeout = TimeSpan.FromSeconds(30),
    Debug = true
};

var client = new SynorClient(config);

Dependency Injection

// In Startup.cs or Program.cs
services.AddSynorCompute(options =>
{
    options.ApiKey = Configuration["Synor:ApiKey"];
    options.DefaultProcessor = ProcessorType.GPU;
});

// In your service
public class ComputeService
{
    private readonly ISynorClient _client;

    public ComputeService(ISynorClient client)
    {
        _client = client;
    }

    public async Task<Tensor> ComputeAsync(Tensor a, Tensor b)
    {
        var result = await _client.MatMulAsync(a, b);
        return result.Data;
    }
}

Error Handling

try
{
    var result = await client.MatMulAsync(a, b);
}
catch (SynorApiException ex)
{
    Console.WriteLine($"API Error {ex.StatusCode}: {ex.Message}");
}
catch (SynorNetworkException ex)
{
    Console.WriteLine($"Network error: {ex.Message}");
}
catch (SynorException ex)
{
    Console.WriteLine($"Error: {ex.Message}");
}

LINQ Integration

// Process multiple tensors
var tensors = new[] { a, b, c, d };
var results = await Task.WhenAll(
    tensors.Select(t => client.MatMulAsync(t, identity))
);

Types

// Processor types
public enum ProcessorType
{
    CPU, GPU, TPU, NPU, LPU, FPGA, Auto
}

// Precision
public enum Precision
{
    FP64, FP32, FP16, BF16, INT8, INT4
}

// Job status
public enum JobStatus
{
    Pending, Running, Completed, Failed, Cancelled
}

// Balancing strategy
public enum BalancingStrategy
{
    Speed, Cost, Energy, Latency, Balanced
}

Cancellation Support

var cts = new CancellationTokenSource();

// Cancel after 10 seconds
cts.CancelAfter(TimeSpan.FromSeconds(10));

try
{
    var result = await client.MatMulAsync(a, b, cancellationToken: cts.Token);
}
catch (OperationCanceledException)
{
    Console.WriteLine("Operation was cancelled");
}

Requirements

  • .NET 6.0 or later
  • System.Text.Json

Testing

dotnet test

License

MIT