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>
This commit is contained in:
193
docs/development/roadmap/phases/phase-50/README.md
Normal file
193
docs/development/roadmap/phases/phase-50/README.md
Normal file
@ -0,0 +1,193 @@
|
||||
# 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定義
|
||||
```nyash
|
||||
// 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. スマートディスパッチ
|
||||
```nyash
|
||||
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. メモリ管理
|
||||
```nyash
|
||||
// GPU メモリ上のBox配列
|
||||
gpu box ImageBuffer {
|
||||
pixels: GPUArrayBox<ColorBox>
|
||||
|
||||
@gpu
|
||||
applyFilter(kernel) {
|
||||
// GPU上で畳み込み演算
|
||||
me.pixels.convolve(kernel)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🌈 応用例
|
||||
|
||||
### 1. リアルタイム画像処理
|
||||
```nyash
|
||||
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. 物理シミュレーション
|
||||
```nyash
|
||||
gpu box FluidCell {
|
||||
density: FloatBox
|
||||
velocity: Vector3Box
|
||||
pressure: FloatBox
|
||||
|
||||
@gpu
|
||||
simulate(neighbors: ArrayBox<FluidCell>) {
|
||||
// ナビエ・ストークス方程式をGPUで解く
|
||||
me.updatePressure(neighbors)
|
||||
me.updateVelocity(neighbors)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 3. AI/機械学習
|
||||
```nyash
|
||||
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. 暗号通貨マイニング(?)
|
||||
```nyash
|
||||
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!"* 🚀
|
||||
154
docs/development/roadmap/phases/phase-50/gpu-box-spec.md
Normal file
154
docs/development/roadmap/phases/phase-50/gpu-box-spec.md
Normal file
@ -0,0 +1,154 @@
|
||||
# GPU Box 技術仕様(案)
|
||||
|
||||
## 🔧 技術的詳細
|
||||
|
||||
### GPU Box の要件
|
||||
|
||||
1. **純粋性**
|
||||
- 副作用を持たない
|
||||
- 外部状態に依存しない
|
||||
- 決定的な実行結果
|
||||
|
||||
2. **型制約**
|
||||
- GPU互換型のみ使用可能
|
||||
- ポインタ/参照の制限
|
||||
- 再帰呼び出し禁止
|
||||
|
||||
3. **メモリモデル**
|
||||
```nyash
|
||||
// GPU メモリレイアウト
|
||||
gpu box ParticleArray {
|
||||
// Structure of Arrays (SoA) で自動配置
|
||||
positions: GPUBuffer<Float3>
|
||||
velocities: GPUBuffer<Float3>
|
||||
masses: GPUBuffer<Float>
|
||||
}
|
||||
```
|
||||
|
||||
### MIR → GPU IR 変換
|
||||
|
||||
```
|
||||
// Nyash MIR
|
||||
BoxCall {
|
||||
box_val: %particles,
|
||||
method: "update",
|
||||
args: [%deltaTime]
|
||||
}
|
||||
|
||||
// ↓ 変換
|
||||
|
||||
// GPU IR(擬似コード)
|
||||
kernel particle_update {
|
||||
params: [particles_ptr, deltaTime]
|
||||
threads: particles.count
|
||||
|
||||
thread_body: {
|
||||
idx = thread_id()
|
||||
pos = load(particles.positions[idx])
|
||||
vel = load(particles.velocities[idx])
|
||||
new_pos = pos + vel * deltaTime
|
||||
store(particles.positions[idx], new_pos)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### バックエンド対応
|
||||
|
||||
1. **CUDA** (NVIDIA GPU)
|
||||
- PTX生成
|
||||
- cuBLAS/cuDNN統合
|
||||
|
||||
2. **OpenCL** (クロスプラットフォーム)
|
||||
- SPIR-V生成
|
||||
- 各種GPU対応
|
||||
|
||||
3. **Vulkan Compute** (モダンAPI)
|
||||
- SPIR-V生成
|
||||
- モバイルGPU対応
|
||||
|
||||
4. **Metal** (Apple GPU)
|
||||
- Metal Shading Language
|
||||
- Apple Silicon最適化
|
||||
|
||||
### 最適化技術
|
||||
|
||||
1. **Box融合**
|
||||
```nyash
|
||||
// これらの操作を1つのGPUカーネルに融合
|
||||
data.map(x => x * 2)
|
||||
.filter(x => x > 10)
|
||||
.reduce(+)
|
||||
```
|
||||
|
||||
2. **メモリ合体アクセス**
|
||||
- Boxフィールドの最適配置
|
||||
- キャッシュ効率の最大化
|
||||
|
||||
3. **占有率最適化**
|
||||
- スレッドブロックサイズ自動調整
|
||||
- レジスタ使用量の制御
|
||||
|
||||
### エラー処理
|
||||
|
||||
```nyash
|
||||
gpu box SafeDiv {
|
||||
@gpu
|
||||
divide(a, b) {
|
||||
if b == 0 {
|
||||
// GPU例外はCPU側で処理
|
||||
gpu.raise(DivisionByZeroError)
|
||||
}
|
||||
return a / b
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 🔍 課題と解決策
|
||||
|
||||
### 課題1: デバッグの困難さ
|
||||
**解決**: GPU実行トレース機能
|
||||
```nyash
|
||||
// デバッグモードでGPU実行を記録
|
||||
local result = particles.gpuExecute("update", 0.016, debug: true)
|
||||
print(result.trace) // 各スレッドの実行履歴
|
||||
```
|
||||
|
||||
### 課題2: CPU/GPU同期オーバーヘッド
|
||||
**解決**: 非同期実行とパイプライン
|
||||
```nyash
|
||||
// GPU実行を非同期化
|
||||
local future = particles.gpuExecuteAsync("update", 0.016)
|
||||
// CPU側で他の処理を継続
|
||||
doOtherWork()
|
||||
// 必要な時に結果を取得
|
||||
local result = await future
|
||||
```
|
||||
|
||||
### 課題3: メモリ制限
|
||||
**解決**: ストリーミング処理
|
||||
```nyash
|
||||
// 大規模データを分割処理
|
||||
largeData.gpuStream(chunkSize: 1_000_000)
|
||||
.map(process)
|
||||
.collect()
|
||||
```
|
||||
|
||||
## 🎓 学習曲線を下げる工夫
|
||||
|
||||
1. **自動GPU化**
|
||||
- コンパイラが自動的にGPU実行可能性を判定
|
||||
- ヒント表示: 「このBoxはGPU実行可能です」
|
||||
|
||||
2. **段階的移行**
|
||||
- 既存コードはCPUで動作保証
|
||||
- `@gpu`を追加するだけでGPU化
|
||||
|
||||
3. **プロファイリング支援**
|
||||
```nyash
|
||||
// GPU実行の効果を可視化
|
||||
local profile = Profiler.compare(
|
||||
cpu: => particles.update(0.016),
|
||||
gpu: => particles.gpuExecute("update", 0.016)
|
||||
)
|
||||
print(profile.speedup) // "GPU: 156.3x faster"
|
||||
```
|
||||
Reference in New Issue
Block a user