# decuda examples
This directory holds a comprehensive set of CUDA input files and the
real decuda output for every supported backend.
## Layout
```
examples/
├── cu/ # CUDA input files (.cu) — single source of truth
│ ├── saxpy.cu # kernels, launches, malloc/free, shared mem
│ ├── histogram.cu # atomics, shared bins, grid-stride, warp intrinsics
│ ├── transpose.cu # 2D dim3 grid/block, shared-memory tile
│ ├── stream_pipeline.cu # streams, events, async memcpy, smem+stream launches
│ ├── device_helpers.cu # __device__ helpers, inline hints, __constant__, __launch_bounds__
│ ├── reduction.cu # warp-shuffle reduction, __shfl_sync, tree reduction, atomicAdd
│ ├── stencil_3d.cu # 3D 7-point stencil, shared-memory halo, 3D dim3
│ ├── device_management.cu # multi-GPU, error handling, pinned memory, cudaDeviceSynchronize
│ ├── managed_memory.cu # cudaMallocManaged, __managed__, unified memory
│ ├── warp_primitives.cu # __shfl_sync, __ballot_sync, __any_sync, __all_sync, __activemask
│ ├── ptx_inline.cu # inline PTX assembly (asm/asm volatile, flagged for manual review)
│ ├── rich.cu # atomics, shared mem, warp intrinsics, 2D launches, constant mem
│ ├── launch_in_comment.cu # launches inside comments/strings (preprocessor invariant test)
│ ├── headers_only.cu # every include-replacement path
│ └── empty.cu # no CUDA constructs (banner + verbatim source)
├── out/ # decuda output (mirrors real <output>/<target>/ layout)
│ ├── hip/*.hip.cpp # --target hip
│ ├── sycl/*.sycl.cpp # --target sycl
│ ├── rust/*.rs # --target rust (cust / rust-gpu scaffold)
│ ├── opencl/*.cl # --target opencl
│ └── migration-report.json.* # structured per-file warnings report
├── inspect.rs # runnable example: programmatic IR inspection
├── migrate.rs # runnable example: programmatic in-memory migration
└── list_apis.rs # runnable example: enumerate the CUDA API database
```
## Regenerate the outputs
After changing decuda, regenerate the example outputs with:
```bash
cargo run -- migrate -i examples/cu -o examples/out --target all
```
This is exactly the command that produced the current `examples/out/`
tree. Each target writes into its own `out/<target>/` subfolder, and a
single timestamped `migration-report.json.<ts>` is written next to them.
## Run the runnable examples
```bash
cargo run --example inspect -- examples/cu/saxpy.cu
cargo run --example migrate -- examples/cu/histogram.cu
cargo run --example list_apis -- hip
```