Implements WASM smart contract compilation, optimization, and ABI generation across JavaScript/TypeScript, Python, Go, Rust, Flutter/Dart, Java, Kotlin, Swift, C, C++, C#/.NET, and Ruby. Features: - Optimization levels: None, Basic, Size, Aggressive - WASM section stripping with customizable options - Contract validation against VM requirements - ABI extraction and generation - Contract metadata handling - Gas estimation for deployment - Security analysis and recommendations - Size breakdown analysis Sub-clients: Contracts, ABI, Analysis, Validation |
||
|---|---|---|
| .. | ||
| lib | ||
| test | ||
| README.md | ||
| synor_compute.gemspec | ||
| synor_rpc.gemspec | ||
| synor_storage.gemspec | ||
| synor_wallet.gemspec | ||
Synor Compute SDK for Ruby
Access distributed heterogeneous compute at 90% cost reduction.
Installation
Add to Gemfile:
gem 'synor_compute'
Then run:
bundle install
Or install directly:
gem install synor_compute
Quick Start
require 'synor_compute'
client = SynorCompute::Client.new('your-api-key')
# Matrix multiplication on GPU
a = SynorCompute::Tensor.random([512, 512])
b = SynorCompute::Tensor.random([512, 512])
result = client.matmul(a, b,
precision: :fp16,
processor: :gpu
)
if result.success?
puts "Time: #{result.execution_time_ms}ms"
puts "Cost: $#{result.cost}"
end
Tensor Operations
# Create tensors
zeros = SynorCompute::Tensor.zeros([3, 3])
ones = SynorCompute::Tensor.ones([2, 2])
random = SynorCompute::Tensor.random([10, 10])
randn = SynorCompute::Tensor.randn([100])
eye = SynorCompute::Tensor.eye(3)
# From array
data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
tensor = SynorCompute::Tensor.new(data, shape: [2, 3])
# Operations
reshaped = tensor.reshape([3, 2])
transposed = tensor.transpose
# Math
mean = tensor.mean
sum = tensor.sum
std = tensor.std
Matrix Operations
# Matrix multiplication
result = client.matmul(a, b,
precision: :fp16,
processor: :gpu,
strategy: :speed
)
# 2D Convolution
conv = client.conv2d(input, kernel,
stride: [1, 1],
padding: [1, 1]
)
# Attention
attention = client.attention(query, key, value,
num_heads: 8,
flash: true
)
LLM Inference
# Single response
response = client.inference('llama-3-70b', 'Explain quantum computing',
max_tokens: 512,
temperature: 0.7
)
puts response.result
# Streaming with block
client.inference_stream('llama-3-70b', 'Write a poem') do |chunk|
print chunk
end
# Streaming with Enumerator
client.inference_stream('llama-3-70b', 'Write a poem').each do |chunk|
print chunk
end
Configuration
config = SynorCompute::Config.new(
api_key: 'your-api-key',
base_url: 'https://api.synor.io/compute/v1',
default_processor: :gpu,
default_precision: :fp16,
timeout: 30,
debug: true
)
client = SynorCompute::Client.new(config)
# Or with block
SynorCompute.configure do |config|
config.api_key = 'your-api-key'
config.default_processor = :gpu
end
Rails Integration
# config/initializers/synor_compute.rb
SynorCompute.configure do |config|
config.api_key = Rails.application.credentials.synor[:api_key]
config.default_processor = :gpu
end
# In your controller/service
class ComputeService
def self.client
@client ||= SynorCompute::Client.new
end
def self.compute(a, b)
client.matmul(a, b)
end
end
Error Handling
begin
result = client.matmul(a, b)
rescue SynorCompute::ApiError => e
puts "API Error #{e.status_code}: #{e.message}"
rescue SynorCompute::NetworkError => e
puts "Network error: #{e.message}"
rescue SynorCompute::Error => e
puts "Error: #{e.message}"
end
Types
# Processor types (symbols)
:cpu, :gpu, :tpu, :npu, :lpu, :fpga, :auto
# Precision (symbols)
:fp64, :fp32, :fp16, :bf16, :int8, :int4
# Job status (symbols)
:pending, :running, :completed, :failed, :cancelled
# Balancing strategy (symbols)
:speed, :cost, :energy, :latency, :balanced
Job Management
# Submit async job
job = client.submit_job(:matmul, a: a, b: b)
# Poll for status
status = client.job_status(job.id)
# Wait for completion
result = client.wait_for_job(job.id, timeout: 60)
# Cancel job
client.cancel_job(job.id)
Ruby-Specific Features
Method Chaining
result = client
.matmul(a, b)
.tap { |r| puts "Computing..." }
.then { |r| r.data if r.success? }
Duck Typing
# Any object with #to_tensor method works
class MyData
def to_tensor
SynorCompute::Tensor.new(@data, shape: @shape)
end
end
result = client.matmul(MyData.new, b)
Frozen String Literals
The gem is compatible with frozen string literals:
# frozen_string_literal: true
require 'synor_compute'
Requirements
- Ruby 3.0+
- faraday gem for HTTP
Testing
bundle exec rake test
# or
bundle exec rspec
License
MIT