Skip to content

Commit

Permalink
Allow using local omp with Apple clang (#181)
Browse files Browse the repository at this point in the history
Tested on my M1 Mac as,

```
OMP_NUM_THREADS=8                                          \
TRITON_LOCAL_LIBOMP_PATH="<path..to>/site-packages/torch/" \
CC=$(which clang)                                          \
TRITON_CPU_BACKEND=1                                       \
$(which python3)                                           \
python/tutorials/02-fused-softmax-cpu.py
```
  • Loading branch information
digantdesai authored Dec 4, 2024
1 parent b3e811b commit ee7aa42
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion python/triton/runtime/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ def quiet():
sys.stdout, sys.stderr = old_stdout, old_stderr


def _is_apple_clang():
if platform.system() != "Darwin":
return False
res = subprocess.run(["clang", "--version"], capture_output=True, text=True)
if res.returncode != 0:
return False
return "Apple clang" in res.stdout


def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
suffix = sysconfig.get_config_var('EXT_SUFFIX')
system = platform.system()
Expand Down Expand Up @@ -64,7 +73,20 @@ def _build(name, src, srcdir, library_dirs, include_dirs, libraries):
if src.endswith(".cpp") or src.endswith(".cc"):
cc_cmd += ["-std=c++17"]
if not os.environ.get("TRITON_DISABLE_OPENMP", None):
cc_cmd += ["-fopenmp"]
libomp_path = os.environ.get("TRITON_LOCAL_LIBOMP_PATH", None)
if _is_apple_clang():
if libomp_path:
cc_cmd += ["-Xclang"]
cc_cmd += ["-fopenmp"]
cc_cmd += [f"-I{libomp_path}/include"]
cc_cmd += [f"-L{libomp_path}/lib"]
cc_cmd += ["-lomp"]
else:
print("Warning: TRITON_LOCAL_LIBOMP_PATH is not set for Apple clang. OpenMP is disabled.")
else:
cc_cmd += ["-fopenmp"]
if libomp_path:
print("Info: Ignoring TRITON_LOCAL_LIBOMP_PATH for non-Apple clang compiler")
if src.endswith(".s"):
# This is required to properly parse .file directives
cc_cmd += ["-g"]
Expand Down

0 comments on commit ee7aa42

Please sign in to comment.