commit ac73df14746bf96ece82d78014621de74793a6dd
parent 447e8aa87e2cca28e5eab789d57f62b2f2395d3b
Author: David Freifeld <freifeld.david@gmail.com>
Date: Fri, 7 Aug 2020 12:32:56 -0700
Attempt to use CMake
Diffstat:
3 files changed, 281 insertions(+), 34 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 3.10.0)
+
+project (jacobian)
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+#add_library(utils ./src/utils.cpp)
+#add_library(bpnn ./src/bpnn.cpp)
+
+SET(GCC_COMPILE_FLAGS "-w")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}")
+
+add_executable(jacobian example.cpp ./src/bpnn.cpp ./src/utils.cpp)
+#target_link_libraries(jacobian PUBLIC utils bpnn)
+
+enable_testing()
+add_test(NAME "Valid run" COMMAND jacobian 16 50)
+add_test(NAME "Large batch" COMMAND jacobian 1000 50)
+add_test(NAME "Small batch" COMMAND jacobian 1 50)
+
diff --git a/Makefile b/Makefile
@@ -1,41 +1,269 @@
-#
-# Makefile
-# Jacobian
-#
-# Created by David Freifeld
-#
-# ---------
-# TODO:
-# Start using CMake to make this less of a headache?
-# ---------
+# CMAKE generated file: DO NOT EDIT!
+# Generated by "Unix Makefiles" Generator, CMake Version 3.18
-GEN_FLAGS = -fpic
+# Default target executed when no arguments are given to make.
+default_target: all
-CXX = icpc
-CXXFLAGS = -shared -std=c++17 -undefined dynamic_lookup `python3 -m pybind11 --includes` ./src/pybind.cpp ./src/bpnn.cpp ./src/utils.cpp mapreduce.a -o mrbpnn`python3-config --extension-suffix`
-#LDFLAGS = -L/usr/local/opt/llvm/lib -lc++
+.PHONY : default_target
-all: compile
+# Allow only one "make -f Makefile2" at a time, but pass parallelism.
+.NOTPARALLEL:
-debug: $(GEN_FLAGS) = -Wall -U NDEBUG
-test: CXXFLAGS = -std=c++17 example.cpp ./src/bpnn.cpp ./src/utils.cpp mapreduce.a -o bpnnexec -O3 -mavx -mfma -march=native -mfpmath=sse -fno-pic -DMKL_ILP64 -D NDEBUG
-test: LDFLAGS = -lpthread -lm -ldl
-test: compile
+#=============================================================================
+# Special targets provided by cmake.
-fast: CXXFLAGS += $(GEN_FLAGS) -O3
-fast: compile
+# Disable implicit rules so canonical targets will work.
+.SUFFIXES:
-faster: CXXFLAGS = -shared -std=c++17 -undefined dynamic_lookup `python3 -m pybind11 --includes` ./src/pybind.cpp ./src/bpnn.cpp ./src/utils.cpp mapreduce.a -o mrbpnn`python3-config --extension-suffix` -O3 -mavx -msse2 -msse3 -fopenmp -march=native -mfpmath=sse -fno-pic -DMKL_ILP64 -D NDEBUG -D EIGEN_USE_BLAS ${MKLROOT}/lib/libmkl_intel_ilp64.a -m64 -I${MKLROOT}/include ${MKLROOT}/lib/libmkl_intel_thread.a ${MKLROOT}/lib/libmkl_core.a -liomp5 -lpthread -lm -ldl
-faster: LDFLAGS = -lpthread -lm -ldl -lblas
-faster: compile
-tradeoffs: CXXFLAGS = -shared -std=c++17 -undefined dynamic_lookup `python3 -m pybind11 --includes` ./src/pybind.cpp ./src/bpnn.cpp ./src/utils.cpp mapreduce.a -o mrbpnn`python3-config --extension-suffix` -O3 -mavx -msse2 -msse3 -march=native -mfpmath=sse -DMKL_ILP64 -fno-pic -ffast-math -D NDEBUG #-qopt-report=5 -qopt-report-file=report
-tradeoffs: compile
+# Disable VCS-based implicit rules.
+% : %,v
-reckless: CXXFLAGS = -O3
-reckless: compile
+# Disable VCS-based implicit rules.
+% : RCS/%
+
+
+# Disable VCS-based implicit rules.
+% : RCS/%,v
+
+
+# Disable VCS-based implicit rules.
+% : SCCS/s.%
+
+
+# Disable VCS-based implicit rules.
+% : s.%
+
+
+.SUFFIXES: .hpux_make_needs_suffix_list
+
+
+# Command-line flag to silence nested $(MAKE).
+$(VERBOSE)MAKESILENT = -s
+
+#Suppress display of executed commands.
+$(VERBOSE).SILENT:
+
+# A target that is always out of date.
+cmake_force:
+
+.PHONY : cmake_force
+
+#=============================================================================
+# Set environment variables for the build.
+
+# The shell in which to execute make rules.
+SHELL = /bin/sh
+
+# The CMake executable.
+CMAKE_COMMAND = /usr/local/Cellar/cmake/3.18.0/bin/cmake
+
+# The command to remove a file.
+RM = /usr/local/Cellar/cmake/3.18.0/bin/cmake -E rm -f
+
+# Escaping for special characters.
+EQUALS = =
+
+# The top-level source directory on which CMake was run.
+CMAKE_SOURCE_DIR = /Users/davidfreifeld/projects/Jacobian
+
+# The top-level build directory on which CMake was run.
+CMAKE_BINARY_DIR = /Users/davidfreifeld/projects/Jacobian
+
+#=============================================================================
+# Targets provided globally by CMake.
+
+# Special rule for the target rebuild_cache
+rebuild_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
+ /usr/local/Cellar/cmake/3.18.0/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : rebuild_cache
+
+# Special rule for the target rebuild_cache
+rebuild_cache/fast: rebuild_cache
+
+.PHONY : rebuild_cache/fast
+
+# Special rule for the target edit_cache
+edit_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
+ /usr/local/Cellar/cmake/3.18.0/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : edit_cache
+
+# Special rule for the target edit_cache
+edit_cache/fast: edit_cache
+
+.PHONY : edit_cache/fast
+
+# Special rule for the target test
+test:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..."
+ /usr/local/Cellar/cmake/3.18.0/bin/ctest --force-new-ctest-process $(ARGS)
+.PHONY : test
+
+# Special rule for the target test
+test/fast: test
+
+.PHONY : test/fast
+
+# The main all target
+all: cmake_check_build_system
+ $(CMAKE_COMMAND) -E cmake_progress_start /Users/davidfreifeld/projects/Jacobian/CMakeFiles /Users/davidfreifeld/projects/Jacobian//CMakeFiles/progress.marks
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
+ $(CMAKE_COMMAND) -E cmake_progress_start /Users/davidfreifeld/projects/Jacobian/CMakeFiles 0
+.PHONY : all
+
+# The main clean target
+clean:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
+.PHONY : clean
+
+# The main clean target
+clean/fast: clean
+
+.PHONY : clean/fast
+
+# Prepare targets for installation.
+preinstall: all
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall
+
+# Prepare targets for installation.
+preinstall/fast:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall/fast
+
+# clear depends
+depend:
+ $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
+.PHONY : depend
+
+#=============================================================================
+# Target rules for targets named jacobian
+
+# Build rule for target.
+jacobian: cmake_check_build_system
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 jacobian
+.PHONY : jacobian
+
+# fast build rule for target.
+jacobian/fast:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/build
+.PHONY : jacobian/fast
+
+example.o: example.cpp.o
+
+.PHONY : example.o
+
+# target to build an object file
+example.cpp.o:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/example.cpp.o
+.PHONY : example.cpp.o
+
+example.i: example.cpp.i
+
+.PHONY : example.i
+
+# target to preprocess a source file
+example.cpp.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/example.cpp.i
+.PHONY : example.cpp.i
+
+example.s: example.cpp.s
+
+.PHONY : example.s
+
+# target to generate assembly for a file
+example.cpp.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/example.cpp.s
+.PHONY : example.cpp.s
+
+src/bpnn.o: src/bpnn.cpp.o
+
+.PHONY : src/bpnn.o
+
+# target to build an object file
+src/bpnn.cpp.o:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/src/bpnn.cpp.o
+.PHONY : src/bpnn.cpp.o
+
+src/bpnn.i: src/bpnn.cpp.i
+
+.PHONY : src/bpnn.i
+
+# target to preprocess a source file
+src/bpnn.cpp.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/src/bpnn.cpp.i
+.PHONY : src/bpnn.cpp.i
+
+src/bpnn.s: src/bpnn.cpp.s
+
+.PHONY : src/bpnn.s
+
+# target to generate assembly for a file
+src/bpnn.cpp.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/src/bpnn.cpp.s
+.PHONY : src/bpnn.cpp.s
+
+src/utils.o: src/utils.cpp.o
+
+.PHONY : src/utils.o
+
+# target to build an object file
+src/utils.cpp.o:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/src/utils.cpp.o
+.PHONY : src/utils.cpp.o
+
+src/utils.i: src/utils.cpp.i
+
+.PHONY : src/utils.i
+
+# target to preprocess a source file
+src/utils.cpp.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/src/utils.cpp.i
+.PHONY : src/utils.cpp.i
+
+src/utils.s: src/utils.cpp.s
+
+.PHONY : src/utils.s
+
+# target to generate assembly for a file
+src/utils.cpp.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/jacobian.dir/build.make CMakeFiles/jacobian.dir/src/utils.cpp.s
+.PHONY : src/utils.cpp.s
+
+# Help Target
+help:
+ @echo "The following are some of the valid targets for this Makefile:"
+ @echo "... all (the default if no target is provided)"
+ @echo "... clean"
+ @echo "... depend"
+ @echo "... edit_cache"
+ @echo "... rebuild_cache"
+ @echo "... test"
+ @echo "... jacobian"
+ @echo "... example.o"
+ @echo "... example.i"
+ @echo "... example.s"
+ @echo "... src/bpnn.o"
+ @echo "... src/bpnn.i"
+ @echo "... src/bpnn.s"
+ @echo "... src/utils.o"
+ @echo "... src/utils.i"
+ @echo "... src/utils.s"
+.PHONY : help
+
+
+
+#=============================================================================
+# Special targets to cleanup operation of make.
+
+# Special rule to run CMake to check the build system integrity.
+# No rule that depends on this can have commands that come from listfiles
+# because they might be regenerated.
+cmake_check_build_system:
+ $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
+.PHONY : cmake_check_build_system
-compile:
- $(CXX) $(CXXFLAGS) $(LDFLAGS) && rm ./mrbpnn/mrbpnn.cpython-37m-darwin.so ; cp ./mrbpnn.cpython-37m-darwin.so ./mrbpnn/mrbpnn.cpython-37m-darwin.s ; rm ./scripts/mrbpnn.cpython-37m-darwin.so ; cp ./mrbpnn.cpython-37m-darwin.so ./scripts/mrbpnn.cpython-37m-darwin.so
diff --git a/example.cpp b/example.cpp
@@ -15,7 +15,7 @@ using namespace indicators;
#include "unistd.h"
#include <ctime>
-double bench(int batch_sz)
+double bench(int batch_sz, int epochs)
{
auto start = std::chrono::high_resolution_clock::now();
Network net ("./data_banknote_authentication.txt", batch_sz, 0.0155, 0.03, 2, 0, 0.9);
@@ -23,16 +23,16 @@ double bench(int batch_sz)
net.add_layer(5, "relu");
net.add_layer(2, "linear");
net.initialize();
- for (int i = 0; i < 1000; i++) {
+ for (int i = 0; i < epochs; i++) {
net.train();
}
auto end = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(end - start).count() / pow(10,9);
}
-int main()
+int main(int argc, char** argv)
{
- std::cout << bench(16) << "\n";
+ std::cout << bench(strtol(argv[1], NULL, 10), strtol(argv[2], NULL, 10)) << "\n";
// show_console_cursor(false);
// BlockProgressBar bar{
// option::BarWidth{80},