Privacy SDK features: - Confidential transactions with Pedersen commitments - Bulletproof range proofs for value validation - Ring signatures for anonymous signing with key images - Stealth addresses for unlinkable payments - Blinding factor generation and value operations Contract SDK features: - Smart contract deployment (standard and CREATE2) - Call (view/pure) and Send (state-changing) operations - Event log filtering, subscription, and decoding - ABI encoding/decoding utilities - Gas estimation and contract verification - Multicall for batched operations - Storage slot reading Languages implemented: - JavaScript/TypeScript - Python (async with httpx) - Go - Rust (async with reqwest/tokio) - Java (async with OkHttp) - Kotlin (coroutines with Ktor) - Swift (async/await with URLSession) - Flutter/Dart - C (header-only interface) - C++ (header-only with std::future) - C#/.NET (async with HttpClient) - Ruby (Faraday HTTP client) All SDKs follow consistent patterns: - Configuration with API key, endpoint, timeout, retries - Custom exception types with error codes - Retry logic with exponential backoff - Health check endpoints - Closed state management |
||
|---|---|---|
| .. | ||
| src | ||
| Synor.Sdk | ||
| SynorCompute | ||
| SynorCompute.Tests | ||
| .gitignore | ||
| README.md | ||
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