@@ -29,32 +29,39 @@ $(foreach flag,$(CFLAGS_COND),$(eval $(call check_and_add_flag,$(flag))))
29
29
# e.g. on MacOS: brew install libomp
30
30
# e.g. on Ubuntu: sudo apt-get install libomp-dev
31
31
# later, run the program by prepending the number of threads, e.g.: OMP_NUM_THREADS=8 ./gpt2
32
- ifeq ($(shell uname) , Darwin)
33
- # Check if the libomp directory exists
34
- ifeq ($(shell [ -d /opt/homebrew/opt/libomp/lib ] && echo "exists"), exists)
35
- # macOS with Homebrew and directory exists
36
- CFLAGS += -Xclang -fopenmp -DOMP
37
- LDFLAGS += -L/opt/homebrew/opt/libomp/lib
38
- LDLIBS += -lomp
39
- INCLUDES += -I/opt/homebrew/opt/libomp/include
40
- $(info OpenMP found, compiling with OpenMP support)
41
- else ifeq ($(shell [ -d /usr/local/opt/libomp/lib ] && echo "exists"), exists)
42
- CFLAGS += -Xclang -fopenmp -DOMP
43
- LDFLAGS += -L/usr/local/opt/libomp/lib
44
- LDLIBS += -lomp
45
- INCLUDES += -I/usr/local/opt/libomp/include
46
- $(info OpenMP found, compiling with OpenMP support)
47
- else
48
- $(warning OpenMP not found, skipping OpenMP support)
49
- endif
32
+ # First, check if NO_OMP is set to 1, if not, proceed with the OpenMP checks
33
+ ifeq ($(NO_OMP ) , 1)
34
+ $(info OpenMP is manually disabled)
50
35
else
51
- ifeq ($(shell echo | $(CC) -fopenmp -x c -E - > /dev/null 2>&1; echo $$?), 0)
52
- # Ubuntu or other Linux distributions
53
- CFLAGS += -fopenmp -DOMP
54
- LDLIBS += -lgomp
55
- $(info OpenMP found, compiling with OpenMP support)
36
+ # Detect if running on macOS or Linux
37
+ ifeq ($(shell uname), Darwin)
38
+ # Check for Homebrew's libomp installation in different common directories
39
+ ifeq ($(shell [ -d /opt/homebrew/opt/libomp/lib ] && echo "exists"), exists)
40
+ # macOS with Homebrew on ARM (Apple Silicon)
41
+ CFLAGS += -Xclang -fopenmp -DOMP
42
+ LDFLAGS += -L/opt/homebrew/opt/libomp/lib
43
+ LDLIBS += -lomp
44
+ INCLUDES += -I/opt/homebrew/opt/libomp/include
45
+ $(info OpenMP found, compiling with OpenMP support)
46
+ else ifeq ($(shell [ -d /usr/local/opt/libomp/lib ] && echo "exists"), exists)
47
+ # macOS with Homebrew on Intel
48
+ CFLAGS += -Xclang -fopenmp -DOMP
49
+ LDFLAGS += -L/usr/local/opt/libomp/lib
50
+ LDLIBS += -lomp
51
+ INCLUDES += -I/usr/local/opt/libomp/include
52
+ $(info OpenMP found, compiling with OpenMP support)
53
+ else
54
+ $(warning OpenMP not found, skipping OpenMP support)
55
+ endif
56
56
else
57
- $(warning OpenMP not found, skipping OpenMP support)
57
+ # Check for OpenMP support in GCC or Clang on Linux
58
+ ifeq ($(shell echo | $(CC) -fopenmp -x c -E - > /dev/null 2>&1; echo $$?), 0)
59
+ CFLAGS += -fopenmp -DOMP
60
+ LDLIBS += -lgomp
61
+ $(info OpenMP found, compiling with OpenMP support)
62
+ else
63
+ $(warning OpenMP not found, skipping OpenMP support)
64
+ endif
58
65
endif
59
66
endif
60
67
0 commit comments