Repository: jerinphilip/slimt (language: python)

Issue:
CI init
Try to test on Mac and Linux, see if clean works.

I figure Mac can wait..


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index a068e6f7..e0f88cfd 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -209,7 +209,7 @@ jobs:
               PYTHON_LOCAL_VERSION_IDENTIFIER=${{ env.PYTHON_LOCAL_VERSION_IDENTIFIER }}
               CCACHE_DIR=/host/${{ env.ccache_dir }}
               CCACHE_BASEDIR=/host/${{ env.ccache_basedir }}
-              CMAKE_ARGS="-DUSE_PYBIND11_SOURCE=ON -DBLA_VENDOR=OpenBLAS -DUSE_BUILTIN_SENTENCEPIECE=ON -DWITH_GEMMOLOGY=OFF -DWITH_INTGEMM=ON -DUSE_AVX2=ON -DUSE_SSE2=ON"
+              CMAKE_ARGS="-DUSE_PYBIND11_SOURCE=ON -DBLA_VENDOR=OpenBLAS -DUSE_BUILTIN_SENTENCEPIECE=ON -DWITH_GEMMOLOGY=ON -DUSE_AVX512=ON -DUSE_AVX2=ON -DUSE_SSSE3=ON -DUSE_SSE2=ON"
 
             CIBW_ENVIRONMENT_MACOS:
               USE_CCACHE=1
@@ -231,11 +231,17 @@ jobs:
 
 
             CIBW_BEFORE_BUILD_LINUX: |
-              yum install -y ccache
+              yum install -y ccache wget
+              yum install -y gdb
 
               # Install Intel MKL.
               # yum-config-manager -y --add-repo https://yum.repos.intel.com/mkl/setup/intel-mkl.repo
               # yum install -y intel-mkl
+              XSIMD_VERSION="11.1.0"
+              wget https://github.com/xtensor-stack/xsimd/archive/refs/tags/${XSIMD_VERSION}.tar.gz -O xsimd.tar.gz
+              tar xf xsimd.tar.gz
+              (cd xsimd-${XSIMD_VERSION} && cmake -DCMAKE_INSTALL_PREFIX=/usr/ -B build -S . && cmake --build build --target all && make -C build install)
+
               
               # Install OpenBLAS
               yum install -y openblas-devel atlas-devel
@@ -276,6 +282,7 @@ jobs:
             CIBW_TEST_EXTRAS: test
             CIBW_TEST_COMMAND: |
               python -m pytest --pyargs slimt -s
+              # gdb -return-child-result -batch -ex 'set follow-fork-mode child' -ex 'run' -ex 'bt' -ex 'quit' --args python -m pytest --pyargs slimt -s
 
 
         - uses: actions/upload-artifact@v2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 77a765c8..7bf712b6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,6 +28,11 @@ option(USE_NEON "Use NEON" OFF)
 
 option(SLIMT_PACKAGE "Package for cmake, pkgconfig" OFF)
 
+include(MacroEnsureOutOfSourceBuild)
+macro_ensure_out_of_source_build(
+  "${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
+)
+
 set(SLIMT_COMPILE_OPTIONS
     -Wall
     -Wextra
@@ -133,7 +138,8 @@ endif(WITH_GEMMOLOGY)
 
 if(USE_AVX512)
   list(APPEND SLIMT_COMPILE_DEFINITIONS USE_AVX512)
-  list(APPEND SLIMT_QMM_COMPILE_OPTIONS -march=skylake-avx512)
+  list(APPEND SLIMT_QMM_COMPILE_OPTIONS -mavx512f -mavx512dq -mavx512cd
+       -mavx512bw)
 endif(USE_AVX512)
 
 if(USE_AVX2)
diff --git a/cmake/MacroEnsureOutOfSourceBuild.cmake b/cmake/MacroEnsureOutOfSourceBuild.cmake
new file mode 100644
index 00000000..da93c196
--- /dev/null
+++ b/cmake/MacroEnsureOutOfSourceBuild.cmake
@@ -0,0 +1,19 @@
+# * MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
+#   MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
+
+# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+macro(MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage)
+
+  string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource)
+  if(_insource)
+    message(SEND_ERROR "${_errorMessage}")
+    message(
+      FATAL_ERROR "Remove the file CMakeCache.txt in ${CMAKE_SOURCE_DIR} first."
+    )
+  endif(_insource)
+
+endmacro(MACRO_ENSURE_OUT_OF_SOURCE_BUILD)
diff --git a/scripts/ci/ubuntu/01-setup.sh b/scripts/ci/ubuntu/01-setup.sh
index d1b3b9da..34580d25 100644
--- a/scripts/ci/ubuntu/01-setup.sh
+++ b/scripts/ci/ubuntu/01-setup.sh
@@ -7,7 +7,12 @@ sudo apt-get install -y build-essential cmake
 XSIMD_VERSION="11.1.0"
 wget https://github.com/xtensor-stack/xsimd/archive/refs/tags/${XSIMD_VERSION}.tar.gz -O xsimd.tar.gz
 tar xf xsimd.tar.gz
-(cd xsimd-${XSIMD_VERSION} && cmake -DCMAKE_INSTALL_PREFIX=/usr/ && sudo make install)
+
+(
+  cd xsimd-${XSIMD_VERSION} \
+    && cmake -DCMAKE_INSTALL_PREFIX=/usr/ -B build -S . \
+    && cmake --build build --target all && sudo make -C build install
+)
 
 lscpu
 
diff --git a/slimt/CMakeLists.txt b/slimt/CMakeLists.txt
index f20841c3..052d11ba 100644
--- a/slimt/CMakeLists.txt
+++ b/slimt/CMakeLists.txt
@@ -54,8 +54,11 @@ set(SLIMT_SOURCES
     Vocabulary.cc
     XHScanner.cc)
 
-set_source_files_properties(QMM.cc PROPERTIES COMPILE_OPTIONS
-                                              "${SLIMT_QMM_COMPILE_OPTIONS}")
+if(WITH_GEMMOLOGY)
+  list(APPEND SLIMT_SOURCES qmm/Gemmology.cc)
+  set_source_files_properties(
+    qmm/Gemmology.cc PROPERTIES COMPILE_OPTIONS "${SLIMT_QMM_COMPILE_OPTIONS}")
+endif(WITH_GEMMOLOGY)
 
 set(SLIMT_LIBRARIES slimt-static slimt-shared)
 add_library(slimt-static STATIC ${SLIMT_SOURCES} ${SLIMT_PUBLIC_HEADERS}
diff --git a/slimt/qmm/Gemmology.cc b/slimt/qmm/Gemmology.cc
new file mode 100644
index 00000000..3df96748
--- /dev/null
+++ b/slimt/qmm/Gemmology.cc
@@ -0,0 +1,89 @@
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+#include "gemmology/gemmology.h"
+#pragma GCC diagnostic pop
+
+#if defined(USE_AVX512)
+#define GEMMOLOGY_SUPPORTED_ARCHS \
+  xsimd::arch_list<xsimd::avx512bw, xsimd::avx2, xsimd::ssse3, xsimd::sse2>
+#elif defined(USE_AVX2)
+#define GEMMOLOGY_SUPPORTED_ARCHS \
+  xsimd::arch_list<xsimd::avx2, xsimd::ssse3, xsimd::sse2>
+#elif defined(USE_SSSE3)
+#define GEMMOLOGY_SUPPORTED_ARCHS xsimd::arch_list<xsimd::ssse3, xsimd::sse2>
+#elif defined(USE_SSE2)
+#define GEMMOLOGY_SUPPORTED_ARCHS xsimd::arch_list<xsimd::sse2>
+#elif defined(USE_NEON) and defined(XSIMD_WITH_NEON64)
+#define GEMMOLOGY_SUPPORTED_ARCHS xsimd::arch_list<xsimd::neon64>
+#else
+#error no supported architecture
+#endif
+
+namespace gemmology {
+
+#ifdef USE_AVX512
+template struct Engine<xsimd::avx512bw>;
+template void Engine<xsimd::avx512bw>::SelectColumnsB(const int8_t*, int8_t*,
+                                                      size_t, const uint32_t*,
+                                                      const uint32_t*);
+template void Engine<xsimd::avx512bw>::Shift::Multiply(
+    const uint8_t*, const int8_t*, size_t, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+template void Engine<xsimd::avx512bw>::Shift::PrepareBias(
+    const int8_t*, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+#endif  // USE_AVX512
+
+#ifdef USE_AVX2
+template struct Engine<xsimd::avx2>;
+template void Engine<xsimd::avx2>::SelectColumnsB(const int8_t*, int8_t*,
+                                                  size_t, const uint32_t*,
+                                                  const uint32_t*);
+template void Engine<xsimd::avx2>::Shift::Multiply(
+    const uint8_t*, const int8_t*, size_t, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+template void Engine<xsimd::avx2>::Shift::PrepareBias(
+    const int8_t*, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+#endif  // USE_AVX2
+
+#ifdef USE_SSSE3
+template struct Engine<xsimd::ssse3>;
+template void Engine<xsimd::ssse3>::SelectColumnsB(const int8_t*, int8_t*,
+                                                   size_t, const uint32_t*,
+                                                   const uint32_t*);
+template void Engine<xsimd::ssse3>::Shift::Multiply(
+    const uint8_t*, const int8_t*, size_t, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+template void Engine<xsimd::ssse3>::Shift::PrepareBias(
+    const int8_t*, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+#endif  // USE_SSSE3
+
+#ifdef USE_SSE2
+template struct Engine<xsimd::sse2>;
+template void Engine<xsimd::sse2>::SelectColumnsB(const int8_t*, int8_t*,
+                                                  size_t, const uint32_t*,
+                                                  const uint32_t*);
+
+template void Engine<xsimd::sse2>::Shift::Multiply(
+    const uint8_t*, const int8_t*, size_t, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+template void Engine<xsimd::sse2>::Shift::PrepareBias(
+    const int8_t*, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+#endif  // USE_SSE2
+
+#ifdef USE_NEON
+template struct Engine<xsimd::neon64>;
+template void Engine<xsimd::neon64>::SelectColumnsB(const int8_t*, int8_t*,
+                                                    size_t, const uint32_t*,
+                                                    const uint32_t*);
+template void Engine<xsimd::neon64>::Shift::Multiply(
+    const uint8_t*, const int8_t*, size_t, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+template void Engine<xsimd::neon64>::Shift::PrepareBias(
+    const int8_t*, size_t, size_t,
+    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
+#endif  // USE_NEON
+}  // namespace gemmology
diff --git a/slimt/qmm/Gemmology.inl.cc b/slimt/qmm/Gemmology.inl.cc
index d23f765a..835e1c6e 100644
--- a/slimt/qmm/Gemmology.inl.cc
+++ b/slimt/qmm/Gemmology.inl.cc
@@ -1,7 +1,6 @@
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-parameter"
-#include "gemmology/gemmology.h"
-#pragma GCC diagnostic pop
+#include <gemmology/gemmology_fwd.h>
+
+#include <xsimd/xsimd.hpp>
 
 #if defined(USE_AVX512)
 #define GEMMOLOGY_SUPPORTED_ARCHS \
@@ -19,76 +18,6 @@
 #error no supported architecture
 #endif
 
-namespace gemmology {
-
-#ifdef USE_AVX512
-template struct Engine<xsimd::avx512bw>;
-template void Engine<xsimd::avx512bw>::SelectColumnsB(const int8_t*, int8_t*,
-                                                      size_t, const uint32_t*,
-                                                      const uint32_t*);
-template void Engine<xsimd::avx512bw>::Shift::Multiply(
-    const uint8_t*, const int8_t*, size_t, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-template void Engine<xsimd::avx512bw>::Shift::PrepareBias(
-    const int8_t*, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-#endif  // USE_AVX512
-
-#ifdef USE_AVX2
-template struct Engine<xsimd::avx2>;
-template void Engine<xsimd::avx2>::SelectColumnsB(const int8_t*, int8_t*,
-                                                  size_t, const uint32_t*,
-                                                  const uint32_t*);
-template void Engine<xsimd::avx2>::Shift::Multiply(
-    const uint8_t*, const int8_t*, size_t, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-template void Engine<xsimd::avx2>::Shift::PrepareBias(
-    const int8_t*, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-#endif  // USE_AVX2
-
-#ifdef USE_SSSE3
-template struct Engine<xsimd::ssse3>;
-template void Engine<xsimd::ssse3>::SelectColumnsB(const int8_t*, int8_t*,
-                                                   size_t, const uint32_t*,
-                                                   const uint32_t*);
-template void Engine<xsimd::ssse3>::Shift::Multiply(
-    const uint8_t*, const int8_t*, size_t, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-template void Engine<xsimd::ssse3>::Shift::PrepareBias(
-    const int8_t*, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-#endif  // USE_SSSE3
-
-#ifdef USE_SSE2
-template struct Engine<xsimd::sse2>;
-template void Engine<xsimd::sse2>::SelectColumnsB(const int8_t*, int8_t*,
-                                                  size_t, const uint32_t*,
-                                                  const uint32_t*);
-
-template void Engine<xsimd::sse2>::Shift::Multiply(
-    const uint8_t*, const int8_t*, size_t, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-template void Engine<xsimd::sse2>::Shift::PrepareBias(
-    const int8_t*, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-#endif  // USE_SSE2
-
-#ifdef USE_NEON
-template struct Engine<xsimd::neon64>;
-template void Engine<xsimd::neon64>::SelectColumnsB(const int8_t*, int8_t*,
-                                                    size_t, const uint32_t*,
-                                                    const uint32_t*);
-template void Engine<xsimd::neon64>::Shift::Multiply(
-    const uint8_t*, const int8_t*, size_t, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-template void Engine<xsimd::neon64>::Shift::PrepareBias(
-    const int8_t*, size_t, size_t,
-    gemmology::callbacks::UnquantizeAndAddBiasAndWrite);
-#endif  // USE_NEON
-
-}  // namespace gemmology
-
 // Dispatch *at runtime* based on run-time hardware and compile-time
 // architectures.
 //


Test patch:
diff --git a/scripts/ci/macos/03-test.sh b/scripts/ci/macos/03-test.sh
index fbd4c86f..296610ce 100644
--- a/scripts/ci/macos/03-test.sh
+++ b/scripts/ci/macos/03-test.sh
@@ -14,3 +14,11 @@ SHORTLIST=lex.s2t.bin
 ./build/app/slimt-cli --root "${PREFIX}" \
   --model ${MODEL} --vocabulary ${VOCAB} --shortlist ${SHORTLIST} \
   < data/sample.txt
+
+# For cursed debugging on CI
+# lldb --batch \
+#   -o "settings set target.input-path ${PWD}/data/sample.txt" \
+#   -o "settings set -- target.run-args --root \"${PREFIX}\" --model \"${MODEL}\" --vocabulary \"${VOCAB}\" --shortlist \"${SHORTLIST}\"" \
+#   -o "process launch" \
+#   -o "bt" -o "exit" \
+#   -- ./build/app/slimt-cli