You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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**.
12
12
13
13
## Supported JIT Frameworks
14
14
15
15
Each framework uses different compilation strategies to accelerate Python code:
16
16
17
-
### Numba
17
+
### Numba (CPU Code)
18
18
19
19
Numba compiles Python functions to optimized machine code using the LLVM compiler infrastructure. Codeflash can suggest Numba optimizations that use:
20
20
21
-
-**`@jit` / `@njit`** - General-purpose JIT compilation with `nopython` mode for removing Python interpreter overhead
-**`@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.
26
26
27
27
### PyTorch
28
28
29
29
PyTorch provides multiple compilation approaches:
30
30
31
31
-**`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.
34
36
35
37
### TensorFlow
36
38
37
39
TensorFlow uses the XLA (Accelerated Linear Algebra) backend for JIT compilation:
38
40
39
41
-**`@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.
40
46
41
47
### JAX
42
48
43
49
JAX captures side-effect-free operations and optimizes them:
44
50
45
51
-**`@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.
46
56
47
57
## How Codeflash Optimizes with JIT
48
58
49
59
When Codeflash identifies a function that could benefit from JIT compilation, it:
50
60
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.
0 commit comments