jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit fc7416d67128f4051248de31c0fa908eb4f79379
parent d6c893f7dabb09e1b3ab6e09cdde4e5d3f47237d
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Fri,  7 Aug 2020 18:23:17 -0700

Overall improvements to quality of CMake build

Diffstat:
M.github/workflows/macos-latest.yml | 2+-
M.github/workflows/ubuntu-latest.yml | 4++--
MCMakeLists.txt | 63++++++++++++++++++++++++++++++++++-----------------------------
DMakefile | 269-------------------------------------------------------------------------------
Mreadme.md | 40++++++++++++++++++----------------------
Msrc/bpnn.hpp | 2+-
6 files changed, 56 insertions(+), 324 deletions(-)

diff --git a/.github/workflows/macos-latest.yml b/.github/workflows/macos-latest.yml @@ -24,7 +24,7 @@ jobs: # make # sudo make install - name: cmake-build - run: cmake . + run: cmake . -DCXX=ON - name: make-build run: make - name: ctest diff --git a/.github/workflows/ubuntu-latest.yml b/.github/workflows/ubuntu-latest.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v2 - name: install run: - sudo apt install libeigen3-dev && + sudo apt install libeigen3-dev sudo apt install cmake # python 3 -m pip install pytest # git clone https://github.com/pybind/pybind11.git @@ -26,7 +26,7 @@ jobs: # make # sudo make install - name: cmake-build - run: cmake . + run: cmake . -DCXX=ON - name: make-build run: make - name: ctest diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -5,37 +5,42 @@ set(CMAKE_CXX_COMPILER "g++") set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(COMPILE_FLAGS, "-w") - -if (!FAST) - set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3") -endif (!FAST) - -if (!FASTER) - set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -ffast-math") -endif (!FASTER) - -if (!TRADEOFFS) - set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -ffast-math -D RECKLESS") -endif (!TRADEOFFS) - -if (!AVX) +if (DEBUG) + set(COMPILE_FLAGS, "-Wall") +else() + set(COMPILE_FLAGS, "-w") +endif() + +if (FAST) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -O3") +elseif (FASTER) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -mfma -march=native -mfpmath=sse -fno-pic -DMKL_ILP64 -D NDEBUG") +elseif (TRADEOFFS) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -msse2 -msse3 -march=native -mfpmath=sse -DMKL_ILP64 -fno-pic -ffast-math -D NDEBUG -ffast-math") +elseif (RECKLESS) + set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -msse2 -msse3 -march=native -mfpmath=sse -DMKL_ILP64 -fno-pic -ffast-math -D NDEBUG -ffast-math -D RECKLESS") +endif() + +if (AVX) + set(CMAKE_CXX_COMPILER "icpc") set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -D AVX") -endif (!AVX) +endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS}") -project (jacobian) -find_package(pybind11 CONFIG REQUIRED) -include_directories(${pybind11_INCLUDE_DIRS}) -#add_library(utils ./src/utils.cpp) -#add_library(bpnn ./src/bpnn.cpp) - -pybind11_add_module(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) +if (PYTHON) + project(jacobian) + find_package(pybind11 CONFIG REQUIRED) + include_directories(${pybind11_INCLUDE_DIRS}) + pybind11_add_module(jacobian example.cpp ./src/bpnn.cpp ./src/utils.cpp) +endif (PYTHON) + +if (CXX) + project(jacobian_cli) + add_executable(jacobian_cli example.cpp ./src/bpnn.cpp ./src/utils.cpp) + enable_testing() + add_test(NAME "Valid run" COMMAND jacobian_cli 16 50) + add_test(NAME "Large batch" COMMAND jacobian_cli 1000 50) + add_test(NAME "Small batch" COMMAND jacobian_cli 1 50) +endif (CXX) diff --git a/Makefile b/Makefile @@ -1,269 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.18 - -# Default target executed when no arguments are given to make. -default_target: all - -.PHONY : default_target - -# Allow only one "make -f Makefile2" at a time, but pass parallelism. -.NOTPARALLEL: - - -#============================================================================= -# Special targets provided by cmake. - -# Disable implicit rules so canonical targets will work. -.SUFFIXES: - - -# Disable VCS-based implicit rules. -% : %,v - - -# 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 - diff --git a/readme.md b/readme.md @@ -54,7 +54,7 @@ for i in range(50):sr ### Rundown What's happening in those seven lines? -First, call the Network constructor (from henceforth all functions will be presented in their C++ form). This is where many of the hyperparameters are defined, and you'll need to pass in the path to your data, the desired batch size, learning rate, bias learning rate (which should usually be smaller), regularization strength, and train-val ratio. +First, call the Network constructor (from henceforth all functions will be presented in their C++ form for clarity). This is where many of the hyperparameters are defined, and you'll need to pass in the path to your data, the desired batch size, learning rate, bias learning rate (which should usually be smaller), regularization strength, and train-val ratio. ```c++ Network(char* path, int batch_sz, float learn_rate, float bias_rate, float l, float ratio); ``` @@ -88,30 +88,26 @@ Note: This is all ideally the process for manual building, but it's so confusing 5. `cd` into `dist` and run `python3 -m pip install --upgrade Jacobian-1.0-cp37-cp37m-macosx_10_13_x86_64.whl` 6. Be unhappy when it doesn't work out and resort to just copying .so files. -### Build Configurations (Building from Source) +### Building with CMake -There are 5 build configurations, each one prioritizing program speed more than the last. **NOTE:** These options change very frequently as I experiment, so this describes the features that have remained generally invariant. +There are two target languages, five main build configurations, and a number of toggleable build 'attributes'. The preferred target language can be specified by setting a CMake variable from the command-line: `-DCXX=ON` or `-DPYTHON=ON`. -#### Level 1: `make` -Simply builds the project with no optimization at all. Use this if you don't want to wait long for the library to compile and don't care too much about speed in the moment. +The five main configurations correspond to differing levels of optimization. + +- `cmake .`: No compiler optimizations. +- `cmake . -DFAST=ON`: Enables the O3 optimization layer in the compiler. +- `cmake . -DFASTER=ON`: Enables O3 as well as extra individual flags. +- `cmake . -DTRADEOFFS=ON`: All previous optimizations as well as ones that sacrifice precision. +- `cmake . -DRECKLESS=ON`: Like `TRADEOFFS`, but defines the RECKLESS macro which skips all checks within the code. -#### Level 2: `make fast` - - Builds the project with the O3 optimization setting. +One you've selected a main optimization level, extra configurations can be passed in. -Use this if you want some speed but shorter build commands and compile times. +- `-DDEBUG=ON` enables debugging features in the compiler (and shows warnings). +- `-DAVX=ON` enables explicit AVX function calls within the code. **Warning: this will not work without the Intel C++ Compiler!** -#### Level 3: `make faster` -Enables extra optimizations, some of which include: - - Building the project with O3. - - Optimizing for native architecture. +A sample build process would look like this: - Use this if you care a lot about speed but are not willing to sacrifice anything but compile time for it. - -#### Level 4: `make tradeoffs` -Some of the new compiler optimizations include: - - Enabling the `-ffast-math` flag. - -In the future this setting may try to parallelize operations (even if the network is already parallelized with MapReduce). - -#### Level 5: `make reckless` -- Defines the `RECKLESS` macro which skips checks anywhere in the program. +``` +cmake . -DCXX=ON -DFASTER=ON -DAVX=ON -DDEBUG=ON +make +``` diff --git a/src/bpnn.hpp b/src/bpnn.hpp @@ -3,7 +3,7 @@ #include <Eigen/Dense> -#include "../../mapreduce/mapreduce.h" +//#include "../../mapreduce/mapreduce.h" #include <vector> #include <array>