[ TARGET BACKENDS ]

Target Backends

BHC is designed for multiple targets. “Haskell” doesn’t have to mean “one runtime on one OS.”

Available Targets

Native

Server deployments and desktop applications.

bhc --target=native Main.hs
# or just:
bhc Main.hs

Status: Supported

  • Full runtime features
  • All profiles available
  • Best performance for server workloads

WASI/WASM

Sandboxed compute and edge deployments.

bhc --target=wasi Main.hs

Status: Supported

  • WebAssembly output
  • WASI system interface
  • Works with edge profile
  • Suitable for serverless and browser environments

Limitations:

  • Some runtime features restricted by WASI
  • Edge profile recommended for size

GPU (CUDA/ROCm)

Accelerated compute for numeric workloads.

bhc --target=cuda Main.hs
bhc --target=rocm Main.hs

Status: Supported

  • NVIDIA CUDA (PTX code generation)
  • AMD ROCm (AMDGCN code generation)
  • Automatic kernel fusion from Tensor IR
  • Device memory management
  • Works with numeric profile

RISC-V

Emerging architecture support.

bhc --target=riscv64 Main.hs

Status: Supported

  • 32-bit and 64-bit RISC-V
  • Native LLVM backend

Experimental

Additional backends under consideration.

TargetStatusNotes
JavaScriptPlannedBrowser-native execution
Bare metalExperimentalNo OS dependencies

Target Selection

Command line

# Native (default)
bhc Main.hs

# WASI/WASM
bhc --target=wasi Main.hs

# Specify output
bhc --target=wasi -o app.wasm Main.hs

Cross-compilation

BHC supports cross-compilation from your development machine to different targets.

# Compile WASM from macOS
bhc --target=wasi Main.hs -o app.wasm

# Run with wasmtime
wasmtime app.wasm

Target-Specific Considerations

Native Target

Full feature set:

  • All runtime profiles
  • Full FFI support
  • Native threads and concurrency
  • System calls unrestricted

WASI Target

Restricted environment:

  • WASI system interface only
  • No native threads (cooperative concurrency)
  • File system access through WASI capabilities
  • Network access through WASI sockets (when available)

Recommended setup:

bhc --target=wasi --profile=edge Main.hs

GPU Target

For numeric workloads with large data parallelism:

  • Tensor IR operations automatically lowered to GPU kernels
  • Device memory managed by runtime
  • Host/device transfers optimized
  • Kernel fusion reduces memory bandwidth

Recommended setup:

bhc --target=cuda --profile=numeric Main.hs

FFI Considerations

Foreign function calls differ by target:

TargetFFI Support
NativeFull C FFI
WASIWASI imports only
GPUDevice-side functions only

For portable code, abstract FFI behind a platform layer.

Runtime Size

Different targets have different runtime sizes:

TargetProfileApproximate Size
Nativedefault~2 MB
Nativeserver~2.5 MB
Nativenumeric~2.2 MB
WASIedge~500 KB
GPUnumeric~3 MB + driver

Sizes are approximate and depend on what features your code uses. GPU targets require platform-specific drivers (CUDA toolkit or ROCm).

Combining Targets and Profiles

ProfileNativeWASIGPU
default
server🟡 (limited)
numeric✅ (recommended)
edge✅ (recommended)

The edge profile is designed for WASI and other constrained targets. GPU targets require the numeric profile for Tensor IR integration.