Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using local omp with Apple clang #181

Merged
merged 1 commit into from
Dec 4, 2024
Merged

Allow using local omp with Apple clang #181

merged 1 commit into from
Dec 4, 2024

Conversation

digantdesai
Copy link
Collaborator

Tested 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

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
```
@digantdesai digantdesai marked this pull request as ready for review December 4, 2024 18:00
@digantdesai digantdesai requested a review from ptillet as a code owner December 4, 2024 18:00
@digantdesai digantdesai requested a review from minjang December 4, 2024 18:01
@digantdesai digantdesai merged commit ee7aa42 into main Dec 4, 2024
2 checks passed
else:
cc_cmd += ["-fopenmp"]
if libomp_path:
print("Info: Ignoring TRITON_LOCAL_LIBOMP_PATH for non-Apple clang compiler")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: print(..., file=sys.stderr) as a warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point. I missed this. I will sneak this in with my next PR.

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.")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens in this case? Can triton still compile the kernel and run it, but with a single core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes because we don't add -fopenmp on cc_cmd

int3 pushed a commit that referenced this pull request Dec 6, 2024
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
```
ienkovich pushed a commit that referenced this pull request Dec 6, 2024
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
```
@minjang minjang deleted the apple_omp branch December 7, 2024 00:09
@int3
Copy link
Collaborator

int3 commented Dec 10, 2024

I know it's meant to be a hack, but a nicer long-term solution would be to handle this at install time

Also I found https://mac.r-project.org/openmp/, we could possibly download libomp from there

@digantdesai
Copy link
Collaborator Author

mac.r-project.org/openmp
Nice I wish I could have found this.
Curious, how is it better than using it from torch pip package (which we already depend on)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants