Skip to content

Commit fe85da4

Browse files
authored
Merge pull request #209 from Ricardicus/master
Adding a github workflow
2 parents 4e4eba0 + 3d2605b commit fe85da4

File tree

2 files changed

+93
-24
lines changed

2 files changed

+93
-24
lines changed

.github/workflows/ci.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build and test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build-and-test-cpu:
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macos-latest]
16+
17+
runs-on: ${{ matrix.os }}
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Install OpenMP
24+
run: |
25+
if [ "${{ runner.os }}" == "Linux" ]; then
26+
sudo apt-get update && sudo apt-get install -y libomp-dev
27+
elif [ "${{ runner.os }}" == "macOS" ]; then
28+
brew install libomp
29+
fi
30+
31+
- name: Install dependencies
32+
run: pip install -r requirements.txt
33+
34+
- name: Run preprocessing
35+
run: python prepro_tinyshakespeare.py
36+
37+
- name: Train model
38+
run: python train_gpt2.py
39+
40+
- name: Compile training and testing program
41+
run: make test_gpt2 train_gpt2
42+
43+
- name: Execute testing program (With OpenMP)
44+
run: OMP_NUM_THREADS=8 ./test_gpt2
45+
46+
- name: Compile training and testing program without OpenMP
47+
run: NO_OMP=1 make test_gpt2 train_gpt2
48+
49+
- name: Execute testing program (No OpenMP)
50+
run: ./test_gpt2
51+
52+
build-with-cuda:
53+
runs-on: ubuntu-latest # Host OS, Docker will run on top of this
54+
container:
55+
image: nvidia/cuda:11.2.2-devel-ubuntu20.04 # Example CUDA development image with nvcc
56+
57+
steps:
58+
- name: Checkout code
59+
uses: actions/checkout@v3
60+
61+
- name: Build project
62+
run: make train_gpt2cu test_gpt2cu

Makefile

+31-24
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,39 @@ $(foreach flag,$(CFLAGS_COND),$(eval $(call check_and_add_flag,$(flag))))
2929
# e.g. on MacOS: brew install libomp
3030
# e.g. on Ubuntu: sudo apt-get install libomp-dev
3131
# 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)
5035
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
5656
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
5865
endif
5966
endif
6067

0 commit comments

Comments
 (0)