Skip to content

Commit 9fe6ef7

Browse files
committed
todo write more about the flags in torch/tensorflow and jax
1 parent 454f20d commit 9fe6ef7

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

docs/support-for-jit/index.mdx

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,58 @@ keywords: ["JIT", "just-in-time", "numba", "pytorch", "tensorflow", "jax", "GPU"
88

99
# Support for Just-in-Time Compilation
1010

11-
Codeflash supports optimizing code using Just-in-Time (JIT) compilation. This allows Codeflash to suggest optimizations that leverage JIT compilers from popular frameworks including **Numba**, **PyTorch**, **TensorFlow**, and **JAX**.
11+
Codeflash supports optimizing numerical code using Just-in-Time (JIT) compilation via leveraging JIT compilers from popular frameworks including **Numba**, **PyTorch**, **TensorFlow**, and **JAX**.
1212

1313
## Supported JIT Frameworks
1414

1515
Each framework uses different compilation strategies to accelerate Python code:
1616

17-
### Numba
17+
### Numba (CPU Code)
1818

1919
Numba compiles Python functions to optimized machine code using the LLVM compiler infrastructure. Codeflash can suggest Numba optimizations that use:
2020

21-
- **`@jit` / `@njit`** - General-purpose JIT compilation with `nopython` mode for removing Python interpreter overhead
22-
- **`parallel=True`** - Enables automatic SIMD parallelization
23-
- **`fastmath=True`** - Uses aggressive floating-point optimizations via LLVM's fastmath flag
24-
- **`@vectorize` / `@guvectorize`** - Creates NumPy universal functions (ufuncs)
25-
- **`@cuda.jit`** - Compiles functions to run on NVIDIA GPUs
21+
- **`@jit`** - General-purpose JIT compilation with optional flags.
22+
- **`noython=True`** - Compiles to machine code without falling back to the python interpreter.
23+
- **`parallel=True`** - Enables automatic thread-level parallelization of the function across multiple CPU cores (no GIL!).
24+
- **`fastmath=True`** - Uses aggressive floating-point optimizations via LLVM's fastmath flag
25+
- **`cache=True`** - Numba writes the result of function compilation to disk which significantly reduces future compilation times.
2626

2727
### PyTorch
2828

2929
PyTorch provides multiple compilation approaches:
3030

3131
- **`torch.compile()`** - The recommended compilation API that uses TorchDynamo to trace operations and create optimized CUDA graphs
32-
- **`torch.jit.script`** - Compiles functions using TorchScript
33-
- **`torch.jit.trace`** - Traces tensor operations to create optimized execution graphs
32+
- **`noython=True`** - Compiles to machine code without falling back to the python interpreter.
33+
- **`parallel=True`** - Enables automatic thread-level parallelization of the function across multiple CPU cores (no GIL!).
34+
- **`fastmath=True`** - Uses aggressive floating-point optimizations via LLVM's fastmath flag
35+
- **`cache=True`** - Numba writes the result of function compilation to disk which significantly reduces future compilation times.
3436

3537
### TensorFlow
3638

3739
TensorFlow uses the XLA (Accelerated Linear Algebra) backend for JIT compilation:
3840

3941
- **`@tf.function`** - Compiles Python functions into optimized TensorFlow graphs using XLA
42+
- **`noython=True`** - Compiles to machine code without falling back to the python interpreter.
43+
- **`parallel=True`** - Enables automatic thread-level parallelization of the function across multiple CPU cores (no GIL!).
44+
- **`fastmath=True`** - Uses aggressive floating-point optimizations via LLVM's fastmath flag
45+
- **`cache=True`** - Numba writes the result of function compilation to disk which significantly reduces future compilation times.
4046

4147
### JAX
4248

4349
JAX captures side-effect-free operations and optimizes them:
4450

4551
- **`@jax.jit`** - JIT compiles functions using XLA, with automatic operation fusion for improved performance
52+
- **`noython=True`** - Compiles to machine code without falling back to the python interpreter.
53+
- **`parallel=True`** - Enables automatic thread-level parallelization of the function across multiple CPU cores (no GIL!).
54+
- **`fastmath=True`** - Uses aggressive floating-point optimizations via LLVM's fastmath flag
55+
- **`cache=True`** - Numba writes the result of function compilation to disk which significantly reduces future compilation times.
4656

4757
## How Codeflash Optimizes with JIT
4858

4959
When Codeflash identifies a function that could benefit from JIT compilation, it:
5060

51-
1. **Rewrites the code** in a JIT-compatible format, which may involve breaking down complex functions into separate JIT-compiled components
52-
2. **Generates appropriate tests** that are compatible with JIT-compiled code, carefully handling data types since JIT compilers have stricter type requirements
53-
3. **Adds GPU synchronization calls** for accurate profiling when code runs on GPU, since GPU operations are inherently non-blocking
61+
1. **Rewrites the code** in a JIT-compatible format, which may involve breaking down complex functions into separate JIT-compiled components.
62+
2. **Generates appropriate tests** that are compatible with JIT-compiled code, carefully handling data types since JIT compilers have stricter input type requirements.
5463

5564
## Accurate Benchmarking with GPU Code
5665

0 commit comments

Comments
 (0)