Skip to content

Commit c399253

Browse files
committed
Feat: Enable injection of extra include paths from env variable.
1 parent e0df003 commit c399253

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ Your hardware needs to support CUDA Compute Capability $8.0$ or later. Make sure
3535
conda env create -n flashrnn -f environment_pt240cu124.yaml
3636
```
3737

38+
For all kinds of custom setups with torch and CUDA, keep in mind that versions have to match. Also, to make sure the correct CUDA libraries are included you can use the "FLASHRNN_EXTRA_INCLUDE_PATHS" environment variable now to inject different include paths, e.g.:
39+
40+
```bash
41+
export FLASHRNN_EXTRA_INCLUDE_PATHS='/usr/local/include/cuda/:/usr/include/cuda/'
42+
```
43+
44+
or within python:
45+
46+
```python
47+
import os
48+
os.environ['FLASHRNN_EXTRA_INCLUDE_PATHS']='/usr/local/include/cuda/:/usr/include/cuda/'
49+
```
50+
51+
52+
3853
## Using FlashRNN
3954

4055
FlashRNN employs a functional structure, none of the parameters are tied to the `flashrnn` function. To apply it simply use:

flashrnn/flashrnn/cuda_init.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,33 @@ def defines_to_cflags(
3434

3535
if torch.cuda.is_available():
3636
from packaging import version
37+
3738
if version.parse(torch.__version__) >= version.parse("2.6.0"):
38-
os.environ["CUDA_LIB"] = os.path.join(os.path.split(torch.utils.cpp_extension.include_paths(device_type="cuda")[-1])[0], "lib")
39+
os.environ["CUDA_LIB"] = os.path.join(
40+
os.path.split(torch.utils.cpp_extension.include_paths(device_type="cuda")[-1])[0], "lib"
41+
)
3942
else:
40-
os.environ["CUDA_LIB"] = os.path.join(os.path.split(torch.utils.cpp_extension.include_paths(cuda=True)[-1])[0], "lib")
43+
os.environ["CUDA_LIB"] = os.path.join(
44+
os.path.split(torch.utils.cpp_extension.include_paths(cuda=True)[-1])[0], "lib"
45+
)
4146

4247

43-
EXTRA_INCLUDE_PATHS = ()
48+
EXTRA_INCLUDE_PATHS = () + (
49+
tuple(os.environ["FLASHRNN_EXTRA_INCLUDE_PATHS"].split(":")) if "FLASHRNN_EXTRA_INCLUDE_PATHS" in os.environ else ()
50+
)
4451
if "CONDA_PREFIX" in os.environ:
4552
# This enforces adding the correct include directory from the CUDA installation via torch. If you use the system
4653
# installation, you might have to add the cflags yourself.
4754
from pathlib import Path
4855
from packaging import version
49-
import sys
5056
import glob
57+
5158
if version.parse(torch.__version__) >= version.parse("2.6.0"):
5259
matching_dirs = glob.glob(f"{os.environ['CONDA_PREFIX']}/targets/**", recursive=True)
53-
EXTRA_INCLUDE_PATHS = tuple(map(str, (Path(os.environ["CONDA_PREFIX"]) / "targets").glob("**/include/")))[:1]
54-
55-
60+
EXTRA_INCLUDE_PATHS = (
61+
EXTRA_INCLUDE_PATHS
62+
+ tuple(map(str, (Path(os.environ["CONDA_PREFIX"]) / "targets").glob("**/include/")))[:1]
63+
)
5664

5765

5866
def load(*, name, sources, extra_cflags=(), extra_cuda_cflags=(), **kwargs):

0 commit comments

Comments
 (0)