commit 361af5481e118947d5ff03a4b78c62cd03f57a7b
parent d14fd2ea92b0e993b0acff196681432a10872560
Author: David Freifeld <freifeld.david@gmail.com>
Date: Tue, 30 Jun 2020 11:04:31 -0700
Significant speedup
Diffstat:
3 files changed, 38 insertions(+), 37 deletions(-)
diff --git a/Makefile b/Makefile
@@ -10,11 +10,12 @@ fast: build
faster: CXXFLAGS = -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` mr_bpnn_2.cpp bpnn.cpp utils.cpp mapreduce.a ${MKLROOT}/lib/libmkl_intel_ilp64.a ${MKLROOT}/lib/libmkl_intel_thread.a ${MKLROOT}/lib/libmkl_core.a -liomp5 -lpthread -lm -ldl -o mrbpnn`python3-config --extension-suffix` -O3 -mavx -mfma -march=native -mfpmath=sse -DMKL_ILP64 -I${MKLROOT}/include -D EIGEN_USE_MKL_ALL -D NDEBUG
faster: build
-tradeoffs: CXXFLAGS = -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` mr_bpnn_2.cpp bpnn.cpp utils.cpp mapreduce.a ${MKLROOT}/lib/libmkl_intel_ilp64.a ${MKLROOT}/lib/libmkl_intel_thread.a ${MKLROOT}/lib/libmkl_core.a -liomp5 -lpthread -lm -ldl -o mrbpnn`python3-config --extension-suffix` -O3 -mavx -mfma -march=native -mfpmath=sse -DMKL_ILP64 -I${MKLROOT}/include -ffinite-math-only -fno-math-errno -ffp-contract=fast -D EIGEN_USE_MKL_ALL -D NDEBUG
+tradeoffs: CXXFLAGS = -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` mr_bpnn_2.cpp bpnn.cpp utils.cpp mapreduce.a ${MKLROOT}/lib/libmkl_intel_ilp64.a ${MKLROOT}/lib/libmkl_intel_thread.a ${MKLROOT}/lib/libmkl_core.a -liomp5 -lpthread -lm -ldl -o mrbpnn`python3-config --extension-suffix` -O3 -mavx -mfma -march=native -mfpmath=sse -DMKL_ILP64 -I${MKLROOT}/include -prof-use -qopenmp -prof-gen -ffast-math -no-prec-div -no-prec-sqrt -fimf-precision=low -fast-transcendentals -D EIGEN_USE_MKL_ALL -D NDEBUG
tradeoffs: build
+
reckless: CXXFLAGS = -O3
reckless: build
build:
- g++ $(CXXFLAGS)
+ icpc $(CXXFLAGS)
diff --git a/bpnn.cpp b/bpnn.cpp
@@ -193,7 +193,7 @@ int Network::next_batch()
int label = -1;
for (int i = 0; i < batch_size; i++) {
// This shouldn't ever happen - tell the compiler that.
- if (__builtin_expect_with_probability(fgets(line, 1024, data), NULL, 0.001)) {
+ if (fgets(line, 1024, data) == NULL) {
break;
}
char *p;
diff --git a/example.py b/example.py
@@ -15,44 +15,44 @@ def bench(batch_sz, layers):
end = time.time()
return (end-init)
-# timesum=0
-# trials = 1000
-# for i in range(trials):
-# timesum+=bench()
-# print("Averages over %s trials\n--------------\nTime: %s seconds.\n" % (trials, timesum/trials))
-x = []
-y = []
-i = 1
-while(i < 1340):
- y.append(bench(i, 1))
- x.append(i)
- i+=1
-print(y)
-plt.plot(x,y, label = "ML-in-Parallel (Sequential)")
-i = 20
-otherlist = [1, 5, 10, 15]
-while(i < 1340):
- otherlist.append(i)
- i += 20
+timesum=0
+trials = 5
+for i in range(trials):
+ timesum+=bench(10,1)
+print("Averages over %s trials\n--------------\nTime: %s seconds.\n" % (trials, timesum/trials))
+# x = []
+# y = []
+# i = 1
+# while(i < 1340):
+# y.append(bench(i, 1))
+# x.append(i)
+# i+=1
+# print(y)
+# plt.plot(x,y, label = "ML-in-Parallel (Sequential)")
+# i = 20
+# otherlist = [1, 5, 10, 15]
+# while(i < 1340):
+# otherlist.append(i)
+# i += 20
-plt.plot(otherlist, [38.563481092453, 8.210114002227783, 4.5140931606292725, 3.3074569702148438, 2.3994078636169434, 1.2735769748687744, 1.0030598640441895, 0.8972160816192627, 0.801548957824707, 0.752018928527832, 0.7073678970336914, 0.6857280731201172, 0.6707980632781982, 0.6421489715576172, 0.6614980697631836, 0.6403779983520508, 0.7251319885253906, 0.6796879768371582, 0.6601080894470215, 0.6711599826812744, 0.6432759761810303, 0.6491389274597168, 0.6762490272521973, 0.6859049797058105, 0.7067179679870605, 0.7142889499664307, 0.7258059978485107, 0.7868969440460205, 0.7326970100402832, 0.7365641593933105, 0.7576079368591309, 0.7772500514984131, 0.8062641620635986, 0.7768490314483643, 0.8253629207611084, 0.8264601230621338, 0.8459320068359375, 0.9670729637145996, 0.8388969898223877, 0.9129719734191895, 0.9009649753570557, 0.8916170597076416, 0.8926799297332764, 0.9171609878540039, 0.9242072105407715, 0.9534740447998047, 0.947465181350708, 0.9723358154296875, 1.018247127532959, 1.1208629608154297, 1.014026165008545, 1.034980058670044, 1.0626468658447266, 1.080394983291626, 1.0627479553222656, 1.0839190483093262, 1.0938241481781006, 1.127730131149292, 1.1265759468078613, 1.136888027191162, 1.140428066253662, 1.1712510585784912, 1.206390142440796, 1.2087180614471436, 1.4066569805145264, 1.2425589561462402, 1.280066967010498, 1.2891559600830078, 1.3243582248687744, 1.3152379989624023], label="Keras")
-plt.legend()
-plt.show()
+# plt.plot(otherlist, [38.563481092453, 8.210114002227783, 4.5140931606292725, 3.3074569702148438, 2.3994078636169434, 1.2735769748687744, 1.0030598640441895, 0.8972160816192627, 0.801548957824707, 0.752018928527832, 0.7073678970336914, 0.6857280731201172, 0.6707980632781982, 0.6421489715576172, 0.6614980697631836, 0.6403779983520508, 0.7251319885253906, 0.6796879768371582, 0.6601080894470215, 0.6711599826812744, 0.6432759761810303, 0.6491389274597168, 0.6762490272521973, 0.6859049797058105, 0.7067179679870605, 0.7142889499664307, 0.7258059978485107, 0.7868969440460205, 0.7326970100402832, 0.7365641593933105, 0.7576079368591309, 0.7772500514984131, 0.8062641620635986, 0.7768490314483643, 0.8253629207611084, 0.8264601230621338, 0.8459320068359375, 0.9670729637145996, 0.8388969898223877, 0.9129719734191895, 0.9009649753570557, 0.8916170597076416, 0.8926799297332764, 0.9171609878540039, 0.9242072105407715, 0.9534740447998047, 0.947465181350708, 0.9723358154296875, 1.018247127532959, 1.1208629608154297, 1.014026165008545, 1.034980058670044, 1.0626468658447266, 1.080394983291626, 1.0627479553222656, 1.0839190483093262, 1.0938241481781006, 1.127730131149292, 1.1265759468078613, 1.136888027191162, 1.140428066253662, 1.1712510585784912, 1.206390142440796, 1.2087180614471436, 1.4066569805145264, 1.2425589561462402, 1.280066967010498, 1.2891559600830078, 1.3243582248687744, 1.3152379989624023], label="Keras")
+# plt.legend()
+# plt.show()
-# sum = 0
-# for i in range(10):
-# sum += bench(10, 1)
-# print(sum/10)
+# # sum = 0
+# # for i in range(10):
+# # sum += bench(10, 1)
+# # print(sum/10)
-# x = ['Keras', 'MIP-Sequential']
-# speed = [4.71297559738, 0.043680644035339354]
+# # x = ['Keras', 'MIP-Sequential']
+# # speed = [4.71297559738, 0.043680644035339354]
-# x_pos = [i for i, _ in enumerate(x)]
+# # x_pos = [i for i, _ in enumerate(x)]
-# plt.bar(x_pos, speed, color='green')
-# plt.ylabel("Time (s)")
-# plt.title("Average Runtime (10 trials)")
+# # plt.bar(x_pos, speed, color='green')
+# # plt.ylabel("Time (s)")
+# # plt.title("Average Runtime (10 trials)")
-# plt.xticks(x_pos, x)
+# # plt.xticks(x_pos, x)
-# plt.show()
+# # plt.show()