Skip to content

Commit 70d6d93

Browse files
committed
Add support for PGO build with clang.
1 parent 8c86710 commit 70d6d93

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

Makefile

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ build: setup.py tsne/bh_sne.pyx \
55
$(wildcard tsne/bh_sne_src/*.cpp)
66
python $< build_ext --inplace
77

8+
PROFILE_LOCATION=$(shell pwd)/profile
9+
10+
$(PROFILE_LOCATION)/bh_sne.profdata: PROFILE=generate
11+
$(PROFILE_LOCATION)/bh_sne.profdata: setup.py Makefile tsne/bh_sne.pyx \
12+
$(wildcard tsne/bh_sne_src/*.h) \
13+
$(wildcard tsne/bh_sne_src/*.cpp)
14+
rm -rf build tsne/*.so *.so
15+
PROFILE=generate python $< build_ext --inplace
16+
mkdir -p $(PROFILE_LOCATION) && cd tsne/tests && LLVM_PROFILE_FILE="$(PROFILE_LOCATION)/%p-%m.profraw" py.test -s
17+
llvm-profdata merge -output=$@ $(PROFILE_LOCATION)/*.profraw
18+
rm -rf tsne/*.so *.so build tsne/*.o
19+
20+
build_pgo: setup.py $(PROFILE_LOCATION)/bh_sne.profdata
21+
PROFILE="$(PROFILE_LOCATION)/bh_sne.profdata" python $< build_ext --inplace
22+
823
install: setup.py build
924
python $< install
1025

@@ -14,10 +29,10 @@ sdist: setup.py tsne/bh_sne.pyx \
1429
python $< sdist
1530

1631
test: build
17-
cd tsne/tests && py.test -s -vv
32+
cd tsne/tests && time py.test -s -vv
1833

1934
clean:
2035
make -C tsne/bh_sne_src clean
21-
rm -rf *.pyc *.so build/ bh_sne.cpp
36+
rm -rf *.pyc *.so build/ profile/ bh_sne.cpp
2237
rm -rf tsne/*.pyc tsne/*.so tsne/*.o tsne/build/ tsne/bh_sne.cpp
2338
rm -rf .pytest_cache/

setup.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
else:
5050
# LINUX
5151
opt_flags = ['-msse3', '-O3', '-flto']
52+
if 'PROFILE' in os.environ:
53+
if os.environ['PROFILE'] == 'generate':
54+
opt_flags.append('-fprofile-instr-generate')
55+
elif os.path.isfile(os.environ['PROFILE']):
56+
opt_flags.append('-fprofile-instr-use='+os.environ['PROFILE'])
5257
ldflags = list(opt_flags)
5358
if 'LDFLAGS' in os.environ and os.environ['LDFLAGS']:
5459
ldflags.extend(os.environ['LDFLAGS'].split(' '))

0 commit comments

Comments
 (0)