cuda-rust-wasm 0.1.7

CUDA to Rust transpiler with WebGPU/WASM support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
name: Comprehensive Testing Suite

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]
  schedule:
    # Run nightly for performance regression detection
    - cron: '0 2 * * *'

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  # Unit Tests - Fast feedback
  unit-tests:
    name: Unit Tests
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        rust: [stable, beta, 1.70.0] # MSRV
        exclude:
          # Reduce matrix for faster CI
          - os: windows-latest
            rust: beta
          - os: macos-latest
            rust: beta
    
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: recursive
    
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: ${{ matrix.rust }}
        profile: minimal
        override: true
        components: rustfmt, clippy
    
    - name: Cache cargo registry
      uses: actions/cache@v3
      with:
        path: ~/.cargo/registry
        key: ${{ runner.os }}-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |

          ${{ runner.os }}-${{ matrix.rust }}-cargo-registry-
    
    - name: Cache cargo index
      uses: actions/cache@v3
      with:
        path: ~/.cargo/git
        key: ${{ runner.os }}-${{ matrix.rust }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |

          ${{ runner.os }}-${{ matrix.rust }}-cargo-index-
    
    - name: Cache target directory
      uses: actions/cache@v3
      with:
        path: target
        key: ${{ runner.os }}-${{ matrix.rust }}-target-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |

          ${{ runner.os }}-${{ matrix.rust }}-target-
    
    - name: Check formatting
      run: cargo fmt -- --check
    
    - name: Run clippy
      run: cargo clippy --all-targets --all-features -- -D warnings
    
    - name: Build
      run: cargo build --verbose --all-features
    
    - name: Run unit tests
      run: cargo test --lib --bins --all-features --verbose
    
    - name: Run doc tests
      run: cargo test --doc --all-features

  # Integration Tests - More comprehensive
  integration-tests:
    name: Integration Tests
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    
    steps:
    - uses: actions/checkout@v4
      with:
        submodules: recursive
    
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
    
    - name: Cache dependencies
      uses: actions/cache@v3
      with:
        path: |

          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-integration-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Install system dependencies (Ubuntu)
      if: matrix.os == 'ubuntu-latest'
      run: |

        sudo apt-get update
        sudo apt-get install -y libnuma-dev
    
    - name: Install system dependencies (macOS)
      if: matrix.os == 'macos-latest'
      run: |

        # Install any macOS-specific dependencies
        echo "macOS dependencies installed"
    
    - name: Install system dependencies (Windows)
      if: matrix.os == 'windows-latest'
      run: |

        # Install any Windows-specific dependencies
        echo "Windows dependencies installed"
    
    - name: Build with all features
      run: cargo build --release --all-features
    
    - name: Run integration tests
      run: cargo test --test '*' --release --all-features
    
    - name: Run cross-platform tests
      run: cargo test cross_platform_tests --release --all-features
    
    - name: Run memory safety tests
      run: cargo test memory_safety_tests --release --all-features
    
    - name: Run runtime tests
      run: cargo test runtime_tests --release --all-features

  # Property-based Testing
  property-tests:
    name: Property-based Tests
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
    
    - name: Cache dependencies
      uses: actions/cache@v3
      with:
        path: |

          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-property-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Run property tests (extended)
      env:
        PROPTEST_CASES: 10000
        PROPTEST_MAX_SHRINK_ITERS: 1000
      run: cargo test property_tests --release -- --test-threads=1

  # Browser Testing
  browser-tests:
    name: Browser Compatibility
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
        target: wasm32-unknown-unknown
    
    - name: Install wasm-pack
      run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
    
    - name: Cache dependencies
      uses: actions/cache@v3
      with:
        path: |

          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-wasm-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Build for WASM
      run: wasm-pack build --target web --dev
    
    - name: Install Node.js
      uses: actions/setup-node@v3
      with:
        node-version: '18'
    
    - name: Install browser test dependencies
      run: |

        npm install -g wasm-bindgen-test-runner
        # Install Chrome for testing
        wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
        echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee /etc/apt/sources.list.d/google-chrome.list
        sudo apt-get update
        sudo apt-get install -y google-chrome-stable
    
    - name: Run browser tests
      env:
        CHROMEDRIVER: /usr/bin/google-chrome
      run: wasm-pack test --chrome --headless
    
    - name: Test WASM module size
      run: |

        wasm-pack build --target web --release
        WASM_SIZE=$(stat -c%s pkg/cuda_rust_wasm_bg.wasm)
        echo "WASM module size: $WASM_SIZE bytes"
        # Fail if module is too large (>10MB)
        if [ $WASM_SIZE -gt 10485760 ]; then
          echo "WASM module too large: $WASM_SIZE bytes"
          exit 1
        fi

  # Performance Benchmarks
  benchmarks:
    name: Performance Benchmarks
    runs-on: ubuntu-latest
    if: github.event_name == 'schedule' || contains(github.event.head_commit.message, '[benchmark]')
    
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0 # Need full history for regression detection
    
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
    
    - name: Cache dependencies
      uses: actions/cache@v3
      with:
        path: |

          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-bench-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Install criterion dependencies
      run: |

        sudo apt-get update
        sudo apt-get install -y gnuplot
    
    - name: Download previous benchmark results
      uses: actions/cache@v3
      with:
        path: target/performance_baselines.json
        key: performance-baselines-${{ github.ref }}
        restore-keys: |

          performance-baselines-refs/heads/main
          performance-baselines-
    
    - name: Run benchmarks
      run: |

        cargo bench --bench memory_benchmarks
        cargo bench --bench kernel_benchmarks
        cargo bench --bench transpiler_benchmarks
        cargo bench --bench wasm_vs_native_benchmarks
        cargo bench --bench regression_benchmarks
    
    - name: Upload benchmark results
      uses: actions/upload-artifact@v3
      with:
        name: benchmark-results
        path: |

          target/criterion/
          target/performance_baselines.json
    
    - name: Check for performance regressions
      run: |

        if [ -f target/performance_baselines.json ]; then
          echo "Checking for performance regressions..."
          # This would be handled by the regression benchmark itself
        fi

  # Code Coverage
  coverage:
    name: Code Coverage
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
        components: llvm-tools-preview
    
    - name: Install grcov
      run: |

        curl -L https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf -
        chmod +x grcov
        sudo mv grcov /usr/local/bin/
    
    - name: Cache dependencies
      uses: actions/cache@v3
      with:
        path: |

          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-coverage-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Run tests with coverage
      env:
        RUSTFLAGS: -Cinstrument-coverage
        LLVM_PROFILE_FILE: coverage-%p-%m.profraw
      run: |

        cargo test --all-features
    
    - name: Generate coverage report
      run: |

        grcov . \
          --binary-path ./target/debug/ \
          -s . \
          -t lcov \
          --branch \
          --ignore-not-existing \
          --ignore "/*" \
          --ignore "tests/*" \
          --ignore "benches/*" \
          --ignore "examples/*" \
          -o coverage.lcov
    
    - name: Upload to codecov.io
      uses: codecov/codecov-action@v3
      with:
        file: coverage.lcov
        flags: unittests
        name: cuda-rust-wasm
        fail_ci_if_error: false
    
    - name: Check coverage threshold
      run: |

        COVERAGE=$(grcov . --binary-path ./target/debug/ -s . -t json --branch --ignore-not-existing --ignore "/*" --ignore "tests/*" --ignore "benches/*" --ignore "examples/*" | jq '.message' | grep -o '[0-9]\+\.[0-9]\+' | head -1)
        echo "Coverage: $COVERAGE%"
        if (( $(echo "$COVERAGE < 80.0" | bc -l) )); then
          echo "Coverage below 80% threshold: $COVERAGE%"
          exit 1
        fi

  # Security Audit
  security:
    name: Security Audit
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
    
    - name: Install cargo-audit
      run: cargo install cargo-audit
    
    - name: Run security audit
      run: cargo audit
    
    - name: Install cargo-deny
      run: cargo install cargo-deny
    
    - name: Check licenses and dependencies
      run: cargo deny check

  # Memory Testing with Sanitizers
  sanitizers:
    name: Memory Sanitizers
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust nightly
      uses: actions-rs/toolchain@v1
      with:
        toolchain: nightly
        profile: minimal
        override: true
        components: rust-src
    
    - name: Cache dependencies
      uses: actions/cache@v3
      with:
        path: |

          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-sanitizer-${{ hashFiles('**/Cargo.lock') }}
    
    - name: Run with AddressSanitizer
      env:
        RUSTFLAGS: -Zsanitizer=address
      run: |

        cargo +nightly test --target x86_64-unknown-linux-gnu --lib --bins
    
    - name: Run with LeakSanitizer
      env:
        RUSTFLAGS: -Zsanitizer=leak
      run: |

        cargo +nightly test --target x86_64-unknown-linux-gnu memory_safety_tests

  # Documentation
  docs:
    name: Documentation
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v4
    
    - name: Install Rust
      uses: actions-rs/toolchain@v1
      with:
        toolchain: stable
        profile: minimal
        override: true
    
    - name: Check documentation
      env:
        RUSTDOCFLAGS: -D warnings
      run: cargo doc --all-features --no-deps
    
    - name: Deploy documentation (main branch only)
      if: github.ref == 'refs/heads/main' && github.event_name == 'push'
      run: |

        cargo doc --all-features --no-deps
        echo '<meta http-equiv="refresh" content="0; url=cuda_rust_wasm">' > target/doc/index.html
    
    - name: Upload documentation
      if: github.ref == 'refs/heads/main' && github.event_name == 'push'
      uses: peaceiris/actions-gh-pages@v3
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: ./target/doc

  # Final Status Check
  ci-success:
    name: CI Success
    runs-on: ubuntu-latest
    needs: [unit-tests, integration-tests, property-tests, browser-tests, coverage, security, docs]
    if: always()
    
    steps:
    - name: Check all jobs
      run: |

        if [[ "${{ needs.unit-tests.result }}" != "success" ]]; then
          echo "Unit tests failed"
          exit 1
        fi
        if [[ "${{ needs.integration-tests.result }}" != "success" ]]; then
          echo "Integration tests failed"
          exit 1
        fi
        if [[ "${{ needs.property-tests.result }}" != "success" ]]; then
          echo "Property tests failed"
          exit 1
        fi
        if [[ "${{ needs.browser-tests.result }}" != "success" ]]; then
          echo "Browser tests failed"
          exit 1
        fi
        if [[ "${{ needs.coverage.result }}" != "success" ]]; then
          echo "Coverage check failed"
          exit 1
        fi
        if [[ "${{ needs.security.result }}" != "success" ]]; then
          echo "Security audit failed"
          exit 1
        fi
        if [[ "${{ needs.docs.result }}" != "success" ]]; then
          echo "Documentation check failed"
          exit 1
        fi
        echo "All checks passed!"
    
    - name: Report success
      run: echo "🎉 All tests passed! Ready for deployment."