Files
hakorune/docs/development/roadmap/phases/phase-50
Selfhosting Dev e114f9bfe3 fix(llvm): Implement handle-based console.log functions for plugin return values
- Add nyash.console.log_handle(i64) -> i64 family functions to nyrt
- Replace invalid int-to-pointer conversion with proper handle-based calls
- Fix bool(i1) -> i64 type conversion in LLVM compiler
- Resolve LLVM function verification errors
- Enable plugin method execution without NYASH_LLVM_ALLOW_BY_NAME
- Merge codex TLV fixes for plugin return value handling (2000+ lines)

Technical Details:
- Root cause: build_int_to_ptr(handle_value, i8*, "arg_i2p") treated
  handle IDs as memory addresses (invalid operation)
- Solution: Direct i64 handle passing to nyrt functions with proper
  handle registry lookup and to_string_box() conversion
- Type safety: Added proper i1/i32/i64 -> i64 conversion handling

Status: Console.log type errors resolved, plugin return value display
still under investigation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-11 00:21:11 +09:00
..

Phase 50: GPU Box Computing 🎮

夢の実行形態Everything is GPU Box

🌟 ビジョン

Nyashの「Everything is Box」哲学を活かし、超並列GPU実行を実現する革命的な実行形態。 箱の独立性と純粋性を利用して、数万〜数百万のBoxを同時にGPU上で実行

📦 なぜBoxとGPUは相性が良いか

1. 完璧な並列性

  • 各Boxは独立 → データ競合なし
  • メッセージパッシングのみ → 同期が単純
  • 副作用なし → GPU実行に最適

2. メモリ効率

  • Boxはイミュータブル → 読み取り専用GPU メモリ
  • 型が明確 → 最適なメモリレイアウト
  • 予測可能なアクセスパターン

3. 計算の均一性

  • 同じ型のBox → 同じGPUカーネル
  • メソッド単位の実行 → SIMD/SIMT に最適

🏗️ アーキテクチャ

GPU Box定義

// GPU実行可能なBox
gpu box Particle {
    position: VectorBox
    velocity: VectorBox  
    mass: FloatBox
    
    @gpu
    update(deltaTime) {
        // このメソッドはGPU上で実行される
        me.position = me.position + me.velocity * deltaTime
    }
}

// 100万個の粒子を同時処理
local particles = new GPUArrayBox(1_000_000, Particle)
particles.gpuExecute("update", 0.016)  // 全粒子並列更新!

実行モデル

Nyashコード
    ↓
MIR (Box呼び出し)
    ↓
GPU IR生成
    ↓
CUDA/OpenCL/Vulkan Compute
    ↓
GPU実行

💡 実装アイデア

1. スマートディスパッチ

box SmartArray from ArrayBox {
    map(func) {
        if me.size > GPU_THRESHOLD {
            // 自動的にGPU実行へ
            return me.gpuMap(func)
        } else {
            return me.cpuMap(func)
        }
    }
}

2. GPU Box制約

  • @gpuテーション付きメソッドのみGPU実行
  • 純粋関数であること(副作用禁止)
  • 基本型またはGPU対応Box型のみ使用可能

3. メモリ管理

// GPU メモリ上のBox配列
gpu box ImageBuffer {
    pixels: GPUArrayBox<ColorBox>
    
    @gpu
    applyFilter(kernel) {
        // GPU上で畳み込み演算
        me.pixels.convolve(kernel)
    }
}

🌈 応用例

1. リアルタイム画像処理

local image = new ImageBox("photo.jpg")
local filters = new GPUPipeline([
    BlurBox(radius: 5),
    BrightnessBox(level: 1.2),
    ContrastBox(amount: 1.5)
])
image.applyGPU(filters)  // 全フィルタ並列実行!

2. 物理シミュレーション

gpu box FluidCell {
    density: FloatBox
    velocity: Vector3Box
    pressure: FloatBox
    
    @gpu
    simulate(neighbors: ArrayBox<FluidCell>) {
        // ナビエ・ストークス方程式をGPUで解く
        me.updatePressure(neighbors)
        me.updateVelocity(neighbors)
    }
}

3. AI/機械学習

gpu box Neuron {
    weights: TensorBox
    bias: FloatBox
    
    @gpu
    forward(input: TensorBox) {
        // テンソル演算をGPUで高速化
        return (me.weights @ input + me.bias).relu()
    }
}

// ニューラルネットワーク全層をGPU実行
local network = new GPUNetwork([
    DenseLayer(neurons: 1024),
    DenseLayer(neurons: 512),
    DenseLayer(neurons: 10)
])

4. 暗号通貨マイニング(?)

gpu box HashBox {
    @gpu
    mine(nonce) {
        // SHA-256をGPUで並列計算
        return me.hash(nonce)
    }
}

🚀 実装ロードマップ

Stage 1: 基礎実装

  • GPU Box アノテーション(@gpu
  • 基本的なGPU IR生成
  • 単純な数値演算のGPU実行

Stage 2: 型システム統合

  • GPU互換型チェッカー
  • GPU メモリ管理
  • CPU ⇔ GPU データ転送最適化

Stage 3: 高度な最適化

  • Box融合最適化カーネル結合
  • 自動CPU/GPUスケジューリング
  • マルチGPU対応

Stage 4: エコシステム

  • GPU Boxライブラリ
  • プロファイリングツール
  • デバッガー対応

🎯 成功指標

  1. パフォーマンス: CPU実行の100倍〜1000倍高速化
  2. 使いやすさ: @gpuを付けるだけで自動GPU実行
  3. 互換性: 既存のBoxコードがそのまま動く

💭 夢の先へ

  • 量子コンピューティング対応: @quantum アノテーション
  • 分散GPU実行: 複数マシンのGPUを透過的に使用
  • AIアシスト最適化: 実行パターンを学習して自動最適化

"Everything is Box, Everything is Parallel, Everything is Fast!" 🚀